blob: 00107386149712684db9b1d114cb107adfa40b86 [file] [log] [blame]
David Crawshawfe71b387b2014-07-09 14:54:11 -04001#!/usr/bin/env bash
David Crawshawa5f8e8f2014-07-09 06:56:49 -04002# Copyright 2014 The Go Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style
4# license that can be found in the LICENSE file.
5
6# For testing Android.
7# The compiler runs locally, then a copy of the GOROOT is pushed to a
8# target device using adb, and the tests are run there.
9
10set -e
11ulimit -c 0 # no core files
12
13if [ ! -f make.bash ]; then
Burcu Dogane13170e2015-01-14 18:49:03 -080014 echo 'androidtest.bash must be run from $GOROOT/src' 1>&2
David Crawshawa5f8e8f2014-07-09 06:56:49 -040015 exit 1
16fi
17
18if [ -z $GOOS ]; then
19 export GOOS=android
20fi
21if [ "$GOOS" != "android" ]; then
22 echo "androidtest.bash requires GOOS=android, got GOOS=$GOOS" 1>&2
23 exit 1
24fi
25
26export CGO_ENABLED=1
David Crawshaw0b36e122015-05-25 07:17:27 -040027unset GOBIN
David Crawshawa5f8e8f2014-07-09 06:56:49 -040028
David Crawshaw0b36e122015-05-25 07:17:27 -040029# Do the build first, so we can build go_android_exec and cleaner.
David Crawshawa5f8e8f2014-07-09 06:56:49 -040030# Also lets us fail early before the (slow) adb push if the build is broken.
David Crawshaw0b36e122015-05-25 07:17:27 -040031. ./make.bash --no-banner
David Crawshawa5f8e8f2014-07-09 06:56:49 -040032export GOROOT=$(dirname $(pwd))
33export PATH=$GOROOT/bin:$PATH
34GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go build \
35 -o ../bin/go_android_${GOARCH}_exec \
36 ../misc/android/go_android_exec.go
37
Hyang-Ah (Hana) Kima81c6562015-07-17 15:40:26 -040038export ANDROID_TEST_DIR=/tmp/androidtest-$$
39
40function cleanup() {
41 rm -rf ${ANDROID_TEST_DIR}
42}
43trap cleanup EXIT
44
David Crawshawa5f8e8f2014-07-09 06:56:49 -040045# Push GOROOT to target device.
46#
47# The adb sync command will sync either the /system or /data
48# directories of an android device from a similar directory
Hyang-Ah Hana Kim25ece4a2015-01-14 12:13:17 -050049# on the host. We copy the files required for running tests under
50# /data/local/tmp/goroot. The adb sync command does not follow
51# symlinks so we have to copy.
Hyang-Ah (Hana) Kima81c6562015-07-17 15:40:26 -040052export ANDROID_PRODUCT_OUT="${ANDROID_TEST_DIR}/out"
David Crawshawa5f8e8f2014-07-09 06:56:49 -040053FAKE_GOROOT=$ANDROID_PRODUCT_OUT/data/local/tmp/goroot
David Crawshaw4c05d322014-09-08 10:07:26 -040054mkdir -p $FAKE_GOROOT
David Crawshaw68f57c82015-04-08 09:28:05 -040055mkdir -p $FAKE_GOROOT/pkg
Hyang-Ah (Hana) Kim69937d22015-02-13 15:31:00 -050056cp -a "${GOROOT}/src" "${FAKE_GOROOT}/"
57cp -a "${GOROOT}/test" "${FAKE_GOROOT}/"
58cp -a "${GOROOT}/lib" "${FAKE_GOROOT}/"
David Crawshaw68f57c82015-04-08 09:28:05 -040059cp -a "${GOROOT}/pkg/android_$GOARCH" "${FAKE_GOROOT}/pkg/"
David Crawshawfa9f3052014-09-04 13:39:51 -040060echo '# Syncing test files to android device'
David Crawshaw0b36e122015-05-25 07:17:27 -040061adb shell mkdir -p /data/local/tmp/goroot
David Crawshawfa9f3052014-09-04 13:39:51 -040062time adb sync data &> /dev/null
David Crawshawa5f8e8f2014-07-09 06:56:49 -040063
Hyang-Ah (Hana) Kima81c6562015-07-17 15:40:26 -040064export CLEANER=${ANDROID_TEST_DIR}/androidcleaner-$$
David Crawshaw0b36e122015-05-25 07:17:27 -040065cp ../misc/android/cleaner.go $CLEANER.go
66echo 'var files = `' >> $CLEANER.go
67(cd $ANDROID_PRODUCT_OUT/data/local/tmp/goroot; find . >> $CLEANER.go)
68echo '`' >> $CLEANER.go
69go build -o $CLEANER $CLEANER.go
70adb push $CLEANER /data/local/tmp/cleaner
David Crawshaw0b36e122015-05-25 07:17:27 -040071adb shell /data/local/tmp/cleaner
72
David Crawshaw0b36e122015-05-25 07:17:27 -040073echo ''
74
75# Run standard tests.
76bash run.bash --no-rebuild