0
Files
android_webview
apps
ash
base
build
3pp_common
android
bytecode
docs
README.md
build_config.md
class_verification_failures.md
coverage.md
java_asserts.md
java_optimization.md
java_toolchain.md
life_of_a_resource.md
lint.md
resources_in_java.md
static_analysis.md
gradle
gtest_apk
gyp
incremental_install
java
junit
native_flags
pylib
stacktrace
test
test_wrapper
tests
unused_resources
update_deps
AndroidManifest.xml
BUILD.gn
COMMON_METADATA
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_webengine_command_line
adb_system_webview_command_line
android_only_explicit_jni_exports.lst
android_only_jni_exports.lst
apk_operations.py
apk_operations.pydeps
asan_symbolize.py
chromium-debug.keystore
chromium_annotations.flags
connect_lldb.sh
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
dump_apk_resource_strings.py
envsetup.sh
fast_local_dev_server.py
fast_local_dev_server_test.py
generate_jacoco_report.py
generate_vscode_project.py
generate_wrap_sh.py
host_heartbeat.py
list_class_verification_failures.py
list_class_verification_failures_test.py
list_java_targets.py
method_count.py
provision_devices.py
pylintrc
resource_sizes.gni
resource_sizes.py
resource_sizes.pydeps
screenshot.py
test_runner.py
test_runner.pydeps
test_runner_test.py
tombstones.py
update_verification.py
video_recorder.py
apple
args
autoroll
chromeos
cipd
config
docs
fuchsia
gn_ast
internal
ios
linux
mac
private_code_test
rust
sanitizers
skia_gold_common
toolchain
util
win
.clang-tidy
.clangd
.git-blame-ignore-revs
.gitignore
.style.yapf
BUILD.gn
DEPS
DIR_METADATA
OWNERS
OWNERS.setnoparent
OWNERS.status
PRESUBMIT.py
PRESUBMIT_test.py
README.md
action_helpers.py
action_helpers_unittest.py
add_rts_filters.py
build-ctags.sh
build_config.h
buildflag.h
buildflag_header.gni
check_gn_headers.py
check_gn_headers_allowlist.txt
check_gn_headers_unittest.py
check_return_value.py
ciopfs.sha1
clobber.py
clobber_unittest.py
compiled_action.gni
compute_build_timestamp.py
copy_test_data_ios.py
cp.py
detect_host_arch.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_editor
gn_helpers.py
gn_helpers_unittest.py
gn_logs.gni
gn_run_binary.py
install-build-deps.py
install-build-deps.sh
install-chroot.sh
landmine_utils.py
landmines.py
locale_tool.py
mac_toolchain.py
metadata.json.in
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_buildflag_header.py
xcode_binaries.yaml
zip_helpers.py
zip_helpers_unittest.py
build_overrides
buildtools
cc
chrome
chromecast
chromeos
clank
codelabs
components
content
crypto
dbus
device
docs
extensions
fuchsia_web
gin
google_apis
gpu
headless
infra
internal
ios
ios_internal
ipc
media
mojo
native_client
native_client_sdk
net
pdf
ppapi
printing
remoting
rlz
sandbox
services
signing_keys
skia
sql
storage
styleguide
testing
third_party
tools
ui
url
v8
webkit
.clang-format
.clang-tidy
.clangd
.git-blame-ignore-revs
.gitallowed
.gitattributes
.gitignore
.gitmodules
.gn
.mailmap
.rustfmt.toml
.vpython3
.yapfignore
ATL_OWNERS
AUTHORS
BUILD.gn
CODE_OF_CONDUCT.md
CPPLINT.cfg
CRYPTO_OWNERS
DEPS
DIR_METADATA
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
Prakhar f41864b0ca Add references to jacoco/clang coverage docs in each other
Bug: 1340699
Change-Id: Ia74ceced02342bac564a9233fb0b8c065eb65b40
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3760793
Auto-Submit: Prakhar Asthana <pasthana@google.com>
Reviewed-by: Zhaoyang Li <zhaoyangli@chromium.org>
Reviewed-by: Benjamin Joyce <bjoyce@chromium.org>
Commit-Queue: Benjamin Joyce <bjoyce@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1025347}
2022-07-18 19:03:51 +00:00

3.1 KiB

Android code coverage instructions

These are instructions for collecting code coverage data for android instrumentation and JUnit tests. For Clang(C++) code coverage refer to clang coverage.

[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:
target_os = "android"
use_jacoco_coverage = true

Now when building, pre-instrumented files will be created in the build directory.

  1. 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.

  2. 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:
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.
  1. 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.
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

build/android/generate_jacoco_report.py \
  --format csv \
  --output-file /tmp/coverage_report/report.csv \
  --coverage-dir /tmp/coverage/ \
  --sources-json-dir out/Debug/ \
  1. If generating coverage and there are duplicate class files, as can happen when generating coverage for downstream targets, use the --include-substr-filter option to choose jars in the desired directory. Eg. for generating coverage report for Clank internal repo
build/android/generate_jacoco_report.py --format html \
 --output-dir /tmp/coverage_report/ --coverage-dir /tmp/coverage/ \
 --sources-json-dir out/java_coverage/ \
 --include-substr-filter obj/clank