diff --git a/etc/autobuild/ab3_defcfg.sh b/etc/autobuild/ab3_defcfg.sh index 5a4ffc87..163d674d 100644 --- a/etc/autobuild/ab3_defcfg.sh +++ b/etc/autobuild/ab3_defcfg.sh @@ -169,4 +169,7 @@ abassigngroup() { : "${ABBUILD:="$(abdetectarch)"}" "${ABHOST:=$ABBUILD}" "${ABTARGET:=$ABHOST}" ABHOST_GROUP="$(abassigngroup $ABHOST)" +# Default configurations for ab3 package integrity check module. +[[ -v $ABTEST_ENABLED ]] || ABTEST_ENABLED=0 # Disabled during current development cycle + unset -f abdetectarch abassigngroup diff --git a/exportvars/tests b/exportvars/tests new file mode 100644 index 00000000..956d14d4 --- /dev/null +++ b/exportvars/tests @@ -0,0 +1,3 @@ +ABTEST_ENABLED +ABTEST_TYPE +ABTEST_TESTPROBES diff --git a/lib/tests.sh b/lib/tests.sh new file mode 100644 index 00000000..4fca3447 --- /dev/null +++ b/lib/tests.sh @@ -0,0 +1,19 @@ +#!/bin/bash +##lib/tests.sh: Functions for test modules. +##Part of AB3 integrated package test module +##@copyright GPL-2.0+ + +abtest_non-zero-handler() { + case $1 in + 0) return 0;; + 127) abwarn "No abtest() available in file ${2}";; + *) abwarn "Non-zero returned: ${1}!";; + esac +} + +abtest_unprivileged_non-zero-handler() { + case $1 in + 127) abwarn "No abtest_unprivileged() available in file ${2}";; + *) abtest_non-zero-handler $1 $2;; + esac +} diff --git a/proc/81-test_funcs.sh b/proc/81-test_funcs.sh new file mode 100644 index 00000000..75363c9e --- /dev/null +++ b/proc/81-test_funcs.sh @@ -0,0 +1,13 @@ +#!/bin/bash +##proc/81-test_funcs: Loads the tests/ functions +##Part of AB3 integrated package build-time test module +##@copyright GPL-2.0+ + +if bool $ABTEST_ENABLED; then + for i in "$AB/tests"/*.sh + do + . "$i" + done +else + abinfo "Build-time package integrity check is disabled. Skipping ..." +fi diff --git a/proc/82-test_probe.sh b/proc/82-test_probe.sh new file mode 100644 index 00000000..21d0c02a --- /dev/null +++ b/proc/82-test_probe.sh @@ -0,0 +1,17 @@ +#!/bin/bash +##proc/82-test_probe.sh: Determining test type +##Part of AB3 integrated package build-time test module +##@copyright GPL-2.0+ + +if bool $ABTEST_ENABLED; then + if [ -z "$ABTEST_TYPE"]; then + abinfo "No $ABTEST_TYPE set, automatically determining ..." + for i in $ABTEST_TESTPROBES; do + if abtest_${i}_probe; then + abinfo "Automatically set ABTEST_TYPE to ${i}" + ABTEST_TYPE=$i + break + fi + done + fi +fi diff --git a/proc/83-test_exec.sh b/proc/83-test_exec.sh new file mode 100644 index 00000000..cf569f03 --- /dev/null +++ b/proc/83-test_exec.sh @@ -0,0 +1,11 @@ +#!/bin/bash +##proc/83-test_exec.sh: Perform test +##Part of AB3 integrated package build-time test module +##@copyright GPL-2.0+ + +if bool $ABTEST_ENABLED; then + cd "$SRCDIR" + # FIXME: use a non-zero handler? + abtest_${ABTEST_TYPE}_test || \ + abwarn "Test exited with non-zero status: $?" +fi diff --git a/tests/00-self_file.sh b/tests/00-self_file.sh new file mode 100644 index 00000000..d4fed8e8 --- /dev/null +++ b/tests/00-self_file.sh @@ -0,0 +1,33 @@ +#!/bin/bash +##tests/00-self_file.sh: invoke testing function defined in `autobuild/test` +##Part of AB3 integrated package build-time test module +##@copyright GPL-2.0+ + +##FIXME: implement unprivileged tests + +abtrylib arch tests || ablibret + +abtest_self_file_probe() { + [ -f "$(arch_trymore=1 arch_findfile test)" ] +} + +abtest_self_file_test() { + + abtest() { + abwarn "ABTEST_TYPE is set to self_file, but no abtest() found in autobuild{,/\$ARCH}/test" + return 127 + } + + abtest_unprivileged() { + abwarn "ABTEST_TYPE is set to self_file, but no abtest_unprivileged() found in autobuild{,/\$ARCH}/test" + return 127 + } + + # Redefine + arch_loadfile test + + abtest || abtest_non-zero-handler $? "$SRCDIR"/test + abtest_unprivileged || abtest_unprivileged_non-zero-handler $? "$SRCDIR"/test +} + +ABTEST_TESTPROBES+=' self_file' diff --git a/tests/01-self_files.sh b/tests/01-self_files.sh new file mode 100644 index 00000000..5296a767 --- /dev/null +++ b/tests/01-self_files.sh @@ -0,0 +1,27 @@ +#!/bin/bash +##tests/01-self_files.sh: invoke testing function defined in `autobuild/tests/T*.sh` +##Part of AB3 integrated package build-time test module +##@copyright GPL-2.0+ + +##FIXME: implement unprivileged tests + +abtrylib tests || ablibret + +abtest_self_files_probe() { + [ -d "$SRCDIR"/autobuild/tests ] +} + +abtest_self_files_test() { + . "$AB/lib/tests.sh" + + for i in "$SRCDIR"/autobuild/tests/T*.sh + do + abinfo "Loading test case file ${i} and performing tests ..." + . $i + abtest || abtest_non-zero-handler $? $i + abtest_unprivileged || abtest_unprivileged_non-zero-handler $? $i + unset abtest abtest_unprivileged + done +} + +ABTEST_TESTPROBES+=' self_files' diff --git a/tests/99-notest.sh b/tests/99-notest.sh new file mode 100644 index 00000000..f4d608ba --- /dev/null +++ b/tests/99-notest.sh @@ -0,0 +1,14 @@ +#!/bin/bash +##tests/99-notest.sh: Dummy file indicates that test is not available or skipped. +##Part of AB3 integrated package build-time test module +##@copyright GPL-2.0+ + +abtest_notest_probe() { + true +} + +abtest_notest_test(){ + abinfo "ABTEST_TYPE is set to 'notest'. Skipping..." +} + +ABTEST_TESTPROBES+=' notest'