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: |
hzl | 1ccac19 | 2016-06-02 18:22:12 | [diff] [blame] | 17 | ``` |
mvanouwerkerk | 0ac0a37 | 2016-10-18 09:00:31 | [diff] [blame^] | 18 | target_os = "android" |
| 19 | emma_coverage = true |
| 20 | emma_filter = "org.chromium.chrome.browser.ntp.*,-*Test*,-*Fake*,-*Mock*" |
hzl | 1ccac19 | 2016-06-02 18:22:12 | [diff] [blame] | 21 | ``` |
mvanouwerkerk | 0ac0a37 | 2016-10-18 09:00:31 | [diff] [blame^] | 22 | 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. |
hzl | 1ccac19 | 2016-06-02 18:22:12 | [diff] [blame] | 26 | 2. Run tests, with option `--coverage-dir <directory>`, to specify where to save |
| 27 | the .ec file. For example, you can run chrome junit tests: |
mvanouwerkerk | 0ac0a37 | 2016-10-18 09:00:31 | [diff] [blame^] | 28 | `out/Debug/bin/run_chrome_junit_tests --coverage-dir /tmp/coverage`. |
| 29 | 3. 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. |
| 32 | 4. Use a pre-L Android OS (running Dalvik) because code coverage is not |
| 33 | supported in ART. |
| 34 | 5. The coverage results of junit and instrumentation tests will be merged |
| 35 | automatically if they are in the same directory. |
| 36 | 6. Now we have both .em and .ec files. We can create a html report using |
| 37 | `generate_emma_html.py`, for example: |
hzl | 1ccac19 | 2016-06-02 18:22:12 | [diff] [blame] | 38 | `build/android/generate_emma_html.py --coverage-dir /tmp/coverage/ |
mvanouwerkerk | 0ac0a37 | 2016-10-18 09:00:31 | [diff] [blame^] | 39 | --metadata-dir out/Debug/ --output example.html`. |
hzl | 1ccac19 | 2016-06-02 18:22:12 | [diff] [blame] | 40 | Then an example.html containing coverage info will be created: |
| 41 | `EMMA: writing [html] report to |
| 42 | [<your_current_directory>/example.html] …` |