Merge "Update acov script to handle new coverage file locations." am: 834c8442cb

Change-Id: Ib845c0ad109545d97c3a6b24e5c73398a900af93
This commit is contained in:
Automerger Merge Worker
2020-03-12 18:05:23 +00:00
2 changed files with 67 additions and 26 deletions

View File

@@ -19,10 +19,13 @@
#
# 1. sudo apt-get install lcov
# 2. Build application/library with coverage information.
# 3. Push the new binaries to the device.
# 4. Run tests with the additional environment variables:
# * GCOV_PREFIX=/data/local/tmp/gcov
# * GCOV_PREFIX_STRIP=`echo $(ANDROID_BUILD_TOP) | grep -o / | wc -l`
# * make NATIVE_COVERAGE=true COVERAGE_PATHS='*'
# 3. Push the new binaries to the device with adb sync.
# (Optional): Run `acov --clean-device`. This will reset coverage for everything
# on the device.
# 4. Run tests.
# (Optional): Run `acov --flush`. This will dump coverage from all processes
# running on the device.
# 5. Run `acov`.
#
# acov will pull all coverage information from the device, push it to the right
@@ -30,21 +33,56 @@
# 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
find $ANDROID_HOST_OUT \( -name '*.gcda' -o -name '*.gcno' \) -delete
find $ANDROID_PRODUCT_OUT \( -name '*.gcda' -o -name '*.gcno' \) -delete
echo "Clearing gcda and gcno files from the local build."
clearGcdaFiles
clearGcnoFiles
exit 0
fi
if [ "$1" = "--prep" ]; then
if [ -d "$ANDROID_HOST_OUT" ]; then
find $ANDROID_HOST_OUT -name '*.gcda' -delete
fi
echo "Clearing gcda files from the local build."
clearGcdaFiles
exit 0
fi
if [ -d "$ANDROID_PRODUCT_OUT" ]; then
find $ANDROID_PRODUCT_OUT -name '*.gcda' -delete
fi
adb root
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
fi
@@ -54,24 +92,24 @@ if [ $? -ne 0 ]; then
sudo apt-get install lcov
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
FILE=cov.info
DIR=$(mktemp -d covreport-XXXXXX)
if [ "$HOST" = "false" ]; then
adb pull /data/local/tmp/gcov
fi
# Build a coverage report for each euid that has reported coverage.
COVERAGE_REPORTS=
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"
genhtml -q -o $DIR $DIR/$FILE
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 $@