mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-11 05:17:44 +03:00
test: modernize TEST-58-REPART
This commit is contained in:
parent
655eb07391
commit
5996f11679
@ -8,76 +8,86 @@ if ! command -v systemd-repart &>/dev/null; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# shellcheck source=test/units/assert.sh
|
||||
. "$(dirname "$0")"/assert.sh
|
||||
|
||||
export SYSTEMD_LOG_LEVEL=debug
|
||||
export PAGER=cat
|
||||
|
||||
seed=750b6cd5c4ae4012a15e7be3c29e6a47
|
||||
|
||||
machine="$(uname -m)"
|
||||
if [ "${machine}" = "x86_64" ]; then
|
||||
root_guid=4f68bce3-e8cd-4db1-96e7-fbcaf984b709
|
||||
root_guid=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709
|
||||
root_uuid=60F33797-1D71-4DCB-AA6F-20564F036CD0
|
||||
usr_guid=8484680c-9521-48c6-9c11-b0720656f69e
|
||||
usr_guid=8484680C-9521-48C6-9C11-B0720656F69E
|
||||
usr_uuid=7E3369DD-D653-4513-ADF5-B993A9F20C16
|
||||
architecture="x86-64"
|
||||
elif [ "${machine}" = "i386" ] || [ "${machine}" = "i686" ] || [ "${machine}" = "x86" ]; then
|
||||
root_guid=44479540-f297-41b2-9af7-d131d5f0458a
|
||||
root_uuid=02b4253f-29a4-404e-8972-1669d3b03c87
|
||||
usr_guid=75250d76-8cc6-458e-bd66-bd47cc81a812
|
||||
usr_uuid=7b42ffb0-b0e1-4395-b20b-c78f4a571648
|
||||
root_guid=44479540-F297-41B2-9AF7-D131D5F0458A
|
||||
root_uuid=02B4253F-29A4-404E-8972-1669D3B03C87
|
||||
usr_guid=75250D76-8CC6-458E-BD66-BD47CC81A812
|
||||
usr_uuid=7B42FFB0-B0E1-4395-B20B-C78F4A571648
|
||||
architecture="x86"
|
||||
elif [ "${machine}" = "aarch64" ] || [ "${machine}" = "aarch64_be" ] || [ "${machine}" = "armv8b" ] || [ "${machine}" = "armv8l" ]; then
|
||||
root_guid=b921b045-1df0-41c3-af44-4c6f280d3fae
|
||||
root_uuid=055d0227-53a6-4033-85c3-9a5973eff483
|
||||
usr_guid=b0e01050-ee5f-4390-949a-9101b17104e9
|
||||
usr_uuid=fce3c75e-d6a4-44c0-87f0-4c105183fb1f
|
||||
root_guid=B921B045-1DF0-41C3-AF44-4C6F280D3FAE
|
||||
root_uuid=055D0227-53A6-4033-85C3-9A5973EFF483
|
||||
usr_guid=B0E01050-EE5F-4390-949A-9101B17104E9
|
||||
usr_uuid=FCE3C75E-D6A4-44C0-87F0-4C105183FB1F
|
||||
architecture="arm64"
|
||||
elif [ "${machine}" = "arm" ]; then
|
||||
root_guid=69dad710-2ce4-4e3c-b16c-21a1d49abed3
|
||||
root_uuid=567da89e-8de2-4499-8d10-18f212dff034
|
||||
usr_guid=7d0359a3-02b3-4f0a-865c-654403e70625
|
||||
usr_uuid=71e93dc2-5073-42cb-8a84-a354e64d8966
|
||||
root_guid=69DAD710-2CE4-4E3C-B16C-21A1D49ABED3
|
||||
root_uuid=567DA89E-8DE2-4499-8D10-18F212DFF034
|
||||
usr_guid=7D0359A3-02B3-4F0A-865C-654403E70625
|
||||
usr_uuid=71E93DC2-5073-42CB-8A84-A354E64D8966
|
||||
architecture="arm"
|
||||
elif [ "${machine}" = "loongarch64" ]; then
|
||||
root_guid=77055800-792c-4f94-b39a-98c91b762bb6
|
||||
root_uuid=d8efc2d2-0133-41e4-bdcb-3b9f4cfddde8
|
||||
usr_guid=e611c702-575c-4cbe-9a46-434fa0bf7e3f
|
||||
usr_uuid=031ffa75-00bb-49b6-a70d-911d2d82a5b7
|
||||
root_guid=77055800-792C-4F94-B39A-98C91B762BB6
|
||||
root_uuid=D8EFC2D2-0133-41E4-BDCB-3B9F4CFDDDE8
|
||||
usr_guid=E611C702-575C-4CBE-9A46-434FA0BF7E3F
|
||||
usr_uuid=031FFA75-00BB-49B6-A70D-911D2D82A5B7
|
||||
architecture="loongarch64"
|
||||
elif [ "${machine}" = "ia64" ]; then
|
||||
root_guid=993d8d3d-f80e-4225-855a-9daf8ed7ea97
|
||||
root_uuid=dcf33449-0896-4ea9-bc24-7d58aeef522d
|
||||
usr_guid=4301d2a6-4e3b-4b2a-bb94-9e0b2c4225ea
|
||||
usr_uuid=bc2bcce7-80d6-449a-85cc-637424ce5241
|
||||
root_guid=993D8D3D-F80E-4225-855A-9DAF8ED7EA97
|
||||
root_uuid=DCF33449-0896-4EA9-BC24-7D58AEEF522D
|
||||
usr_guid=4301D2A6-4E3B-4B2A-BB94-9E0B2C4225EA
|
||||
usr_uuid=BC2BCCE7-80D6-449A-85CC-637424CE5241
|
||||
architecture="ia64"
|
||||
elif [ "${machine}" = "s390x" ]; then
|
||||
root_guid=5eead9a9-fe09-4a1e-a1d7-520d00531306
|
||||
root_uuid=7ebe0c85-e27e-48ec-b164-f4807606232e
|
||||
usr_guid=8a4f5770-50aa-4ed3-874a-99b710db6fea
|
||||
usr_uuid=51171d30-35cf-4a49-b8b5-9478b9b796a5
|
||||
root_guid=5EEAD9A9-FE09-4A1E-A1D7-520D00531306
|
||||
root_uuid=7EBE0C85-E27E-48EC-B164-F4807606232E
|
||||
usr_guid=8A4F5770-50AA-4ED3-874A-99B710DB6FEA
|
||||
usr_uuid=51171D30-35CF-4A49-B8B5-9478B9B796A5
|
||||
architecture="s390x"
|
||||
elif [ "${machine}" = "ppc64le" ]; then
|
||||
root_guid=c31c45e6-3f39-412e-80fb-4809c4980599
|
||||
root_uuid=061e67a1-092f-482f-8150-b525d50d6654
|
||||
usr_guid=15bb03af-77e7-4d4a-b12b-c0d084f7491c
|
||||
usr_uuid=c0d0823b-8040-4c7c-a629-026248e297fb
|
||||
root_guid=C31C45E6-3F39-412E-80FB-4809C4980599
|
||||
root_uuid=061E67A1-092F-482F-8150-B525D50D6654
|
||||
usr_guid=15BB03AF-77E7-4D4A-B12B-C0D084F7491C
|
||||
usr_uuid=C0D0823B-8040-4C7C-A629-026248E297FB
|
||||
architecture="ppc64-le"
|
||||
else
|
||||
echo "Unexpected uname -m: ${machine} in testsuite-58.sh, please fix me"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -f /var/tmp/testsuite-58.img /var/tmp/testsuite-58.2.img /tmp/testsuite-58.dump
|
||||
mkdir -p /tmp/testsuite-58-defs/
|
||||
test_copy_blocks() {
|
||||
local defs imgs output
|
||||
|
||||
# First part: create a disk image and verify its in order
|
||||
defs="$(mktemp --directory "/tmp/test-repart.XXXXXXXXXX")"
|
||||
imgs="$(mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")"
|
||||
# shellcheck disable=SC2064
|
||||
trap "rm -rf '$defs' '$imgs'" RETURN
|
||||
|
||||
cat >/tmp/testsuite-58-defs/esp.conf <<EOF
|
||||
# First, create a disk image and verify its in order
|
||||
|
||||
cat >"$defs/esp.conf" <<EOF
|
||||
[Partition]
|
||||
Type=esp
|
||||
SizeMinBytes=10M
|
||||
Format=vfat
|
||||
EOF
|
||||
|
||||
cat >/tmp/testsuite-58-defs/usr.conf <<EOF
|
||||
cat >"$defs/usr.conf" <<EOF
|
||||
[Partition]
|
||||
Type=usr-${architecture}
|
||||
SizeMinBytes=10M
|
||||
@ -85,7 +95,7 @@ Format=ext4
|
||||
ReadOnly=yes
|
||||
EOF
|
||||
|
||||
cat >/tmp/testsuite-58-defs/root.conf <<EOF
|
||||
cat >"$defs/root.conf" <<EOF
|
||||
[Partition]
|
||||
Type=root-${architecture}
|
||||
SizeMinBytes=10M
|
||||
@ -93,148 +103,185 @@ Format=ext4
|
||||
MakeDirectories=/usr /efi
|
||||
EOF
|
||||
|
||||
systemd-repart --definitions=/tmp/testsuite-58-defs/ \
|
||||
--empty=create \
|
||||
--size=auto \
|
||||
--seed=750b6cd5c4ae4012a15e7be3c29e6a47 \
|
||||
/var/tmp/testsuite-58.img
|
||||
systemd-repart --definitions="$defs" \
|
||||
--empty=create \
|
||||
--size=auto \
|
||||
--seed="$seed" \
|
||||
"$imgs/zzz"
|
||||
|
||||
sfdisk --dump /var/tmp/testsuite-58.img | tee /tmp/testsuite-58.dump
|
||||
output=$(sfdisk --dump "$imgs/zzz")
|
||||
|
||||
grep -qixF "/var/tmp/testsuite-58.img1 : start= 2048, size= 20480, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=39107B09-615D-48FB-BA37-C663885FCE67, name=\"esp\"" /tmp/testsuite-58.dump
|
||||
grep -qixF "/var/tmp/testsuite-58.img2 : start= 22528, size= 20480, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\"" /tmp/testsuite-58.dump
|
||||
grep -qixF "/var/tmp/testsuite-58.img3 : start= 43008, size= 20480, type=${usr_guid}, uuid=${usr_uuid}, name=\"usr-${architecture}\", attrs=\"GUID:60\"" /tmp/testsuite-58.dump
|
||||
assert_in "$imgs/zzz1 : start= 2048, size= 20480, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=39107B09-615D-48FB-BA37-C663885FCE67, name=\"esp\"" "$output"
|
||||
assert_in "$imgs/zzz2 : start= 22528, size= 20480, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\"" "$output"
|
||||
assert_in "$imgs/zzz3 : start= 43008, size= 20480, type=${usr_guid}, uuid=${usr_uuid}, name=\"usr-${architecture}\", attrs=\"GUID:60\"" "$output"
|
||||
|
||||
# Second part, duplicate it with CopyBlocks=auto
|
||||
# Then, create another image with CopyBlocks=auto
|
||||
|
||||
cat >/tmp/testsuite-58-defs/esp.conf <<EOF
|
||||
cat >"$defs/esp.conf" <<EOF
|
||||
[Partition]
|
||||
Type=esp
|
||||
CopyBlocks=auto
|
||||
EOF
|
||||
|
||||
cat >/tmp/testsuite-58-defs/usr.conf <<EOF
|
||||
cat >"$defs/usr.conf" <<EOF
|
||||
[Partition]
|
||||
Type=usr-${architecture}
|
||||
ReadOnly=yes
|
||||
CopyBlocks=auto
|
||||
EOF
|
||||
|
||||
cat >/tmp/testsuite-58-defs/root.conf <<EOF
|
||||
cat >"$defs/root.conf" <<EOF
|
||||
[Partition]
|
||||
Type=root-${architecture}
|
||||
CopyBlocks=auto
|
||||
EOF
|
||||
|
||||
systemd-repart --definitions=/tmp/testsuite-58-defs/ \
|
||||
--empty=create \
|
||||
--size=auto \
|
||||
--seed=750b6cd5c4ae4012a15e7be3c29e6a47 \
|
||||
--image=/var/tmp/testsuite-58.img \
|
||||
/var/tmp/testsuite-58.2.img
|
||||
systemd-repart --definitions="$defs" \
|
||||
--empty=create \
|
||||
--size=auto \
|
||||
--seed="$seed" \
|
||||
--image="$imgs/zzz" \
|
||||
"$imgs/yyy"
|
||||
|
||||
cmp /var/tmp/testsuite-58.img /var/tmp/testsuite-58.2.img
|
||||
cmp "$imgs/zzz" "$imgs/yyy"
|
||||
}
|
||||
|
||||
rm /var/tmp/testsuite-58.img /var/tmp/testsuite-58.2.img /tmp/testsuite-58.dump
|
||||
rm -r /tmp/testsuite-58-defs/
|
||||
test_unaligned_partition() {
|
||||
local defs imgs output
|
||||
|
||||
# Third part: operate on an an image with unaligned partition, to see if that works.
|
||||
defs="$(mktemp --directory "/tmp/test-repart.XXXXXXXXXX")"
|
||||
imgs="$(mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")"
|
||||
# shellcheck disable=SC2064
|
||||
trap "rm -rf '$defs' '$imgs'" RETURN
|
||||
|
||||
rm -f /var/tmp/testsuite-58.3.img /tmp/testsuite-58-3.dump
|
||||
mkdir -p /tmp/testsuite-58.3-defs/
|
||||
# Operate on an image with unaligned partition.
|
||||
|
||||
cat >/tmp/testsuite-58.3-defs/root.conf <<EOF
|
||||
cat >"$defs/root.conf" <<EOF
|
||||
[Partition]
|
||||
Type=root-${architecture}
|
||||
EOF
|
||||
|
||||
truncate -s 10g /var/tmp/testsuite-58.3.img
|
||||
sfdisk /var/tmp/testsuite-58.3.img <<EOF
|
||||
truncate -s 10g "$imgs/unaligned"
|
||||
sfdisk "$imgs/unaligned" <<EOF
|
||||
label: gpt
|
||||
|
||||
start=2048, size=69044
|
||||
start=71092, size=3591848
|
||||
EOF
|
||||
|
||||
systemd-repart --definitions=/tmp/testsuite-58.3-defs/ \
|
||||
--seed=750b6cd5c4ae4012a15e7be3c29e6a47 \
|
||||
--dry-run=no \
|
||||
/var/tmp/testsuite-58.3.img
|
||||
systemd-repart --definitions="$defs" \
|
||||
--seed="$seed" \
|
||||
--dry-run=no \
|
||||
"$imgs/unaligned"
|
||||
|
||||
sfdisk --dump /var/tmp/testsuite-58.3.img | tee /tmp/testsuite-58.3.dump
|
||||
output=$(sfdisk --dump "$imgs/unaligned")
|
||||
|
||||
grep -qF '/var/tmp/testsuite-58.3.img1 : start= 2048, size= 69044,' /tmp/testsuite-58.3.dump
|
||||
grep -qF '/var/tmp/testsuite-58.3.img2 : start= 71092, size= 3591848,' /tmp/testsuite-58.3.dump
|
||||
grep -qixF "/var/tmp/testsuite-58.3.img3 : start= 3662944, size= 17308536, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\"" /tmp/testsuite-58.3.dump
|
||||
assert_in "$imgs/unaligned1 : start= 2048, size= 69044," "$output"
|
||||
assert_in "$imgs/unaligned2 : start= 71092, size= 3591848," "$output"
|
||||
assert_in "$imgs/unaligned3 : start= 3662944, size= 17308536, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\"" "$output"
|
||||
}
|
||||
|
||||
rm /var/tmp/testsuite-58.3.img /tmp/testsuite-58.3.dump
|
||||
rm -r /tmp/testsuite-58.3-defs/
|
||||
test_issue_21817() {
|
||||
local defs imgs output
|
||||
|
||||
# testcase for #21817
|
||||
mkdir -p /tmp/testsuite-58-issue-21817-defs/
|
||||
truncate -s 100m /var/tmp/testsuite-58-issue-21817.img
|
||||
sfdisk /var/tmp/testsuite-58-issue-21817.img <<EOF
|
||||
# testcase for #21817
|
||||
|
||||
defs="$(mktemp --directory "/tmp/test-repart.XXXXXXXXXX")"
|
||||
imgs="$(mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")"
|
||||
# shellcheck disable=SC2064
|
||||
trap "rm -rf '$defs' '$imgs'" RETURN
|
||||
|
||||
cat >"$defs/test.conf" <<EOF
|
||||
[Partition]
|
||||
Type=root
|
||||
EOF
|
||||
|
||||
truncate -s 100m "$imgs/21817.img"
|
||||
sfdisk "$imgs/21817.img" <<EOF
|
||||
label: gpt
|
||||
|
||||
size=50M, type=${root_guid}
|
||||
,
|
||||
EOF
|
||||
cat >/tmp/testsuite-58-issue-21817-defs/test.conf <<EOF
|
||||
[Partition]
|
||||
Type=root
|
||||
EOF
|
||||
systemd-repart --pretty=yes --definitions /tmp/testsuite-58-issue-21817-defs/ --dry-run=no /var/tmp/testsuite-58-issue-21817.img
|
||||
sfdisk --dump /var/tmp/testsuite-58-issue-21817.img | tee /tmp/testsuite-58-issue-21817.dump
|
||||
|
||||
grep -qiF "/var/tmp/testsuite-58-issue-21817.img1 : start= 2048, size= 102400, type=${root_guid}," /tmp/testsuite-58-issue-21817.dump
|
||||
# Accept both unpadded (pre-v2.38 util-linux) and padded (v2.38+ util-linux) sizes
|
||||
grep -qE "/var/tmp/testsuite-58-issue-21817.img2 : start= 104448, size= (100319| 98304)," /tmp/testsuite-58-issue-21817.dump
|
||||
systemd-repart --pretty=yes \
|
||||
--definitions "$imgs" \
|
||||
--seed="$seed" \
|
||||
--dry-run=no \
|
||||
"$imgs/21817.img"
|
||||
|
||||
rm /var/tmp/testsuite-58-issue-21817.img /tmp/testsuite-58-issue-21817.dump
|
||||
rm -r /tmp/testsuite-58-issue-21817-defs/
|
||||
output=$(sfdisk --dump "$imgs/21817.img")
|
||||
|
||||
testsector()
|
||||
{
|
||||
echo "Running sector test with sector size $1..."
|
||||
assert_in "$imgs/21817.img1 : start= 2048, size= 102400, type=${root_guid}," "$output"
|
||||
# Accept both unpadded (pre-v2.38 util-linux) and padded (v2.38+ util-linux) sizes
|
||||
assert_in "$imgs/21817.img2 : start= 104448, size= (100319| 98304)," "$output"
|
||||
}
|
||||
|
||||
mkdir -p /tmp/testsuite-58-sector
|
||||
cat > /tmp/testsuite-58-sector/a.conf <<EOF
|
||||
test_sector() {
|
||||
local defs imgs output loop
|
||||
local start size ratio
|
||||
local sector="${1?}"
|
||||
|
||||
defs="$(mktemp --directory "/tmp/test-repart.XXXXXXXXXX")"
|
||||
imgs="$(mktemp --directory "/var/tmp/test-repart.XXXXXXXXXX")"
|
||||
# shellcheck disable=SC2064
|
||||
trap "rm -rf '$defs' '$imgs'" RETURN
|
||||
|
||||
cat > "$defs/a.conf" <<EOF
|
||||
[Partition]
|
||||
Type=root
|
||||
SizeMaxBytes=15M
|
||||
SizeMinBytes=15M
|
||||
EOF
|
||||
cat > /tmp/testsuite-58-sector/b.conf <<EOF
|
||||
cat > "$defs/b.conf" <<EOF
|
||||
[Partition]
|
||||
Type=linux-generic
|
||||
Weight=250
|
||||
EOF
|
||||
|
||||
cat > /tmp/testsuite-58-sector/c.conf <<EOF
|
||||
cat > "$defs/c.conf" <<EOF
|
||||
[Partition]
|
||||
Type=linux-generic
|
||||
Weight=750
|
||||
EOF
|
||||
|
||||
truncate -s 100m "/tmp/testsuite-58-sector-$1.img"
|
||||
LOOP=$(losetup -b "$1" -P --show -f "/tmp/testsuite-58-sector-$1.img" )
|
||||
udevadm wait --timeout 60 --settle "${LOOP:?}"
|
||||
systemd-repart --pretty=yes --definitions=/tmp/testsuite-58-sector/ --seed=750b6cd5c4ae4012a15e7be3c29e6a47 --empty=require --dry-run=no "$LOOP"
|
||||
rm -rf /tmp/testsuite-58-sector
|
||||
sfdisk --verify "$LOOP"
|
||||
sfdisk --dump "$LOOP"
|
||||
losetup -d "$LOOP"
|
||||
truncate -s 100m "$imgs/$sector.img"
|
||||
loop=$(losetup -b "$sector" -P --show -f "$imgs/$sector.img" )
|
||||
udevadm wait --timeout 60 --settle "${loop:?}"
|
||||
systemd-repart --pretty=yes \
|
||||
--definitions="$defs" \
|
||||
--seed="$seed" \
|
||||
--empty=require \
|
||||
--dry-run=no \
|
||||
"$loop"
|
||||
|
||||
rm "/tmp/testsuite-58-sector-$1.img"
|
||||
sfdisk --verify "$loop"
|
||||
output=$(sfdisk --dump "$loop")
|
||||
losetup -d "$loop"
|
||||
|
||||
ratio=$(( sector / 512 ))
|
||||
start=$(( 2048 / ratio ))
|
||||
size=$(( 30720 / ratio ))
|
||||
assert_in "${loop}p1 : start= *${start}, size= *${size}, type=${root_guid}, uuid=${root_uuid}, name=\"root-${architecture}\", attrs=\"GUID:59\"" "$output"
|
||||
start=$(( start + size ))
|
||||
size=$(( 42992 / ratio ))
|
||||
assert_in "${loop}p2 : start= *${start}, size= *${size}, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=DF71F5E3-080A-4D16-824B-18591B881380, name=\"linux-generic\"" "$output"
|
||||
start=$(( start + size ))
|
||||
size=$(( 129000 / ratio ))
|
||||
assert_in "${loop}p3 : start= *${start}, size= *${size}, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=DB081670-07AE-48CA-9F5E-813D5E40B976, name=\"linux-generic-2\"" "$output"
|
||||
}
|
||||
|
||||
test_copy_blocks
|
||||
test_unaligned_partition
|
||||
test_issue_21817
|
||||
|
||||
# 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
|
||||
# typical hardware
|
||||
testsector 512
|
||||
testsector 1024
|
||||
testsector 2048
|
||||
testsector 4096
|
||||
test_sector 512
|
||||
test_sector 1024
|
||||
test_sector 2048
|
||||
test_sector 4096
|
||||
|
||||
echo OK >/testok
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user