0
Files
android_webview
apps
ash
base
build
android
bytecode
docs
README.md
android_app_bundles.md
build_config.md
class_verification_failures.md
coverage.md
java_optimization.md
java_toolchain.md
life_of_a_resource.md
lint.md
gradle
gtest_apk
gyp
incremental_install
java
native_flags
pylib
stacktrace
test
test_wrapper
tests
update_deps
AndroidManifest.xml
BUILD.gn
CheckInstallApk-debug.apk
DIR_METADATA
OWNERS
PRESUBMIT.py
adb_chrome_public_command_line
adb_command_line.py
adb_gdb
adb_install_apk.py
adb_logcat_monitor.py
adb_logcat_printer.py
adb_profile_chrome
adb_profile_chrome_startup
adb_reverse_forwarder.py
adb_system_webview_command_line
android_only_explicit_jni_exports.lst
android_only_jni_exports.lst
apk_operations.py
apk_operations.pydeps
apply_shared_preference_file.py
asan_symbolize.py
chromium-debug.keystore
convert_dex_profile.py
convert_dex_profile_tests.py
dcheck_is_off.flags
devil_chromium.json
devil_chromium.py
devil_chromium.pydeps
diff_resource_sizes.py
download_doclava.py
dump_apk_resource_strings.py
emma_coverage_stats.py
emma_coverage_stats_test.py
envsetup.sh
fast_local_dev_server.py
generate_jacoco_report.py
host_heartbeat.py
lighttpd_server.py
list_class_verification_failures.py
list_class_verification_failures_test.py
list_java_targets.py
main_dex_classes.flags
method_count.py
multidex.flags
provision_devices.py
pylintrc
resource_sizes.gni
resource_sizes.py
resource_sizes.pydeps
screenshot.py
test_runner.py
test_runner.pydeps
tombstones.py
update_verification.py
video_recorder.py
apple
args
chromeos
cipd
config
docs
fuchsia
internal
ios
lacros
linux
mac
sanitizers
skia_gold_common
toolchain
util
win
.gitignore
.style.yapf
BUILD.gn
DIR_METADATA
OWNERS
OWNERS.setnoparent
OWNERS.status
README.md
add_rts_filters.py
build-ctags.sh
build_config.h
buildflag.h
buildflag_header.gni
check_gn_headers.py
check_gn_headers_unittest.py
check_gn_headers_whitelist.txt
check_return_value.py
ciopfs.sha1
clobber.py
compiled_action.gni
compute_build_timestamp.py
copy_test_data_ios.py
cp.py
detect_host_arch.py
dir_exists.py
dotfile_settings.gni
download_nacl_toolchains.py
env_dump.py
extract_from_cab.py
extract_partition.py
find_depot_tools.py
fix_gn_headers.py
gdb-add-index
get_landmines.py
get_symlink_targets.py
gn_helpers.py
gn_helpers_unittest.py
gn_logs.gni
gn_run_binary.py
install-build-deps-android.sh
install-build-deps.sh
install-chroot.sh
landmine_utils.py
landmines.py
locale_tool.py
mac_toolchain.py
nocompile.gni
noop.py
partitioned_shared_library.gni
precompile.cc
precompile.h
print_python_deps.py
protoc_java.py
protoc_java.pydeps
redirect_stdout.py
rm.py
sample_arg_file.gn
sanitize-mac-build-log.sed
sanitize-mac-build-log.sh
sanitize-win-build-log.sed
sanitize-win-build-log.sh
shim_headers.gni
symlink.gni
symlink.py
timestamp.gni
tree_truth.sh
update-linux-sandbox.sh
vs_toolchain.py
whitespace_file.txt
write_build_date_header.py
write_buildflag_header.py
xcode_binaries.yaml
build_overrides
buildtools
cc
chrome
chromecast
chromeos
cloud_print
codelabs
components
content
courgette
crypto
dbus
device
docs
extensions
fuchsia
gin
google_apis
google_update
gpu
headless
infra
ios
ipc
jingle
media
mojo
native_client_sdk
net
pdf
ppapi
printing
remoting
rlz
sandbox
services
skia
sql
storage
styleguide
testing
third_party
tools
ui
url
weblayer
.clang-format
.clang-tidy
.eslintrc.js
.git-blame-ignore-revs
.gitattributes
.gitignore
.gn
.vpython
.vpython3
.yapfignore
AUTHORS
BUILD.gn
CODE_OF_CONDUCT.md
DEPS
DIR_METADATA
ENG_REVIEW_OWNERS
LICENSE
LICENSE.chromium_os
OWNERS
PRESUBMIT.py
PRESUBMIT_test.py
PRESUBMIT_test_mocks.py
README.md
WATCHLISTS
codereview.settings
src/build/android/docs/coverage.md
Finnur Thorarinsson ab966867f2 Fix documentation for Android code coverage generation.
The instructions seem to assume running the script from /src and
the intent is to create two directories

