blob: 39e73c350b67b5ebd81029d6c607028ba5fdb8df [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
38# Push GOROOT to target device.
39#
40# The adb sync command will sync either the /system or /data
41# directories of an android device from a similar directory
Hyang-Ah Hana Kim25ece4a2015-01-14 12:13:17 -050042# on the host. We copy the files required for running tests under
43# /data/local/tmp/goroot. The adb sync command does not follow
44# symlinks so we have to copy.
David Crawshawa5f8e8f2014-07-09 06:56:49 -040045export ANDROID_PRODUCT_OUT=/tmp/androidtest-$$
46FAKE_GOROOT=$ANDROID_PRODUCT_OUT/data/local/tmp/goroot
David Crawshaw4c05d322014-09-08 10:07:26 -040047mkdir -p $FAKE_GOROOT
David Crawshaw68f57c82015-04-08 09:28:05 -040048mkdir -p $FAKE_GOROOT/pkg
Hyang-Ah (Hana) Kim69937d22015-02-13 15:31:00 -050049cp -a "${GOROOT}/src" "${FAKE_GOROOT}/"
50cp -a "${GOROOT}/test" "${FAKE_GOROOT}/"
51cp -a "${GOROOT}/lib" "${FAKE_GOROOT}/"
David Crawshaw68f57c82015-04-08 09:28:05 -040052cp -a "${GOROOT}/pkg/android_$GOARCH" "${FAKE_GOROOT}/pkg/"
David Crawshawfa9f3052014-09-04 13:39:51 -040053echo '# Syncing test files to android device'
David Crawshaw0b36e122015-05-25 07:17:27 -040054adb shell mkdir -p /data/local/tmp/goroot
David Crawshawfa9f3052014-09-04 13:39:51 -040055time adb sync data &> /dev/null
David Crawshawa5f8e8f2014-07-09 06:56:49 -040056
David Crawshaw0b36e122015-05-25 07:17:27 -040057export CLEANER=/tmp/androidcleaner-$$
58cp ../misc/android/cleaner.go $CLEANER.go
59echo 'var files = `' >> $CLEANER.go
60(cd $ANDROID_PRODUCT_OUT/data/local/tmp/goroot; find . >> $CLEANER.go)
61echo '`' >> $CLEANER.go
62go build -o $CLEANER $CLEANER.go
63adb push $CLEANER /data/local/tmp/cleaner
64rm $CLEANER $CLEANER.go
65adb shell /data/local/tmp/cleaner
66
67rm -rf "$ANDROID_PRODUCT_OUT"
68echo ''
69
70# Run standard tests.
71bash run.bash --no-rebuild