Update acov script to handle new coverage file locations.

Test: Build with native coverage and run acov, check report contents.
Change-Id: I47afd35216cfcc7df7da2378cccdf8dba23bd8e2
This commit is contained in:
Oliver Nguyen
2019-10-02 12:06:04 -07:00
parent 41dca08dfc
commit f7421ae9db
2 changed files with 67 additions and 26 deletions

View File

@@ -19,10 +19,13 @@
# #
# 1. sudo apt-get install lcov # 1. sudo apt-get install lcov
# 2. Build application/library with coverage information. # 2. Build application/library with coverage information.
# 3. Push the new binaries to the device. # * make NATIVE_COVERAGE=true COVERAGE_PATHS='*'
# 4. Run tests with the additional environment variables: # 3. Push the new binaries to the device with adb sync.
# * GCOV_PREFIX=/data/local/tmp/gcov # (Optional): Run `acov --clean-device`. This will reset coverage for everything
# * GCOV_PREFIX_STRIP=`echo $(ANDROID_BUILD_TOP) | grep -o / | wc -l` # on the device.
# 4. Run tests.
# (Optional): Run `acov --flush`. This will dump coverage from all processes
# running on the device.
# 5. Run `acov`. # 5. Run `acov`.
# #
# acov will pull all coverage information from the device, push it to the right # acov will pull all coverage information from the device, push it to the right
@@ -30,21 +33,56 @@
# it in your browser). # it in your browser).
# #
ANDROID_OUT=${OUT_DIR:-out}
FLUSH_SLEEP=${FLUSH_SLEEP:-60}
function clearGcdaFiles() {
if [ -d "$ANDROID_OUT" ]; then
find $ANDROID_OUT -name '*.gcda' -delete
fi
}
function clearGcnoFiles() {
if [ -d "$ANDROID_OUT" ]; then
find $ANDROID_OUT -name '*.gcno' -delete
fi
}
if [ "$1" = "--clean" ]; then if [ "$1" = "--clean" ]; then
find $ANDROID_HOST_OUT \( -name '*.gcda' -o -name '*.gcno' \) -delete echo "Clearing gcda and gcno files from the local build."
find $ANDROID_PRODUCT_OUT \( -name '*.gcda' -o -name '*.gcno' \) -delete clearGcdaFiles
clearGcnoFiles
exit 0 exit 0
fi fi
if [ "$1" = "--prep" ]; then if [ "$1" = "--prep" ]; then
if [ -d "$ANDROID_HOST_OUT" ]; then echo "Clearing gcda files from the local build."
find $ANDROID_HOST_OUT -name '*.gcda' -delete clearGcdaFiles
fi exit 0
fi
if [ -d "$ANDROID_PRODUCT_OUT" ]; then adb root
find $ANDROID_PRODUCT_OUT -name '*.gcda' -delete
fi
if [ "$1" = "--clean-device" ]; then
echo "Resetting coverage on the device..."
adb shell kill -37 -1
echo "Waiting $FLUSH_SLEEP seconds for coverage to be written..."
sleep $FLUSH_SLEEP
adb shell rm -rf /data/misc/trace/*
exit 0
fi
if [ "$1" = "--flush" ]; then
shift
if [ -z $@ ]; then
echo "Flushing coverage for all processes on the device..."
adb shell kill -37 -1
else
echo "Flushing coverage for [$@] on the device..."
adb shell kill -37 $(adb shell pidof $@)
fi
echo "Waiting $FLUSH_SLEEP seconds for coverage to be written..."
sleep $FLUSH_SLEEP
exit 0 exit 0
fi fi
@@ -54,24 +92,24 @@ if [ $? -ne 0 ]; then
sudo apt-get install lcov sudo apt-get install lcov
fi fi
HOST=false
ANDROID_OUT=$ANDROID_PRODUCT_OUT
EXTRA_ARGS="$@"
if [ "$1" = "--host" ]; then
HOST=true
ANDROID_OUT=$ANDROID_HOST_OUT
EXTRA_ARGS="--gcov-tool=/usr/bin/gcov-4.6 ${@:2}"
fi
cd $ANDROID_BUILD_TOP cd $ANDROID_BUILD_TOP
FILE=cov.info
DIR=$(mktemp -d covreport-XXXXXX) DIR=$(mktemp -d covreport-XXXXXX)
if [ "$HOST" = "false" ]; then # Build a coverage report for each euid that has reported coverage.
adb pull /data/local/tmp/gcov COVERAGE_REPORTS=
fi for USER_ID in $(adb shell ls /data/misc/trace)
do
FILE=cov-$USER_ID.info
adb shell tar -czf - -C /data/misc/trace/$USER_ID/proc/self/cwd $ANDROID_OUT | tar zxvf -
lcov -c -d $ANDROID_OUT -o $DIR/$FILE $EXTRA_ARGS lcov -c -d $ANDROID_OUT -o $DIR/$FILE --gcov-tool=llvm-gcov $@
COVERAGE_REPORTS="-a $DIR/$FILE $COVERAGE_REPORTS"
clearGcdaFiles
done
FILE=merged.info
lcov $COVERAGE_REPORTS -o $DIR/$FILE
echo "Generating coverage report at $DIR" echo "Generating coverage report at $DIR"
genhtml -q -o $DIR $DIR/$FILE genhtml -q -o $DIR $DIR/$FILE
xdg-open $DIR/index.html >/dev/null xdg-open $DIR/index.html >/dev/null

3
scripts/llvm-gcov Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
# Wrapper script around 'llvm-cov gcov'.
exec llvm-cov gcov $@