diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-07-17 08:44:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-17 08:44:01 +0200 |
commit | 4a747647b3c55686c8f7360b91a1ded77e4e7e42 (patch) | |
tree | 4c3290d1d13564e6c5f3335dad0b9e33dcba8f65 /test | |
parent | 59279e9618d259cf7bf8534908f91e0cdb978a3b (diff) | |
parent | e96386521cebbb51a36b0ac98d349e513ee217fb (diff) | |
download | systemd-4a747647b3c55686c8f7360b91a1ded77e4e7e42.tar.gz |
Merge pull request #13082 from ddstreet/minor
Minor fixes in test framework
Diffstat (limited to 'test')
32 files changed, 87 insertions, 207 deletions
diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index a34e2adbe2..007ee7a91f 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -6,9 +6,7 @@ RUN_IN_UNPRIVILEGED_CONTAINER=${RUN_IN_UNPRIVILEGED_CONTAINER:-yes} . $TEST_BASE_DIR/test-functions test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( @@ -31,9 +29,6 @@ EOF setup_testsuite ) setup_nspawn_root - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-02-CRYPTSETUP/test.sh b/test/TEST-02-CRYPTSETUP/test.sh index 9d25e94250..2dd2cce6e5 100755 --- a/test/TEST-02-CRYPTSETUP/test.sh +++ b/test/TEST-02-CRYPTSETUP/test.sh @@ -25,13 +25,11 @@ check_result_qemu() { test_setup() { - create_empty_image + create_empty_image_rootdir echo -n test >$TESTDIR/keyfile cryptsetup -q luksFormat --pbkdf pbkdf2 --pbkdf-force-iterations 1000 ${LOOPDEV}p2 $TESTDIR/keyfile cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile mkfs.ext4 -L var /dev/mapper/varcrypt - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root mkdir -p $TESTDIR/root/var mount /dev/mapper/varcrypt $TESTDIR/root/var @@ -76,20 +74,23 @@ EOF /dev/mapper/varcrypt /var ext4 defaults 0 1 EOF ) +} +cleanup_root_var() { ddebug "umount $TESTDIR/root/var" - umount $TESTDIR/root/var - cryptsetup luksClose /dev/mapper/varcrypt - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root + mountpoint $TESTDIR/root/var && umount $TESTDIR/root/var + [[ -b /dev/mapper/varcrypt ]] && cryptsetup luksClose /dev/mapper/varcrypt } test_cleanup() { - [ -d $TESTDIR/root/var ] && mountpoint $TESTDIR/root/var && umount $TESTDIR/root/var - [[ -b /dev/mapper/varcrypt ]] && cryptsetup luksClose /dev/mapper/varcrypt - umount $TESTDIR/root 2>/dev/null || true - [[ $LOOPDEV ]] && losetup -d $LOOPDEV - return 0 + # ignore errors, so cleanup can continue + cleanup_root_var || true + _test_cleanup +} + +test_setup_cleanup() { + cleanup_root_var + _test_setup_cleanup } do_test "$@" diff --git a/test/TEST-03-JOBS/test.sh b/test/TEST-03-JOBS/test.sh index 2a7df79a47..b815e7cb67 100755 --- a/test/TEST-03-JOBS/test.sh +++ b/test/TEST-03-JOBS/test.sh @@ -6,9 +6,7 @@ TEST_NO_QEMU=1 . $TEST_BASE_DIR/test-functions test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( @@ -46,9 +44,6 @@ EOF setup_testsuite ) setup_nspawn_root - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-04-JOURNAL/test.sh b/test/TEST-04-JOURNAL/test.sh index a5ba7c8434..cabc71f4ff 100755 --- a/test/TEST-04-JOURNAL/test.sh +++ b/test/TEST-04-JOURNAL/test.sh @@ -5,9 +5,7 @@ TEST_DESCRIPTION="Journal-related tests" . $TEST_BASE_DIR/test-functions test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( @@ -48,9 +46,6 @@ EOF setup_testsuite ) setup_nspawn_root - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-05-RLIMITS/test.sh b/test/TEST-05-RLIMITS/test.sh index 176014d270..159c1e0ea8 100755 --- a/test/TEST-05-RLIMITS/test.sh +++ b/test/TEST-05-RLIMITS/test.sh @@ -5,9 +5,7 @@ TEST_DESCRIPTION="Resource limits-related tests" . $TEST_BASE_DIR/test-functions test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( @@ -44,9 +42,6 @@ EOF setup_testsuite ) setup_nspawn_root - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-06-SELINUX/test.sh b/test/TEST-06-SELINUX/test.sh index 5d26cb0f0a..4a6cf126ab 100755 --- a/test/TEST-06-SELINUX/test.sh +++ b/test/TEST-06-SELINUX/test.sh @@ -16,9 +16,7 @@ SETUP_SELINUX=yes KERNEL_APPEND="$KERNEL_APPEND selinux=1 security=selinux" test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( @@ -100,9 +98,6 @@ EOF ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-07-ISSUE-1981/test.sh b/test/TEST-07-ISSUE-1981/test.sh index e488cb4347..2e4f67c5fe 100755 --- a/test/TEST-07-ISSUE-1981/test.sh +++ b/test/TEST-07-ISSUE-1981/test.sh @@ -8,9 +8,7 @@ TEST_NO_QEMU=1 NSPAWN_TIMEOUT=30s test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( @@ -42,9 +40,6 @@ EOF setup_testsuite ) setup_nspawn_root - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-08-ISSUE-2730/test.sh b/test/TEST-08-ISSUE-2730/test.sh index d455d5d555..6c5edd4d2f 100755 --- a/test/TEST-08-ISSUE-2730/test.sh +++ b/test/TEST-08-ISSUE-2730/test.sh @@ -8,9 +8,7 @@ QEMU_TIMEOUT=180 FSTYPE=ext4 test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( @@ -72,9 +70,6 @@ EOF ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-09-ISSUE-2691/test.sh b/test/TEST-09-ISSUE-2691/test.sh index bef31cd096..9bc53d5e69 100755 --- a/test/TEST-09-ISSUE-2691/test.sh +++ b/test/TEST-09-ISSUE-2691/test.sh @@ -7,9 +7,7 @@ TEST_NO_NSPAWN=1 QEMU_TIMEOUT=180 test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( @@ -40,9 +38,6 @@ EOF ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-10-ISSUE-2467/test.sh b/test/TEST-10-ISSUE-2467/test.sh index 081d22b44d..bb4c0f3ac4 100755 --- a/test/TEST-10-ISSUE-2467/test.sh +++ b/test/TEST-10-ISSUE-2467/test.sh @@ -5,9 +5,7 @@ TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2467" . $TEST_BASE_DIR/test-functions test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( @@ -54,9 +52,6 @@ EOF ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-11-ISSUE-3166/test.sh b/test/TEST-11-ISSUE-3166/test.sh index 267224c042..c50efb8c9b 100755 --- a/test/TEST-11-ISSUE-3166/test.sh +++ b/test/TEST-11-ISSUE-3166/test.sh @@ -6,9 +6,7 @@ TEST_NO_NSPAWN=1 . $TEST_BASE_DIR/test-functions test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( @@ -65,9 +63,6 @@ EOF chmod 0755 $initdir/test-fail-on-restart.sh setup_testsuite ) - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-12-ISSUE-3171/test.sh b/test/TEST-12-ISSUE-3171/test.sh index 08b59ae165..5b1c3aa313 100755 --- a/test/TEST-12-ISSUE-3171/test.sh +++ b/test/TEST-12-ISSUE-3171/test.sh @@ -6,9 +6,7 @@ TEST_NO_QEMU=1 . $TEST_BASE_DIR/test-functions test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( @@ -93,9 +91,6 @@ EOF ) setup_nspawn_root - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-13-NSPAWN-SMOKE/test.sh b/test/TEST-13-NSPAWN-SMOKE/test.sh index 6a40bebbe0..7243959b2e 100755 --- a/test/TEST-13-NSPAWN-SMOKE/test.sh +++ b/test/TEST-13-NSPAWN-SMOKE/test.sh @@ -6,9 +6,7 @@ TEST_NO_NSPAWN=1 . $TEST_BASE_DIR/test-functions test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( @@ -185,9 +183,6 @@ EOF chmod 0755 $initdir/test-nspawn.sh setup_testsuite ) - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-14-MACHINE-ID/test.sh b/test/TEST-14-MACHINE-ID/test.sh index c22fc7c3c0..81e76f381f 100755 --- a/test/TEST-14-MACHINE-ID/test.sh +++ b/test/TEST-14-MACHINE-ID/test.sh @@ -6,9 +6,7 @@ TEST_NO_NSPAWN=1 . $TEST_BASE_DIR/test-functions test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( @@ -81,9 +79,6 @@ chmod +x $initdir/test-machine-id-setup.sh ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-15-DROPIN/test.sh b/test/TEST-15-DROPIN/test.sh index fab127362a..47a4067276 100755 --- a/test/TEST-15-DROPIN/test.sh +++ b/test/TEST-15-DROPIN/test.sh @@ -25,8 +25,4 @@ test_setup() { setup_nspawn_root } -test_cleanup() { - return 0 -} - do_test "$@" diff --git a/test/TEST-16-EXTEND-TIMEOUT/test.sh b/test/TEST-16-EXTEND-TIMEOUT/test.sh index 7e6dc45f6b..016a877b96 100755 --- a/test/TEST-16-EXTEND-TIMEOUT/test.sh +++ b/test/TEST-16-EXTEND-TIMEOUT/test.sh @@ -8,8 +8,6 @@ TEST_NO_QEMU=1 test_setup() { create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root # Create what will eventually be our root filesystem onto an overlay ( @@ -39,13 +37,6 @@ test_setup() { ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service setup_nspawn_root - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root -} - -test_cleanup() { - return 0 } do_test "$@" diff --git a/test/TEST-17-UDEV-WANTS/test.sh b/test/TEST-17-UDEV-WANTS/test.sh index 02578d33c7..065fa9624f 100755 --- a/test/TEST-17-UDEV-WANTS/test.sh +++ b/test/TEST-17-UDEV-WANTS/test.sh @@ -7,9 +7,7 @@ TEST_NO_NSPAWN=1 QEMU_TIMEOUT=300 test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir ( LOG_LEVEL=5 @@ -39,9 +37,6 @@ EOF setup_testsuite ) - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-18-FAILUREACTION/test.sh b/test/TEST-18-FAILUREACTION/test.sh index 0cf6391bdc..1ef43a4e7b 100755 --- a/test/TEST-18-FAILUREACTION/test.sh +++ b/test/TEST-18-FAILUREACTION/test.sh @@ -6,9 +6,7 @@ TEST_DESCRIPTION="FailureAction= operation" QEMU_TIMEOUT=180 test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir ( LOG_LEVEL=5 @@ -39,9 +37,6 @@ EOF ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-19-DELEGATE/test.sh b/test/TEST-19-DELEGATE/test.sh index 25461af9dc..abfb6a77a2 100755 --- a/test/TEST-19-DELEGATE/test.sh +++ b/test/TEST-19-DELEGATE/test.sh @@ -8,9 +8,7 @@ QEMU_TIMEOUT=180 UNIFIED_CGROUP_HIERARCHY=yes test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir ( LOG_LEVEL=5 @@ -41,9 +39,6 @@ EOF setup_testsuite ) - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-20-MAINPIDGAMES/test.sh b/test/TEST-20-MAINPIDGAMES/test.sh index 8adaf490e2..457ef6ae74 100755 --- a/test/TEST-20-MAINPIDGAMES/test.sh +++ b/test/TEST-20-MAINPIDGAMES/test.sh @@ -5,9 +5,7 @@ TEST_DESCRIPTION="test changing main PID" . $TEST_BASE_DIR/test-functions test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir ( LOG_LEVEL=5 @@ -40,9 +38,6 @@ EOF setup_testsuite ) setup_nspawn_root - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-23-TYPE-EXEC/test.sh b/test/TEST-23-TYPE-EXEC/test.sh index 68423637ce..9163f88c82 100755 --- a/test/TEST-23-TYPE-EXEC/test.sh +++ b/test/TEST-23-TYPE-EXEC/test.sh @@ -5,9 +5,7 @@ TEST_DESCRIPTION="test Type=exec" . $TEST_BASE_DIR/test-functions test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir ( LOG_LEVEL=5 @@ -40,9 +38,6 @@ EOF setup_testsuite ) setup_nspawn_root - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-24-UNIT-TESTS/test.sh b/test/TEST-24-UNIT-TESTS/test.sh index 5d60b548dd..f853dd1d3c 100755 --- a/test/TEST-24-UNIT-TESTS/test.sh +++ b/test/TEST-24-UNIT-TESTS/test.sh @@ -58,9 +58,7 @@ test_setup() { exit 1 fi - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( @@ -98,9 +96,6 @@ EOF ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-25-IMPORT/test.sh b/test/TEST-25-IMPORT/test.sh index 4beaa6456e..026c38a264 100755 --- a/test/TEST-25-IMPORT/test.sh +++ b/test/TEST-25-IMPORT/test.sh @@ -5,9 +5,7 @@ TEST_DESCRIPTION="test importd" . $TEST_BASE_DIR/test-functions test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir ( LOG_LEVEL=5 @@ -33,9 +31,6 @@ EOF setup_testsuite ) setup_nspawn_root - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-26-SETENV/test.sh b/test/TEST-26-SETENV/test.sh index b1a965aff1..fc216ee5bf 100755 --- a/test/TEST-26-SETENV/test.sh +++ b/test/TEST-26-SETENV/test.sh @@ -5,9 +5,7 @@ TEST_DESCRIPTION="test setenv" . $TEST_BASE_DIR/test-functions test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir ( LOG_LEVEL=5 @@ -32,9 +30,6 @@ EOF setup_testsuite ) setup_nspawn_root - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-27-STDOUTFILE/test.sh b/test/TEST-27-STDOUTFILE/test.sh index e78e317d6d..d481f1b8bf 100755 --- a/test/TEST-27-STDOUTFILE/test.sh +++ b/test/TEST-27-STDOUTFILE/test.sh @@ -5,9 +5,7 @@ TEST_DESCRIPTION="test StandardOutput=file:" . $TEST_BASE_DIR/test-functions test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir ( LOG_LEVEL=5 @@ -42,9 +40,6 @@ EOF setup_testsuite ) setup_nspawn_root - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-28-PERCENTJ-WANTEDBY/test.sh b/test/TEST-28-PERCENTJ-WANTEDBY/test.sh index 42db3b621d..cc34efe074 100755 --- a/test/TEST-28-PERCENTJ-WANTEDBY/test.sh +++ b/test/TEST-28-PERCENTJ-WANTEDBY/test.sh @@ -6,9 +6,7 @@ RUN_IN_UNPRIVILEGED_CONTAINER=yes . $TEST_BASE_DIR/test-functions test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir # Create what will eventually be our root filesystem onto an overlay ( @@ -58,9 +56,6 @@ EOF ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-29-UDEV-ID_RENAMING/test.sh b/test/TEST-29-UDEV-ID_RENAMING/test.sh index 3e297492ea..a24f98d208 100755 --- a/test/TEST-29-UDEV-ID_RENAMING/test.sh +++ b/test/TEST-29-UDEV-ID_RENAMING/test.sh @@ -7,9 +7,7 @@ TEST_NO_NSPAWN=1 QEMU_TIMEOUT=300 test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir ( LOG_LEVEL=5 @@ -39,9 +37,6 @@ EOF setup_testsuite ) - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-30-ONCLOCKCHANGE/test.sh b/test/TEST-30-ONCLOCKCHANGE/test.sh index 47f1fff1d3..98a9db8007 100755 --- a/test/TEST-30-ONCLOCKCHANGE/test.sh +++ b/test/TEST-30-ONCLOCKCHANGE/test.sh @@ -6,9 +6,7 @@ TEST_NO_NSPAWN=1 . $TEST_BASE_DIR/test-functions test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir ( LOG_LEVEL=5 @@ -50,9 +48,6 @@ EOF setup_testsuite ) - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-31-DEVICE-ENUMERATION/test.sh b/test/TEST-31-DEVICE-ENUMERATION/test.sh index 1eda377ea0..a8723779a5 100755 --- a/test/TEST-31-DEVICE-ENUMERATION/test.sh +++ b/test/TEST-31-DEVICE-ENUMERATION/test.sh @@ -7,9 +7,7 @@ TEST_NO_NSPAWN=1 QEMU_TIMEOUT=300 test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir ( LOG_LEVEL=5 @@ -39,9 +37,6 @@ EOF setup_testsuite ) - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-32-OOMPOLICY/test.sh b/test/TEST-32-OOMPOLICY/test.sh index aef3db5db5..17610af21d 100755 --- a/test/TEST-32-OOMPOLICY/test.sh +++ b/test/TEST-32-OOMPOLICY/test.sh @@ -8,9 +8,7 @@ TEST_NO_NSPAWN=1 UNIFIED_CGROUP_HIERARCHY=yes test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir ( LOG_LEVEL=5 @@ -42,9 +40,6 @@ EOF setup_testsuite ) - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/TEST-34-DYNAMICUSERMIGRATE/test.sh b/test/TEST-34-DYNAMICUSERMIGRATE/test.sh index 5964311793..7339d3b656 100755 --- a/test/TEST-34-DYNAMICUSERMIGRATE/test.sh +++ b/test/TEST-34-DYNAMICUSERMIGRATE/test.sh @@ -5,9 +5,7 @@ TEST_DESCRIPTION="test migrating state directory from DynamicUser=1 to DynamicUs . $TEST_BASE_DIR/test-functions test_setup() { - create_empty_image - mkdir -p $TESTDIR/root - mount ${LOOPDEV}p1 $TESTDIR/root + create_empty_image_rootdir ( LOG_LEVEL=5 @@ -40,9 +38,6 @@ EOF setup_testsuite ) setup_nspawn_root - - ddebug "umount $TESTDIR/root" - umount $TESTDIR/root } do_test "$@" diff --git a/test/test-functions b/test/test-functions index 32136bf534..a970a5d6dc 100644 --- a/test/test-functions +++ b/test/test-functions @@ -556,6 +556,13 @@ EOF fi } +create_empty_image_rootdir() { + create_empty_image + mkdir -p $TESTDIR/root + mount ${LOOPDEV}p1 $TESTDIR/root + TEST_SETUP_CLEANUP_ROOTDIR=1 +} + check_asan_reports() { local ret=0 local root="$1" @@ -634,7 +641,7 @@ strip_binaries() { ddebug "Strip binaries" find "$initdir" -executable -not -path '*/lib/modules/*.ko' -type f | \ xargs strip --strip-unneeded |& \ - grep -v 'file format not recognized' | \ + grep -vi 'file format not recognized' | \ ddebug } @@ -1579,7 +1586,7 @@ instmods() { | instmods else ( [[ "$_mpargs" ]] && echo $_mpargs - find "$KERNEL_MODS" -path "*/${_mod#=}/*" -printf '%f\n' ) \ + find "$KERNEL_MODS" -path "*/${_mod#=}/*" -type f -printf '%f\n' ) \ | instmods fi ;; @@ -1658,11 +1665,39 @@ setup_suse() { inst_simple "/usr/lib/systemd/system/haveged.service" } +_test_setup_cleanup() { + # only umount if create_empty_image_rootdir() was called to mount it + if [[ $TEST_SETUP_CLEANUP_ROOTDIR ]]; then + ddebug "umount $TESTDIR/root" + umount $TESTDIR/root + fi +} + +# can be overridden in specific test +test_setup_cleanup() { + _test_setup_cleanup +} + +_test_cleanup() { + # (post-test) cleanup should always ignore failure and cleanup as much as possible + ( + set +e + if mountpoint $TESTDIR/root; then + ddebug "umount $TESTDIR/root" + umount $TESTDIR/root + fi + if [[ $LOOPDEV && -b $LOOPDEV ]]; then + ddebug "losetup -d $LOOPDEV" + losetup -d $LOOPDEV + fi + rm -fr "$TESTDIR" + rm -f "$STATEFILE" + ) || true +} + # can be overridden in specific test test_cleanup() { - umount $TESTDIR/root 2>/dev/null || true - [[ $LOOPDEV ]] && losetup -d $LOOPDEV || true - return 0 + _test_cleanup } test_run() { @@ -1726,24 +1761,21 @@ do_test() { --setup) echo "TEST SETUP: $TEST_DESCRIPTION" test_setup + test_setup_cleanup ;; --clean) echo "TEST CLEANUP: $TEST_DESCRIPTION" test_cleanup - rm -fr "$TESTDIR" - rm -f "$STATEFILE" ;; --all) ret=0 - echo -n "TEST: $TEST_DESCRIPTION "; + echo -n "TEST: $TEST_DESCRIPTION " ( - test_setup && test_run - ret=$? - test_cleanup - rm -fr "$TESTDIR" - rm -f "$STATEFILE" - exit $ret + test_setup + test_setup_cleanup + test_run ) </dev/null >"$TESTLOG" 2>&1 || ret=$? + test_cleanup if [ $ret -eq 0 ]; then rm "$TESTLOG" echo "[OK]" |