github.com/jonasi/go@v0.0.0-20150930005915-e78e654c1de0/src/androidtest.bash (about)

     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  export CGO_ENABLED=1
    27  unset GOBIN
    28  
    29  # Do the build first, so we can build go_android_exec and cleaner.
    30  # Also lets us fail early before the (slow) adb push if the build is broken.
    31  . ./make.bash --no-banner
    32  export GOROOT=$(dirname $(pwd))
    33  export PATH=$GOROOT/bin:$PATH
    34  GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go build \
    35  	-o ../bin/go_android_${GOARCH}_exec \
    36  	../misc/android/go_android_exec.go
    37  
    38  export ANDROID_TEST_DIR=/tmp/androidtest-$$
    39  
    40  function cleanup() {
    41  	rm -rf ${ANDROID_TEST_DIR}
    42  }
    43  trap cleanup EXIT
    44  
    45  # Push GOROOT to target device.
    46  #
    47  # The adb sync command will sync either the /system or /data
    48  # directories of an android device from a similar directory
    49  # on the host. We copy the files required for running tests under
    50  # /data/local/tmp/goroot. The adb sync command does not follow
    51  # symlinks so we have to copy.
    52  export ANDROID_PRODUCT_OUT="${ANDROID_TEST_DIR}/out"
    53  FAKE_GOROOT=$ANDROID_PRODUCT_OUT/data/local/tmp/goroot
    54  mkdir -p $FAKE_GOROOT
    55  mkdir -p $FAKE_GOROOT/pkg
    56  cp -a "${GOROOT}/src" "${FAKE_GOROOT}/"
    57  cp -a "${GOROOT}/test" "${FAKE_GOROOT}/"
    58  cp -a "${GOROOT}/lib" "${FAKE_GOROOT}/"
    59  cp -a "${GOROOT}/pkg/android_$GOARCH" "${FAKE_GOROOT}/pkg/"
    60  echo '# Syncing test files to android device'
    61  adb shell mkdir -p /data/local/tmp/goroot
    62  time adb sync data &> /dev/null
    63  
    64  export CLEANER=${ANDROID_TEST_DIR}/androidcleaner-$$
    65  cp ../misc/android/cleaner.go $CLEANER.go
    66  echo 'var files = `' >> $CLEANER.go
    67  (cd $ANDROID_PRODUCT_OUT/data/local/tmp/goroot; find . >> $CLEANER.go)
    68  echo '`' >> $CLEANER.go
    69  go build -o $CLEANER $CLEANER.go
    70  adb push $CLEANER /data/local/tmp/cleaner
    71  adb shell /data/local/tmp/cleaner
    72  
    73  echo ''
    74  
    75  # Run standard tests.
    76  bash run.bash --no-rebuild