37 lines · 2.4 KB · ShellRaw
#!/usr/bin/env bashset -euo pipefailADB="${ADB:-adb}"PACKAGE="com.cottondb.cotton"RUNNER="androidx.test.runner.AndroidJUnitRunner"TEST_CLASS="com.cottondb.android.ui.meetings.recording.MeetingProcessDeathRecoveryTest#forceStoppedRecordingRepairsAndFilesExactPcmPayloadThroughPublicCore"FIXTURE="$(python3 -c 'import uuid; print(uuid.uuid4())')"ROOT="no_backup/meeting-process-death/${FIXTURE}"mapfile -t DEVICES < <("$ADB" devices | awk 'NR > 1 && $2 == "device" { print $1 }')[[ ${#DEVICES[@]} -eq 1 ]] || { echo "Need exactly one attached emulator/device; found ${#DEVICES[@]}." >&2; exit 2; }SERIAL="${DEVICES[0]}"[[ "$SERIAL" == emulator-* ]] || { echo "Use the dedicated Android emulator." >&2; exit 2; }a() { "$ADB" -s "$SERIAL" "$@"; }a shell pm path "$PACKAGE" >/dev/null || { echo "Install the debug APK first; this harness does not build or install it." >&2; exit 2; }a shell pm path "${PACKAGE}.test" >/dev/null || { echo "Install the test APK first; this harness does not build or install it." >&2; exit 2; }for permission in android.permission.RECORD_AUDIO android.permission.POST_NOTIFICATIONS; do a shell pm grant "$PACKAGE" "$permission"; done# Exact fixture-owned cleanup only; no database path is read or removed.cleanup() { a shell am force-stop "$PACKAGE" >/dev/null 2>&1 || true; a shell run-as "$PACKAGE" rm -rf "$ROOT" >/dev/null 2>&1 || true; }trap cleanup EXITa shell am start -W -n "$PACKAGE/com.cottondb.android.ui.meetings.recording.MeetingProcessDeathHarnessActivity" -a com.cottondb.android.meeting.processdeath.RECORD --es fixture "$FIXTURE" >/dev/nullfor _ in $(seq 1 100); do phase="$(a shell run-as "$PACKAGE" cat "$ROOT/diagnostic.json" 2>/dev/null || true)" [[ "$phase" == *'"phase":"recording"'* ]] && break [[ "$phase" == *'"phase":"failed"'* ]] && { echo "$phase" >&2; exit 1; } sleep 0.2done[[ "${phase:-}" == *'"phase":"recording"'* ]] || { echo "Recorder did not reach a positive PCM payload." >&2; exit 1; }# This is the deliberate process-death boundary; the first process and its live FGS are gone here.a shell am force-stop "$PACKAGE"set +eRESULT="$(a shell am instrument -w -e class "$TEST_CLASS" -e fixture "$FIXTURE" -e runProcessDeath true "$PACKAGE.test/$RUNNER" 2>&1)"STATUS=$?set -eprintf '%s\n' "$RESULT"[[ $STATUS -eq 0 && "$RESULT" == *"OK (1 test)"* ]] || { echo "Recovery instrumentation failed." >&2; exit 1; }