ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
8d419f
From 9a98a3b83e9e974d8d1cdc31e2286a862cc548be Mon Sep 17 00:00:00 2001
8d419f
From: Lennart Poettering <lennart@poettering.net>
8d419f
Date: Mon, 7 Feb 2022 14:35:40 +0100
8d419f
Subject: [PATCH] tests: add repart tests for block devices with 1024, 2048,
8d419f
 4096 byte sector sizes
8d419f
8d419f
let's make sure repart works with 4K drives and exotic sector sizes.
8d419f
8d419f
(cherry picked from commit 2cd341afb96486bd4afcdba23f02a27631c5b8db)
8d419f
8d419f
Related: #2017035
8d419f
---
8d419f
 test/units/testsuite-58.sh | 42 ++++++++++++++++++++++++++++++++++++++
8d419f
 1 file changed, 42 insertions(+)
8d419f
8d419f
diff --git a/test/units/testsuite-58.sh b/test/units/testsuite-58.sh
8d419f
index 4b3c984c84..7aed965fb4 100755
8d419f
--- a/test/units/testsuite-58.sh
8d419f
+++ b/test/units/testsuite-58.sh
8d419f
@@ -189,6 +189,48 @@ grep -qF 'p2 : start=      104448, size=      100319,' /tmp/testsuite-58-issue-2
8d419f
 rm /tmp/testsuite-58-issue-21817.img /tmp/testsuite-58-issue-21817.dump
8d419f
 rm -r /tmp/testsuite-58-issue-21817-defs/
8d419f
 
8d419f
+testsector()
8d419f
+{
8d419f
+    echo "Running sector test with sector size $1..."
8d419f
+
8d419f
+    mkdir -p /tmp/testsuite-58-sector
8d419f
+    cat > /tmp/testsuite-58-sector/a.conf <
8d419f
+[Partition]
8d419f
+Type=root
8d419f
+SizeMaxBytes=15M
8d419f
+SizeMinBytes=15M
8d419f
+EOF
8d419f
+    cat > /tmp/testsuite-58-sector/b.conf <
8d419f
+[Partition]
8d419f
+Type=linux-generic
8d419f
+Weight=250
8d419f
+EOF
8d419f
+
8d419f
+    cat > /tmp/testsuite-58-sector/c.conf <
8d419f
+[Partition]
8d419f
+Type=linux-generic
8d419f
+Weight=750
8d419f
+EOF
8d419f
+
8d419f
+    truncate -s 100m "/tmp/testsuite-58-sector-$1.img"
8d419f
+    LOOP=$(losetup -b "$1" -P --show -f "/tmp/testsuite-58-sector-$1.img" )
8d419f
+    systemd-repart --pretty=yes --definitions=/tmp/testsuite-58-sector/ --seed=750b6cd5c4ae4012a15e7be3c29e6a47 --empty=require --dry-run=no "$LOOP"
8d419f
+    rm -rf /tmp/testsuite-58-sector
8d419f
+    sfdisk --verify "$LOOP"
8d419f
+    sfdisk --dump "$LOOP"
8d419f
+    losetup -d "$LOOP"
8d419f
+
8d419f
+    rm "/tmp/testsuite-58-sector-$1.img"
8d419f
+}
8d419f
+
8d419f
+# Valid block sizes on the Linux block layer are >= 512 and <= PAGE_SIZE, and
8d419f
+# must be powers of 2. Which leaves exactly four different ones to test on
8d419f
+# typical hardware
8d419f
+testsector 512
8d419f
+testsector 1024
8d419f
+testsector 2048
8d419f
+testsector 4096
8d419f
+
8d419f
 echo OK >/testok
8d419f
 
8d419f
 exit 0