• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# It is to be used with BYOB setup to run CTS tests.
3#
4# It will return 0 if it is able to execute tests, otherwise
5# it will return 1.
6#
7# Owner: mattwachakagrawal@google.com
8
9# Echo vars to the log
10set -x
11
12DIST_DIR=$1
13# Build ID is used for identifying the builds during upload
14BUILD_ID=$2
15# Module list file
16MODULE_LIST_FILE=$3
17# Emulator GPU option
18GPU_FLAG=$4
19# Directory containing the system image to run the tests against. Default is gphone_x86_64-user
20PRODUCT_DIR=${5:-gphone_x86_64-user}
21
22# Kill any emulators that might still be active from older sessions.
23killall qemu-system-x86_64-headless
24
25# Working files for the testing process
26WORK_DIR="$DIST_DIR/tradefed-make"
27TEST_DIR="$DIST_DIR/tradefed-test"
28rm -rf $WORK_DIR
29mkdir -p $WORK_DIR
30
31function cleanup_dirs {
32  echo "Cleanup prebuilts"
33  rm -rf /buildbot/prebuilt/*
34  rm -rf $WORK_DIR
35  rm -rf $TEST_DIR/common
36  # Extra files that may sometimes be of use, but in general seem
37  # to create a lot of artifact clutter.
38  find $TEST_DIR \( \
39    -name 'adbkey*' -o \
40    -name '*.cache' -o \
41    -name '*.conf' -o \
42    -name 'cts.dynamic' -o \
43    -name '*.data' -o \
44    -name '*.json' -o \
45    -name '*.lock' -o \
46    -name 'modem-nv-ram-*' -o \
47    -name '*.pb' -o \
48    -name '*.png' -o \
49    -name '*.protobuf' -o \
50    -name 'sepolicy' -o \
51    -name '*.zip' \
52    \) -print0 | xargs -0 -n 10 rm
53}
54# Always remove working files, even on error
55trap cleanup_dirs EXIT
56# Exit on errors.
57set -e
58
59function die {
60  echo "run_test_suite.sh: $1">&2
61  exit 1
62}
63
64function fetch_latest_emulator {
65  local emu_dir=$1
66  mkdir -p $emu_dir
67  local fetch_stdout=$(fetch_artifacts.py \
68    -build_target linux-sdk_tools_linux \
69    -branch aosp-emu-master-dev \
70    -image_path gs://android-build-emu/builds \
71    -dest $emu_dir)
72  # extract build_id from fetch fetch_artifacts.py stdout
73  # stdout looks like:
74  #   Fetching latest build 5800753 for linux-sdk_tools_linux
75  echo $(echo $fetch_stdout | grep "Fetching latest build" | awk '{ print $4 }')
76}
77
78function find_zip_in_dir {
79  local target_name=$1
80  local zip_dir=$2
81  [[ -d $zip_dir ]] || die "Could not find $target_name dir: $zip_dir"
82  local zip_path=$zip_dir/$(ls $zip_dir)
83  [[ -f $zip_path ]] || die "Could not find $target_name zip file: $zip_path"
84  [[ "$zip_path" == *.zip ]] || die "Bad image $target_name zip pathname: $zip_path"
85  echo $zip_path
86}
87
88# Check that we have the expected version of java.
89EXPECTED_VERSION=9.0.4
90export PATH=~/jdk-${EXPECTED_VERSION}/bin:$PATH
91java --version | grep $EXPECTED_VERSION  # Fails if version string not found.
92
93MODULE_LIST_PATH=$(dirname ${BASH_SOURCE[0]})/$MODULE_LIST_FILE
94[[ -f $MODULE_LIST_PATH ]] || die "The module list path $MODULE_LIST_PATH was not found"
95
96# Directory where tradefed-make tools are cloned
97TRADEFED_MAKE_DIR="$WORK_DIR/tradefed-make"
98git clone \
99  --branch v1 \
100  https://team.googlesource.com/android-devtools-emulator/tradefed-make \
101  $TRADEFED_MAKE_DIR
102
103# The emulator requires files in the platforms directory
104PLATFORMS_DIR="${HOME}/Android_sys_image/sdk/platforms/android-28"
105
106# Platform tools contain core tools, like adb
107PLATFORM_TOOLS_DIR="${HOME}/Android_sys_image/sdk/platform-tools"
108
109# More tools dependencies.
110SDK_TOOLS_DIR="${HOME}/Android_sys_image/sdk/build-tools/27.0.3"
111
112# Where to put the testing configuration file
113CONFIG_PATH="$WORK_DIR/tradefed-make-config.yaml"
114
115# Fetch the latest emulator
116EMU_DIR=$WORK_DIR/emulator
117EMU_BUILD_ID=$(fetch_latest_emulator $EMU_DIR)
118EMU_ZIP=$(find_zip_in_dir emulator $EMU_DIR)
119ls -l $EMU_ZIP
120
121# Directory where system images, and cts can be found
122BUILD_DIR=out/prebuilt_cached/builds
123
124IMAGE_DIR=$BUILD_DIR/$PRODUCT_DIR
125IMAGE_ZIP=$(find_zip_in_dir image $IMAGE_DIR)
126ls -l $IMAGE_ZIP
127
128if [[ -f "$BUILD_DIR/test_suite/android-cts.zip" ]]; then
129  TEST_SUITE=cts
130  IMAGE_FLAVOR=user
131elif [[ -f "$BUILD_DIR/test_suite/android-gts.zip" ]]; then
132  TEST_SUITE=gts
133  IMAGE_FLAVOR=user
134elif [[ -f "$BUILD_DIR/test_suite/android-vts.zip" ]]; then
135  TEST_SUITE=vts
136  IMAGE_FLAVOR=userdebug
137  export VTS_PYPI_PATH=$WORK_DIR/venv
138  pip install --user virtualenv
139  virtualenv $VTS_PYPI_PATH
140  curl https://android.googlesource.com/platform/test/vts/+/master/script/pip_requirements.txt?format=TEXT | base64 -d > $WORK_DIR/pip_requirements.txt
141  pip download -d $VTS_PYPI_PATH -r $WORK_DIR/pip_requirements.txt --no-binary protobuf,grpcio,matplotlib,numpy,Pillow,scipy==1.2.2
142else
143  die "Could not find android-cts.zip, android-gts.zip or android-vts.zip in $BUILD_DIR/test_suite"
144fi
145
146
147# Setup the testing configuration
148$TRADEFED_MAKE_DIR/make-config \
149  $TRADEFED_MAKE_DIR/config.yaml \
150  $CONFIG_PATH \
151  --override \
152    config.tradefed.ape_api_key=/home/android-build/gts-android-emulator.json \
153    vars.emulator.files.download.build_id=$EMU_BUILD_ID \
154    vars.emulator.files.local_zip_path=$EMU_ZIP \
155    vars.emulator.flags.feature=PlayStoreImage,GLAsyncSwap,GLESDynamicVersion \
156    vars.emulator.flags.gpu=$GPU_FLAG \
157    vars.image.files.local_zip_path.${IMAGE_FLAVOR}=$IMAGE_ZIP \
158    vars.image.files.download.branch=git_rvc-release \
159    vars.image.files.download.build_id=$BUILD_ID \
160    vars.image.flavor.default=user \
161    vars.root_dir=$TEST_DIR \
162    vars.tradefed.timeout_seconds=10000 \
163    vars.tools.android_level=28 \
164    vars.tools.files.download.build_id=0 \
165    vars.tools.files.local_dir.platforms=$PLATFORMS_DIR \
166    vars.tools.files.local_dir.platform_tools=$PLATFORM_TOOLS_DIR \
167    vars.tools.files.local_dir.sdk_tools=$SDK_TOOLS_DIR \
168    vars.tradefed.files.download.build_id=$BUILD_ID \
169    vars.tradefed.files.local_zip_path.$TEST_SUITE=$BUILD_DIR/test_suite/android-$TEST_SUITE.zip \
170  --add \
171    vars.emulator.flags.no-window=True \
172
173if [[ "$GPU_FLAG" == "host" ]]; then
174  $TRADEFED_MAKE_DIR/make-config \
175  $CONFIG_PATH \
176  --inline \
177  --override \
178    config.emulator.command_prefix='vglrun +v -c proxy' \
179
180fi
181
182# Start the tests
183set +x
184set -e
185# Override the jdk's built-in certs to use the system ones.
186export RDBG_FLAG=-Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts
187export DISPLAY=:0
188$TRADEFED_MAKE_DIR/tradefed-make $CONFIG_PATH -j4 prepare.$TEST_SUITE.all_modules
189$TRADEFED_MAKE_DIR/tradefed-make $CONFIG_PATH -j4 $(cat $MODULE_LIST_PATH | sed 's/^/run./')
190$TRADEFED_MAKE_DIR/tradefed-make $CONFIG_PATH stop.emulator.$TEST_SUITE
191
192# TODO: Further analyze the results.
193
194exit 0
195