/tmp/coverage
/tmp/coverage_report

but the lack of a slash prefix results in the creation of...

/tmp/coverage
/src/tmp/coverage_report

Bug: None
Change-Id: Ib10050a577fc8e9494a903386d5886ccbef8aa1e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2124256
Commit-Queue: John Budorick <jbudorick@chromium.org>
Reviewed-by: Yun Liu <yliuyliu@google.com>
Reviewed-by: John Budorick <jbudorick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754026}
2020-03-27 15:31:38 +00:00

74 lines
2.3 KiB
Markdown

# Android code coverage instructions
These are instructions for collecting code coverage data for android
instrumentation and JUnit tests.
[TOC]
## How JaCoCo coverage works
In order to use JaCoCo code coverage, we need to create build time pre-instrumented
class files and runtime **.exec** files. Then we need to process them using the
**build/android/generate_jacoco_report.py** script.
## How to collect coverage data
1. Use the following GN build arguments:
```gn
target_os = "android"
use_jacoco_coverage = true
```
Now when building, pre-instrumented files will be created in the build directory.
2. Run tests, with option `--coverage-dir <directory>`, to specify where to save
the .exec file. For example, you can run chrome JUnit tests:
`out/Debug/bin/run_chrome_junit_tests --coverage-dir /tmp/coverage`.
3. The coverage results of JUnit and instrumentation tests will be merged
automatically if they are in the same directory.
## How to generate coverage report
1. Now we have generated .exec files already. We can create a JaCoCo HTML/XML/CSV
report using `generate_jacoco_report.py`, for example:
```shell
build/android/generate_jacoco_report.py \
--format html \
--output-dir /tmp/coverage_report/ \
--coverage-dir /tmp/coverage/ \
--sources-json-dir out/Debug/ \
```
Then an index.html containing coverage info will be created in output directory:
```
[INFO] Loading execution data file /tmp/coverage/testTitle.exec.
[INFO] Loading execution data file /tmp/coverage/testSelected.exec.
[INFO] Loading execution data file /tmp/coverage/testClickToSelect.exec.
[INFO] Loading execution data file /tmp/coverage/testClickToClose.exec.
[INFO] Loading execution data file /tmp/coverage/testThumbnail.exec.
[INFO] Analyzing 58 classes.
```
2. For XML and CSV reports, we need to specify `--output-file` instead of `--output-dir` since
only one file will be generated as XML or CSV report.
```shell
build/android/generate_jacoco_report.py \
--format xml \
--output-file /tmp/coverage_report/report.xml \
--coverage-dir /tmp/coverage/ \
--sources-json-dir out/Debug/ \
```
or
```shell
build/android/generate_jacoco_report.py \
--format csv \
--output-file /tmp/coverage_report/report.csv \
--coverage-dir /tmp/coverage/ \
--sources-json-dir out/Debug/ \
```