Skip to content

Commit d479acb

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

File tree

2 files changed

+102
-40
lines changed

2 files changed

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

0 commit comments

Comments
 (0)