richardphibel / rpms / systemd

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