From 1506edca913250fa043618cb972d555c7646d397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 20 Mar 2020 20:17:11 +0100 Subject: [PATCH] test: stop caching loopdev It is more trouble than it is worth. The setup is of a loopback device is very quick, so it's better to always create it when needed and immediately drop afterwards. --- test/TEST-02-CRYPTSETUP/test.sh | 7 +++-- test/TEST-24-UNIT-TESTS/test.sh | 4 +-- test/test-functions | 47 ++++++++++++++++++--------------- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/test/TEST-02-CRYPTSETUP/test.sh b/test/TEST-02-CRYPTSETUP/test.sh index cdaed130476..157a70021b4 100755 --- a/test/TEST-02-CRYPTSETUP/test.sh +++ b/test/TEST-02-CRYPTSETUP/test.sh @@ -8,16 +8,15 @@ TEST_NO_NSPAWN=1 check_result_qemu() { ret=1 - mkdir -p $initdir - mount ${LOOPDEV}p1 $initdir + mount_initdir [[ -e $initdir/testok ]] && ret=0 [[ -f $initdir/failed ]] && cp -a $initdir/failed $TESTDIR cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile mount /dev/mapper/varcrypt $initdir/var cp -a $initdir/var/log/journal $TESTDIR rm -r $initdir/var/log/journal/* - umount $initdir/var - umount $initdir + _umount_dir $initdir/var + _umount_dir $initdir cryptsetup luksClose /dev/mapper/varcrypt [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed ls -l $TESTDIR/journal/*/*.journal diff --git a/test/TEST-24-UNIT-TESTS/test.sh b/test/TEST-24-UNIT-TESTS/test.sh index 2c70d42914f..251ac9ef9be 100755 --- a/test/TEST-24-UNIT-TESTS/test.sh +++ b/test/TEST-24-UNIT-TESTS/test.sh @@ -24,7 +24,7 @@ check_result_nspawn() { fi cp -a $1/var/log/journal $TESTDIR rm -r $1/var/log/journal/* - umount_initdir + _umount_dir $initdir [[ -n "$TIMED_OUT" ]] && _ret=$(($_ret+1)) return $_ret } @@ -49,7 +49,7 @@ check_result_qemu() { fi cp -a $initdir/var/log/journal $TESTDIR rm -r $initdir/var/log/journal/* - umount_initdir + _umount_dir $initdir [[ -n "$TIMED_OUT" ]] && _ret=$(($_ret+1)) return $_ret } diff --git a/test/test-functions b/test/test-functions index 732e25a8b27..73213c3aa7a 100644 --- a/test/test-functions +++ b/test/test-functions @@ -18,6 +18,7 @@ EFI_MOUNT="${EFI_MOUNT:-$(bootctl -x 2>/dev/null || echo /boot)}" QEMU_MEM="${QEMU_MEM:-512M}" IMAGE_NAME=${IMAGE_NAME:-default} TEST_REQUIRE_INSTALL_TESTS="${TEST_REQUIRE_INSTALL_TESTS:-1}" +LOOPDEV= # Decide if we can (and want to) run QEMU with KVM acceleration. # Check if nested KVM is explicitly enabled (TEST_NESTED_KVM). If not, @@ -284,7 +285,7 @@ run_qemu() { find_qemu_bin || return 1 # Umount initdir to avoid concurrent access to the filesystem - umount_initdir + _umount_dir $initdir local _cgroup_args if [[ "$UNIFIED_CGROUP_HIERARCHY" = "yes" ]]; then @@ -667,6 +668,15 @@ install_missing_libraries() { done } +cleanup_loopdev() { + if [ -n "${LOOPDEV}" ]; then + ddebug "losetup -d $LOOPDEV" + losetup -d "${LOOPDEV}" + fi +} + +trap cleanup_loopdev EXIT + create_empty_image() { if [ -z "$IMAGE_NAME" ]; then echo "create_empty_image: \$IMAGE_NAME not set" @@ -689,7 +699,6 @@ create_empty_image() { LOOPDEV=$(losetup --show -P -f "$public") [ -b "$LOOPDEV" ] || return 1 - echo "LOOPDEV=$LOOPDEV" >>$STATEFILE sfdisk "$LOOPDEV" <>$STATEFILE + + udevadm settle fi - mkdir -p $initdir - mount ${LOOPDEV}p1 $initdir - TEST_SETUP_CLEANUP_ROOTDIR=1 -} - -umount_initdir() { - _umount_dir $initdir - if [[ $LOOPDEV && -b $LOOPDEV ]]; then - ddebug "losetup -d $LOOPDEV" - losetup -d $LOOPDEV + if ! mountpoint -q $initdir; then + mkdir -p $initdir + mount ${LOOPDEV}p1 $initdir + TEST_SETUP_CLEANUP_ROOTDIR=1 fi - LOOPDEV= - sed -i /LOOPDEV=/d $STATEFILE } cleanup_initdir() { @@ -800,7 +803,7 @@ check_result_nspawn() { test -s $TESTDIR/failed && ret=$(($ret+1)) [ -n "$TIMED_OUT" ] && ret=$(($ret+1)) check_asan_reports "$1" || ret=$(($ret+1)) - umount_initdir + _umount_dir $initdir return $ret } @@ -813,7 +816,7 @@ check_result_qemu() { cp -a $initdir/var/log/journal $TESTDIR rm -r $initdir/var/log/journal/* check_asan_reports "$initdir" || ret=$(($ret+1)) - umount $initdir + _umount_dir $initdir [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed ls -l $TESTDIR/journal/*/*.journal test -s $TESTDIR/failed && ret=$(($ret+1)) @@ -1164,7 +1167,10 @@ inst_libs() { } import_testdir() { + # make sure we don't get a stale LOOPDEV value from old times + __LOOPDEV=$LOOPDEV [[ -e $STATEFILE ]] && . $STATEFILE + LOOPDEV=$__LOOPDEV if [[ ! -d "$TESTDIR" ]]; then if [[ -z "$TESTDIR" ]]; then TESTDIR=$(mktemp --tmpdir=/var/tmp -d -t systemd-test.XXXXXX) @@ -1174,7 +1180,6 @@ import_testdir() { cat >$STATEFILE<