2020-08-06 00:47:01 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# This script generates coverage for bionic.
|
|
|
|
#
|
|
|
|
# Prereqs: Coverage-enabled build.
|
2020-08-08 00:25:27 +02:00
|
|
|
#
|
2020-08-06 00:47:01 +02:00
|
|
|
# $ lunch <target>
|
|
|
|
# $ m NATIVE_COVERAGE_PATHS="bionic" CLANG_COVERAGE=true
|
|
|
|
# $ m NATIVE_COVERAGE_PATHS="bionic" CLANG_COVERAGE=true bionic-unit-tests
|
2020-08-08 00:25:27 +02:00
|
|
|
#
|
|
|
|
# Do *NOT* then rebuild at the top level, or you'll clobber the
|
|
|
|
# coverage-enabled libc!
|
|
|
|
#
|
|
|
|
# Flash image and set $ANDROID_SERIAL.
|
2020-08-06 00:47:01 +02:00
|
|
|
#
|
|
|
|
# Usage: $ bionic/build/coverage.sh
|
|
|
|
# Output: HTML report is generated to /tmp/bionic-coverage/html/index.html
|
|
|
|
#
|
|
|
|
|
2020-08-08 00:25:27 +02:00
|
|
|
eval "$(cd ${ANDROID_BUILD_TOP}; build/soong/soong_ui.bash --dumpvars-mode --vars="TARGET_ARCH TARGET_ARCH_VARIANT")"
|
2020-08-06 00:47:01 +02:00
|
|
|
|
|
|
|
LLVM_PROFDATA=${ANDROID_BUILD_TOP}/prebuilts/clang/host/linux-x86/llvm-binutils-stable/llvm-profdata
|
|
|
|
LLVM_COV=${ANDROID_BUILD_TOP}/prebuilts/clang/host/linux-x86/llvm-binutils-stable/llvm-cov
|
|
|
|
|
2020-08-08 00:25:27 +02:00
|
|
|
DEVICE_TEST_DIR32=/data/local/tmp/bionic-coverage32
|
|
|
|
DEVICE_TEST_DIR64=/data/local/tmp/bionic-coverage64
|
|
|
|
DEVICE_PROF_DIR=/data/local/tmp/bionic-profraw
|
2020-08-06 00:47:01 +02:00
|
|
|
HOST_PROFDATA_DIR=/tmp/bionic-coverage
|
|
|
|
|
|
|
|
# Run bionic-unit-tests
|
2020-08-08 00:25:27 +02:00
|
|
|
adb shell rm -rf ${DEVICE_TEST_DIR32} ${DEVICE_TEST_DIR64} ${DEVICE_PROF_DIR}
|
|
|
|
adb shell mkdir ${DEVICE_TEST_DIR32} ${DEVICE_TEST_DIR64} ${DEVICE_PROF_DIR}
|
|
|
|
adb push $OUT/data/nativetest/bionic-loader-test-libs ${DEVICE_TEST_DIR32}
|
|
|
|
adb push $OUT/data/nativetest/bionic-unit-tests ${DEVICE_TEST_DIR32}
|
|
|
|
adb push $OUT/data/nativetest64/bionic-loader-test-libs ${DEVICE_TEST_DIR64}
|
|
|
|
adb push $OUT/data/nativetest64/bionic-unit-tests ${DEVICE_TEST_DIR64}
|
|
|
|
adb shell LLVM_PROFILE_FILE=${DEVICE_PROF_DIR}/bionic-%p-%m.profraw \
|
|
|
|
LD_LIBRARY_PATH=${DEVICE_TEST_DIR32}/bionic-loader-test-libs \
|
|
|
|
${DEVICE_TEST_DIR32}/bionic-unit-tests/bionic-unit-tests
|
|
|
|
adb shell LLVM_PROFILE_FILE=${DEVICE_PROF_DIR}/bionic-%p-%m.profraw \
|
|
|
|
LD_LIBRARY_PATH=${DEVICE_TEST_DIR64}/bionic-loader-test-libs \
|
|
|
|
${DEVICE_TEST_DIR64}/bionic-unit-tests/bionic-unit-tests
|
2020-08-06 00:47:01 +02:00
|
|
|
|
|
|
|
# Pull coverage files and post-process
|
|
|
|
rm -rf ${HOST_PROFDATA_DIR}
|
|
|
|
mkdir ${HOST_PROFDATA_DIR}
|
2020-08-08 00:25:27 +02:00
|
|
|
adb pull ${DEVICE_PROF_DIR} ${HOST_PROFDATA_DIR}/profraws
|
2020-08-06 00:47:01 +02:00
|
|
|
|
|
|
|
${LLVM_PROFDATA} merge \
|
|
|
|
--output=${HOST_PROFDATA_DIR}/bionic.profdata \
|
|
|
|
${HOST_PROFDATA_DIR}/profraws/*.profraw
|
|
|
|
|
|
|
|
${LLVM_COV} show \
|
|
|
|
--instr-profile=${HOST_PROFDATA_DIR}/bionic.profdata \
|
|
|
|
--format=html \
|
2020-08-08 00:25:27 +02:00
|
|
|
$OUT/symbols/apex/com.android.runtime/lib64/bionic/libc.so \
|
2020-08-12 19:25:45 +02:00
|
|
|
--object=$OUT/symbols/apex/com.android.runtime/lib64/bionic/libm.so \
|
2020-08-08 00:25:27 +02:00
|
|
|
--object=$OUT/symbols/data/nativetest64/bionic-unit-tests/bionic-unit-tests \
|
|
|
|
--object=$OUT/symbols/apex/com.android.runtime/lib/bionic/libc.so \
|
2020-08-12 19:25:45 +02:00
|
|
|
--object=$OUT/symbols/apex/com.android.runtime/lib/bionic/libm.so \
|
2020-08-08 00:25:27 +02:00
|
|
|
--object=$OUT/symbols/data/nativetest/bionic-unit-tests/bionic-unit-tests \
|
2020-08-06 00:47:01 +02:00
|
|
|
/proc/self/cwd/bionic/libc \
|
2020-08-12 19:25:45 +02:00
|
|
|
/proc/self/cwd/bionic/libm \
|
2020-08-06 00:47:01 +02:00
|
|
|
--output-dir=${HOST_PROFDATA_DIR}/html \
|
|
|
|
--show-region-summary=false
|