mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-12 21:27:41 +02:00
Add application and Zygisk tests to avd_test.sh
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
emu="$ANDROID_SDK_ROOT/emulator/emulator"
|
||||
avd="$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager"
|
||||
sdk="$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager"
|
||||
emu_args='-no-window -gpu swiftshader_indirect -read-only -no-snapshot -noaudio -no-boot-anim -show-kernel'
|
||||
emu_args='-no-window -gpu swiftshader_indirect -read-only -no-snapshot -no-audio -no-boot-anim -show-kernel'
|
||||
boot_timeout=600
|
||||
emu_pid=
|
||||
|
||||
@ -20,8 +20,16 @@ type='google_apis'
|
||||
|
||||
api_list='23 26 28 29 34'
|
||||
|
||||
print_title() {
|
||||
echo -e "\n\033[44;39m${1}\033[0m\n"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "\n\033[41;39m${1}\033[0m\n"
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
echo -e '\n\033[41;39m! An error occurred\033[0m\n'
|
||||
print_error "! An error occurred when testing $pkg"
|
||||
|
||||
for api in $api_list; do
|
||||
set_api_env $api
|
||||
@ -77,16 +85,43 @@ restore_avd() {
|
||||
fi
|
||||
}
|
||||
|
||||
test_emu() {
|
||||
"$emu" @test $emu_args &
|
||||
emu_pid=$!
|
||||
timeout $boot_timeout bash -c wait_for_boot &
|
||||
wait_emu() {
|
||||
local wait_fn=$1
|
||||
local which_pid
|
||||
|
||||
timeout $boot_timeout bash -c $wait_fn &
|
||||
local wait_pid=$!
|
||||
|
||||
# Handle the case when emulator dies with error
|
||||
wait -n $emu_pid $wait_pid
|
||||
# Handle the case when emulator dies earlier than wait
|
||||
wait -p which_pid -n $emu_pid $wait_pid
|
||||
[ $which_pid -eq $wait_pid ]
|
||||
}
|
||||
|
||||
test_emu() {
|
||||
local variant=$1
|
||||
|
||||
print_title "* Testing $pkg ($variant)"
|
||||
|
||||
"$emu" @test $emu_args &
|
||||
emu_pid=$!
|
||||
wait_emu wait_for_boot
|
||||
|
||||
adb shell magisk -v
|
||||
|
||||
# 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'
|
||||
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'
|
||||
adb shell echo "'su -c id'" \| /system/xbin/su 2000 | tee /dev/fd/2 | grep -q 'uid=0'
|
||||
}
|
||||
|
||||
|
||||
@ -96,27 +131,27 @@ run_test() {
|
||||
set_api_env $api
|
||||
|
||||
# Setup emulator
|
||||
echo -e "\n\033[44;39m* Testing $pkg\033[0m\n"
|
||||
"$sdk" $pkg
|
||||
echo no | "$avd" create avd -f -n test -k $pkg
|
||||
|
||||
# Launch stock emulator
|
||||
print_title "* Launching $pkg"
|
||||
restore_avd
|
||||
"$emu" @test $emu_args &
|
||||
emu_pid=$!
|
||||
timeout $boot_timeout bash -c wait_for_bootanim
|
||||
wait_emu wait_for_bootanim
|
||||
|
||||
# Patch and test debug build
|
||||
./build.py avd_patch -s "$ramdisk"
|
||||
kill -INT $emu_pid
|
||||
wait $emu_pid
|
||||
test_emu
|
||||
test_emu debug
|
||||
|
||||
# Re-patch and test release build
|
||||
./build.py -r avd_patch -s "$ramdisk"
|
||||
kill -INT $emu_pid
|
||||
wait $emu_pid
|
||||
test_emu
|
||||
test_emu release
|
||||
|
||||
# Cleanup
|
||||
kill -INT $emu_pid
|
||||
|
Reference in New Issue
Block a user