Skip to content

Commit ecac46a

Browse files
committed
Add options for native/jvm crash
1 parent 1396cec commit ecac46a

File tree

2 files changed

+110
-39
lines changed

2 files changed

+110
-39
lines changed
Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Gradle Test App Random Native Crashes
1+
name: Trigger Android Crash Test Loop E2E test
22

33
on:
44
workflow_dispatch:
@@ -11,8 +11,10 @@ on:
1111

1212
jobs:
1313
run_random_native_crashes:
14+
name: Android gradle-test-app crash loop test
1415
runs-on: ubuntu-latest-8-cores
1516
env:
17+
CRASH_LOOP_API_KEY: ${{ secrets.CRASH_LOOP_API_KEY }}
1618
SKIP_PROTO_GEN: 1
1719
steps:
1820
- name: Checkout project sources
@@ -23,53 +25,23 @@ jobs:
2325
with:
2426
setup-emulator: 'true'
2527

26-
- name: AVD cache
27-
uses: actions/cache@v4
28-
id: avd-cache
29-
with:
30-
path: |
31-
~/.android/avd/*
32-
~/.android/adb*
33-
key: ${{ runner.os }}-avd-api-23-random-native-crashes-v1
34-
35-
- name: Create AVD and generate snapshot for caching
36-
if: steps.avd-cache.outputs.cache-hit != 'true'
37-
timeout-minutes: 30
38-
uses: reactivecircus/android-emulator-runner@b530d96654c385303d652368551fb075bc2f0b6b
39-
with:
40-
channel: stable
41-
force-avd-creation: false
42-
api-level: 23
43-
target: default
44-
ram-size: 2048M
45-
arch: x86_64
46-
disk-size: 6144M
47-
profile: Nexus 6
48-
disable-animations: true
49-
emulator-options: -no-window -accel on -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
50-
script: echo "Generated AVD snapshot for caching."
28+
- name: Build gradle-test-app debug APK
29+
timeout-minutes: 45
30+
run: ./tools/android_sdk_wrapper.sh platform/jvm/gradlew -Prust-target=x86_64 -PskipGradleTestAppLintOnAssemble=true -p platform/jvm gradle-test-app:assembleDebug --stacktrace
5131

5232
- name: Run random native crashes
5333
timeout-minutes: 360
5434
uses: reactivecircus/android-emulator-runner@b530d96654c385303d652368551fb075bc2f0b6b
5535
with:
36+
avd-name: android-gradle-test-app-crash-loop-test
5637
channel: stable
5738
force-avd-creation: false
58-
api-level: 23
59-
target: default
39+
api-level: 31
40+
target: google_apis
6041
ram-size: 2048M
6142
arch: x86_64
6243
disk-size: 6144M
6344
profile: Nexus 6
6445
disable-animations: true
65-
emulator-options: -no-snapshot-save -no-window -accel on -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
66-
script: |
67-
ITERATIONS="${{ github.event.inputs.iterations || '5000' }}"
68-
if ! [[ "$ITERATIONS" =~ ^[0-9]+$ ]] || [[ "$ITERATIONS" -lt 1 ]]; then
69-
echo "iterations must be a positive integer"
70-
exit 1
71-
fi
72-
curl -Ls "https://get.maestro.mobile.dev" | bash
73-
export PATH="$PATH:$HOME/.maestro/bin"
74-
./tools/android_sdk_wrapper.sh platform/jvm/gradlew -Prust-target=x86_64 -p platform/jvm gradle-test-app:assembleDebug gradle-test-app:installDebug --stacktrace
75-
ITERATIONS="$ITERATIONS" maestro test tools/maestro/native-crash-loop.yaml
46+
emulator-options: -no-snapshot-save -no-window -accel on -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -no-metrics
47+
script: bash ./ci/run_gradle_test_app_random_native_crashes.sh "${{ github.event.inputs.iterations }}"
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
readonly iterations="${1:-5000}"
6+
readonly emulator_serial="${ANDROID_SERIAL:-emulator-5554}"
7+
readonly crash_loop_api_key="${CRASH_LOOP_API_KEY:-}"
8+
readonly shared_prefs_path="shared_prefs/io.bitdrift.gradletestapp_preferences.xml"
9+
readonly apk_path="platform/jvm/gradle-test-app/build/outputs/apk/debug/gradle-test-app-debug.apk"
10+
readonly maestro_flow="tools/maestro/native-crash-loop.yaml"
11+
readonly maestro_retries=3
12+
13+
if ! [[ "$iterations" =~ ^[0-9]+$ ]] || [[ "$iterations" -lt 1 ]]; then
14+
echo "iterations must be a positive integer"
15+
exit 1
16+
fi
17+
18+
if [[ -z "$crash_loop_api_key" ]]; then
19+
echo "CRASH_LOOP_API_KEY must be set"
20+
exit 1
21+
fi
22+
23+
if [[ ! -f "$apk_path" ]]; then
24+
echo "Expected APK not found at $apk_path"
25+
exit 1
26+
fi
27+
28+
wait_for_emulator_ready() {
29+
adb -s "$emulator_serial" wait-for-device
30+
31+
for _ in $(seq 1 45); do
32+
local sys_boot_completed
33+
local dev_boot_completed
34+
local boot_anim
35+
36+
sys_boot_completed="$(adb -s "$emulator_serial" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')"
37+
dev_boot_completed="$(adb -s "$emulator_serial" shell getprop dev.bootcomplete 2>/dev/null | tr -d '\r')"
38+
boot_anim="$(adb -s "$emulator_serial" shell getprop init.svc.bootanim 2>/dev/null | tr -d '\r')"
39+
40+
if [[ "$sys_boot_completed" == "1" ]] &&
41+
[[ "$dev_boot_completed" == "1" ]] &&
42+
[[ "$boot_anim" == "stopped" ]] &&
43+
adb -s "$emulator_serial" shell cmd package list packages >/dev/null 2>&1; then
44+
return 0
45+
fi
46+
47+
adb reconnect offline >/dev/null 2>&1 || true
48+
sleep 2
49+
done
50+
51+
echo "Timed out waiting for emulator package manager readiness"
52+
return 1
53+
}
54+
55+
seed_gradle_test_app_settings() {
56+
local escaped_api_key
57+
local prefs_xml
58+
59+
escaped_api_key="$(printf '%s' "$crash_loop_api_key" | sed -e 's/&/\&amp;/g' -e 's/"/\&quot;/g' -e "s/'/\\&apos;/g" -e 's/</\&lt;/g' -e 's/>/\&gt;/g')"
60+
prefs_xml="$(cat <<EOF
61+
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
62+
<map>
63+
<string name='apiUrl'>https://api.bitdrift.dev</string>
64+
<string name='api_key'>$escaped_api_key</string>
65+
</map>
66+
EOF
67+
)"
68+
69+
printf '%s' "$prefs_xml" | adb -s "$emulator_serial" shell "run-as io.bitdrift.gradletestapp sh -c 'mkdir -p shared_prefs && cat > $shared_prefs_path'"
70+
}
71+
72+
curl -Ls "https://get.maestro.mobile.dev" | bash
73+
export PATH="$PATH:$HOME/.maestro/bin"
74+
export MAESTRO_CLI_NO_ANALYTICS=1
75+
export ANDROID_SERIAL="$emulator_serial"
76+
77+
adb start-server
78+
wait_for_emulator_ready
79+
adb -s "$emulator_serial" install -r "$apk_path"
80+
adb -s "$emulator_serial" shell input keyevent 82 >/dev/null 2>&1 || true
81+
seed_gradle_test_app_settings
82+
83+
for attempt in $(seq 1 "$maestro_retries"); do
84+
echo "Running Maestro attempt $attempt/$maestro_retries"
85+
86+
if maestro test -e ITERATIONS="$iterations" "$maestro_flow"; then
87+
exit 0
88+
fi
89+
90+
if [[ "$attempt" -eq "$maestro_retries" ]]; then
91+
exit 1
92+
fi
93+
94+
echo "Maestro failed, restarting adb before retry"
95+
adb kill-server || true
96+
adb start-server
97+
wait_for_emulator_ready
98+
seed_gradle_test_app_settings
99+
done

0 commit comments

Comments
 (0)