onnxruntime/tools/ci_build/github/azure-pipelines/templates/use-android-emulator.yml
Scott McKay ae211999dd
Attempt to make the usage of the Android emulator in CIs more robust (#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 <18449977+edgchen1@users.noreply.github.com>
2023-10-15 08:42:36 +10:00

64 lines
2 KiB
YAML

# Android Emulator helpers
parameters:
- name: create
type: boolean
default: false
- name: start
type: boolean
default: false
- name: stop
type: boolean
default: false
steps:
- ${{ if eq(parameters.create, true) }}:
- script: |
set -e -x
python3 tools/python/run_android_emulator.py \
--android-sdk-root $(ANDROID_SDK_ROOT) \
--create-avd --system-image "system-images;android-31;default;x86_64"
displayName: Create Android Emulator
- ${{ if eq(parameters.start, true) }}:
- script: |
if test -f $(Build.BinariesDirectory)/emulator.pid; then
echo "Emulator PID file was not expected to exist but does and has pid:" \
`cat $(Build.BinariesDirectory)/emulator.pid`
exit 1
fi
displayName: Check emulator.pid does not exist
# Add -verbose to --emulator-extra-args to enable additional logging.
- script: |
set -e -x
python3 tools/python/run_android_emulator.py \
--android-sdk-root $(ANDROID_SDK_ROOT) \
--start --emulator-extra-args="-partition-size 2047" \
--emulator-pid-file $(Build.BinariesDirectory)/emulator.pid
echo "Emulator PID:"`cat $(Build.BinariesDirectory)/emulator.pid`
displayName: Start Android Emulator
- ${{ if eq(parameters.stop, true) }}:
- script: |
set -e -x
python3 -m pip install psutil
displayName: Install psutil for emulator shutdown by run_android_emulator.py
condition: always()
- script: |
set -e -x
if test -f $(Build.BinariesDirectory)/emulator.pid; then
echo "Emulator PID:"`cat $(Build.BinariesDirectory)/emulator.pid`
python3 tools/python/run_android_emulator.py \
--android-sdk-root $(ANDROID_SDK_ROOT) \
--stop \
--emulator-pid-file $(Build.BinariesDirectory)/emulator.pid
rm $(Build.BinariesDirectory)/emulator.pid
else
echo "Emulator PID file was expected to exist but does not."
fi
displayName: Stop Android Emulator
condition: always()