1#!/bin/bash 2set -eux 3 4PYTORCH_DIR="$(cd $(dirname $0)/..; pwd -P)" 5PYTORCH_ANDROID_DIR=$PYTORCH_DIR/android 6 7source "$PYTORCH_ANDROID_DIR/common.sh" 8 9check_android_sdk 10check_gradle 11 12# Run android instrumented tests on x86 emulator 13 14ADB_PATH=$ANDROID_HOME/platform-tools/adb 15 16echo "Expecting running emulator" 17$ADB_PATH devices 18 19DEVICES_COUNT=$($ADB_PATH devices | awk 'NF' | wc -l) 20echo "DEVICES_COUNT:$DEVICES_COUNT" 21 22if [ "$DEVICES_COUNT" -eq 1 ]; then 23 echo "Unable to found connected android emulators" 24cat <<- EOF 25 To start android emulator: 26 1. Install android sdkmanager packages 27 $ANDROID_HOME/tools/bin/sdkmanager "system-images;android-25;google_apis;x86" 28 29 to specify proxy add params: --proxy=http --proxy_host=fwdproxy --proxy_port=8080 30 31 2. Create android virtual device 32 $ANDROID_HOME/tools/bin/avdmanager create avd --name "x86_android25" --package "system-images;android-25;google_apis;x86" 33 34 3. Start emulator in headless mode without audio 35 $ANDROID_HOME/tools/emulator -avd x86_android25 -no-audio -no-window 36 37 4. Check that emulator is running 38 $ANDROID_HOME/platform-tools/adb devices 39 40 If everything is ok the output will be: 41 42 List of devices attached 43 emulator-5554 device 44EOF 45 exit 1 46fi 47 48echo "Waiting for emulator boot completed" 49$ADB_PATH wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;' 50 51{ 52 # The test currently takes about 10 minutes 53 retry $GRADLE_PATH -PABI_FILTERS=x86 -p $PYTORCH_ANDROID_DIR connectedAndroidTest 54} || { 55 echo "::error::Check https://github.com/pytorch/pytorch/tree/master/test/mobile/model_test to see how to fix the failed mobile test" 56 exit 1 57} 58