From 161711dea3cdfdd42f73bec7af08762a9b32e50b Mon Sep 17 00:00:00 2001 From: Caleb Connolly Date: Sun, 1 Oct 2023 19:52:09 +0100 Subject: [PATCH] main/postmarketos-test: new aport (MR 4420) This package provides a helper for writing a pmtest subpackage, as well as being a place to write generic tests that aren't specific to a device (e.g. a suspend test). Signed-off-by: Caleb Connolly [ci:ignore-count] --- main/postmarketos-test/APKBUILD | 56 +++++++++++++++++++ .../initramfs-test-suspend.sh | 22 ++++++++ 2 files changed, 78 insertions(+) create mode 100644 main/postmarketos-test/APKBUILD create mode 100644 main/postmarketos-test/initramfs-test-suspend.sh diff --git a/main/postmarketos-test/APKBUILD b/main/postmarketos-test/APKBUILD new file mode 100644 index 000000000..ab2095001 --- /dev/null +++ b/main/postmarketos-test/APKBUILD @@ -0,0 +1,56 @@ +# Maintainer: Caleb Connolly +pkgname=postmarketos-test +pkgver=0.1.0 +pkgrel=0 +pkgdesc="Common test utilities for postmarketOS" +url="https://postmarketos.org" +arch="noarch" +license="GPL2" +depends="devicepkg-utils" +source=" + initramfs-test-suspend.sh +" +options="!check" + +# Tests that are common to all devices +# TODO: more tests +# maybe test cpu frequency scaling, thermals under load, etc. +subpackages=" + $pkgname-suspend:_test + $pkgname-shell +" + +package() { + mkdir -p $pkgdir +} + +_test() { + # no install_if here, these tests are generic but should be enabled + # on a per-device basis. Depend on the relevant test in your devices + # pmtest subpackage + depends="postmarketos-mkinitfs-hook-ci" + + _testname=${subpkgname#postmarketos-test-} + + # Install the test script for both initramfs and rootfs + for _type in initramfs rootfs; do + _script="$srcdir/$_type-test-$_testname.sh" + + if [ -f "$_script" ]; then + install -Dm755 "$_script" \ + "$subpkgdir"/usr/libexec/pmos-tests-"$_type"/90-"$_testname".sh + fi + done +} + +# Installs a "test" which just runs a shell on the console for debugging +shell() { + depends="postmarketos-mkinitfs-hook-ci" + mkdir -p "$subpkgdir"/usr/libexec/pmos-tests-initramfs + echo -e "#!/bin/sh\n\nexec sh" > "$subpkgdir"/usr/libexec/pmos-tests-initramfs/99-sh + chmod +x "$subpkgdir"/usr/libexec/pmos-tests-initramfs/99-sh +} + +sha512sums=" +73d75e067f6bb99dab219e0154514841462dc171644756dcdfcb2daa039bd3052d61f35996608499fb0958042cc817ba0ac8196410c68e9133c2670d4cf36529 initramfs-test-suspend.sh +" diff --git a/main/postmarketos-test/initramfs-test-suspend.sh b/main/postmarketos-test/initramfs-test-suspend.sh new file mode 100644 index 000000000..69776e67b --- /dev/null +++ b/main/postmarketos-test/initramfs-test-suspend.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# Validate suspend/resume cycle + +echo "Checking that suspend works" + +SLEEP_TIME=6 + +if [ ! -e /sys/class/rtc/rtc0 ]; then + echo "SKIP: No RTC found" + exit 0 +fi + +time=$(($(cat /sys/class/rtc/rtc0/since_epoch) + $SLEEP_TIME)) +echo $time | tee /sys/class/rtc/rtc0/wakealarm +echo mem | tee /sys/power/state +sleep 3 # wait for the system to suspend +if [ $(cat /sys/class/rtc/rtc0/since_epoch) -lt $time ]; then + echo "FAIL: System did not suspend" + exit 1 +fi +echo "PASS: System suspended and woke up again" +# The other failure mode is that we don't wake up again...