summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDan Streetman <ddstreet@canonical.com>2019-07-12 11:47:26 -0400
committerDan Streetman <ddstreet@canonical.com>2019-07-16 18:05:15 -0400
commitec4cab49c95d03d23cad9741685f3837a8ccaab4 (patch)
tree315c884c2c3e9e09af252b54297e2dca2d1a26cd /test
parent26408c7d5f39ac5b7afb3902eb340917ae821c88 (diff)
downloadsystemd-ec4cab49c95d03d23cad9741685f3837a8ccaab4.tar.gz
test: add create_empty_image_rootdir() to simplify testcase setup
Almost all tests were manually mounting/unmounting $TESTDIR/root from the loopback image; this moves all that into test-functions so the test setup functions are simplier. Also add test_setup_cleanup() function, to cleanup what is mounted by create_empty_image_rootdir()
Diffstat (limited to 'test')
-rwxr-xr-xtest/TEST-01-BASIC/test.sh7
-rwxr-xr-xtest/TEST-02-CRYPTSETUP/test.sh24
-rwxr-xr-xtest/TEST-03-JOBS/test.sh7
-rwxr-xr-xtest/TEST-04-JOURNAL/test.sh7
-rwxr-xr-xtest/TEST-05-RLIMITS/test.sh7
-rwxr-xr-xtest/TEST-06-SELINUX/test.sh7
-rwxr-xr-xtest/TEST-07-ISSUE-1981/test.sh7
-rwxr-xr-xtest/TEST-08-ISSUE-2730/test.sh7
-rwxr-xr-xtest/TEST-09-ISSUE-2691/test.sh7
-rwxr-xr-xtest/TEST-10-ISSUE-2467/test.sh7
-rwxr-xr-xtest/TEST-11-ISSUE-3166/test.sh7
-rwxr-xr-xtest/TEST-12-ISSUE-3171/test.sh7
-rwxr-xr-xtest/TEST-13-NSPAWN-SMOKE/test.sh7
-rwxr-xr-xtest/TEST-14-MACHINE-ID/test.sh7
-rwxr-xr-xtest/TEST-15-DROPIN/test.sh4
-rwxr-xr-xtest/TEST-16-EXTEND-TIMEOUT/test.sh9
-rwxr-xr-xtest/TEST-17-UDEV-WANTS/test.sh7
-rwxr-xr-xtest/TEST-18-FAILUREACTION/test.sh7
-rwxr-xr-xtest/TEST-19-DELEGATE/test.sh7
-rwxr-xr-xtest/TEST-20-MAINPIDGAMES/test.sh7
-rwxr-xr-xtest/TEST-23-TYPE-EXEC/test.sh7
-rwxr-xr-xtest/TEST-24-UNIT-TESTS/test.sh7
-rwxr-xr-xtest/TEST-25-IMPORT/test.sh7
-rwxr-xr-xtest/TEST-26-SETENV/test.sh7
-rwxr-xr-xtest/TEST-27-STDOUTFILE/test.sh7
-rwxr-xr-xtest/TEST-28-PERCENTJ-WANTEDBY/test.sh7
-rwxr-xr-xtest/TEST-29-UDEV-ID_RENAMING/test.sh7
-rwxr-xr-xtest/TEST-30-ONCLOCKCHANGE/test.sh7
-rwxr-xr-xtest/TEST-31-DEVICE-ENUMERATION/test.sh7
-rwxr-xr-xtest/TEST-32-OOMPOLICY/test.sh7
-rwxr-xr-xtest/TEST-34-DYNAMICUSERMIGRATE/test.sh7
-rw-r--r--test/test-functions40
32 files changed, 76 insertions, 197 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..e28cec0340 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,22 @@ 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
+ cleanup_root_var
+ _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 1aef07a44e..f652e82dd0 100644
--- a/test/test-functions
+++ b/test/test-functions
@@ -557,6 +557,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"
@@ -1685,11 +1692,33 @@ 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() {
+ 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
+}
+
# 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() {
@@ -1753,6 +1782,7 @@ do_test() {
--setup)
echo "TEST SETUP: $TEST_DESCRIPTION"
test_setup
+ test_setup_cleanup
;;
--clean)
echo "TEST CLEANUP: $TEST_DESCRIPTION"
@@ -1764,7 +1794,9 @@ do_test() {
ret=0
echo -n "TEST: $TEST_DESCRIPTION ";
(
- test_setup && test_run
+ test_setup
+ test_setup_cleanup
+ test_run
ret=$?
test_cleanup
rm -fr "$TESTDIR"