blob: 3cc4c99fea65f9567a53b934b5800061f07e410a [file] [log] [blame] [view]
hzl1ccac192016-06-02 18:22:121# Android code coverage instructions
2
mvanouwerkerk0ac0a372016-10-18 09:00:313These are instructions for collecting code coverage data for android
4instrumentation and junit tests.
hzl1ccac192016-06-02 18:22:125
6[TOC]
7
8## How EMMA coverage works
9
mvanouwerkerk0ac0a372016-10-18 09:00:3110In order to use EMMA code coverage, we need to create build time **.em** files
11and runtime **.ec** files. Then we need to process them using the
hzl1ccac192016-06-02 18:22:1212build/android/generate_emma_html.py script.
13
14## How to collect EMMA coverage data
15
mvanouwerkerk0ac0a372016-10-18 09:00:31161. Use the following GN build arguments:
hzl1ccac192016-06-02 18:22:1217 ```
mvanouwerkerk0ac0a372016-10-18 09:00:3118 target_os = "android"
19 emma_coverage = true
20 emma_filter = "org.chromium.chrome.browser.ntp.*,-*Test*,-*Fake*,-*Mock*"
hzl1ccac192016-06-02 18:22:1221 ```
mvanouwerkerk0ac0a372016-10-18 09:00:3122 The filter syntax is as documented for the [EMMA coverage
23 filters](http://emma.sourceforge.net/reference/ch02s06s02.html).
24
25 Now when building, **.em** files will be created in the build directory.
hzl1ccac192016-06-02 18:22:12262. Run tests, with option `--coverage-dir <directory>`, to specify where to save
27 the .ec file. For example, you can run chrome junit tests:
mvanouwerkerk0ac0a372016-10-18 09:00:3128 `out/Debug/bin/run_chrome_junit_tests --coverage-dir /tmp/coverage`.
293. Turn off strict mode when running instrumentation tests by adding
30 `--strict-mode=off` because the EMMA code causes strict mode violations by
31 accessing disk.
324. Use a pre-L Android OS (running Dalvik) because code coverage is not
33 supported in ART.
345. The coverage results of junit and instrumentation tests will be merged
35 automatically if they are in the same directory.
366. Now we have both .em and .ec files. We can create a html report using
37 `generate_emma_html.py`, for example:
hzl1ccac192016-06-02 18:22:1238 `build/android/generate_emma_html.py --coverage-dir /tmp/coverage/
mvanouwerkerk0ac0a372016-10-18 09:00:3139 --metadata-dir out/Debug/ --output example.html`.
hzl1ccac192016-06-02 18:22:1240 Then an example.html containing coverage info will be created:
41 `EMMA: writing [html] report to
42 [<your_current_directory>/example.html] …`