diff --git a/ci/fedora.sh b/ci/fedora.sh index e60de79..198034a 100755 --- a/ci/fedora.sh +++ b/ci/fedora.sh @@ -45,7 +45,9 @@ yum -y install \ vim-common \ wget \ which \ - zstd + zstd \ + haveged \ + systemd yum -y install docbook5-style-xsl || true yum -y install swtpm || true diff --git a/tests/functions.sh b/tests/functions.sh index d0a9e8e..03785db 100755 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -271,6 +271,25 @@ _report_exit_and_cleanup() { [ $testsfail -gt 0 ] && echo -n "$RED" || echo -n "$NORM" echo " FAIL: $testsfail" echo "$NORM" + # Signal failure to the testing environment creator with an unclean shutdown. + if [ -n "$TST_ENV" ] && [ $$ -eq 1 ]; then + if [ -z "$(command -v poweroff)" ]; then + echo "Warning: cannot properly shutdown system" + fi + + # If no test was executed and the script was successful, + # do a clean shutdown. + if [ $testsfail -eq 0 ] && [ $testspass -eq 0 ] && [ $testsskip -eq 0 ] && + [ $exit_code -ne "$FAIL" ] && [ $exit_code -ne "$HARDFAIL" ]; then + poweroff -f + fi + + # If tests were executed and no test failed, do a clean shutdown. + if { [ $testspass -gt 0 ] || [ $testsskip -gt 0 ]; } && + [ $testsfail -eq 0 ]; then + poweroff -f + fi + fi if [ $testsfail -gt 0 ]; then exit "$FAIL" elif [ $testspass -gt 0 ]; then @@ -319,3 +338,75 @@ _softhsm_teardown() { unset SOFTHSM_SETUP_CONFIGDIR SOFTHSM2_CONF PKCS11_KEYURI \ EVMCTL_ENGINE OPENSSL_ENGINE OPENSSL_KEYFORM } + +# Syntax: _run_env +_run_env() { + if [ -z "$TST_ENV" ]; then + return + fi + + if [ $$ -eq 1 ]; then + return + fi + + if [ "$TST_ENV" = "um" ]; then + expect_pass "$1" rootfstype=hostfs rw init="$2" quiet mem=2048M "$3" + else + echo $RED"Testing environment $TST_ENV not supported"$NORM + exit "$FAIL" + fi +} + +# Syntax: _exit_env +_exit_env() { + if [ -z "$TST_ENV" ]; then + return + fi + + if [ $$ -eq 1 ]; then + return + fi + + exit "$OK" +} + +# Syntax: _init_env +_init_env() { + if [ -z "$TST_ENV" ]; then + return + fi + + if [ $$ -ne 1 ]; then + return + fi + + mount -t tmpfs tmpfs /tmp + mount -t proc proc /proc + mount -t sysfs sysfs /sys + mount -t securityfs securityfs /sys/kernel/security + + if [ -n "$(command -v haveged 2> /dev/null)" ]; then + $(command -v haveged) -w 1024 &> /dev/null + fi + + pushd "$PWD" > /dev/null || exit "$FAIL" +} + +# Syntax: _cleanup_env +_cleanup_env() { + if [ -z "$TST_ENV" ]; then + $1 + return + fi + + if [ $$ -ne 1 ]; then + return + fi + + $1 + + umount /sys/kernel/security + umount /sys + umount /proc + umount /tmp +}