Magisk/scripts/avd_test.sh

215 lines
4.1 KiB
Bash
Raw Normal View History

2022-03-18 04:56:19 -07:00
#!/usr/bin/env bash
set -xe
. scripts/test_common.sh
2024-07-22 03:39:04 -07:00
emu_args_base="-no-window -no-audio -no-boot-anim -gpu swiftshader_indirect -read-only -no-snapshot -cores $core_count"
2023-10-11 22:42:45 -07:00
emu_pid=
2022-03-18 04:56:19 -07:00
2023-11-16 14:29:45 -08:00
atd_min_api=30
2024-12-02 15:13:29 -08:00
atd_max_api=35
2024-01-28 00:46:03 -08:00
huge_ram_min_api=26
2022-09-15 19:45:58 -07:00
cleanup() {
2024-12-20 01:55:22 -08:00
print_error "! An error occurred"
2022-09-15 19:45:58 -07:00
rm -f magisk_patched.img
2022-09-15 19:45:58 -07:00
"$avd" delete avd -n test
2023-05-09 23:11:11 -07:00
pkill -INT -P $$
wait
2023-10-11 22:42:45 -07:00
trap - EXIT
exit 1
}
wait_for_bootanim() {
2024-12-02 15:13:29 -08:00
set -e
2023-10-11 22:42:45 -07:00
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-15 19:45:58 -07:00
}
2022-03-18 04:56:19 -07:00
wait_for_boot() {
2024-12-02 15:13:29 -08:00
set -e
2023-05-09 23:11:11 -07:00
adb wait-for-device
2022-03-18 04:56:19 -07:00
while true; do
2023-10-11 22:42:45 -07:00
local result="$(adb exec-out getprop sys.boot_completed)"
if [ $? -ne 0 ]; then
exit 1
elif [ "$result" = "1" ]; then
2022-03-18 04:56:19 -07: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 16:45:24 -07: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-11 22:42:45 -07:00
test_emu() {
local variant=$1
2023-11-16 14:29:45 -08:00
local api=$2
2024-12-20 01:55:22 -08:00
print_title "* Testing $avd_pkg ($variant)"
2024-07-25 03:48:13 -07:00
if [ -n "$AVD_TEST_LOG" ]; then
"$emu" @test $emu_args > kernel.log 2>&1 &
2024-06-21 02:45:48 -07:00
else
2024-07-25 03:48:13 -07:00
"$emu" @test $emu_args > /dev/null 2>&1 &
2024-06-21 02:45:48 -07:00
fi
2024-07-25 03:48:13 -07:00
emu_pid=$!
wait_emu wait_for_boot
2023-10-11 22:42:45 -07:00
2024-12-20 01:55:22 -08:00
run_setup $variant
2023-11-16 14:29:45 -08:00
adb reboot
wait_emu wait_for_boot
2024-12-20 01:55:22 -08:00
run_tests
2023-10-11 22:42:45 -07:00
}
2024-12-20 01:55:22 -08:00
test_main() {
2024-06-20 18:25:49 -07: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 ;;
2024-12-02 15:13:29 -08:00
Baklava) api=36 ;;
2024-06-20 18:25:49 -07:00
*)
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
2024-12-20 01:55:22 -08:00
local avd_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-20 18:25:49 -07: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-09 23:11:11 -07:00
2024-06-21 02:45:48 -07:00
emu_args="$emu_args_base -memory $memory"
2022-09-15 19:45:58 -07:00
# Setup emulator
2024-12-20 01:55:22 -08:00
"$sdk" --channel=3 $avd_pkg
echo no | "$avd" create avd -f -n test -k $avd_pkg
2022-09-15 19:45:58 -07:00
2023-10-11 22:42:45 -07:00
# Launch stock emulator
2024-12-20 01:55:22 -08:00
print_title "* Launching $avd_pkg"
2024-07-25 03:48:13 -07:00
"$emu" @test $emu_args >/dev/null 2>&1 &
2023-10-11 22:42:45 -07:00
emu_pid=$!
wait_emu wait_for_bootanim
2023-04-25 04:54:46 +08:00
# Update arguments for Magisk runs
emu_args="$emu_args -ramdisk magisk_patched.img -feature -SystemAsRoot"
2024-07-25 03:48:13 -07:00
if [ -n "$AVD_TEST_LOG" ]; then
emu_args="$emu_args -show-kernel -logcat '' -logcat-output logcat.log"
fi
if [ -z "$AVD_TEST_SKIP_DEBUG" ]; then
# Patch and test debug build
./build.py avd_patch -s "$ramdisk" magisk_patched.img
kill -INT $emu_pid
wait $emu_pid
test_emu debug $api
fi
2022-03-18 04:56:19 -07:00
if [ -z "$AVD_TEST_SKIP_RELEASE" ]; then
# Patch and test release build
./build.py -r avd_patch -s "$ramdisk" magisk_patched.img
kill -INT $emu_pid
wait $emu_pid
test_emu release $api
fi
2023-10-09 20:47:50 +08:00
2023-10-11 22:42:45 -07:00
# Cleanup
kill -INT $emu_pid
wait $emu_pid
rm -f magisk_patched.img
2022-03-18 04:56:19 -07:00
}
2022-09-15 19:45:58 -07:00
trap cleanup EXIT
export -f wait_for_boot
2023-10-11 22:42:45 -07:00
export -f wait_for_bootanim
2022-09-15 19:45:58 -07:00
case $(uname -m) in
'arm64'|'aarch64')
arch=arm64-v8a
;;
*)
arch=x86_64
;;
esac
2024-04-10 02:56:23 -07: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 14:29:45 -08:00
yes | "$sdk" --licenses > /dev/null
2024-08-26 18:34:49 +08:00
"$sdk" --channel=3 platform-tools emulator
2024-12-23 19:49:21 -08:00
adb kill-server
adb start-server
2023-05-09 23:11:11 -07:00
if [ -n "$1" ]; then
2024-12-20 01:55:22 -08:00
test_main $1 $2
2023-05-09 23:11:11 -07:00
else
2024-12-02 15:13:29 -08:00
for api in $(seq 23 35); do
2024-12-20 01:55:22 -08:00
test_main $api
2023-05-09 23:11:11 -07:00
done
2024-12-02 15:13:29 -08:00
# Android 16 Beta
2024-12-20 01:55:22 -08:00
test_main Baklava google_apis
2024-06-20 18:25:49 -07:00
# Run 16k page tests
2024-12-20 01:55:22 -08:00
test_main Baklava google_apis_ps16k
2023-05-09 23:11:11 -07:00
fi
2022-03-18 04:56:19 -07:00
2022-04-16 07:21:02 -07:00
"$avd" delete avd -n test
2022-03-18 04:56:19 -07:00
trap - EXIT