From 5cb025e7cc5bb300ff6f2a5e80d3eca9ec0c5d4b Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 17 Mar 2026 20:04:47 -0700 Subject: [PATCH] Setup CI for app-ng --- .github/workflows/build.yml | 13 ++--- build.py | 1 + scripts/avd.sh | 102 ++++++++++++++++++++++++------------ scripts/cuttlefish.sh | 30 ++++++----- scripts/test_common.sh | 12 ++++- 5 files changed, 103 insertions(+), 55 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9343c6201..a12646b28 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/build.py b/build.py index 40f9de0e3..301622e6d 100755 --- a/build.py +++ b/build.py @@ -517,6 +517,7 @@ def cleanup(): def build_all(): build_native() build_app() + build_app_ng() build_test() diff --git a/scripts/avd.sh b/scripts/avd.sh index e0714d444..e823431bd 100755 --- a/scripts/avd.sh +++ b/scripts/avd.sh @@ -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" } diff --git a/scripts/cuttlefish.sh b/scripts/cuttlefish.sh index cb20c37ad..ec72d82d3 100755 --- a/scripts/cuttlefish.sh +++ b/scripts/cuttlefish.sh @@ -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 diff --git a/scripts/test_common.sh b/scripts/test_common.sh index 64afae62f..d2cb4f485 100644 --- a/scripts/test_common.sh +++ b/scripts/test_common.sh @@ -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"