|
| 1 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# This source code is licensed under the BSD-style license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | + |
| 7 | +name: Android Emulator Tests |
| 8 | + |
| 9 | +on: |
| 10 | + pull_request: |
| 11 | + branches: [main] |
| 12 | + paths: |
| 13 | + - 'dl3/android/**' |
| 14 | + - 'mv3/android/**' |
| 15 | + - '.github/workflows/android-emulator.yml' |
| 16 | + workflow_dispatch: |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + |
| 21 | +jobs: |
| 22 | + instrumentation-test: |
| 23 | + runs-on: 8-core-ubuntu |
| 24 | + strategy: |
| 25 | + fail-fast: false |
| 26 | + matrix: |
| 27 | + demo: |
| 28 | + - path: 'dl3/android/DeepLabV3Demo' |
| 29 | + name: 'DeepLabV3Demo' |
| 30 | + - path: 'mv3/android/MV3Demo' |
| 31 | + name: 'MV3Demo' |
| 32 | + env: |
| 33 | + API_LEVEL: 34 |
| 34 | + ARCH: x86_64 |
| 35 | + DEMO_PATH: ${{ matrix.demo.path }} |
| 36 | + |
| 37 | + name: Instrumentation Test ${{ matrix.demo.name }} |
| 38 | + steps: |
| 39 | + - name: Checkout repository |
| 40 | + uses: actions/checkout@v4 |
| 41 | + |
| 42 | + - name: Determine demo name |
| 43 | + id: demo-info |
| 44 | + run: | |
| 45 | + DEMO_NAME=$(basename "${{ env.DEMO_PATH }}") |
| 46 | + echo "demo_name=$DEMO_NAME" >> $GITHUB_OUTPUT |
| 47 | + echo "Testing: $DEMO_NAME" |
| 48 | + echo "=== Test Configuration ===" |
| 49 | + echo "Demo: $DEMO_NAME" |
| 50 | + echo "Model will be downloaded by the test if not present" |
| 51 | +
|
| 52 | + - name: Enable KVM group perms |
| 53 | + run: | |
| 54 | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules |
| 55 | + sudo udevadm control --reload-rules |
| 56 | + sudo udevadm trigger --name-match=kvm |
| 57 | +
|
| 58 | + - name: Set up JDK 17 |
| 59 | + uses: actions/setup-java@v4 |
| 60 | + with: |
| 61 | + java-version: '17' |
| 62 | + distribution: 'temurin' |
| 63 | + |
| 64 | + - name: Setup Gradle |
| 65 | + uses: gradle/actions/setup-gradle@v4 |
| 66 | + |
| 67 | + - name: AVD cache |
| 68 | + uses: actions/cache@v4 |
| 69 | + id: avd-cache |
| 70 | + with: |
| 71 | + path: | |
| 72 | + ~/.android/avd/* |
| 73 | + ~/.android/adb* |
| 74 | + key: avd-${{ env.API_LEVEL }}-${{ env.ARCH }}-ram8G-disk8G-${{ steps.demo-info.outputs.demo_name }}-v1 |
| 75 | + |
| 76 | + - name: Create AVD and generate snapshot for caching |
| 77 | + if: steps.avd-cache.outputs.cache-hit != 'true' |
| 78 | + uses: reactivecircus/android-emulator-runner@v2 |
| 79 | + with: |
| 80 | + api-level: ${{ env.API_LEVEL }} |
| 81 | + arch: ${{ env.ARCH }} |
| 82 | + ram-size: 8192M |
| 83 | + disk-size: 8192M |
| 84 | + force-avd-creation: true |
| 85 | + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -no-snapshot-save -memory 8192 |
| 86 | + disable-animations: false |
| 87 | + working-directory: ${{ env.DEMO_PATH }} |
| 88 | + script: echo "Generated AVD snapshot for caching." |
| 89 | + |
| 90 | + - name: Run instrumentation tests |
| 91 | + uses: reactivecircus/android-emulator-runner@v2 |
| 92 | + with: |
| 93 | + api-level: ${{ env.API_LEVEL }} |
| 94 | + arch: ${{ env.ARCH }} |
| 95 | + ram-size: 8192M |
| 96 | + disk-size: 8192M |
| 97 | + force-avd-creation: true |
| 98 | + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -no-snapshot-save -memory 8192 |
| 99 | + disable-animations: true |
| 100 | + working-directory: ${{ env.DEMO_PATH }} |
| 101 | + script: | |
| 102 | + set -ex |
| 103 | + DEMO_NAME=$(basename "$PWD") |
| 104 | + LOGCAT_FILE="/tmp/logcat-${DEMO_NAME}.txt" |
| 105 | + echo "=== Emulator Memory Info ===" |
| 106 | + adb shell cat /proc/meminfo | head -5 |
| 107 | + echo "=== Emulator Disk Space ===" |
| 108 | + adb shell df -h /data |
| 109 | + adb logcat -c |
| 110 | + adb logcat > "$LOGCAT_FILE" & |
| 111 | + LOGCAT_PID=$! |
| 112 | + echo "=== Starting Gradle ===" |
| 113 | + ./gradlew connectedCheck |
| 114 | + TEST_EXIT_CODE=$? |
| 115 | + if [ -n "$LOGCAT_PID" ]; then kill $LOGCAT_PID 2>/dev/null || true; fi |
| 116 | + echo "=== Test completion status ===" |
| 117 | + if [ $TEST_EXIT_CODE -eq 0 ]; then echo "✅ Tests passed successfully"; else echo "❌ Tests failed with exit code $TEST_EXIT_CODE"; fi |
| 118 | + echo "=== Checking for test results in logcat ===" |
| 119 | + grep -E "SanityCheck|UIWorkflowTest" "$LOGCAT_FILE" || echo "No test logs found" |
| 120 | + exit $TEST_EXIT_CODE |
| 121 | +
|
| 122 | + - name: Upload logcat |
| 123 | + if: always() |
| 124 | + uses: actions/upload-artifact@v4 |
| 125 | + with: |
| 126 | + name: logcat-${{ steps.demo-info.outputs.demo_name }} |
| 127 | + path: /tmp/logcat-*.txt |
| 128 | + retention-days: 7 |
0 commit comments