2014-07-09 12:54:11 -06:00
|
|
|
#!/usr/bin/env bash
|
2014-07-09 04:56:49 -06:00
|
|
|
# Copyright 2014 The Go Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
# For testing Android.
|
|
|
|
# The compiler runs locally, then a copy of the GOROOT is pushed to a
|
|
|
|
# target device using adb, and the tests are run there.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
ulimit -c 0 # no core files
|
|
|
|
|
|
|
|
if [ ! -f make.bash ]; then
|
2015-01-14 19:49:03 -07:00
|
|
|
echo 'androidtest.bash must be run from $GOROOT/src' 1>&2
|
2014-07-09 04:56:49 -06:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z $GOOS ]; then
|
|
|
|
export GOOS=android
|
|
|
|
fi
|
|
|
|
if [ "$GOOS" != "android" ]; then
|
|
|
|
echo "androidtest.bash requires GOOS=android, got GOOS=$GOOS" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-10-26 09:15:09 -06:00
|
|
|
if [ -z $GOARM ]; then
|
|
|
|
export GOARM=7
|
|
|
|
fi
|
|
|
|
if [ "$GOARM" != "7" ]; then
|
|
|
|
echo "android only supports GOARM=7, got GOARM=$GOARM" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-07-09 04:56:49 -06:00
|
|
|
export CGO_ENABLED=1
|
2015-05-25 05:17:27 -06:00
|
|
|
unset GOBIN
|
2014-07-09 04:56:49 -06:00
|
|
|
|
2015-05-25 05:17:27 -06:00
|
|
|
# Do the build first, so we can build go_android_exec and cleaner.
|
2014-07-09 04:56:49 -06:00
|
|
|
# Also lets us fail early before the (slow) adb push if the build is broken.
|
2015-05-25 05:17:27 -06:00
|
|
|
. ./make.bash --no-banner
|
2014-07-09 04:56:49 -06:00
|
|
|
export GOROOT=$(dirname $(pwd))
|
|
|
|
export PATH=$GOROOT/bin:$PATH
|
|
|
|
GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go build \
|
|
|
|
-o ../bin/go_android_${GOARCH}_exec \
|
|
|
|
../misc/android/go_android_exec.go
|
|
|
|
|
2015-07-17 13:40:26 -06:00
|
|
|
export ANDROID_TEST_DIR=/tmp/androidtest-$$
|
|
|
|
|
|
|
|
function cleanup() {
|
|
|
|
rm -rf ${ANDROID_TEST_DIR}
|
|
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
2014-07-09 04:56:49 -06:00
|
|
|
# Push GOROOT to target device.
|
|
|
|
#
|
|
|
|
# The adb sync command will sync either the /system or /data
|
|
|
|
# directories of an android device from a similar directory
|
2015-01-14 10:13:17 -07:00
|
|
|
# on the host. We copy the files required for running tests under
|
|
|
|
# /data/local/tmp/goroot. The adb sync command does not follow
|
|
|
|
# symlinks so we have to copy.
|
2015-07-17 13:40:26 -06:00
|
|
|
export ANDROID_PRODUCT_OUT="${ANDROID_TEST_DIR}/out"
|
2014-07-09 04:56:49 -06:00
|
|
|
FAKE_GOROOT=$ANDROID_PRODUCT_OUT/data/local/tmp/goroot
|
2014-09-08 08:07:26 -06:00
|
|
|
mkdir -p $FAKE_GOROOT
|
2015-04-08 07:28:05 -06:00
|
|
|
mkdir -p $FAKE_GOROOT/pkg
|
2015-02-13 13:31:00 -07:00
|
|
|
cp -a "${GOROOT}/src" "${FAKE_GOROOT}/"
|
|
|
|
cp -a "${GOROOT}/test" "${FAKE_GOROOT}/"
|
|
|
|
cp -a "${GOROOT}/lib" "${FAKE_GOROOT}/"
|
2015-10-21 11:50:06 -06:00
|
|
|
|
|
|
|
# For android, the go tool will install the compiled package in
|
|
|
|
# pkg/android_${GOARCH}_shared directory by default, not in
|
|
|
|
# the usual pkg/${GOOS}_${GOARCH}. Some tests in src/go/* assume
|
|
|
|
# the compiled packages were installed in the usual places.
|
|
|
|
# Instead of reflecting this exception into the go/* packages,
|
|
|
|
# we copy the compiled packages into the usual places.
|
|
|
|
cp -a "${GOROOT}/pkg/android_${GOARCH}_shared" "${FAKE_GOROOT}/pkg/"
|
|
|
|
mv "${FAKE_GOROOT}/pkg/android_${GOARCH}_shared" "${FAKE_GOROOT}/pkg/android_${GOARCH}"
|
|
|
|
|
2014-09-04 11:39:51 -06:00
|
|
|
echo '# Syncing test files to android device'
|
2015-05-25 05:17:27 -06:00
|
|
|
adb shell mkdir -p /data/local/tmp/goroot
|
2014-09-04 11:39:51 -06:00
|
|
|
time adb sync data &> /dev/null
|
2015-05-25 05:17:27 -06:00
|
|
|
|
2015-07-17 13:40:26 -06:00
|
|
|
export CLEANER=${ANDROID_TEST_DIR}/androidcleaner-$$
|
2015-05-25 05:17:27 -06:00
|
|
|
cp ../misc/android/cleaner.go $CLEANER.go
|
|
|
|
echo 'var files = `' >> $CLEANER.go
|
|
|
|
(cd $ANDROID_PRODUCT_OUT/data/local/tmp/goroot; find . >> $CLEANER.go)
|
|
|
|
echo '`' >> $CLEANER.go
|
|
|
|
go build -o $CLEANER $CLEANER.go
|
|
|
|
adb push $CLEANER /data/local/tmp/cleaner
|
|
|
|
adb shell /data/local/tmp/cleaner
|
|
|
|
|
|
|
|
echo ''
|
2014-07-09 04:56:49 -06:00
|
|
|
|
2015-05-25 05:17:27 -06:00
|
|
|
# Run standard tests.
|
|
|
|
bash run.bash --no-rebuild
|