David Crawshaw | fe71b387b | 2014-07-09 14:54:11 -0400 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Emmanuel Odeke | 53fd522 | 2016-04-10 14:32:26 -0700 | [diff] [blame] | 2 | # Copyright 2014 The Go Authors. All rights reserved. |
David Crawshaw | a5f8e8f | 2014-07-09 06:56:49 -0400 | [diff] [blame] | 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 | |
| 10 | set -e |
| 11 | ulimit -c 0 # no core files |
| 12 | |
| 13 | if [ ! -f make.bash ]; then |
Burcu Dogan | e13170e | 2015-01-14 18:49:03 -0800 | [diff] [blame] | 14 | echo 'androidtest.bash must be run from $GOROOT/src' 1>&2 |
David Crawshaw | a5f8e8f | 2014-07-09 06:56:49 -0400 | [diff] [blame] | 15 | exit 1 |
| 16 | fi |
| 17 | |
| 18 | if [ -z $GOOS ]; then |
| 19 | export GOOS=android |
| 20 | fi |
| 21 | if [ "$GOOS" != "android" ]; then |
| 22 | echo "androidtest.bash requires GOOS=android, got GOOS=$GOOS" 1>&2 |
| 23 | exit 1 |
| 24 | fi |
| 25 | |
David Crawshaw | 0be3c40 | 2015-10-26 11:15:09 -0400 | [diff] [blame] | 26 | if [ -z $GOARM ]; then |
| 27 | export GOARM=7 |
| 28 | fi |
| 29 | if [ "$GOARM" != "7" ]; then |
| 30 | echo "android only supports GOARM=7, got GOARM=$GOARM" 1>&2 |
| 31 | exit 1 |
| 32 | fi |
Josh Bleecher Snyder | 8dd069b | 2016-08-28 08:53:20 -0700 | [diff] [blame] | 33 | if [ "$GOARCH" = "" ]; then |
| 34 | echo "GOARCH must be set" 1>&2 |
| 35 | exit 1 |
| 36 | fi |
David Crawshaw | 0be3c40 | 2015-10-26 11:15:09 -0400 | [diff] [blame] | 37 | |
David Crawshaw | a5f8e8f | 2014-07-09 06:56:49 -0400 | [diff] [blame] | 38 | export CGO_ENABLED=1 |
David Crawshaw | 0b36e12 | 2015-05-25 07:17:27 -0400 | [diff] [blame] | 39 | unset GOBIN |
David Crawshaw | a5f8e8f | 2014-07-09 06:56:49 -0400 | [diff] [blame] | 40 | |
David Crawshaw | 0b36e12 | 2015-05-25 07:17:27 -0400 | [diff] [blame] | 41 | # Do the build first, so we can build go_android_exec and cleaner. |
David Crawshaw | a5f8e8f | 2014-07-09 06:56:49 -0400 | [diff] [blame] | 42 | # Also lets us fail early before the (slow) adb push if the build is broken. |
David Crawshaw | 0b36e12 | 2015-05-25 07:17:27 -0400 | [diff] [blame] | 43 | . ./make.bash --no-banner |
David Crawshaw | a5f8e8f | 2014-07-09 06:56:49 -0400 | [diff] [blame] | 44 | export GOROOT=$(dirname $(pwd)) |
| 45 | export PATH=$GOROOT/bin:$PATH |
| 46 | GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go build \ |
| 47 | -o ../bin/go_android_${GOARCH}_exec \ |
| 48 | ../misc/android/go_android_exec.go |
| 49 | |
Josh Bleecher Snyder | 26124030 | 2016-08-28 09:03:08 -0700 | [diff] [blame] | 50 | export pkgdir=$(dirname $(go list -f '{{.Target}}' runtime)) |
| 51 | if [ "$pkgdir" = "" ]; then |
| 52 | echo "could not find android pkg dir" 1>&2 |
| 53 | exit 1 |
| 54 | fi |
| 55 | |
Hyang-Ah (Hana) Kim | a81c656 | 2015-07-17 15:40:26 -0400 | [diff] [blame] | 56 | export ANDROID_TEST_DIR=/tmp/androidtest-$$ |
| 57 | |
| 58 | function cleanup() { |
| 59 | rm -rf ${ANDROID_TEST_DIR} |
| 60 | } |
| 61 | trap cleanup EXIT |
| 62 | |
David Crawshaw | a5f8e8f | 2014-07-09 06:56:49 -0400 | [diff] [blame] | 63 | # 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 Kim | 25ece4a | 2015-01-14 12:13:17 -0500 | [diff] [blame] | 67 | # 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) Kim | a81c656 | 2015-07-17 15:40:26 -0400 | [diff] [blame] | 70 | export ANDROID_PRODUCT_OUT="${ANDROID_TEST_DIR}/out" |
David Crawshaw | a5f8e8f | 2014-07-09 06:56:49 -0400 | [diff] [blame] | 71 | FAKE_GOROOT=$ANDROID_PRODUCT_OUT/data/local/tmp/goroot |
David Crawshaw | 4c05d32 | 2014-09-08 10:07:26 -0400 | [diff] [blame] | 72 | mkdir -p $FAKE_GOROOT |
David Crawshaw | 68f57c8 | 2015-04-08 09:28:05 -0400 | [diff] [blame] | 73 | mkdir -p $FAKE_GOROOT/pkg |
Hyang-Ah (Hana) Kim | 69937d2 | 2015-02-13 15:31:00 -0500 | [diff] [blame] | 74 | cp -a "${GOROOT}/src" "${FAKE_GOROOT}/" |
| 75 | cp -a "${GOROOT}/test" "${FAKE_GOROOT}/" |
| 76 | cp -a "${GOROOT}/lib" "${FAKE_GOROOT}/" |
Josh Bleecher Snyder | 26124030 | 2016-08-28 09:03:08 -0700 | [diff] [blame] | 77 | cp -a "${pkgdir}" "${FAKE_GOROOT}/pkg/" |
Hyang-Ah Hana Kim | 2e47b28 | 2015-10-21 13:50:06 -0400 | [diff] [blame] | 78 | |
David Crawshaw | fa9f305 | 2014-09-04 13:39:51 -0400 | [diff] [blame] | 79 | echo '# Syncing test files to android device' |
Elias Naur | 919e85a | 2018-01-20 19:56:51 +0100 | [diff] [blame] | 80 | adb $GOANDROID_ADB_FLAGS shell mkdir -p /data/local/tmp/goroot |
| 81 | time adb $GOANDROID_ADB_FLAGS sync data &> /dev/null |
David Crawshaw | a5f8e8f | 2014-07-09 06:56:49 -0400 | [diff] [blame] | 82 | |
Hyang-Ah (Hana) Kim | a81c656 | 2015-07-17 15:40:26 -0400 | [diff] [blame] | 83 | export CLEANER=${ANDROID_TEST_DIR}/androidcleaner-$$ |
David Crawshaw | 0b36e12 | 2015-05-25 07:17:27 -0400 | [diff] [blame] | 84 | cp ../misc/android/cleaner.go $CLEANER.go |
| 85 | echo 'var files = `' >> $CLEANER.go |
| 86 | (cd $ANDROID_PRODUCT_OUT/data/local/tmp/goroot; find . >> $CLEANER.go) |
| 87 | echo '`' >> $CLEANER.go |
| 88 | go build -o $CLEANER $CLEANER.go |
Elias Naur | 919e85a | 2018-01-20 19:56:51 +0100 | [diff] [blame] | 89 | adb $GOANDROID_ADB_FLAGS push $CLEANER /data/local/tmp/cleaner |
| 90 | adb $GOANDROID_ADB_FLAGS shell /data/local/tmp/cleaner |
David Crawshaw | 0b36e12 | 2015-05-25 07:17:27 -0400 | [diff] [blame] | 91 | |
David Crawshaw | 0b36e12 | 2015-05-25 07:17:27 -0400 | [diff] [blame] | 92 | echo '' |
| 93 | |
| 94 | # Run standard tests. |
| 95 | bash run.bash --no-rebuild |