summaryrefslogtreecommitdiff
path: root/service/generate_local_coverage.sh
blob: b60e3e1e7af3d83b97a8377e0680c5fdbc7134ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash

set -e

# Setup tmp folder
COVERAGE_TMP_FOLDER=/tmp/coverage_robolectric
rm -rf ${COVERAGE_TMP_FOLDER}
mkdir -p ${COVERAGE_TMP_FOLDER}/com/android/server/

# Run test + collect coverage
script -q ${COVERAGE_TMP_FOLDER}/atest_log \
  -c 'atest ServiceBluetoothRoboTests -- \
  --jacocoagent-path gs://tradefed_test_resources/teams/code_coverage/jacocoagent.jar \
  --coverage --coverage-toolchain JACOCO'

# "Atest results and logs directory: /tmp/path<CR><LF>" -> "/tmp/path"
COVERAGE_COLLECTED=$(rg 'Atest results and logs directory:' ${COVERAGE_TMP_FOLDER}/atest_log | cut -d ':' -f 2 | tr -d '\r' | xargs)

# Link source into the tmp folder
ln -s "${ANDROID_BUILD_TOP}"/packages/modules/Bluetooth/service/src ${COVERAGE_TMP_FOLDER}/com/android/server/bluetooth

# Extract class coverage and delete unwanted class for the report
unzip "${ANDROID_HOST_OUT}"/testcases/ServiceBluetoothRoboTests/ServiceBluetoothRoboTests.jar "com/android/server/bluetooth*" -d ${COVERAGE_TMP_FOLDER}/ServiceBluetoothRobo_unzip
# shellcheck disable=SC2046
rm -rf $(find ${COVERAGE_TMP_FOLDER}/ServiceBluetoothRobo_unzip -iname "*test*")
# shellcheck disable=SC2016
rm -rf ${COVERAGE_TMP_FOLDER}/ServiceBluetoothRobo_unzip/com/android/server/bluetooth/'BluetoothAdapterState$waitForState$3$invokeSuspend$$inlined$filter$1.class'
# shellcheck disable=SC2016
rm -rf ${COVERAGE_TMP_FOLDER}/ServiceBluetoothRobo_unzip/com/android/server/bluetooth/'BluetoothAdapterState$waitForState$3$invokeSuspend$$inlined$filter$1$2.class'
rm -rf ${COVERAGE_TMP_FOLDER}/ServiceBluetoothRobo_unzip/com/android/server/bluetooth/R.class

# Generate report:
# You may want to run "m jacoco-cli" if above command failed
java -jar "${ANDROID_BUILD_TOP}"/out/host/linux-x86/framework/jacoco-cli.jar report "${COVERAGE_COLLECTED}"/log/invocation_*/inv_*/coverage_*.ec --classfiles ${COVERAGE_TMP_FOLDER}/ServiceBluetoothRobo_unzip --html ${COVERAGE_TMP_FOLDER}/coverage --name coverage.html --sourcefiles ${COVERAGE_TMP_FOLDER}

# Start python server and expose URL
printf "Url to connect to the coverage \033[32m http://%s:8000 \033[0m\n" "$(hostname)"
python3 -m http.server --directory ${COVERAGE_TMP_FOLDER}/coverage