Skip to content

Commit

Permalink
Attempt to make the usage of the Android emulator in CIs more robust (m…
Browse files Browse the repository at this point in the history
…icrosoft#17903)

### Description
<!-- Describe your changes. -->
Android emulator usage updates:
- Change approach to detecting boot has completed
- use `-delay-adb` and a simple command (`ls`) with `wait-for-device` as
the first step
    - this ensures enough startup has occurred for adb to be responsive
- use secondary loop on the python side to check for sys.boot_completed
to be set
- doing the check on the python side provides more feedback and seems to
work well
- make the 'stop' logic more precise by using psutil
- add internal timeout of 20 mins for emulator startup
  - waiting for the CI jobs overall timeout is way too long
- value is hardcoded for now (most CIs startup in under 10 mins) but
could be made configurable if needed

CI updates:
- add template for using the Android emulator
  - update CIs to use template
- reorder React Native CI
- minimize the time the Android emulator or iOS simulator is running by
moving some build steps around
  - don't run both at the same time
- unnecessary and potentially adds significant memory pressure to the
machine
- fix QNN Android emulator CI as much as possible
- now everything works apart from running onnx_test_runner with the QNN
EP

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
Fix inconsistent detection of the emulator boot completing.

---------

Co-authored-by: Edward Chen <[email protected]>
  • Loading branch information
skottmckay and edgchen1 authored Oct 14, 2023
1 parent a55b268 commit ae21199
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ jobs:
--build_dir build_qnn \
--android_sdk_path $ANDROID_HOME \
--android_ndk_path $ANDROID_NDK_HOME \
--android_abi=arm64-v8a \
--android_api=30 \
--android_abi=x86_64 \
--android_api=31 \
--parallel \
--use_qnn \
--qnn_home $(QNN_SDK_ROOT) \
Expand All @@ -85,48 +85,36 @@ jobs:
- script: |
mkdir -p build_qnn/Release/testdata/QNN/node_tests
cp -r cmake/external/onnx//onnx/backend/test/data/node/test_basic_conv_with_padding build_qnn/Release/testdata/QNN/node_tests
cp -r cmake/external/onnx/onnx/backend/test/data/node/test_basic_conv_with_padding build_qnn/Release/testdata/QNN/node_tests
displayName: Initialize test directories
- task: JavaToolInstaller@0
displayName: Use jdk 8
displayName: Use jdk 11
inputs:
versionSpec: '8'
versionSpec: '11'
jdkArchitectureOption: 'x64'
jdkSourceOption: 'PreInstalled'

- script: |
python3 tools/python/run_android_emulator.py \
--android-sdk-root ${ANDROID_SDK_ROOT} \
--create-avd --system-image "system-images;android-30;google_apis;arm64-v8a" \
--start --emulator-extra-args="-partition-size 4096" \
--emulator-pid-file $(Build.BinariesDirectory)/emulator.pid
displayName: Start Android emulator
enabled: false
continueOnError: true
# This is commented out for now. The emulator runs correctly, onnx_test_runner is executable, and the test passes
# with the CPU EP but returns 139 when attempting to use the QNN EP. Maybe some QNN EP parameters need to be provided?
#
# - template: templates/use-android-emulator.yml
# parameters:
# create: true
# start: true

- script: |
$ANDROID_SDK_ROOT/emulator/emulator -list-avds
displayName: List emulators
# - task: CmdLine@2
# inputs:
# script: |
# set -e -x
# ${ANDROID_SDK_ROOT}/platform-tools/adb push onnx_test_runner /data/local/tmp/
# ${ANDROID_SDK_ROOT}/platform-tools/adb push testdata/QNN/node_tests/test_basic_conv_with_padding /data/local/tmp/
# ${ANDROID_SDK_ROOT}/platform-tools/adb shell "chmod +x /data/local/tmp/onnx_test_runner"
# ${ANDROID_SDK_ROOT}/platform-tools/adb shell "/data/local/tmp/onnx_test_runner -v /data/local/tmp/test_basic_conv_with_padding"
# ${ANDROID_SDK_ROOT}/platform-tools/adb shell "/data/local/tmp/onnx_test_runner -v -e qnn /data/local/tmp/test_basic_conv_with_padding"
# workingDirectory: build_qnn/Release
# displayName: Run test_basic_conv_with_padding on emulator

- task: CmdLine@2
inputs:
script: |
${ANDROID_SDK_ROOT}/platform-tools/adb shell "mkdir /data/local/tmp/qnn"
${ANDROID_SDK_ROOT}/platform-tools/adb push onnx_test_runner /data/local/tmp/qnn
${ANDROID_SDK_ROOT}/platform-tools/adb push testdata/QNN/node_tests/test_basic_conv_with_padding /data/local/tmp/qnn
${ANDROID_SDK_ROOT}/platform-tools/adb shell "/data/local/tmp/qnn/onnx_test_runner -e qnn /data/local/tmp/qnn/test_basic_conv_with_padding"
workingDirectory: build_qnn/Release
displayName: Run tests
enabled: false
continueOnError: true

- script: |
python3 tools/python/run_android_emulator.py \
--android-sdk-root ${ANDROID_SDK_ROOT} \
--stop \
--emulator-pid-file $(Build.BinariesDirectory)/emulator.pid
displayName: Stop Android emulator
condition: always()
enabled: false
continueOnError: true
# - template: templates/use-android-emulator.yml
# parameters:
# stop: true
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,10 @@ stages:

- template: "templates/use-android-ndk.yml"

- script: |
python3 tools/python/run_android_emulator.py \
--android-sdk-root ${ANDROID_SDK_ROOT} \
--create-avd --system-image "system-images;android-31;default;x86_64" \
--start --emulator-extra-args="-partition-size 4096" \
--emulator-pid-file $(Build.BinariesDirectory)/emulator.pid
displayName: Start Android emulator
- template: templates/use-android-emulator.yml
parameters:
create: true
start: true

- script: |
python3 tools/ci_build/build.py \
Expand All @@ -277,13 +274,9 @@ stages:
--test
displayName: CPU EP, Test on Android Emulator
- script: |
python3 tools/python/run_android_emulator.py \
--android-sdk-root ${ANDROID_SDK_ROOT} \
--stop \
--emulator-pid-file $(Build.BinariesDirectory)/emulator.pid
displayName: Stop Android emulator
condition: always()
- template: templates/use-android-emulator.yml
parameters:
stop: true

- template: templates/clean-agent-build-directory-step.yml

Expand Down Expand Up @@ -329,13 +322,10 @@ stages:

- template: "templates/use-android-ndk.yml"

- script: |
python3 tools/python/run_android_emulator.py \
--android-sdk-root ${ANDROID_SDK_ROOT} \
--create-avd --system-image "system-images;android-31;default;x86_64" \
--start --emulator-extra-args="-partition-size 4096" \
--emulator-pid-file $(Build.BinariesDirectory)/emulator.pid
displayName: Start Android emulator
- template: templates/use-android-emulator.yml
parameters:
create: true
start: true

- script: |
python3 tools/ci_build/build.py \
Expand All @@ -358,13 +348,10 @@ stages:
# Build Minimal ORT with NNAPI and reduced Ops, run unit tests on Android Emulator
displayName: Build Minimal ORT with NNAPI and run tests

- script: |
python3 tools/python/run_android_emulator.py \
--android-sdk-root ${ANDROID_SDK_ROOT} \
--stop \
--emulator-pid-file $(Build.BinariesDirectory)/emulator.pid
displayName: Stop Android emulator
condition: always()
- template: templates/use-android-emulator.yml
parameters:
stop: true

- template: templates/clean-agent-build-directory-step.yml

- stage: MASTER_BUILD_STAGE
Expand Down Expand Up @@ -415,13 +402,10 @@ stages:
$(Build.SourcesDirectory)/protobuf_install
displayName: Build Host Protoc
- script: |
python3 tools/python/run_android_emulator.py \
--android-sdk-root ${ANDROID_SDK_ROOT} \
--create-avd --system-image "system-images;android-31;default;x86_64" \
--start --emulator-extra-args="-partition-size 4096" \
--emulator-pid-file $(Build.BinariesDirectory)/emulator.pid
displayName: Start Android emulator
- template: templates/use-android-emulator.yml
parameters:
create: true
start: true

- script: |
python3 tools/ci_build/build.py \
Expand Down Expand Up @@ -460,13 +444,10 @@ stages:
# Build Minimal ORT with NNAPI and reduced Ops, run unit tests on Android Emulator
displayName: Build Minimal ORT with NNAPI and run tests

- script: |
python3 tools/python/run_android_emulator.py \
--android-sdk-root ${ANDROID_SDK_ROOT} \
--stop \
--emulator-pid-file $(Build.BinariesDirectory)/emulator.pid
displayName: Stop Android emulator
condition: always()
- template: templates/use-android-emulator.yml
parameters:
stop: true

- template: templates/clean-agent-build-directory-step.yml

- job: Update_Dashboard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,10 @@ jobs:

- template: install-appcenter.yml

- script: |
python3 $(Build.SourcesDirectory)/tools/python/run_android_emulator.py \
--android-sdk-root ${ANDROID_SDK_ROOT} \
--create-avd --system-image "system-images;android-31;default;x86_64" \
--start --emulator-extra-args="-partition-size 4096" \
--emulator-pid-file $(Build.BinariesDirectory)/emulator.pid
displayName: Start Android emulator
- template: use-android-emulator.yml
parameters:
create: true
start: true

- script: |
set -e -x
Expand All @@ -70,6 +67,10 @@ jobs:
displayName: Run E2E test using Emulator
workingDirectory: $(Build.BinariesDirectory)
- template: use-android-emulator.yml
parameters:
stop: true

- script: |
set -e -x
cd android_test/android
Expand All @@ -84,14 +85,6 @@ jobs:
displayName: Run E2E tests using App Center
workingDirectory: $(Build.BinariesDirectory)
- script: |
python3 $(Build.SourcesDirectory)/tools/python/run_android_emulator.py \
--android-sdk-root ${ANDROID_SDK_ROOT} \
--stop \
--emulator-pid-file $(Build.BinariesDirectory)/emulator.pid
displayName: Stop Android emulator
condition: always()
- template: component-governance-component-detection-steps.yml
parameters :
condition : 'succeeded'
Expand Down
Loading

0 comments on commit ae21199

Please sign in to comment.