diff options
author | Martin Pitt <martinpitt@users.noreply.github.com> | 2017-08-04 14:34:14 +0200 |
---|---|---|
committer | Evgeny Vereshchagin <evvers@ya.ru> | 2017-08-04 15:34:14 +0300 |
commit | 054ee249a28194626115a23257870f257bf69fda (patch) | |
tree | 309bf895976f355f02e89277d8c91b0d2028248f /test/test-functions | |
parent | Merge pull request #6518 from joukewitteveen/process-rename (diff) | |
download | systemd-054ee249a28194626115a23257870f257bf69fda.tar.gz systemd-054ee249a28194626115a23257870f257bf69fda.tar.bz2 systemd-054ee249a28194626115a23257870f257bf69fda.zip |
test: Factorize common integration test functions (#6540)
All test/TEST* but TEST-02-CRYPTSETUP share the same check_result_qemu()
and test_cleanup(), so move them into test_functions and only override
them in TEST-02-CRYPTSETUP.
Also provide a common test_run() which by default assumes that both QEMU
and nspawn tests are run. Particular tests which don't support either
need to explicitly opt out by setting $TEST_NO_{QEMU,NSPAWN}. Do it this
way around to avoid accidentally forgetting to opt in, and to encourage
test authors to at least always support nspawn.
Diffstat (limited to 'test/test-functions')
-rw-r--r-- | test/test-functions | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/test-functions b/test/test-functions index 64926089d..5d66b7bc5 100644 --- a/test/test-functions +++ b/test/test-functions @@ -375,6 +375,22 @@ check_result_nspawn() { return $ret } +# can be overridden in specific test +check_result_qemu() { + ret=1 + mkdir -p $TESTDIR/root + mount ${LOOPDEV}p1 $TESTDIR/root + [[ -e $TESTDIR/root/testok ]] && ret=0 + [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR + cp -a $TESTDIR/root/var/log/journal $TESTDIR + umount $TESTDIR/root + [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed + ls -l $TESTDIR/journal/*/*.journal + test -s $TESTDIR/failed && ret=$(($ret+1)) + [ -n "$TIMED_OUT" ] && ret=$(($ret+1)) + return $ret +} + strip_binaries() { if [[ "$STRIP_BINARIES" = "no" ]]; then ddebug "Don't strip binaries" @@ -1360,6 +1376,31 @@ setup_suse() { inst_simple "/usr/lib/systemd/system/haveged.service" } +# can be overridden in specific test +test_cleanup() { + umount $TESTDIR/root 2>/dev/null || true + [[ $LOOPDEV ]] && losetup -d $LOOPDEV + return 0 +} + +test_run() { + if [ -z "$TEST_NO_QEMU" ]; then + if run_qemu; then + check_result_qemu || return 1 + else + dwarn "can't run QEMU, skipping" + fi + fi + if [ -z "$TEST_NO_NSPAWN" ]; then + if run_nspawn; then + check_result_nspawn || return 1 + else + dwarn "can't run systemd-nspawn, skipping" + fi + fi + return 0 +} + do_test() { if [[ $UID != "0" ]]; then echo "TEST: $TEST_DESCRIPTION [SKIPPED]: not root" >&2 |