blob: 49175ec97d6526b32580e96e91256ca560574866 [file] [log] [blame]
Mads Ager418d1ca2017-05-22 09:35:49 +02001#!/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
27set -e
28
29readonly R8_ROOT=$(cd "$(dirname ${BASH_SOURCE[0]})"/..; pwd)
30readonly AOSP_ROOT="$R8_ROOT/build/aosp"
31readonly CTS_BASELINE="$R8_ROOT/third_party/android_cts_baseline/test_result.xml"
32readonly D8_JAR="$R8_ROOT/build/libs/d8.jar"
33readonly J_OPTION="-j8"
34readonly OUT_IMG=out_img # output dir for android image build
35readonly 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#
48flatten_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
68cd "$R8_ROOT"
69tools/gradle.py d8
70
71mkdir -p "$AOSP_ROOT"
72cd "$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.
76mkdir -p "$OUT_IMG" "$OUT_CTS"
77
78# remove dex files older than the current d8 tool
79find "$OUT_IMG" ! -newer "$R8_ROOT/build/libs/d8.jar" -name '*.dex' -exec rm {} \;
80
81# checkout AOSP source
82mkdir -p .repo/manifests
83cp "$R8_ROOT/third_party/aosp_manifest.xml" .repo/manifests
84
85repo init -u "https://android.googlesource.com/platform/manifest" -m aosp_manifest.xml
86repo sync -dq $J_OPTION
87
88# activate $OUT_CTS
89rm -rf out
90ln -s "$OUT_CTS" out
91
92. build/envsetup.sh
93lunch aosp_x86-eng
94make $J_OPTION cts
95
96# activate $OUT_IMG
97rm -rf out
98ln -s "$OUT_IMG" out
99
100. build/envsetup.sh
101lunch aosp_x86-eng
102make $J_OPTION ANDROID_COMPILE_WITH_JACK=false DX_ALT_JAR="$D8_JAR"
103
104# create sdcard image for media tests
105
106mkdir -p "$R8_ROOT/build/tmp"
107sdcard_file="$R8_ROOT/build/tmp/sdcard.img"
108rm -f "$sdcard_file"
109mksdcard 4G "$sdcard_file"
110
111emulator -partition-size 4096 -wipe-data -sdcard "$sdcard_file" &
112emulator_pid=$!
113
114adb wait-for-device
115adb shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82'
116
117echo "exit" | \
118 ANDROID_BUILD_TOP= \
119 "$OUT_CTS/host/linux-x86/cts/android-cts/tools/cts-tradefed" run cts
120
121kill $emulator_pid
122rm -f "$sdcard_file"
123
124# find the newest test_result.xml
125
126results_dir="$OUT_CTS/host/linux-x86/cts/android-cts/results"
127timestamp="$(ls --group-directories-first -t "$results_dir" | head -1)"
128results_xml="$results_dir/$timestamp/test_result.xml"
129
130echo "Summary from current test results: $results_xml"
131grep "<Summary " "$results_xml"
132
133echo "Summary from baseline: $CTS_BASELINE"
134grep "<Summary " "$CTS_BASELINE"
135
136echo "Comparing test results to baseline"
137
138diff <(flatten_xml "$results_xml") <(flatten_xml "$CTS_BASELINE")
139exit $? # make it explicit that the result of the diff must be the result of this script
140