blob: a790f95920cf8b1eeff3c0d632df984462b900e2 [file] [log] [blame]
David Crawshawfe71b387b2014-07-09 14:54:11 -04001#!/usr/bin/env bash
Emmanuel Odeke53fd5222016-04-10 14:32:26 -07002# Copyright 2014 The Go Authors. All rights reserved.
David Crawshawa5f8e8f2014-07-09 06:56:49 -04003# 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
David Crawshaw0be3c402015-10-26 11:15:09 -040026if [ -z $GOARM ]; then
27 export GOARM=7
28fi
29if [ "$GOARM" != "7" ]; then
30 echo "android only supports GOARM=7, got GOARM=$GOARM" 1>&2
31 exit 1
32fi
Josh Bleecher Snyder8dd069b2016-08-28 08:53:20 -070033if [ "$GOARCH" = "" ]; then
34 echo "GOARCH must be set" 1>&2
35 exit 1
36fi
David Crawshaw0be3c402015-10-26 11:15:09 -040037
David Crawshawa5f8e8f2014-07-09 06:56:49 -040038export CGO_ENABLED=1
David Crawshaw0b36e122015-05-25 07:17:27 -040039unset GOBIN
David Crawshawa5f8e8f2014-07-09 06:56:49 -040040
David Crawshaw0b36e122015-05-25 07:17:27 -040041# Do the build first, so we can build go_android_exec and cleaner.
David Crawshawa5f8e8f2014-07-09 06:56:49 -040042# Also lets us fail early before the (slow) adb push if the build is broken.
David Crawshaw0b36e122015-05-25 07:17:27 -040043. ./make.bash --no-banner
David Crawshawa5f8e8f2014-07-09 06:56:49 -040044export GOROOT=$(dirname $(pwd))
45export PATH=$GOROOT/bin:$PATH
46GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go build \
47 -o ../bin/go_android_${GOARCH}_exec \
48 ../misc/android/go_android_exec.go
49
Josh Bleecher Snyder261240302016-08-28 09:03:08 -070050export pkgdir=$(dirname $(go list -f '{{.Target}}' runtime))
51if [ "$pkgdir" = "" ]; then
52 echo "could not find android pkg dir" 1>&2
53 exit 1
54fi
55
Hyang-Ah (Hana) Kima81c6562015-07-17 15:40:26 -040056export ANDROID_TEST_DIR=/tmp/androidtest-$$
57
58function cleanup() {
59 rm -rf ${ANDROID_TEST_DIR}
60}
61trap cleanup EXIT
62
David Crawshawa5f8e8f2014-07-09 06:56:49 -040063# Push GOROOT to target device.
64#
65# The adb sync command will sync either the /system or /data
66# directories of an android device from a similar directory
Hyang-Ah Hana Kim25ece4a2015-01-14 12:13:17 -050067# on the host. We copy the files required for running tests under
68# /data/local/tmp/goroot. The adb sync command does not follow
69# symlinks so we have to copy.
Hyang-Ah (Hana) Kima81c6562015-07-17 15:40:26 -040070export ANDROID_PRODUCT_OUT="${ANDROID_TEST_DIR}/out"
David Crawshawa5f8e8f2014-07-09 06:56:49 -040071FAKE_GOROOT=$ANDROID_PRODUCT_OUT/data/local/tmp/goroot
David Crawshaw4c05d322014-09-08 10:07:26 -040072mkdir -p $FAKE_GOROOT
David Crawshaw68f57c82015-04-08 09:28:05 -040073mkdir -p $FAKE_GOROOT/pkg
Hyang-Ah (Hana) Kim69937d22015-02-13 15:31:00 -050074cp -a "${GOROOT}/src" "${FAKE_GOROOT}/"
75cp -a "${GOROOT}/test" "${FAKE_GOROOT}/"
76cp -a "${GOROOT}/lib" "${FAKE_GOROOT}/"
Josh Bleecher Snyder261240302016-08-28 09:03:08 -070077cp -a "${pkgdir}" "${FAKE_GOROOT}/pkg/"
Hyang-Ah Hana Kim2e47b282015-10-21 13:50:06 -040078
David Crawshawfa9f3052014-09-04 13:39:51 -040079echo '# Syncing test files to android device'
Elias Naur919e85a2018-01-20 19:56:51 +010080adb $GOANDROID_ADB_FLAGS shell mkdir -p /data/local/tmp/goroot
81time adb $GOANDROID_ADB_FLAGS sync data &> /dev/null
David Crawshawa5f8e8f2014-07-09 06:56:49 -040082
Hyang-Ah (Hana) Kima81c6562015-07-17 15:40:26 -040083export CLEANER=${ANDROID_TEST_DIR}/androidcleaner-$$
David Crawshaw0b36e122015-05-25 07:17:27 -040084cp ../misc/android/cleaner.go $CLEANER.go
85echo 'var files = `' >> $CLEANER.go
86(cd $ANDROID_PRODUCT_OUT/data/local/tmp/goroot; find . >> $CLEANER.go)
87echo '`' >> $CLEANER.go
88go build -o $CLEANER $CLEANER.go
Elias Naur919e85a2018-01-20 19:56:51 +010089adb $GOANDROID_ADB_FLAGS push $CLEANER /data/local/tmp/cleaner
90adb $GOANDROID_ADB_FLAGS shell /data/local/tmp/cleaner
David Crawshaw0b36e122015-05-25 07:17:27 -040091
David Crawshaw0b36e122015-05-25 07:17:27 -040092echo ''
93
94# Run standard tests.
95bash run.bash --no-rebuild