Setup CI for app-ng

This commit is contained in:
topjohnwu
2026-03-17 20:04:47 -07:00
parent e4f4239f5c
commit 5cb025e7cc
5 changed files with 103 additions and 55 deletions

View File

@@ -102,10 +102,8 @@ jobs:
run: .github/kvm.sh
- name: Run AVD test
timeout-minutes: 15
env:
AVD_TEST_LOG: 1
run: scripts/avd.sh test ${{ matrix.version }} ${{ matrix.type }}
timeout-minutes: 18
run: scripts/avd.sh test -l -v ${{ matrix.version }} -t ${{ matrix.type }}
- name: Upload logs on error
if: ${{ failure() }}
@@ -140,11 +138,10 @@ jobs:
run: .github/kvm.sh
- name: Run AVD test
timeout-minutes: 15
timeout-minutes: 18
env:
FORCE_32_BIT: 1
AVD_TEST_LOG: 1
run: scripts/avd.sh test ${{ matrix.version }}
run: scripts/avd.sh test -l -v ${{ matrix.version }}
- name: Upload logs on error
if: ${{ failure() }}
@@ -188,7 +185,7 @@ jobs:
scripts/cuttlefish.sh download ${{ matrix.branch }} ${{ matrix.device }}
- name: Run Cuttlefish test
timeout-minutes: 15
timeout-minutes: 18
run: sudo -E -u $USER scripts/cuttlefish.sh test
- name: Upload logs on error

View File

@@ -517,6 +517,7 @@ def cleanup():
def build_all():
build_native()
build_app()
build_app_ng()
build_test()

View File

