]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: build the image once and then copy/extend it 18363/head
authorLuca Boccassi <bluca@debian.org>
Wed, 6 Jan 2021 21:42:28 +0000 (21:42 +0000)
committerLuca Boccassi <bluca@debian.org>
Sun, 24 Jan 2021 13:07:39 +0000 (13:07 +0000)
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.

test/TEST-01-BASIC/test.sh
test/TEST-06-SELINUX/test.sh
test/TEST-08-ISSUE-2730/test.sh
test/TEST-13-NSPAWN-SMOKE/test.sh
test/TEST-14-MACHINE-ID/test.sh
test/TEST-24-CRYPTSETUP/test.sh
test/TEST-29-UDEV-ID_RENAMING/test.sh
test/TEST-50-DISSECT/test.sh
test/test-functions

index 58ad6f8fd2a5e7daf49e91046258f61094d1ac91..606b0dbfaf9b4f7fc7880de0bba738b49bdcad45 100755 (executable)
@@ -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
index 0acd7a10e8004df6e0a27543ea0871fcfd929d20..37528a1a26ca11fb01bad7ced796c0f836407ec9 100755 (executable)
@@ -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
index e5dedf2f0c2765f3289a7c905bec7b28bd4c9297..34d68835d8fee92283b7742ddd23db0acb6e6038 100755 (executable)
@@ -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
index 236378a3802c7347b7f85a99d3a4ca47b899e4a4..0f6bf587a65916f8d4122a5867b1e5b1fe427d25 100755 (executable)
@@ -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
     )
 }
 
index e8dbf23c580c954de3306d4a37ef9d12e9f61cc9..87abe2e439a64e2cb093f7d5a3bd51588670ac4d 100755 (executable)
@@ -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
index 2a6ad310ed24096c7a34c8d067477dad5b5c34df..d7b338c7f0f388cbf6e5d9169f85eb6cf2628c61 100755 (executable)
@@ -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
 
index ddf6db9735926517bbf38c64a7e6dac554f65783..c918e5af6aaed39021904a5bb972a132ccf43a45 100755 (executable)
@@ -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
     )
index 073ca8c31b91bada4eb57dc138ee3207fc9d95ac..c9e4faf5cbd16500bf6c8e61cd0436bba036d014 100755 (executable)
@@ -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
index 14fdedaa8516c4576058414413c95a9e40c5a1cc..837082890a0bcdb04c12d953c83c69bf85a74daf 100644 (file)
@@ -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