From 94d74c9cd7c09ef0cd305ba186fb9adf6d0a61d5 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Mon, 5 Jun 2023 15:29:47 +0200 Subject: [PATCH] test: Test --offline= in TEST-58-REPART Instead of using a privileged and unprivileged user to test the offline and online logic of systemd-repart, let's always run repart as root and use the --offline= argument to specify repart to use either the offline or online logic. --- test/units/testsuite-58.sh | 293 ++++++++++++++++++++----------------- 1 file changed, 155 insertions(+), 138 deletions(-) diff --git a/test/units/testsuite-58.sh b/test/units/testsuite-58.sh index 521584892fb..6ddb96d26e3 100755 --- a/test/units/testsuite-58.sh +++ b/test/units/testsuite-58.sh @@ -96,17 +96,18 @@ testcase_basic() { local loop volume defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")" - imgs="$(runas testuser mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")" + imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")" # shellcheck disable=SC2064 trap "rm -rf '$defs' '$imgs'" RETURN chmod a+rx "$defs" echo "*** 1. create an empty image ***" - runas testuser systemd-repart --empty=create \ - --size=1G \ - --seed="$seed" \ - "$imgs/zzz" + systemd-repart --offline="$OFFLINE" \ + --empty=create \ + --size=1G \ + --seed="$seed" \ + "$imgs/zzz" output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$') @@ -140,11 +141,13 @@ SizeMaxBytes=64M PaddingMinBytes=92M EOF - runas testuser systemd-repart --definitions="$defs" \ - --dry-run=no \ - --seed="$seed" \ - --include-partitions=home,swap \ - "$imgs/zzz" + systemd-repart --offline="$OFFLINE" \ + --definitions="$defs" \ + --dry-run=no \ + --seed="$seed" \ + --include-partitions=home,swap \ + --offline="$OFFLINE" \ + "$imgs/zzz" output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$') @@ -157,12 +160,13 @@ last-lba: 2097118 $imgs/zzz1 : start= 2048, size= 1775576, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=4980595D-D74A-483A-AA9E-9903879A0EE5, name=\"home-first\", attrs=\"GUID:59\" $imgs/zzz2 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=78C92DB8-3D2B-4823-B0DC-792B78F66F1E, name=\"swap\"" - runas testuser systemd-repart --definitions="$defs" \ - --dry-run=no \ - --seed="$seed" \ - --empty=force \ - --defer-partitions=home,root \ - "$imgs/zzz" + systemd-repart --offline="$OFFLINE" \ + --definitions="$defs" \ + --dry-run=no \ + --seed="$seed" \ + --empty=force \ + --defer-partitions=home,root \ + "$imgs/zzz" output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$') @@ -174,10 +178,11 @@ first-lba: 2048 last-lba: 2097118 $imgs/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=78C92DB8-3D2B-4823-B0DC-792B78F66F1E, name=\"swap\"" - runas testuser systemd-repart --definitions="$defs" \ - --dry-run=no \ - --seed="$seed" \ - "$imgs/zzz" + systemd-repart --offline="$OFFLINE" \ + --definitions="$defs" \ + --dry-run=no \ + --seed="$seed" \ + "$imgs/zzz" output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$') @@ -210,10 +215,11 @@ EOF echo "Label=ignored_label" >>"$defs/home.conf" echo "UUID=b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" >>"$defs/home.conf" - runas testuser systemd-repart --definitions="$defs" \ - --dry-run=no \ - --seed="$seed" \ - "$imgs/zzz" + systemd-repart --offline="$OFFLINE" \ + --definitions="$defs" \ + --dry-run=no \ + --seed="$seed" \ + "$imgs/zzz" output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$') @@ -231,11 +237,12 @@ $imgs/zzz5 : start= 1908696, size= 188416, type=0FC63DAF-8483-4772-8E79 echo "*** 4. Resizing to 2G ***" - runas testuser systemd-repart --definitions="$defs" \ - --size=2G \ - --dry-run=no \ - --seed="$seed" \ - "$imgs/zzz" + systemd-repart --offline="$OFFLINE" \ + --definitions="$defs" \ + --size=2G \ + --dry-run=no \ + --seed="$seed" \ + "$imgs/zzz" output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$') @@ -263,11 +270,12 @@ UUID=2a1d97e1d0a346cca26eadc643926617 CopyBlocks=$imgs/block-copy EOF - runas testuser systemd-repart --definitions="$defs" \ - --size=3G \ - --dry-run=no \ - --seed="$seed" \ - "$imgs/zzz" + systemd-repart --offline="$OFFLINE" \ + --definitions="$defs" \ + --size=3G \ + --dry-run=no \ + --seed="$seed" \ + "$imgs/zzz" output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$') @@ -299,15 +307,12 @@ CopyFiles=$defs:/def SizeMinBytes=48M EOF - # CopyFiles will fail if we try to chown the target file to root. - # Make the files owned by the user so that the invocation below works. - chown testuser -R "$defs" - - runas testuser systemd-repart --definitions="$defs" \ - --size=auto \ - --dry-run=no \ - --seed="$seed" \ - "$imgs/zzz" + systemd-repart --offline="$OFFLINE" \ + --definitions="$defs" \ + --size=auto \ + --dry-run=no \ + --seed="$seed" \ + "$imgs/zzz" output=$(sfdisk -d "$imgs/zzz" | grep -v -e 'sector-size' -e '^$') @@ -350,7 +355,7 @@ testcase_dropin() { local defs imgs output defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")" - imgs="$(runas testuser mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")" + imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")" # shellcheck disable=SC2064 trap "rm -rf '$defs' '$imgs'" RETURN chmod a+rx "$defs" @@ -374,11 +379,12 @@ EOF Label=label2 EOF - output=$(runas testuser systemd-repart --definitions="$defs" \ - --empty=create \ - --size=100M \ - --json=pretty \ - "$imgs/zzz") + output=$(systemd-repart --offline="$OFFLINE" \ + --definitions="$defs" \ + --empty=create \ + --size=100M \ + --json=pretty \ + "$imgs/zzz") diff -u <(echo "$output") - <= 512 and <= PAGE_SIZE, and # must be powers of 2. Which leaves exactly four different ones to test on # typical hardware