github.com/gocuntian/go@v0.0.0-20160610041250-fee02d270bf8/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  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
    33  
    34  export CGO_ENABLED=1
    35  unset GOBIN
    36  
    37  # Do the build first, so we can build go_android_exec and cleaner.
    38  # Also lets us fail early before the (slow) adb push if the build is broken.
    39  . ./make.bash --no-banner
    40  export GOROOT=$(dirname $(pwd))
    41  export PATH=$GOROOT/bin:$PATH
    42  GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go build \
    43  	-o ../bin/go_android_${GOARCH}_exec \
    44  	../misc/android/go_android_exec.go
    45  
    46  export ANDROID_TEST_DIR=/tmp/androidtest-$$
    47  
    48  function cleanup() {
    49  	rm -rf ${ANDROID_TEST_DIR}
    50  }
    51  trap cleanup EXIT
    52  
    53  # Push GOROOT to target device.
    54  #
    55  # The adb sync command will sync either the /system or /data
    56  # directories of an android device from a similar directory
    57  # on the host. We copy the files required for running tests under
    58  # /data/local/tmp/goroot. The adb sync command does not follow
    59  # symlinks so we have to copy.
    60  export ANDROID_PRODUCT_OUT="${ANDROID_TEST_DIR}/out"
    61  FAKE_GOROOT=$ANDROID_PRODUCT_OUT/data/local/tmp/goroot
    62  mkdir -p $FAKE_GOROOT
    63  mkdir -p $FAKE_GOROOT/pkg
    64  cp -a "${GOROOT}/src" "${FAKE_GOROOT}/"
    65  cp -a "${GOROOT}/test" "${FAKE_GOROOT}/"
    66  cp -a "${GOROOT}/lib" "${FAKE_GOROOT}/"
    67  
    68  # For android, the go tool will install the compiled package in
    69  # pkg/android_${GOARCH}_shared directory by default, not in
    70  # the usual pkg/${GOOS}_${GOARCH}. Some tests in src/go/* assume
    71  # the compiled packages were installed in the usual places.
    72  # Instead of reflecting this exception into the go/* packages,
    73  # we copy the compiled packages into the usual places.
    74  cp -a "${GOROOT}/pkg/android_${GOARCH}_shared" "${FAKE_GOROOT}/pkg/"
    75  mv "${FAKE_GOROOT}/pkg/android_${GOARCH}_shared" "${FAKE_GOROOT}/pkg/android_${GOARCH}"
    76  
    77  echo '# Syncing test files to android device'
    78  adb shell mkdir -p /data/local/tmp/goroot
    79  time adb sync data &> /dev/null
    80  
    81  export CLEANER=${ANDROID_TEST_DIR}/androidcleaner-$$
    82  cp ../misc/android/cleaner.go $CLEANER.go
    83  echo 'var files = `' >> $CLEANER.go
    84  (cd $ANDROID_PRODUCT_OUT/data/local/tmp/goroot; find . >> $CLEANER.go)
    85  echo '`' >> $CLEANER.go
    86  go build -o $CLEANER $CLEANER.go
    87  adb push $CLEANER /data/local/tmp/cleaner
    88  adb shell /data/local/tmp/cleaner
    89  
    90  echo ''
    91  
    92  # Run standard tests.
    93  bash run.bash --no-rebuild