From a81c6563525521a116582b93a4a95f3e8a6ceec9 Mon Sep 17 00:00:00 2001 From: "Hyang-Ah (Hana) Kim" Date: Fri, 17 Jul 2015 15:40:26 -0400 Subject: [PATCH] androidtest.bash: robust cleanup in case of failure. Change-Id: I69ed001bca4987e08b46a8288f6feae2aca6a142 Reviewed-on: https://go-review.googlesource.com/12380 Reviewed-by: David Crawshaw --- src/androidtest.bash | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/androidtest.bash b/src/androidtest.bash index 39e73c350b..0010738614 100755 --- a/src/androidtest.bash +++ b/src/androidtest.bash @@ -35,6 +35,13 @@ GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go build \ -o ../bin/go_android_${GOARCH}_exec \ ../misc/android/go_android_exec.go +export ANDROID_TEST_DIR=/tmp/androidtest-$$ + +function cleanup() { + rm -rf ${ANDROID_TEST_DIR} +} +trap cleanup EXIT + # Push GOROOT to target device. # # The adb sync command will sync either the /system or /data @@ -42,7 +49,7 @@ GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go build \ # 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. -export ANDROID_PRODUCT_OUT=/tmp/androidtest-$$ +export ANDROID_PRODUCT_OUT="${ANDROID_TEST_DIR}/out" FAKE_GOROOT=$ANDROID_PRODUCT_OUT/data/local/tmp/goroot mkdir -p $FAKE_GOROOT mkdir -p $FAKE_GOROOT/pkg @@ -54,17 +61,15 @@ echo '# Syncing test files to android device' adb shell mkdir -p /data/local/tmp/goroot time adb sync data &> /dev/null -export CLEANER=/tmp/androidcleaner-$$ +export CLEANER=${ANDROID_TEST_DIR}/androidcleaner-$$ 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 -rm $CLEANER $CLEANER.go adb shell /data/local/tmp/cleaner -rm -rf "$ANDROID_PRODUCT_OUT" echo '' # Run standard tests. -- 2.50.0