Update avd_test to support custom type

This commit is contained in:
topjohnwu 2024-06-20 18:25:49 -07:00
parent a89b9e6af1
commit df6ada5ce3

View File

@ -3,20 +3,17 @@
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_base='-no-window -no-audio -no-boot-anim -gpu swiftshader_indirect -read-only -no-snapshot -show-kernel -memory $memory'
emu_args_base='-no-window -no-audio -no-boot-anim -gpu swiftshader_indirect -read-only -no-snapshot -show-kernel'
lsposed_url='https://github.com/LSPosed/LSPosed/releases/download/v1.9.2/LSPosed-v1.9.2-7024-zygisk-release.zip'
boot_timeout=600
emu_pid=
export PATH="$PATH:$ANDROID_SDK_ROOT/platform-tools"
min_api=23
max_api=34
atd_min_api=30
atd_max_api=34
lsposed_min_api=27
huge_ram_min_api=26
i386_max_api=30
print_title() {
echo -e "\n\033[44;39m${1}\033[0m\n"
@ -29,10 +26,8 @@ print_error() {
cleanup() {
print_error "! An error occurred when testing $pkg"
for api in $api_list; do
set_api_env $api
restore_avd
done
find $ANDROID_SDK_ROOT/system-images -name 'ramdisk.img' -exec cp -v {}.bak {} \; 2>/dev/null
find $ANDROID_SDK_ROOT/system-images -name 'advancedFeatures.ini' -exec cp -v {}.bak {} \; 2>/dev/null
"$avd" delete avd -n test
pkill -INT -P $$
@ -67,32 +62,9 @@ wait_for_boot() {
done
}
set_api_env() {
local memory
local type='default'
if [ $1 -ge $atd_min_api -a $1 -le $atd_max_api ]; then
# Use the lightweight ATD images if possible
type='aosp_atd'
fi
# Old Linux kernels will not boot with memory larger than 3GB
if [ $1 -lt $huge_ram_min_api ]; then
memory=3072
else
memory=8192
fi
eval emu_args=\"$emu_args_base\"
pkg="system-images;android-$1;$type;$arch"
local img_dir="$ANDROID_SDK_ROOT/system-images/android-$1/$type/$arch"
ramdisk="$img_dir/ramdisk.img"
features="$img_dir/advancedFeatures.ini"
}
restore_avd() {
if [ -f "${ramdisk}.bak" ]; then
cp "${ramdisk}.bak" "$ramdisk"
fi
if [ -f "${features}.bak" ]; then
cp "${features}.bak" "$features"
restore_backup() {
if [ -f "${1}.bak" ]; then
cp "${1}.bak" "$1"
fi
}
@ -164,11 +136,48 @@ test_emu() {
fi
}
run_test() {
local api=$1
local ver=$1
local type=$2
set_api_env $api
# 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 img_dir="$ANDROID_SDK_ROOT/system-images/android-$ver/$type/$arch"
local ramdisk="$img_dir/ramdisk.img"
local features="$img_dir/advancedFeatures.ini"
# 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
local emu_args="$emu_args_base -memory $memory"
# Setup emulator
"$sdk" --channel=3 $pkg
@ -176,7 +185,8 @@ run_test() {
# Launch stock emulator
print_title "* Launching $pkg"
restore_avd
restore_backup $ramdisk
restore_backup $features
"$emu" @test $emu_args &
emu_pid=$!
wait_emu wait_for_bootanim
@ -196,7 +206,8 @@ run_test() {
# Cleanup
kill -INT $emu_pid
wait $emu_pid
restore_avd
restore_backup $ramdisk
restore_backup $features
}
trap cleanup EXIT
@ -228,18 +239,20 @@ if [ -n "$FORCE_32_BIT" ]; then
esac
fi
api_list=$(seq $min_api $max_api)
yes | "$sdk" --licenses > /dev/null
curl -L $lsposed_url -o out/lsposed.zip
"$sdk" --channel=3 tools platform-tools emulator
if [ -n "$1" ]; then
run_test $1
run_test $1 $2
else
for api in $api_list; do
for api in $(seq 23 34); do
run_test $api
done
# Android 15 Beta
run_test 35 google_apis
# Run 16k page tests
run_test VanillaIceCream google_apis_ps16k
fi
"$avd" delete avd -n test