test: add test case for systemd-repart --seed=random
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 5 Sep 2024 08:58:29 +0000 (17:58 +0900)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 10 Sep 2024 12:56:05 +0000 (14:56 +0200)
For issue #34257.

(cherry picked from commit 56d6ebd40468e2a743b39ad7d87b0675bdf9a042)

test/units/TEST-58-REPART.sh

index f8c22abd3a41c1b1f81ae4a7e3319542ec22525d..a989043c5e5e072b9fe0169ff277f643358cf2f4 100755 (executable)
@@ -1288,6 +1288,49 @@ testcase_dropped_partitions() {
     [[ "$(sfdisk -q -l "$image" | grep -c "$image")" -eq 2 ]]
 }
 
+testcase_random_seed() {
+    local defs imgs output
+
+    # For issue #34257
+
+    defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")"
+    imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")"
+    # shellcheck disable=SC2064
+    trap "rm -rf '$defs' '$imgs'" RETURN
+    chmod 0755 "$defs"
+
+    tee "$defs/root.conf" <<EOF
+[Partition]
+Type=root
+EOF
+
+    tee "$defs/home.conf" <<EOF
+[Partition]
+Type=home
+Label=home-first
+EOF
+
+    tee "$defs/swap.conf" <<EOF
+[Partition]
+Type=swap
+SizeMaxBytes=64M
+PaddingMinBytes=92M
+EOF
+
+    systemd-repart --offline="$OFFLINE" \
+                   --definitions="$defs" \
+                   --empty=create \
+                   --size=1G \
+                   --dry-run=no \
+                   --seed=random \
+                   --offline="$OFFLINE" \
+                   --json=pretty \
+                   "$imgs/zzz"
+
+    sfdisk -d "$imgs/zzz"
+    [[ "$(sfdisk -d "$imgs/zzz" | grep -F 'uuid=' | awk '{ print $8 }' | sort -u | wc -l)" == "3" ]]
+}
+
 OFFLINE="yes"
 run_testcases