1#!/bin/bash
2# It is to be used with BYOB setup to run tests on cloud VMs.
3# The script will run ADB tests.
4#
5# It takes 1 command line argument.
6# DIST_DIR => Absolute path for the distribution directory.
7#
8# It will return 0 if it is able to execute tests, otherwise
9# it will return 1.
10#
11# Owner: akagrawal@google.com
12
13DIST_DIR=$1
14
15function run_with_timeout () {
16   ( $1 $2 ) & pid=$!
17   ( sleep $3 && kill -HUP $pid ) 2>/dev/null & watcher=$!
18   if wait $pid 2>/dev/null; then
19      pkill -HUP -P $watcher
20      wait $watcher
21   else
22      echo "Test time out."
23      # kill the process tree for test
24      pkill -9 -g $pid
25      exit 1
26   fi
27}
28
29echo "Checkout adt-infra repo"
30# $ADT_INFRA has to be set on the build machine. It should have absolute path
31# where adt-infra needs to be checked out.
32rm -rf $ADT_INFRA
33git clone https://android.googlesource.com/platform/external/adt-infra -b emu-master-dev $ADT_INFRA
34
35BUILD_DIR="out/prebuilt_cached/builds"
36
37export ANDROID_HOME=$SDK_PLAT_TOOLS
38export ANDROID_SDK_ROOT=$SDK_PLAT_TOOLS
39
40echo "Setup new ADB"
41rm -rf $ANDROID_SDK_ROOT/platform-tools
42unzip -o $BUILD_DIR/sdk-repo* -d $ANDROID_SDK_ROOT
43
44echo "Extract tests from general-tests.zip"
45unzip -l $BUILD_DIR/general-tests.zip | grep -q adb_integration_test
46if [[ "$?" == "0" ]]
47then
48    mkdir -p $DIST_DIR/general-tests
49    unzip $BUILD_DIR/general-tests.zip host/testcases/adb_integration_test_*/* -d $DIST_DIR/general-tests
50fi
51
52echo "Run ADB tests from $ADT_INFRA"
53cmd="$ADT_INFRA/emu_test/utils/run_test_android_bridge.sh"
54run_with_timeout $cmd $DIST_DIR 5400
55
56echo "Cleanup prebuilts"
57rm -rf /buildbot/prebuilt/*
58
59exit 0
60