Skip to content

Commit

Permalink
adbd: add unit tests to coverage report.
Browse files Browse the repository at this point in the history
Test: ./coverage.sh
Change-Id: I268367b857efc2125c6714a1d0b0e874fa8d143d
  • Loading branch information
jmgao committed Apr 22, 2020
1 parent c185a93 commit d231cda
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,33 @@

set -euxo pipefail

ADB_TESTS="adbd_test adb_crypto_test adb_pairing_auth_test adb_pairing_connection_test adb_tls_connection_test"

TRACEDIR=`mktemp -d`

adb root

### Run the adb unit tests and fetch traces from them.
mkdir "$TRACEDIR"/test_traces
adb shell rm -rf /data/local/tmp/adb_coverage
adb shell mkdir /data/local/tmp/adb_coverage

for TEST in $ADB_TESTS; do
adb shell LLVM_PROFILE_FILE=/data/local/tmp/adb_coverage/$TEST.profraw /data/nativetest64/$TEST/$TEST
adb pull /data/local/tmp/adb_coverage/$TEST.profraw "$TRACEDIR"/test_traces/
done

adb pull /data/local/tmp/adb_coverage "$TRACEDIR"/test_traces

### Run test_device.py, and fetch traces from adbd itself.
adb shell logcat -c -G128M
adb shell setprop persist.adb.trace_mask 1
adb shell killall adbd

# TODO: Add `adb transport-id` and wait-for-offline on it.
sleep 5

adb wait-for-device shell rm "/data/misc/trace/*"
adb wait-for-device shell rm -rf "/data/misc/trace/*" /data/local/tmp/adb_coverage/

./test_device.py

Expand All @@ -33,11 +51,9 @@ adb shell killall -37 adbd
echo Waiting for adbd to finish dumping traces
sleep 5

TRACEDIR=`mktemp -d`
adb pull /data/misc/trace "$TRACEDIR"/
echo Pulled traces to $TRACEDIR


# Identify which of the trace files are actually adbd, in case something else exited simultaneously.
ADBD_PIDS=$(adb shell "logcat -d -s adbd --format=process | grep 'adbd started' | cut -c 3-7 | tr -d ' ' | sort | uniq")
mkdir "$TRACEDIR"/adbd_traces
Expand All @@ -48,16 +64,25 @@ IFS=$'\n'
for PID in $ADBD_PIDS; do
cp "$TRACEDIR"/trace/clang-$PID-*.profraw "$TRACEDIR"/adbd_traces 2>/dev/null || true
done
unset IFS

ADB_TEST_BINARIES=""
for TEST in $ADB_TESTS; do
ADB_TEST_BINARIES="--object=$ANDROID_PRODUCT_OUT/data/nativetest64/$TEST/$TEST $ADB_TEST_BINARIES"
done

llvm-profdata merge --output="$TRACEDIR"/adbd.profdata "$TRACEDIR"/adbd_traces/*
### Merge the traces and generate a report.
llvm-profdata merge --output="$TRACEDIR"/adbd.profdata "$TRACEDIR"/adbd_traces/* "$TRACEDIR"/test_traces/*

cd $ANDROID_BUILD_TOP
llvm-cov report --instr-profile="$TRACEDIR"/adbd.profdata \
$ANDROID_PRODUCT_OUT/apex/com.android.adbd/bin/adbd \
--show-region-summary=false \
/proc/self/cwd/system/core/adb
/proc/self/cwd/system/core/adb \
$ADB_TEST_BINARIES

llvm-cov show --instr-profile="$TRACEDIR"/adbd.profdata \
$ANDROID_PRODUCT_OUT/apex/com.android.adbd/bin/adbd \
--format=html \
/proc/self/cwd/system/core/adb > $TRACEDIR/report.html
/proc/self/cwd/system/core/adb \
$ADB_TEST_BINARIES > $TRACEDIR/report.html

0 comments on commit d231cda

Please sign in to comment.