Magisk/scripts/test_common.sh

93 lines
2.2 KiB
Bash
Raw Normal View History

if [ -z $ANDROID_HOME ]; then
export ANDROID_HOME=$ANDROID_SDK_ROOT
fi
2024-12-23 19:49:21 -08:00
# Make sure paths are consistent
export ANDROID_USER_HOME="$HOME/.android"
export ANDROID_EMULATOR_HOME="$ANDROID_USER_HOME"
export ANDROID_AVD_HOME="$ANDROID_EMULATOR_HOME/avd"
export PATH="$PATH:$ANDROID_HOME/platform-tools"
emu="$ANDROID_HOME/emulator/emulator"
2024-07-22 03:39:04 -07:00
sdk="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager"
avd="$ANDROID_HOME/cmdline-tools/latest/bin/avdmanager"
2024-07-20 03:10:18 -07:00
boot_timeout=600
2024-07-22 03:39:04 -07:00
core_count=$(nproc)
if [ $core_count -gt 8 ]; then
core_count=8
fi
2024-07-20 03:10:18 -07:00
print_title() {
echo -e "\n\033[44;39m${1}\033[0m\n"
}
print_error() {
echo -e "\n\033[41;39m${1}\033[0m\n"
}
2024-12-17 22:11:01 -08:00
# $1 = TestClass#method
# $2: boolean = isRepackaged
2024-12-20 01:55:22 -08:00
am_instrument() {
2024-12-17 22:11:01 -08:00
local test_pkg
2024-12-20 01:55:22 -08:00
if [ -n "$2" -a "$2" ]; then
2024-12-17 22:11:01 -08:00
test_pkg="repackaged.com.topjohnwu.magisk.test"
else
test_pkg=com.topjohnwu.magisk.test
fi
local out=$(adb shell am instrument -w --user 0 \
-e class "com.topjohnwu.magisk.test.$1" \
"$test_pkg/com.topjohnwu.magisk.test.TestRunner")
2024-12-13 01:09:52 -08:00
grep -q 'OK (' <<< "$out"
2024-07-20 03:10:18 -07:00
}
2024-12-17 22:11:01 -08:00
# $1 = pkg
wait_for_pm() {
sleep 5
adb shell pm uninstall $1 || true
}
2024-12-20 01:55:22 -08:00
run_setup() {
2024-07-20 03:10:18 -07:00
local variant=$1
adb shell 'PATH=$PATH:/debug_ramdisk magisk -v'
# Install the Magisk app
adb install -r -g out/app-${variant}.apk
2024-12-13 01:09:52 -08:00
# Install the test app
adb install -r -g out/test-${variant}.apk
# Run setup through the test app
2024-12-20 01:55:22 -08:00
am_instrument 'Environment#setupMagisk'
2024-07-20 03:10:18 -07:00
}
2024-12-20 01:55:22 -08:00
run_tests() {
2024-07-20 03:10:18 -07:00
# Run app tests
2024-12-20 01:55:22 -08:00
am_instrument 'MagiskAppTest'
2024-12-13 01:09:52 -08:00
# Test shell su request
2024-12-20 01:55:22 -08:00
am_instrument 'Environment#setupShellGrantTest'
2024-07-20 15:08:06 -07:00
adb shell /system/xbin/su 2000 su -c id | tee /dev/fd/2 | grep -q 'uid=0'
2024-12-17 22:11:01 -08:00
adb shell am force-stop com.topjohnwu.magisk
# Test app hiding
2024-12-20 01:55:22 -08:00
am_instrument 'Environment#setupAppHide'
2024-12-17 22:11:01 -08:00
wait_for_pm com.topjohnwu.magisk
# Make sure it still works
2024-12-20 01:55:22 -08:00
am_instrument 'MagiskAppTest' true
2024-12-17 22:11:01 -08:00
# Test shell su request
2024-12-20 01:55:22 -08:00
am_instrument 'Environment#setupShellGrantTest' true
2024-12-17 22:11:01 -08:00
adb shell /system/xbin/su 2000 su -c id | tee /dev/fd/2 | grep -q 'uid=0'
adb shell am force-stop repackaged.com.topjohnwu.magisk
# Test app restore
2024-12-20 01:55:22 -08:00
am_instrument 'Environment#setupAppRestore' true
2024-12-17 22:11:01 -08:00
wait_for_pm repackaged.com.topjohnwu.magisk
# Make sure it still works
2024-12-20 01:55:22 -08:00
am_instrument 'MagiskAppTest'
2024-07-20 03:10:18 -07:00
}