Magisk/scripts/avd_test.sh

230 lines
4.8 KiB
Bash
Raw Normal View History

2022-03-18 11:56:19 +00:00
#!/usr/bin/env bash
set -xe
. scripts/test_common.sh
2024-06-21 09:45:48 +00:00
emu_args_base='-no-window -no-audio -no-boot-anim -gpu swiftshader_indirect -read-only -no-snapshot'
2023-11-16 22:29:45 +00:00
lsposed_url='https://github.com/LSPosed/LSPosed/releases/download/v1.9.2/LSPosed-v1.9.2-7024-zygisk-release.zip'
2023-10-12 05:42:45 +00:00
emu_pid=
2022-03-18 11:56:19 +00:00
2023-11-16 22:29:45 +00:00
atd_min_api=30
2023-12-08 09:59:24 +00:00
atd_max_api=34
2023-11-16 22:29:45 +00:00
lsposed_min_api=27
2024-01-28 08:46:03 +00:00
huge_ram_min_api=26
2022-09-16 02:45:58 +00:00
cleanup() {
print_error "! An error occurred when testing $pkg"
2022-09-16 02:45:58 +00:00
rm -f magisk_patched.img
2022-09-16 02:45:58 +00:00
"$avd" delete avd -n test
2023-05-10 06:11:11 +00:00
pkill -INT -P $$
wait
2023-10-12 05:42:45 +00:00
trap - EXIT
exit 1
}
wait_for_bootanim() {
adb wait-for-device
while true; do
local result="$(adb exec-out getprop init.svc.bootanim)"
if [ $? -ne 0 ]; then
exit 1
elif [ "$result" = "stopped" ]; then
break
fi
sleep 2
done
2022-09-16 02:45:58 +00:00
}
2022-03-18 11:56:19 +00:00
wait_for_boot() {
2023-05-10 06:11:11 +00:00
adb wait-for-device
2022-03-18 11:56:19 +00:00
while true; do
2023-10-12 05:42:45 +00:00
local result="$(adb exec-out getprop sys.boot_completed)"
if [ $? -ne 0 ]; then
exit 1
elif [ "$result" = "1" ]; then
2022-03-18 11:56:19 +00:00
break
fi
sleep 2
done
}
wait_emu() {
local wait_fn=$1
local which_pid
timeout $boot_timeout bash -c $wait_fn &
local wait_pid=$!
2023-10-24 23:45:24 +00:00
# Handle the case when emulator dies earlier than timeout
wait -p which_pid -n $emu_pid $wait_pid
[ $which_pid -eq $wait_pid ]
}
2023-10-12 05:42:45 +00:00
test_emu() {
local variant=$1
2023-11-16 22:29:45 +00:00
local api=$2
print_title "* Testing $pkg ($variant)"
2024-06-21 09:45:48 +00:00
if [ -n "$AVD_TEST_VERBOSE" ]; then
"$emu" @test $emu_args &
emu_pid=$!
adb logcat &
else
"$emu" @test $emu_args 2>/dev/null &
emu_pid=$!
fi
wait_emu wait_for_boot
2023-10-12 05:42:45 +00:00
2024-07-20 10:10:18 +00:00
test_setup $variant
2023-11-16 22:29:45 +00:00
# Install LSPosed
if [ $api -ge $lsposed_min_api -a $api -le $atd_max_api ]; then
adb push out/lsposed.zip /data/local/tmp/lsposed.zip
2024-07-20 11:52:25 +00:00
echo 'PATH=$PATH:/debug_ramdisk magisk --install-module /data/local/tmp/lsposed.zip' | adb shell /system/xbin/su
2023-11-16 22:29:45 +00:00
fi
adb reboot
2024-06-21 09:45:48 +00:00
if [ -n "$AVD_TEST_VERBOSE" ]; then
adb logcat &
fi
wait_emu wait_for_boot
2024-07-20 10:10:18 +00:00
test_app
2023-11-16 22:29:45 +00:00
# Try to launch LSPosed
if [ $api -ge $lsposed_min_api -a $api -le $atd_max_api ]; then
2023-12-11 12:32:33 +00:00
adb shell rm -f /data/local/tmp/window_dump.xml
2023-11-16 22:29:45 +00:00
adb shell am start -c org.lsposed.manager.LAUNCH_MANAGER com.android.shell/.BugreportWarningActivity
2023-12-11 12:32:33 +00:00
while adb shell '[ ! -f /data/local/tmp/window_dump.xml ]'; do
sleep 10
adb shell uiautomator dump /data/local/tmp/window_dump.xml
done
adb shell grep -q org.lsposed.manager /data/local/tmp/window_dump.xml
2023-11-16 22:29:45 +00:00
fi
2023-10-12 05:42:45 +00:00
}
2022-09-16 02:45:58 +00:00
run_test() {
2024-06-21 01:25:49 +00:00
local ver=$1
local type=$2
# Determine API level
local api
case $ver in
[0-9]*) api=$ver ;;
TiramisuPrivacySandbox) api=33 ;;
UpsideDownCakePrivacySandbox) api=34 ;;
VanillaIceCream) api=35 ;;
*)
print_error "! Unknown system image version '$ver'"
exit 1
;;
esac
# Determine image type
if [ -z $type ]; then
if [ $api -ge $atd_min_api -a $api -le $atd_max_api ]; then
# Use the lightweight ATD images if possible
type='aosp_atd'
else
type='default'
fi
fi
# System image variable and paths
local pkg="system-images;android-$ver;$type;$arch"
local sys_img_dir="$ANDROID_HOME/system-images/android-$ver/$type/$arch"
local ramdisk="$sys_img_dir/ramdisk.img"
2024-06-21 01:25:49 +00:00
# Old Linux kernels will not boot with memory larger than 3GB
local memory
if [ $api -lt $huge_ram_min_api ]; then
memory=3072
else
memory=8192
fi
2023-05-10 06:11:11 +00:00
2024-06-21 09:45:48 +00:00
emu_args="$emu_args_base -memory $memory"
if [ -n "$AVD_TEST_VERBOSE" ]; then
emu_args="$emu_args -show-kernel"
fi
2022-09-16 02:45:58 +00:00
# Setup emulator
2023-11-16 22:29:45 +00:00
"$sdk" --channel=3 $pkg
2022-09-16 02:45:58 +00:00
echo no | "$avd" create avd -f -n test -k $pkg
2023-10-12 05:42:45 +00:00
# Launch stock emulator
print_title "* Launching $pkg"
2024-06-21 09:45:48 +00:00
"$emu" @test $emu_args 2>/dev/null &
2023-10-12 05:42:45 +00:00
emu_pid=$!
wait_emu wait_for_bootanim
2023-04-24 20:54:46 +00:00
# Update arguments for Magisk runs
emu_args="$emu_args -ramdisk magisk_patched.img -feature -SystemAsRoot"
2023-10-12 05:42:45 +00:00
# Patch and test debug build
./build.py avd_patch -s "$ramdisk" magisk_patched.img
2023-10-12 05:42:45 +00:00
kill -INT $emu_pid
wait $emu_pid
2023-11-16 22:29:45 +00:00
test_emu debug $api
2022-03-18 11:56:19 +00:00
2024-07-20 10:10:18 +00:00
# Patch and test release build
./build.py -r avd_patch -s "$ramdisk" magisk_patched.img
2023-10-12 05:42:45 +00:00
kill -INT $emu_pid
wait $emu_pid
2023-11-16 22:29:45 +00:00
test_emu release $api
2023-10-09 12:47:50 +00:00
2023-10-12 05:42:45 +00:00
# Cleanup
kill -INT $emu_pid
wait $emu_pid
rm -f magisk_patched.img
2022-03-18 11:56:19 +00:00
}
2022-09-16 02:45:58 +00:00
trap cleanup EXIT
export -f wait_for_boot
2023-10-12 05:42:45 +00:00
export -f wait_for_bootanim
2022-09-16 02:45:58 +00:00
case $(uname -m) in
'arm64'|'aarch64')
arch=arm64-v8a
;;
*)
arch=x86_64
;;
esac
2024-04-10 09:56:23 +00:00
if [ -n "$FORCE_32_BIT" ]; then
case $arch in
'arm64-v8a')
echo "! ARM32 is not supported"
exit 1
;;
'x86_64')
arch=x86
max_api=$i386_max_api
;;
esac
fi
2023-11-16 22:29:45 +00:00
yes | "$sdk" --licenses > /dev/null
curl -L $lsposed_url -o out/lsposed.zip
2024-01-23 02:10:26 +00:00
"$sdk" --channel=3 tools platform-tools emulator
2023-05-10 06:11:11 +00:00
if [ -n "$1" ]; then
2024-06-21 01:25:49 +00:00
run_test $1 $2
2023-05-10 06:11:11 +00:00
else
2024-06-21 01:25:49 +00:00
for api in $(seq 23 34); do
2023-05-10 06:11:11 +00:00
run_test $api
done
2024-06-21 01:25:49 +00:00
# Android 15 Beta
run_test 35 google_apis
# Run 16k page tests
run_test VanillaIceCream google_apis_ps16k
2023-05-10 06:11:11 +00:00
fi
2022-03-18 11:56:19 +00:00
2022-04-16 14:21:02 +00:00
"$avd" delete avd -n test
2022-03-18 11:56:19 +00:00
trap - EXIT