blob: 3c6c7c3e75043b920fe2ff6abd016524796c55cc [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:
mvanouwerkerk0ac0a372016-10-18 09:00:3117
David 'Digit' Turner40560ef72018-03-07 09:44:2818```
19 target_os = "android"
20 emma_coverage = true
21 emma_filter = "org.chromium.chrome.browser.ntp.*,-*Test*,-*Fake*,-*Mock*"
22```
23
24The filter syntax is as documented for the [EMMA coverage
25filters](http://emma.sourceforge.net/reference/ch02s06s02.html).
26
27Now when building, **.em** files will be created in the build directory.
28
hzl1ccac192016-06-02 18:22:12292. Run tests, with option `--coverage-dir <directory>`, to specify where to save
30 the .ec file. For example, you can run chrome junit tests:
mvanouwerkerk0ac0a372016-10-18 09:00:3131 `out/Debug/bin/run_chrome_junit_tests --coverage-dir /tmp/coverage`.
David 'Digit' Turner40560ef72018-03-07 09:44:2832
mvanouwerkerk0ac0a372016-10-18 09:00:31333. Turn off strict mode when running instrumentation tests by adding
34 `--strict-mode=off` because the EMMA code causes strict mode violations by
35 accessing disk.
David 'Digit' Turner40560ef72018-03-07 09:44:2836
mvanouwerkerk0ac0a372016-10-18 09:00:31374. Use a pre-L Android OS (running Dalvik) because code coverage is not
38 supported in ART.
David 'Digit' Turner40560ef72018-03-07 09:44:2839
mvanouwerkerk0ac0a372016-10-18 09:00:31405. The coverage results of junit and instrumentation tests will be merged
41 automatically if they are in the same directory.
David 'Digit' Turner40560ef72018-03-07 09:44:2842
mvanouwerkerk0ac0a372016-10-18 09:00:31436. Now we have both .em and .ec files. We can create a html report using
44 `generate_emma_html.py`, for example:
David 'Digit' Turner40560ef72018-03-07 09:44:2845
46```
47 build/android/generate_emma_html.py \
48 --coverage-dir /tmp/coverage/ \
49 --metadata-dir out/Debug/ \
50 --output example.html
51```
hzl1ccac192016-06-02 18:22:1252 Then an example.html containing coverage info will be created:
David 'Digit' Turner40560ef72018-03-07 09:44:2853
54```
55 EMMA: writing [html] report to [<your_current_directory>/example.html] ...
56```