Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

[WIP] Build-time check implementation #129

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions etc/autobuild/ab3_defcfg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions exportvars/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ABTEST_ENABLED
ABTEST_TYPE
ABTEST_TESTPROBES
19 changes: 19 additions & 0 deletions lib/tests.sh
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 13 additions & 0 deletions proc/81-test_funcs.sh
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions proc/82-test_probe.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions proc/83-test_exec.sh
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions tests/00-self_file.sh
Original file line number Diff line number Diff line change
@@ -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'
27 changes: 27 additions & 0 deletions tests/01-self_files.sh
Original file line number Diff line number Diff line change
@@ -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'
14 changes: 14 additions & 0 deletions tests/99-notest.sh
Original file line number Diff line number Diff line change
@@ -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'