Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file |
| 4 | # for details. All rights reserved. Use of this source code is governed by a |
| 5 | # BSD-style license that can be found in the LICENSE file. |
| 6 | # |
| 7 | # Clone and build AOSP, using D8 instead of JACK or DX, |
| 8 | # then run the Android-CTS on the emulator and compare results |
| 9 | # to a baseline. |
| 10 | # |
| 11 | # This script uses the repo manifest file 'third_party/aosp_manifest.xml' |
| 12 | # which is a snapshot of the aosp repo set. |
| 13 | # The manifest file can be updated with the following commands: |
| 14 | # |
| 15 | # cd build/aosp |
| 16 | # repo manifest -o ../../third_party/aosp_manifest.xml -r |
| 17 | # |
| 18 | # The baseline is the `test_result.xml` file which is created with an AOSP |
| 19 | # build which uses the default (JACK) toolset. |
| 20 | # |
| 21 | # To reproduce the baseline results, follow the instructions in this script, |
| 22 | # except don't set `ANDROID_COMPILE_WITH_JACK=false` for the `make` command. |
| 23 | # Also, you don't need to apply either of the patches (PATCH#1 and #2, see |
| 24 | # below) |
| 25 | # |
| 26 | |
| 27 | set -e |
| 28 | |
| 29 | readonly R8_ROOT=$(cd "$(dirname ${BASH_SOURCE[0]})"/..; pwd) |
| 30 | readonly AOSP_ROOT="$R8_ROOT/build/aosp" |
| 31 | readonly CTS_BASELINE="$R8_ROOT/third_party/android_cts_baseline/test_result.xml" |
| 32 | readonly D8_JAR="$R8_ROOT/build/libs/d8.jar" |
| 33 | readonly J_OPTION="-j8" |
| 34 | readonly OUT_IMG=out_img # output dir for android image build |
| 35 | readonly OUT_CTS=out_cts # output dir for CTS build |
| 36 | |
| 37 | # Process an Android CTS test_result.xml file for easy comparison with a |
| 38 | # baseline. |
| 39 | # |
| 40 | # The function transforms these lines: |
| 41 | # |
| 42 | # <Test result="pass|fail" name="<name>" /> |
| 43 | # |
| 44 | # to this: |
| 45 | # |
| 46 | # <module-name>/<testcase-name>/<name> -> PASS|FAIL |
| 47 | # |
| 48 | flatten_xml() { |
| 49 | local input_file="$1" |
| 50 | local module |
| 51 | local testcase |
| 52 | local testname |
| 53 | while IFS='' read -r line || [[ -n "$line" ]]; do |
| 54 | if [[ $line =~ \<Module\ name=\"([^\"]*)\" ]]; then |
| 55 | module=${BASH_REMATCH[1]} |
| 56 | elif [[ $line =~ \<TestCase\ name=\"([^\"]*)\" ]]; then |
| 57 | testcase=${BASH_REMATCH[1]} |
| 58 | elif [[ $line =~ \<Test\ result=\"pass\"\ name=\"([^\"]*)\" ]]; then |
| 59 | echo "$module/$testcase/${BASH_REMATCH[1]} -> PASS" |
| 60 | elif [[ $line =~ \<Test\ result=\"fail\"\ name=\"([^\"]*)\" ]]; then |
| 61 | echo "$module/$testcase/${BASH_REMATCH[1]} -> FAIL" |
| 62 | fi |
| 63 | done < "$input_file" |
| 64 | } |
| 65 | |
| 66 | #### MAIN #### |
| 67 | |
| 68 | cd "$R8_ROOT" |
| 69 | tools/gradle.py d8 |
| 70 | |
| 71 | mkdir -p "$AOSP_ROOT" |
| 72 | cd "$AOSP_ROOT" |
| 73 | |
| 74 | # Two output dirs, one for the android image and one for cts tests. The output |
| 75 | # is compiled with d8 and jack, respectively. |
| 76 | mkdir -p "$OUT_IMG" "$OUT_CTS" |
| 77 | |
| 78 | # remove dex files older than the current d8 tool |
| 79 | find "$OUT_IMG" ! -newer "$R8_ROOT/build/libs/d8.jar" -name '*.dex' -exec rm {} \; |
| 80 | |
| 81 | # checkout AOSP source |
| 82 | mkdir -p .repo/manifests |
| 83 | cp "$R8_ROOT/third_party/aosp_manifest.xml" .repo/manifests |
| 84 | |
| 85 | repo init -u "https://android.googlesource.com/platform/manifest" -m aosp_manifest.xml |
| 86 | repo sync -dq $J_OPTION |
| 87 | |
| 88 | # activate $OUT_CTS |
| 89 | rm -rf out |
| 90 | ln -s "$OUT_CTS" out |
| 91 | |
| 92 | . build/envsetup.sh |
| 93 | lunch aosp_x86-eng |
| 94 | make $J_OPTION cts |
| 95 | |
| 96 | # activate $OUT_IMG |
| 97 | rm -rf out |
| 98 | ln -s "$OUT_IMG" out |
| 99 | |
| 100 | . build/envsetup.sh |
| 101 | lunch aosp_x86-eng |
| 102 | make $J_OPTION ANDROID_COMPILE_WITH_JACK=false DX_ALT_JAR="$D8_JAR" |
| 103 | |
| 104 | # create sdcard image for media tests |
| 105 | |
| 106 | mkdir -p "$R8_ROOT/build/tmp" |
| 107 | sdcard_file="$R8_ROOT/build/tmp/sdcard.img" |
| 108 | rm -f "$sdcard_file" |
| 109 | mksdcard 4G "$sdcard_file" |
| 110 | |
| 111 | emulator -partition-size 4096 -wipe-data -sdcard "$sdcard_file" & |
| 112 | emulator_pid=$! |
| 113 | |
| 114 | adb wait-for-device |
| 115 | adb shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82' |
| 116 | |
| 117 | echo "exit" | \ |
| 118 | ANDROID_BUILD_TOP= \ |
| 119 | "$OUT_CTS/host/linux-x86/cts/android-cts/tools/cts-tradefed" run cts |
| 120 | |
| 121 | kill $emulator_pid |
| 122 | rm -f "$sdcard_file" |
| 123 | |
| 124 | # find the newest test_result.xml |
| 125 | |
| 126 | results_dir="$OUT_CTS/host/linux-x86/cts/android-cts/results" |
| 127 | timestamp="$(ls --group-directories-first -t "$results_dir" | head -1)" |
| 128 | results_xml="$results_dir/$timestamp/test_result.xml" |
| 129 | |
| 130 | echo "Summary from current test results: $results_xml" |
| 131 | grep "<Summary " "$results_xml" |
| 132 | |
| 133 | echo "Summary from baseline: $CTS_BASELINE" |
| 134 | grep "<Summary " "$CTS_BASELINE" |
| 135 | |
| 136 | echo "Comparing test results to baseline" |
| 137 | |
| 138 | diff <(flatten_xml "$results_xml") <(flatten_xml "$CTS_BASELINE") |
| 139 | exit $? # make it explicit that the result of the diff must be the result of this script |
| 140 | |