...
Run Format

Text file src/androidtest.bash

Documentation: Index

     1	#!/usr/bin/env bash
     2	# 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	
    10	set -e
    11	ulimit -c 0 # no core files
    12	
    13	if [ ! -f make.bash ]; then
    14		echo 'androidtest.bash must be run from $GOROOT/src' 1>&2
    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	
    26	if [ -n "$GOARM" ] && [ "$GOARM" != "7" ]; then
    27		echo "android only supports GOARM=7, got GOARM=$GOARM" 1>&2
    28		exit 1
    29	fi
    30	
    31	export CGO_ENABLED=1
    32	unset GOBIN
    33	
    34	# Do the build first, so we can build go_android_exec and cleaner.
    35	# Also lets us fail early before the (slow) adb push if the build is broken.
    36	. ./make.bash --no-banner
    37	export GOROOT=$(dirname $(pwd))
    38	export PATH=$GOROOT/bin:$PATH
    39	GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go build \
    40		-o ../bin/go_android_${GOARCH}_exec \
    41		../misc/android/go_android_exec.go
    42	
    43	export pkgdir=$(dirname $(go list -f '{{.Target}}' runtime))
    44	if [ "$pkgdir" = "" ]; then
    45		echo "could not find android pkg dir" 1>&2
    46		exit 1
    47	fi
    48	
    49	export ANDROID_TEST_DIR=/tmp/androidtest-$$
    50	
    51	function cleanup() {
    52		rm -rf ${ANDROID_TEST_DIR}
    53	}
    54	trap cleanup EXIT
    55	
    56	# Push GOROOT to target device.
    57	#
    58	# The adb sync command will sync either the /system or /data
    59	# directories of an android device from a similar directory
    60	# on the host. We copy the files required for running tests under
    61	# /data/local/tmp/goroot. The adb sync command does not follow
    62	# symlinks so we have to copy.
    63	export ANDROID_PRODUCT_OUT="${ANDROID_TEST_DIR}/out"
    64	FAKE_GOROOT=$ANDROID_PRODUCT_OUT/data/local/tmp/goroot
    65	mkdir -p $FAKE_GOROOT
    66	mkdir -p $FAKE_GOROOT/pkg
    67	cp -a "${GOROOT}/src" "${FAKE_GOROOT}/"
    68	cp -a "${GOROOT}/test" "${FAKE_GOROOT}/"
    69	cp -a "${GOROOT}/lib" "${FAKE_GOROOT}/"
    70	cp -a "${pkgdir}" "${FAKE_GOROOT}/pkg/"
    71	
    72	echo '# Syncing test files to android device'
    73	adb $GOANDROID_ADB_FLAGS shell mkdir -p /data/local/tmp/goroot
    74	time adb $GOANDROID_ADB_FLAGS sync data &> /dev/null
    75	
    76	export CLEANER=${ANDROID_TEST_DIR}/androidcleaner-$$
    77	cp ../misc/android/cleaner.go $CLEANER.go
    78	echo 'var files = `' >> $CLEANER.go
    79	(cd $ANDROID_PRODUCT_OUT/data/local/tmp/goroot; find . >> $CLEANER.go)
    80	echo '`' >> $CLEANER.go
    81	go build -o $CLEANER $CLEANER.go
    82	adb $GOANDROID_ADB_FLAGS push $CLEANER /data/local/tmp/cleaner
    83	adb $GOANDROID_ADB_FLAGS shell /data/local/tmp/cleaner
    84	
    85	echo ''
    86	
    87	# Run standard tests.
    88	bash run.bash --no-rebuild

View as plain text