Make avd_test less flaky

This commit is contained in:
topjohnwu
2023-10-24 16:45:24 -07:00
parent 985454afd4
commit d2f2a9e4c8
2 changed files with 18 additions and 14 deletions

View File

@ -92,11 +92,24 @@ wait_emu() {
timeout $boot_timeout bash -c $wait_fn &
local wait_pid=$!
# Handle the case when emulator dies earlier than wait
# Handle the case when emulator dies earlier than timeout
wait -p which_pid -n $emu_pid $wait_pid
[ $which_pid -eq $wait_pid ]
}
run_content_cmd() {
while true; do
local out=$(adb shell echo "'content call --uri content://com.topjohnwu.magisk.provider --method $1'" \| /system/xbin/su | tee /dev/fd/2)
if ! grep -q 'Bundle\[' <<< "$out"; then
# The call failed, wait a while and retry later
sleep 30
else
grep -q 'result=true' <<< "$out"
return $?
fi
done
}
test_emu() {
local variant=$1
@ -110,17 +123,14 @@ test_emu() {
# Install the Magisk app
adb install -r -g out/app-${variant}.apk
adb shell appops set com.topjohnwu.magisk REQUEST_INSTALL_PACKAGES allow
# Use the app to run setup and reboot
adb shell echo "'content call --uri content://com.topjohnwu.magisk.provider --method setup'" \| /system/xbin/su \
| tee /dev/fd/2 | grep -q 'result=true'
run_content_cmd setup
adb reboot
wait_emu wait_for_boot
# Run app tests
adb shell echo "'content call --uri content://com.topjohnwu.magisk.provider --method test'" \| /system/xbin/su \
| tee /dev/fd/2 | grep -q 'result=true'
run_content_cmd test
adb shell echo "'su -c id'" \| /system/xbin/su 2000 | tee /dev/fd/2 | grep -q 'uid=0'
}