Pirama Arumuga Nainar | abf4032 | 2020-08-05 15:47:01 -0700 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # This script generates coverage for bionic. |
| 4 | # |
| 5 | # Prereqs: Coverage-enabled build. |
| 6 | # $ lunch <target> |
| 7 | # $ m NATIVE_COVERAGE_PATHS="bionic" CLANG_COVERAGE=true |
| 8 | # $ m NATIVE_COVERAGE_PATHS="bionic" CLANG_COVERAGE=true bionic-unit-tests |
| 9 | # Flash image and set $ANDROID_SERIAL |
| 10 | # |
| 11 | # Usage: $ bionic/build/coverage.sh |
| 12 | # Output: HTML report is generated to /tmp/bionic-coverage/html/index.html |
| 13 | # |
| 14 | |
| 15 | eval "$(cd ${ANDROID_BUILD_TOP}; build/soong/soong_ui.bash --dumpvars-mode --vars="TARGET_ARCH")" |
| 16 | |
| 17 | LLVM_PROFDATA=${ANDROID_BUILD_TOP}/prebuilts/clang/host/linux-x86/llvm-binutils-stable/llvm-profdata |
| 18 | LLVM_COV=${ANDROID_BUILD_TOP}/prebuilts/clang/host/linux-x86/llvm-binutils-stable/llvm-cov |
| 19 | |
| 20 | DEVICE_TEST_DIR=/data/local/tmp/bionic-coverage |
| 21 | HOST_PROFDATA_DIR=/tmp/bionic-coverage |
| 22 | |
| 23 | # Run bionic-unit-tests |
| 24 | adb shell rm -rf ${DEVICE_TEST_DIR} |
| 25 | adb shell mkdir ${DEVICE_TEST_DIR} |
| 26 | adb push $OUT/data/nativetest/bionic-loader-test-libs ${DEVICE_TEST_DIR} |
| 27 | adb push $OUT/data/nativetest/bionic-unit-tests ${DEVICE_TEST_DIR} |
| 28 | adb shell LLVM_PROFILE_FILE=${DEVICE_TEST_DIR}/profraws/bionic-%p-%m.profraw LD_LIBRARY_PATH=${DEVICE_TEST_DIR}/bionic-loader-test-libs ${DEVICE_TEST_DIR}/bionic-unit-tests/bionic-unit-tests |
| 29 | |
| 30 | # Pull coverage files and post-process |
| 31 | rm -rf ${HOST_PROFDATA_DIR} |
| 32 | mkdir ${HOST_PROFDATA_DIR} |
| 33 | adb pull ${DEVICE_TEST_DIR}/profraws ${HOST_PROFDATA_DIR}/profraws |
| 34 | |
| 35 | |
| 36 | ${LLVM_PROFDATA} merge \ |
| 37 | --output=${HOST_PROFDATA_DIR}/bionic.profdata \ |
| 38 | ${HOST_PROFDATA_DIR}/profraws/*.profraw |
| 39 | |
| 40 | ${LLVM_COV} show \ |
| 41 | --instr-profile=${HOST_PROFDATA_DIR}/bionic.profdata \ |
| 42 | --format=html \ |
| 43 | out/soong/.intermediates/bionic/libc/libc/android_${TARGET_ARCH}_shared_cov/unstripped/libc.so \ |
| 44 | --object=out/soong/.intermediates/bionic/tests/bionic-unit-tests/android_${TARGET_ARCH}_cov/unstripped/bionic-unit-tests \ |
| 45 | /proc/self/cwd/bionic/libc \ |
| 46 | --output-dir=${HOST_PROFDATA_DIR}/html \ |
| 47 | --show-region-summary=false |