blob: 3162b5886ceae0f4eb5d5970cb8212204f7f3fc4 [file] [log] [blame] [view]
Ryan Harrisonc16df7f2017-07-18 13:44:31 -04001# Code Coverage Support for PDFium
2
3[TOC]
4
5This guide explains how to generate code coverage information for the PDFium
6library on a local computer.
7
8## Prerequisites
9
10You will need the PDFium source code on your computer. You can see
11the [README](/README.md) for instructions on checking out PDFium's source.
12
13The tools used for code coverage are known to work on Ubuntu 14.04. They should
14work correctly on newer versions of Ubuntu and related Linux distros. They have
15not been tested on Windows and Mac.
16
17### lcov
18
19The code coverage scripts depend on having a version of `lcov` of 1.11 or
20greater available, which is enforced by the script. Unfortunately the default
21version of `lcov` for Ubuntu 14.04 is 1.10, thus you will need to install a
22newer version.
23
24You can build a newer version of `lcov` from source, which is
25available [here](http://ltp.sourceforge.net/coverage/lcov.php).
26
27If you don't want to build from source and use an RPM based Linux, not
28Ubuntu/Debian, then there are pre-built RPMs
29available [here](http://downloads.sourceforge.net/ltp/lcov-1.13-1.noarch.rpm).
30
31For Ubuntu/Debian users these RPMs can be converted to .deb using `alien`. More
32information about how to do this can be found in `man alien`.
33
34### llvm-cov
35
36The other external dependency for generating code coverage information is having
37a version of `llvm-cov` that supports the `gcov` command. This should be all
38versions of 3.5.0 or greater.
39
40Again, unfortunately, the default llvm-cov that comes with Ubuntu 14.04, 3.4, is
41lower then what is needed. The 14.04 repositories do support having multiple
42versions of the `llvm` package, and thus `llvm-cov`. Through your favourite
43package manager you should be able to install any version of `llvm` of 3.5 or
44greater and the coverage scripts should find it.
45
46## Generating Code Coverage
47
48### Setup
49
50This step assumes that you have already checked out the PDFium source code and
51installed the proper versions of the external tools. If you have not, please
52consult the above Prerequisites section.
53
54Before generating code coverage information, you will need to have a build
55directory with coverage enabled. This can be done by running the `gn args`
56command and adding `use_coverage = true` in the editor that is opened. If not
57using the default directory, `out/Coverage`, then replace it with the correct
58location in the following command.
59
60```shell
61gn args out/Coverage
62```
63
64If you already have a build directory, you can append the coverage flag to the
65existing `args.gn` as follows. If not using the default directory,
66`out/Coverage`, then replace it with the correct location in the following
67command.
68
69```shell
70echo "use_coverage = true" >> out/Coverage/args.gn
71```
72
73
74### Usage
75
76Generating code coverage information is done via the
77`tools/coverage/coverage_report.py` script. This script will build any binaries
78that it needs, perform test runs, collect coverage data, and finally generate a
79nice HTML coverage report.
80
81Running the script with no arguments, as below, will assume that you are
82currently at the root of your PDFium checkout, the build directory to use is
83`./out/Coverage/` and that HTML should be outputted to `./coverage_report/`. By
84default, it will also only run `pdfium_unittests` and `pdfium_embeddertests` for
85coverage data. This is because the other tests are known to take a long time to
86run, so they are not included in the defaults.
87
88```shell
89tools/coverage/coverage_report.py
90```
91
92If the current working directory is not the root of your PDFium checkout, then
93you will need to pass in `--source-directory` with the appropriate directory. If
94you are using a different build directory, then `--build-directory` will need to
95be passed in. Finally, if you want the HTML report in a different location then
96you will need to pass in `--output-directory`.
97
98An example of all these flags being used:
99
100```shell
101coverage_report.py --source-directory ~/pdfium/pdfium \
102 --build-directory ~/pdfium/pdfium/out/Debug_with_Coverage \
103 --output-directory ~/Documents/PDFium_coverage
104```
105
106To run different tests then the default set, there are two ways to achieve
107this. If you want to run everything, including tests that are known to take a
108long time, then you just need to add the `--slow` flag.
109
110```shell
111tools/coverage/coverage_report.py --slow
112```
113
114If you want more fine grained control, including running just a single test, you
115can specify the test names on the command line. The `--slow` flag is not needed
116if you are explicitly invoking tests. The list of supported tests can be found
117by running the script with `--help`.
118
119An example running the default tests explicitly:
120
121```shell
122tools/coverage/coverage_report.py pdfium_unittests pdfium_embeddertests
123```
124
125NOTE:
126At the present time, there is no mechanism for combining data from different
127invocations of `coverage_report.py`. Instead you must specify all of the tests
128to be included in the report in a single invocation.
129
130There are additional developer debugging flags available, `--dry-run` and
131`--verbose`. `--dry-run` will output a trace of commands that would have been
132run, but doesn't actually execute them. `--verbose` turns on outputting
133additional logging information.
134
135### Viewing
136
137Once the script has run, the output directory should contain a set of HTML files
138containing the coverage report.
139
140These files are static HTML, so you can point your browser at them directly on
141your local file system and they should render fine. You can also serve them via a
142web server if you want, but how to achieve that is beyond the scope of this
143documentation.
144
145## Issues
146
147For help with using the code coverage tools please contact the PDFium
148maintainers via the PDFium
149mailing [list](https://groups.google.com/forum/#!forum/pdfium).
150
151Please file bugs against the code coverage
152support [here](https://bugs.chromium.org/p/pdfium/issues/list).