summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLuca Boccassi <bluca@debian.org>2021-01-06 22:42:28 +0100
committerLuca Boccassi <bluca@debian.org>2021-01-24 14:07:39 +0100
commitd9e606e89f3ee47db28f6cc7829a0cadc53983c8 (patch)
tree4b9d63296d88ec7da79165e559489750ae09a018 /test
parenttest: note where the bionic-* CI tool/integration lives (diff)
downloadsystemd-d9e606e89f3ee47db28f6cc7829a0cadc53983c8.tar.xz
systemd-d9e606e89f3ee47db28f6cc7829a0cadc53983c8.zip
tests: build the image once and then copy/extend it
Building custom images for each test takes a lot of time. Build the default one, and if the test needs incompatible changes just copy it and extend it instead.
Diffstat (limited to 'test')
-rwxr-xr-xtest/TEST-01-BASIC/test.sh17
-rwxr-xr-xtest/TEST-06-SELINUX/test.sh25
-rwxr-xr-xtest/TEST-08-ISSUE-2730/test.sh12
-rwxr-xr-xtest/TEST-13-NSPAWN-SMOKE/test.sh13
-rwxr-xr-xtest/TEST-14-MACHINE-ID/test.sh12
-rwxr-xr-xtest/TEST-24-CRYPTSETUP/test.sh1
-rwxr-xr-xtest/TEST-29-UDEV-ID_RENAMING/test.sh9
-rwxr-xr-xtest/TEST-50-DISSECT/test.sh10
-rw-r--r--test/test-functions42
9 files changed, 55 insertions, 86 deletions
diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh
index 58ad6f8fd2..606b0dbfaf 100755
--- a/test/TEST-01-BASIC/test.sh
+++ b/test/TEST-01-BASIC/test.sh
@@ -7,19 +7,10 @@ TEST_REQUIRE_INSTALL_TESTS=0
. $TEST_BASE_DIR/test-functions
-test_create_image() {
- create_empty_image_rootdir
-
- # Create what will eventually be our root filesystem onto an overlay
- (
- LOG_LEVEL=5
- setup_basic_environment
- mask_supporting_services
-
- # install tests manually so the test is functional even when -Dinstall-tests=false
- mkdir -p $initdir/usr/lib/systemd/tests/testdata/units/
- cp -v $(dirname $0)/../units/{testsuite-01,end}.service $initdir/usr/lib/systemd/tests/testdata/units/
- )
+test_append_files() {
+ # install tests manually so the test is functional even when -Dinstall-tests=false
+ mkdir -p $1/usr/lib/systemd/tests/testdata/units/
+ cp -v $(dirname $0)/../units/{testsuite-01,end}.service $1/usr/lib/systemd/tests/testdata/units/
}
do_test "$@" 01
diff --git a/test/TEST-06-SELINUX/test.sh b/test/TEST-06-SELINUX/test.sh
index 0acd7a10e8..37528a1a26 100755
--- a/test/TEST-06-SELINUX/test.sh
+++ b/test/TEST-06-SELINUX/test.sh
@@ -16,34 +16,27 @@ test -f /usr/share/selinux/devel/include/system/systemd.if || exit 0
SETUP_SELINUX=yes
KERNEL_APPEND="$KERNEL_APPEND selinux=1 security=selinux"
-test_create_image() {
- create_empty_image_rootdir
-
- # Create what will eventually be our root filesystem onto an overlay
+test_append_files() {
(
- LOG_LEVEL=5
-
- setup_basic_environment
- mask_supporting_services
-
+ setup_selinux
local _modules_dir=/var/lib/selinux
- rm -rf $initdir/$_modules_dir
- if ! cp -ar $_modules_dir $initdir/$_modules_dir; then
+ rm -rf $1/$_modules_dir
+ if ! cp -ar $_modules_dir $1/$_modules_dir; then
dfatal "Failed to copy $_modules_dir"
exit 1
fi
local _policy_headers_dir=/usr/share/selinux/devel
- rm -rf $initdir/$_policy_headers_dir
+ rm -rf $1/$_policy_headers_dir
inst_dir /usr/share/selinux
- if ! cp -ar $_policy_headers_dir $initdir/$_policy_headers_dir; then
+ if ! cp -ar $_policy_headers_dir $1/$_policy_headers_dir; then
dfatal "Failed to copy $_policy_headers_dir"
exit 1
fi
- mkdir $initdir/systemd-test-module
- cp systemd_test.te $initdir/systemd-test-module
- cp systemd_test.if $initdir/systemd-test-module
+ mkdir $1/systemd-test-module
+ cp systemd_test.te $1/systemd-test-module
+ cp systemd_test.if $1/systemd-test-module
dracut_install -o sesearch
dracut_install runcon
dracut_install checkmodule semodule semodule_package m4 make load_policy sefcontext_compile
diff --git a/test/TEST-08-ISSUE-2730/test.sh b/test/TEST-08-ISSUE-2730/test.sh
index e5dedf2f0c..34d68835d8 100755
--- a/test/TEST-08-ISSUE-2730/test.sh
+++ b/test/TEST-08-ISSUE-2730/test.sh
@@ -7,16 +7,6 @@ TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
QEMU_TIMEOUT=300
FSTYPE=ext4
-
-test_create_image() {
- create_empty_image_rootdir
-
- # Create what will eventually be our root filesystem onto an overlay
- (
- LOG_LEVEL=5
- setup_basic_environment
- )
- mask_supporting_services
-}
+TEST_FORCE_NEWIMAGE=1
do_test "$@" 08
diff --git a/test/TEST-13-NSPAWN-SMOKE/test.sh b/test/TEST-13-NSPAWN-SMOKE/test.sh
index 236378a380..0f6bf587a6 100755
--- a/test/TEST-13-NSPAWN-SMOKE/test.sh
+++ b/test/TEST-13-NSPAWN-SMOKE/test.sh
@@ -6,17 +6,10 @@ TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
-test_create_image() {
- create_empty_image_rootdir
-
- # Create what will eventually be our root filesystem onto an overlay
+test_append_files() {
(
- LOG_LEVEL=5
- setup_basic_environment
- mask_supporting_services
-
- ../create-busybox-container $initdir/testsuite-13.nc-container
- initdir="$initdir/testsuite-13.nc-container" dracut_install nc ip md5sum
+ ../create-busybox-container $1/testsuite-13.nc-container
+ initdir="$1/testsuite-13.nc-container" dracut_install nc ip md5sum
)
}
diff --git a/test/TEST-14-MACHINE-ID/test.sh b/test/TEST-14-MACHINE-ID/test.sh
index e8dbf23c58..87abe2e439 100755
--- a/test/TEST-14-MACHINE-ID/test.sh
+++ b/test/TEST-14-MACHINE-ID/test.sh
@@ -6,16 +6,8 @@ TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
-test_create_image() {
- create_empty_image_rootdir
-
- # Create what will eventually be our root filesystem onto an overlay
- (
- LOG_LEVEL=5
- setup_basic_environment
- mask_supporting_services
- printf "556f48e837bc4424a710fa2e2c9d3e3c\ne3d\n" >$initdir/etc/machine-id
- )
+test_append_files() {
+ printf "556f48e837bc4424a710fa2e2c9d3e3c\ne3d\n" >$1/etc/machine-id
}
do_test "$@" 14
diff --git a/test/TEST-24-CRYPTSETUP/test.sh b/test/TEST-24-CRYPTSETUP/test.sh
index 2a6ad310ed..d7b338c7f0 100755
--- a/test/TEST-24-CRYPTSETUP/test.sh
+++ b/test/TEST-24-CRYPTSETUP/test.sh
@@ -3,6 +3,7 @@ set -e
TEST_DESCRIPTION="cryptsetup systemd setup"
IMAGE_NAME="cryptsetup"
TEST_NO_NSPAWN=1
+TEST_FORCE_NEWIMAGE=1
. $TEST_BASE_DIR/test-functions
diff --git a/test/TEST-29-UDEV-ID_RENAMING/test.sh b/test/TEST-29-UDEV-ID_RENAMING/test.sh
index ddf6db9735..c918e5af6a 100755
--- a/test/TEST-29-UDEV-ID_RENAMING/test.sh
+++ b/test/TEST-29-UDEV-ID_RENAMING/test.sh
@@ -7,15 +7,8 @@ TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions
QEMU_TIMEOUT=300
-test_create_image() {
- create_empty_image_rootdir
-
- # Create what will eventually be our root filesystem onto an overlay
+test_append_files() {
(
- LOG_LEVEL=5
- setup_basic_environment
- mask_supporting_services
-
instmods dummy
generate_module_dependencies
)
diff --git a/test/TEST-50-DISSECT/test.sh b/test/TEST-50-DISSECT/test.sh
index 073ca8c31b..c9e4faf5cb 100755
--- a/test/TEST-50-DISSECT/test.sh
+++ b/test/TEST-50-DISSECT/test.sh
@@ -13,16 +13,8 @@ command -v veritysetup >/dev/null 2>&1 || exit 0
command -v sfdisk >/dev/null 2>&1 || exit 0
# Need loop devices for systemd-dissect
-test_create_image() {
- create_empty_image_rootdir
-
- # Create what will eventually be our root filesystem onto an overlay
- # If some pieces are missing from the host, skip rather than fail
+test_append_files() {
(
- LOG_LEVEL=5
- setup_basic_environment
- mask_supporting_services
-
instmods loop =block
instmods squashfs =squashfs
instmods dm_verity =md
diff --git a/test/test-functions b/test/test-functions
index 14fdedaa85..837082890a 100644
--- a/test/test-functions
+++ b/test/test-functions
@@ -17,6 +17,11 @@ TIMED_OUT= # will be 1 after run_* if *_TIMEOUT is set and test timed out
UNIFIED_CGROUP_HIERARCHY="${UNIFIED_CGROUP_HIERARCHY:-default}"
EFI_MOUNT="${EFI_MOUNT:-$(bootctl -x 2>/dev/null || echo /boot)}"
QEMU_MEM="${QEMU_MEM:-512M}"
+# Note that defining a different IMAGE_NAME in a test setup script will only result
+# in default.img being copied and renamed. It can then be extended by defining
+# a test_append_files() function. The $1 parameter will be the root directory.
+# To force creating a new image from scratch (eg: to encrypt it), also define
+# TEST_FORCE_NEWIMAGE=1 in the test setup script.
IMAGE_NAME=${IMAGE_NAME:-default}
TEST_REQUIRE_INSTALL_TESTS="${TEST_REQUIRE_INSTALL_TESTS:-1}"
TEST_PARALLELIZE="${TEST_PARALLELIZE:-0}"
@@ -2065,24 +2070,43 @@ test_setup() {
mount_initdir
else
if [ ! -e "$IMAGE_PUBLIC" ]; then
- # Create the backing public image, but then completely unmount
- # it and drop the loopback device responsible for it, since we're
- # going to symlink/copy the image and mount it again from
- # elsewhere.
- test_create_image
- test_setup_cleanup
- umount_loopback
- cleanup_loopdev
+ # default.img is the base that every test uses and optionally appends to
+ if [ ! -e "${IMAGESTATEDIR}/default.img" ] || [ -n "${TEST_FORCE_NEWIMAGE}" ]; then
+ # Create the backing public image, but then completely unmount
+ # it and drop the loopback device responsible for it, since we're
+ # going to symlink/copy the image and mount it again from
+ # elsewhere.
+ local image_old=${IMAGE_PUBLIC}
+ if [ -z "${TEST_FORCE_NEWIMAGE}" ]; then
+ IMAGE_PUBLIC="${IMAGESTATEDIR}/default.img"
+ fi
+ test_create_image
+ test_setup_cleanup
+ umount_loopback
+ cleanup_loopdev
+ IMAGE_PUBLIC="${image_old}"
+ fi
+ if [ "${IMAGE_NAME}" != "default" ] && [ -z "${TEST_FORCE_NEWIMAGE}" ]; then
+ cp -v "$(realpath "${IMAGESTATEDIR}/default.img")" "$IMAGE_PUBLIC"
+ fi
+ fi
+
+ local hook_defined=1
+ if declare -f -F test_append_files > /dev/null; then
+ hook_defined=$?
fi
echo "Reusing existing cached image $IMAGE_PUBLIC → $(realpath $IMAGE_PUBLIC)"
- if [ ${TEST_PARALLELIZE} -ne 0 ]; then
+ if [ ${TEST_PARALLELIZE} -ne 0 ] || [ ${hook_defined} -eq 0 ]; then
cp -v "$(realpath $IMAGE_PUBLIC)" "$IMAGE_PRIVATE"
else
ln -sv "$(realpath $IMAGE_PUBLIC)" "$IMAGE_PRIVATE"
fi
mount_initdir
+ if [ ${hook_defined} -eq 0 ]; then
+ test_append_files "$initdir"
+ fi
fi
setup_nspawn_root