1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

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()
This commit is contained in:
Dan Streetman 2019-07-12 11:47:26 -04:00
parent 26408c7d5f
commit ec4cab49c9
32 changed files with 76 additions and 197 deletions

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -25,8 +25,4 @@ test_setup() {
setup_nspawn_root
}
test_cleanup() {
return 0
}
do_test "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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 "$@"

View File

@ -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"