hzl | 1ccac19 | 2016-06-02 18:22:12 | [diff] [blame] | 1 | # Android code coverage instructions |
| 2 | |
mvanouwerkerk | 0ac0a37 | 2016-10-18 09:00:31 | [diff] [blame] | 3 | These are instructions for collecting code coverage data for android |
| 4 | instrumentation and junit tests. |
hzl | 1ccac19 | 2016-06-02 18:22:12 | [diff] [blame] | 5 | |
| 6 | [TOC] |
| 7 | |
| 8 | ## How EMMA coverage works |
| 9 | |
mvanouwerkerk | 0ac0a37 | 2016-10-18 09:00:31 | [diff] [blame] | 10 | In order to use EMMA code coverage, we need to create build time **.em** files |
| 11 | and runtime **.ec** files. Then we need to process them using the |
hzl | 1ccac19 | 2016-06-02 18:22:12 | [diff] [blame] | 12 | build/android/generate_emma_html.py script. |
| 13 | |
| 14 | ## How to collect EMMA coverage data |
| 15 | |
mvanouwerkerk | 0ac0a37 | 2016-10-18 09:00:31 | [diff] [blame] | 16 | 1. Use the following GN build arguments: |
mvanouwerkerk | 0ac0a37 | 2016-10-18 09:00:31 | [diff] [blame] | 17 | |
David 'Digit' Turner | 40560ef7 | 2018-03-07 09:44:28 | [diff] [blame^] | 18 | ``` |
| 19 | target_os = "android" |
| 20 | emma_coverage = true |
| 21 | emma_filter = "org.chromium.chrome.browser.ntp.*,-*Test*,-*Fake*,-*Mock*" |
| 22 | ``` |
| 23 | |
| 24 | The filter syntax is as documented for the [EMMA coverage |
| 25 | filters](http://emma.sourceforge.net/reference/ch02s06s02.html). |
| 26 | |
| 27 | Now when building, **.em** files will be created in the build directory. |
| 28 | |
hzl | 1ccac19 | 2016-06-02 18:22:12 | [diff] [blame] | 29 | 2. Run tests, with option `--coverage-dir <directory>`, to specify where to save |
| 30 | the .ec file. For example, you can run chrome junit tests: |
mvanouwerkerk | 0ac0a37 | 2016-10-18 09:00:31 | [diff] [blame] | 31 | `out/Debug/bin/run_chrome_junit_tests --coverage-dir /tmp/coverage`. |
David 'Digit' Turner | 40560ef7 | 2018-03-07 09:44:28 | [diff] [blame^] | 32 | |
mvanouwerkerk | 0ac0a37 | 2016-10-18 09:00:31 | [diff] [blame] | 33 | 3. 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' Turner | 40560ef7 | 2018-03-07 09:44:28 | [diff] [blame^] | 36 | |
mvanouwerkerk | 0ac0a37 | 2016-10-18 09:00:31 | [diff] [blame] | 37 | 4. Use a pre-L Android OS (running Dalvik) because code coverage is not |
| 38 | supported in ART. |
David 'Digit' Turner | 40560ef7 | 2018-03-07 09:44:28 | [diff] [blame^] | 39 | |
mvanouwerkerk | 0ac0a37 | 2016-10-18 09:00:31 | [diff] [blame] | 40 | 5. The coverage results of junit and instrumentation tests will be merged |
| 41 | automatically if they are in the same directory. |
David 'Digit' Turner | 40560ef7 | 2018-03-07 09:44:28 | [diff] [blame^] | 42 | |
mvanouwerkerk | 0ac0a37 | 2016-10-18 09:00:31 | [diff] [blame] | 43 | 6. Now we have both .em and .ec files. We can create a html report using |
| 44 | `generate_emma_html.py`, for example: |
David 'Digit' Turner | 40560ef7 | 2018-03-07 09:44:28 | [diff] [blame^] | 45 | |
| 46 | ``` |
| 47 | build/android/generate_emma_html.py \ |
| 48 | --coverage-dir /tmp/coverage/ \ |
| 49 | --metadata-dir out/Debug/ \ |
| 50 | --output example.html |
| 51 | ``` |
hzl | 1ccac19 | 2016-06-02 18:22:12 | [diff] [blame] | 52 | Then an example.html containing coverage info will be created: |
David 'Digit' Turner | 40560ef7 | 2018-03-07 09:44:28 | [diff] [blame^] | 53 | |
| 54 | ``` |
| 55 | EMMA: writing [html] report to [<your_current_directory>/example.html] ... |
| 56 | ``` |