# Co-Maintainer: Pablo Correa Gomez <pabloyoyoista@postmarketos.org>
maintainer="Casey Connolly <kcxt@postmarketos.org>"
pkgname=postmarketos-test
pkgver=1.4.0
pkgrel=2
pkgdesc="Common test utilities for postmarketOS"
url="https://postmarketos.org"
arch="noarch"
license="GPL-3.0-or-later"
depends="devicepkg-utils"
# The _test split function will take files and prepare them for running
# in the initramfs test for postmarketos-mkinitfs-hook-ci. The function
# will match the suffix of the subpackage name and:
# * sources with -files.files as mkinitfs include files
# * sources with -test.sh as files to be executed in initramfs tests
source="
	00-bootrr-files.files
	00-bootrr-test.sh
	30-unl0kr-test.sh
	90-suspend-test.sh
"
options="!check"

# Tests that are common to all devices
# TODO: more tests
# maybe test cpu frequency scaling, thermals under load, etc.
subpackages="
	$pkgname-bootrr
	$pkgname-suspend:_test
	$pkgname-shell
	$pkgname-unl0kr
"

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
	_testname=${subpkgname#postmarketos-test-}

	_script="$srcdir"/*"$_testname"-test.sh
	_files="$srcdir"/*"$_testname"-files.files

	if [ -f $_script ]; then
		install -Dm755 $_script \
			-t "$subpkgdir"/usr/libexec/pmos-tests-initramfs/
	fi
	if [ -f $_files ]; then
		install -Dm644 $_files \
			-t "$subpkgdir"/usr/share/mkinitfs/files/
	fi
}

bootrr() {
	depends="bootrr"
	_test
}

# Installs a "test" which just runs a shell on the console for debugging
shell() {
	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
}

unl0kr() {
	depends="unl0kr"
	_test
}
sha512sums="
03bea177e69c6f68976aa766918c9b662601671bb4a1336299f9cff7ed0d3e8d1accf8622c4f152aa78c00a97f46cecfa150ca59b633a76d8b25a85cfa87ce68  00-bootrr-files.files
f5568803fe5d0254da222e09e06a062f77a98cfa5f438c54c788f6a08d56ea1a7b85f75595ad46c2a173e95681df58552ae572eba30b3239d5e4c225b4c54a2a  00-bootrr-test.sh
407180b49c1a05f12bd6ee6e59dca0a6e74fe7b01f195087dcf2865598c47827d0bb569afdba55defa2f9a16437230fa62aa64f35111508b906bcbf9537acba4  30-unl0kr-test.sh
73d75e067f6bb99dab219e0154514841462dc171644756dcdfcb2daa039bd3052d61f35996608499fb0958042cc817ba0ac8196410c68e9133c2670d4cf36529  90-suspend-test.sh
"
