blob: bf46f79819ef54b4403a53c537c1f29b6b6cbdd4 [file] [log] [blame]
Josh Gaoc0d86862020-04-20 17:23:32 -07001#!/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
16set -euxo pipefail
17
Josh Gao03bee482020-04-20 19:21:41 -070018ADB_TESTS="adbd_test adb_crypto_test adb_pairing_auth_test adb_pairing_connection_test adb_tls_connection_test"
19
20TRACEDIR=`mktemp -d`
21
Josh Gaoc0d86862020-04-20 17:23:32 -070022adb root
Josh Gao03bee482020-04-20 19:21:41 -070023
24### Run the adb unit tests and fetch traces from them.
25mkdir "$TRACEDIR"/test_traces
26adb shell rm -rf /data/local/tmp/adb_coverage
27adb shell mkdir /data/local/tmp/adb_coverage
28
29for 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/
32done
33
34adb pull /data/local/tmp/adb_coverage "$TRACEDIR"/test_traces
35
36### Run test_device.py, and fetch traces from adbd itself.
Josh Gaoc0d86862020-04-20 17:23:32 -070037adb shell logcat -c -G128M
38adb shell setprop persist.adb.trace_mask 1
39adb shell killall adbd
40
41# TODO: Add `adb transport-id` and wait-for-offline on it.
42sleep 5
43
Josh Gao03bee482020-04-20 19:21:41 -070044adb wait-for-device shell rm -rf "/data/misc/trace/*" /data/local/tmp/adb_coverage/
Josh Gaoc0d86862020-04-20 17:23:32 -070045
46./test_device.py
47
48# Dump traces from the currently running adbd.
49adb shell killall -37 adbd
50
51echo Waiting for adbd to finish dumping traces
52sleep 5
53
Josh Gaoc0d86862020-04-20 17:23:32 -070054adb pull /data/misc/trace "$TRACEDIR"/
55echo Pulled traces to $TRACEDIR
56
Josh Gaoc0d86862020-04-20 17:23:32 -070057# Identify which of the trace files are actually adbd, in case something else exited simultaneously.
58ADBD_PIDS=$(adb shell "logcat -d -s adbd --format=process | grep 'adbd started' | cut -c 3-7 | tr -d ' ' | sort | uniq")
59mkdir "$TRACEDIR"/adbd_traces
60
61adb shell 'setprop persist.adb.trace_mask 0; killall adbd'
62
63IFS=$'\n'
64for PID in $ADBD_PIDS; do
65 cp "$TRACEDIR"/trace/clang-$PID-*.profraw "$TRACEDIR"/adbd_traces 2>/dev/null || true
66done
Josh Gao03bee482020-04-20 19:21:41 -070067unset IFS
Josh Gaoc0d86862020-04-20 17:23:32 -070068
Josh Gao03bee482020-04-20 19:21:41 -070069ADB_TEST_BINARIES=""
70for TEST in $ADB_TESTS; do
71 ADB_TEST_BINARIES="--object=$ANDROID_PRODUCT_OUT/data/nativetest64/$TEST/$TEST $ADB_TEST_BINARIES"
72done
73
74### Merge the traces and generate a report.
75llvm-profdata merge --output="$TRACEDIR"/adbd.profdata "$TRACEDIR"/adbd_traces/* "$TRACEDIR"/test_traces/*
Josh Gaoc0d86862020-04-20 17:23:32 -070076
77cd $ANDROID_BUILD_TOP
78llvm-cov report --instr-profile="$TRACEDIR"/adbd.profdata \
79 $ANDROID_PRODUCT_OUT/apex/com.android.adbd/bin/adbd \
80 --show-region-summary=false \
Josh Gao03bee482020-04-20 19:21:41 -070081 /proc/self/cwd/system/core/adb \
82 $ADB_TEST_BINARIES
Josh Gaoc0d86862020-04-20 17:23:32 -070083
84llvm-cov show --instr-profile="$TRACEDIR"/adbd.profdata \
85 $ANDROID_PRODUCT_OUT/apex/com.android.adbd/bin/adbd \
86 --format=html \
Josh Gao03bee482020-04-20 19:21:41 -070087 /proc/self/cwd/system/core/adb \
88 $ADB_TEST_BINARIES > $TRACEDIR/report.html