Josh Gao | c0d8686 | 2020-04-20 17:23:32 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright (C) 2020 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | set -euxo pipefail |
| 17 | |
Josh Gao | 03bee48 | 2020-04-20 19:21:41 -0700 | [diff] [blame] | 18 | ADB_TESTS="adbd_test adb_crypto_test adb_pairing_auth_test adb_pairing_connection_test adb_tls_connection_test" |
| 19 | |
| 20 | TRACEDIR=`mktemp -d` |
| 21 | |
Josh Gao | c0d8686 | 2020-04-20 17:23:32 -0700 | [diff] [blame] | 22 | adb root |
Josh Gao | 03bee48 | 2020-04-20 19:21:41 -0700 | [diff] [blame] | 23 | |
| 24 | ### Run the adb unit tests and fetch traces from them. |
| 25 | mkdir "$TRACEDIR"/test_traces |
| 26 | adb shell rm -rf /data/local/tmp/adb_coverage |
| 27 | adb shell mkdir /data/local/tmp/adb_coverage |
| 28 | |
| 29 | for TEST in $ADB_TESTS; do |
| 30 | adb shell LLVM_PROFILE_FILE=/data/local/tmp/adb_coverage/$TEST.profraw /data/nativetest64/$TEST/$TEST |
| 31 | adb pull /data/local/tmp/adb_coverage/$TEST.profraw "$TRACEDIR"/test_traces/ |
| 32 | done |
| 33 | |
| 34 | adb pull /data/local/tmp/adb_coverage "$TRACEDIR"/test_traces |
| 35 | |
| 36 | ### Run test_device.py, and fetch traces from adbd itself. |
Josh Gao | c0d8686 | 2020-04-20 17:23:32 -0700 | [diff] [blame] | 37 | adb shell logcat -c -G128M |
| 38 | adb shell setprop persist.adb.trace_mask 1 |
| 39 | adb shell killall adbd |
| 40 | |
| 41 | # TODO: Add `adb transport-id` and wait-for-offline on it. |
| 42 | sleep 5 |
| 43 | |
Josh Gao | 03bee48 | 2020-04-20 19:21:41 -0700 | [diff] [blame] | 44 | adb wait-for-device shell rm -rf "/data/misc/trace/*" /data/local/tmp/adb_coverage/ |
Josh Gao | c0d8686 | 2020-04-20 17:23:32 -0700 | [diff] [blame] | 45 | |
| 46 | ./test_device.py |
| 47 | |
| 48 | # Dump traces from the currently running adbd. |
| 49 | adb shell killall -37 adbd |
| 50 | |
| 51 | echo Waiting for adbd to finish dumping traces |
| 52 | sleep 5 |
| 53 | |
Josh Gao | c0d8686 | 2020-04-20 17:23:32 -0700 | [diff] [blame] | 54 | adb pull /data/misc/trace "$TRACEDIR"/ |
| 55 | echo Pulled traces to $TRACEDIR |
| 56 | |
Josh Gao | c0d8686 | 2020-04-20 17:23:32 -0700 | [diff] [blame] | 57 | # Identify which of the trace files are actually adbd, in case something else exited simultaneously. |
| 58 | ADBD_PIDS=$(adb shell "logcat -d -s adbd --format=process | grep 'adbd started' | cut -c 3-7 | tr -d ' ' | sort | uniq") |
| 59 | mkdir "$TRACEDIR"/adbd_traces |
| 60 | |
| 61 | adb shell 'setprop persist.adb.trace_mask 0; killall adbd' |
| 62 | |
| 63 | IFS=$'\n' |
| 64 | for PID in $ADBD_PIDS; do |
| 65 | cp "$TRACEDIR"/trace/clang-$PID-*.profraw "$TRACEDIR"/adbd_traces 2>/dev/null || true |
| 66 | done |
Josh Gao | 03bee48 | 2020-04-20 19:21:41 -0700 | [diff] [blame] | 67 | unset IFS |
Josh Gao | c0d8686 | 2020-04-20 17:23:32 -0700 | [diff] [blame] | 68 | |
Josh Gao | 03bee48 | 2020-04-20 19:21:41 -0700 | [diff] [blame] | 69 | ADB_TEST_BINARIES="" |
| 70 | for TEST in $ADB_TESTS; do |
| 71 | ADB_TEST_BINARIES="--object=$ANDROID_PRODUCT_OUT/data/nativetest64/$TEST/$TEST $ADB_TEST_BINARIES" |
| 72 | done |
| 73 | |
| 74 | ### Merge the traces and generate a report. |
| 75 | llvm-profdata merge --output="$TRACEDIR"/adbd.profdata "$TRACEDIR"/adbd_traces/* "$TRACEDIR"/test_traces/* |
Josh Gao | c0d8686 | 2020-04-20 17:23:32 -0700 | [diff] [blame] | 76 | |
| 77 | cd $ANDROID_BUILD_TOP |
| 78 | llvm-cov report --instr-profile="$TRACEDIR"/adbd.profdata \ |
| 79 | $ANDROID_PRODUCT_OUT/apex/com.android.adbd/bin/adbd \ |
| 80 | --show-region-summary=false \ |
Josh Gao | 03bee48 | 2020-04-20 19:21:41 -0700 | [diff] [blame] | 81 | /proc/self/cwd/system/core/adb \ |
| 82 | $ADB_TEST_BINARIES |
Josh Gao | c0d8686 | 2020-04-20 17:23:32 -0700 | [diff] [blame] | 83 | |
| 84 | llvm-cov show --instr-profile="$TRACEDIR"/adbd.profdata \ |
| 85 | $ANDROID_PRODUCT_OUT/apex/com.android.adbd/bin/adbd \ |
| 86 | --format=html \ |
Josh Gao | 03bee48 | 2020-04-20 19:21:41 -0700 | [diff] [blame] | 87 | /proc/self/cwd/system/core/adb \ |
| 88 | $ADB_TEST_BINARIES > $TRACEDIR/report.html |