@@ -32,7 +32,7 @@ case $(uname -m) in
esac
cleanup() {
rm -f magisk_*.img
rm -f magisk-*.img
"$avd" delete avd -n test
}
@@ -72,17 +72,45 @@ wait_emu() {
dump_vars() {
local val
for name in $@ emu_args; do
for name in $@; do
eval val=\$$name
echo $name=\"$val\"\;
echo local $name=\"$val\"\;
done
}
resolve_vars() {
parse_args() {
set +x
local arg_list="$1"
local ver=$2
local type=$3
local return_vals="$1"
shift
local ver=
local type=
while getopts ":v:t:l" opt; do
case $opt in
v )
ver="$OPTARG"
;;
t )
type="$OPTARG"
;;
l )
export AVD_TEST_LOG=1
;;
\? )
echo "Error: Invalid option: -$OPTARG" 1>&2
exit 1
;;
: )
# Missing a required argument is fine as we perform validations later
;;
esac
done
if [ -z $ver ]; then
print_error "! No system image version specified"
exit 1
fi
# Determine API level
local api
@@ -128,8 +156,12 @@ resolve_vars() {
local sys_img_dir="$ANDROID_HOME/system-images/android-$ver/$type/$arch"
local ramdisk="$sys_img_dir/ramdisk.img"
# Dump variables to output
dump_vars $arg_list
# Dump global variables
echo emu_args=\"$emu_args\"
echo OPTIND=$OPTIND
# Dump local variables
dump_vars $return_vals
}
dl_emu() {
@@ -151,9 +183,10 @@ setup_emu() {
}
test_emu() {
local variant=$1
local apk=$1
local image=$2
local magisk_args="-ramdisk magisk_${variant}.img -feature -SystemAsRoot"
local magisk_args="-ramdisk $image -feature -SystemAsRoot"
if [ -n "$AVD_TEST_LOG" ]; then
rm -f logcat.log
@@ -165,7 +198,7 @@ test_emu() {
emu_pid=$!
wait_emu
run_setup $variant
run_setup $apk
adb reboot
wait_emu
@@ -177,8 +210,13 @@ test_emu() {
}
test_main() {
local ver avd_pkg ramdisk
eval $(resolve_vars "ver avd_pkg ramdisk" $1 $2)
local vars
vars=$(parse_args "ver avd_pkg ramdisk" "$@")
eval "$vars"
# Shift off the options we just parsed so that "$@" only contains the remaining positional arguments
shift $((OPTIND - 1))
local apks=($(print_apks "$@"))
# Specify an explicit port so that tests can run with other emulators running at the same time
local emu_port=5682
@@ -198,32 +236,28 @@ test_main() {
wait_emu
# Patch images
if [ -z "$AVD_TEST_SKIP_DEBUG" ]; then
./build.py -v avd_patch "$ramdisk" magisk_debug.img
fi
if [ -z "$AVD_TEST_SKIP_RELEASE" ]; then
./build.py -vr avd_patch "$ramdisk" magisk_release.img
fi
local images=()
for apk in "${apks[@]}"; do
images+=("magisk-$(basename $apk .apk).img")
./build.py -v avd_patch --apk "$apk" "$ramdisk" "${images[-1]}"
done
kill -INT $emu_pid
wait $emu_pid
if [ -z "$AVD_TEST_SKIP_DEBUG" ]; then
print_title "* Testing $avd_pkg (debug)"
test_emu debug
fi
if [ -z "$AVD_TEST_SKIP_RELEASE" ]; then
print_title "* Testing $avd_pkg (release)"
test_emu release
fi
for i in "${!apks[@]}"; do
print_title "* Testing $avd_pkg ($(basename ${apks[i]}))"
test_emu ${apks[i]} ${images[i]}
done
cleanup
}
run_main() {
local ver avd_pkg
eval $(resolve_vars "ver avd_pkg" $1 $2)
local vars
vars=$(parse_args "ver avd_pkg" "$@")
eval "$vars"
setup_emu "$avd_pkg" $ver
print_title "* Launching $avd_pkg"
"$emu" @test $emu_args 2>/dev/null
@@ -231,8 +265,10 @@ run_main() {
}
dl_main() {
local avd_pkg
eval $(resolve_vars "avd_pkg" $1 $2)
local vars
vars=$(parse_args "avd_pkg" "$@")
eval "$vars"
print_title "* Downloading $avd_pkg"
dl_emu "$avd_pkg"
}

View File

@@ -4,12 +4,11 @@ set -xe
. scripts/test_common.sh
cvd_args="-daemon -enable_sandbox=false -memory_mb=8192 -report_anonymous_usage_stats=n -cpus=$core_count"
magisk_args='-init_boot_image=magisk_patched.img'
cleanup() {
print_error "! An error occurred"
run_cvd_bin stop_cvd || true
rm -f magisk_patched.img*
rm -f magisk-*.img
}
run_cvd_bin() {
@@ -58,14 +57,16 @@ download_cf() {
}
test_cf() {
local variant=$1
local apk=$1
local image=$2
run_cvd_bin stop_cvd || true
print_title "* Testing $variant builds"
local magisk_args="-init_boot_image=$image"
timeout $boot_timeout bash -c "run_cvd_bin launch_cvd $cvd_args $magisk_args -resume=false"
adb wait-for-device
run_setup $variant
run_setup $apk
adb reboot
sleep 5
@@ -81,17 +82,22 @@ test_main() {
run_cvd_bin launch_cvd $cvd_args -resume=false
adb wait-for-device
# Patch and test debug build
./build.py -v avd_patch "$CF_HOME/init_boot.img" magisk_patched.img
test_cf debug
# Patch images
local apks=($(print_apks))
local images=()
for apk in "${apks[@]}"; do
images+=("magisk-$(basename $apk .apk).img")
./build.py -v avd_patch --apk "$apk" "$CF_HOME/init_boot.img" "${images[-1]}"
done
# Patch and test release build
./build.py -vr avd_patch "$CF_HOME/init_boot.img" magisk_patched.img
test_cf release
for i in "${!apks[@]}"; do
print_title "* Testing $(basename ${apks[i]})"
test_cf ${apks[i]} ${images[i]}
done
# Cleanup
run_cvd_bin stop_cvd || true
rm -f magisk_patched.img*
rm -f magisk-*.img
}
if [ -z $CF_HOME ]; then

View File

@@ -49,11 +49,11 @@ wait_for_pm() {
}
run_setup() {
local variant=$1
local apk=$1
adb shell 'PATH=$PATH:/debug_ramdisk magisk -v'
# Install the Magisk app
adb install -r -g out/app-${variant}.apk
adb install -r -g $apk
# Install the test app
adb install -r -g out/test.apk
@@ -64,6 +64,14 @@ run_setup() {
am_instrument '.Environment#setupEnvironment' $app
}
print_apks() {
if [ "$#" -eq 0 ]; then
find out -maxdepth 1 -type f -name "app-*.apk" -or -name "apk-*.apk"
else
echo "$@"
fi
}
run_tests() {
local pkg='com.topjohnwu.magisk.test'
local self="$pkg/$pkg.TestRunner"