]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: Add Minimize= integration test 24908/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 10 Nov 2022 11:33:02 +0000 (12:33 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 14 Nov 2022 12:06:17 +0000 (13:06 +0100)
test/TEST-58-REPART/test.sh
test/test-functions
test/units/testsuite-58.sh

index 31c5e67e6a048a45d039e63690b01b46469c47f7..1638cb2b1638303e69a170f567df5bde188153e9 100755 (executable)
@@ -3,6 +3,8 @@
 set -e
 
 TEST_DESCRIPTION="test systemd-repart"
+IMAGE_NAME="repart"
+TEST_FORCE_NEWIMAGE=1
 
 # shellcheck source=test/test-functions
 . "$TEST_BASE_DIR/test-functions"
@@ -15,6 +17,7 @@ test_append_files() {
         fi
         instmods dm_verity =md
         generate_module_dependencies
+        image_install -o /sbin/mksquashfs
     fi
 }
 
index ff0cc963ce16ef7eb87599fd6fc2fbf4c6b495c2..18c76a69abd0583371944997b3465f2438aa8996 100644 (file)
@@ -1346,6 +1346,9 @@ create_empty_image() {
         root_size=$((4 * root_size))
         data_size=$((2 * data_size))
     fi
+    if [ "$IMAGE_NAME" = "repart" ]; then
+        root_size=$((root_size+=1000))
+    fi
 
     echo "Setting up ${IMAGE_PUBLIC:?} (${root_size} MB)"
     rm -f "${IMAGE_PRIVATE:?}" "$IMAGE_PUBLIC"
index 640b8440dc1c2e91648c1282abbba99be66b86be..f726dd548bdea707d4ca6c399b00acacb351a178 100755 (executable)
@@ -831,6 +831,58 @@ EOF
     losetup -d "$loop"
 }
 
+test_minimize() {
+    local defs imgs output
+
+    if systemd-detect-virt --quiet --container; then
+        echo "Skipping minimize test in container."
+        return
+    fi
+
+    defs="$(mktemp --directory "/tmp/test-repart.XXXXXXXXXX")"
+    imgs="$(mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")"
+    # shellcheck disable=SC2064
+    trap "rm -rf '$defs' '$imgs'" RETURN
+
+    for format in ext4 vfat; do
+        if ! command -v "mkfs.$format" >/dev/null; then
+            continue
+        fi
+
+        cat >"$defs/root-$format.conf" <<EOF
+[Partition]
+Type=root-${architecture}
+Format=${format}
+CopyFiles=${defs}
+Minimize=yes
+EOF
+    done
+
+    if ! command -v mksquashfs >/dev/null; then
+        cat >"$defs/root-squashfs.conf" <<EOF
+[Partition]
+Type=root-${architecture}
+Format=squashfs
+CopyFiles=${defs}
+Minimize=yes
+EOF
+    fi
+
+    output=$(systemd-repart --definitions="$defs" \
+                            --seed="$seed" \
+                            --dry-run=no \
+                            --empty=create \
+                            --size=auto \
+                            --json=pretty \
+                            "$imgs/zzz")
+
+    # Check that we can dissect, mount and unmount a minimized image.
+
+    systemd-dissect "$imgs/zzz"
+    systemd-dissect "$imgs/zzz" -M "$imgs/mnt"
+    systemd-dissect -U "$imgs/mnt"
+}
+
 test_sector() {
     local defs imgs output loop
     local start size ratio
@@ -900,6 +952,7 @@ test_issue_24553
 test_zero_uuid
 test_verity
 test_issue_24786
+test_minimize
 
 # Valid block sizes on the Linux block layer are >= 512 and <= PAGE_SIZE, and
 # must be powers of 2. Which leaves exactly four different ones to test on