From c189d3bd788950484d13fb5529976601495d077f Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 4 Apr 2022 15:58:03 +0200 Subject: [PATCH 1/2] test: use the new `udevadm wait` verb to wait for the loop device The original workaround didn't work, as `systemd-repart` kept failing even when the `/dev/loopX` device was present: ``` [ 13.959419] H testsuite-58.sh[280]: + LOOP=/dev/loop1 [ 13.959636] H testsuite-58.sh[280]: + : [ 13.959764] H testsuite-58.sh[280]: + test -e /dev/loop1 [ 13.959895] H testsuite-58.sh[280]: + break [ 13.960023] H testsuite-58.sh[280]: + systemd-repart --pretty=yes --definitions=/tmp/testsuite-58-sector/ --seed=750b6cd5c4ae4012a15e7be3c29e6a47 --empty=require --dry-run=no /dev/loop1 [ 13.970538] H testsuite-58.sh[363]: Device '/dev/loop1' has no dm-crypt/dm-verity device, no need to look for underlying block device. [ 13.970538] H testsuite-58.sh[363]: Failed to determine canonical path for '/dev/loop1': No such file or directory [ 13.970538] H testsuite-58.sh[363]: Failed to open file or determine backing device of /dev/loop1: No such file or directory ``` --- test/units/testsuite-58.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/test/units/testsuite-58.sh b/test/units/testsuite-58.sh index cef7d094fd..21f762d399 100755 --- a/test/units/testsuite-58.sh +++ b/test/units/testsuite-58.sh @@ -174,10 +174,7 @@ rm -r /tmp/testsuite-58.3-defs/ mkdir -p /tmp/testsuite-58-issue-21817-defs/ truncate -s 100m /var/tmp/testsuite-58-issue-21817.img LOOP=$(losetup -P --show -f /var/tmp/testsuite-58-issue-21817.img) -while : ; do - test -e "$LOOP" && break - sleep .2 -done +udevadm wait --timeout 60 --initialized=yes --settle "${LOOP:?}" printf 'size=50M,type=%s\n,\n' "${root_guid}" | sfdisk -X gpt "$LOOP" cat >/tmp/testsuite-58-issue-21817-defs/test.conf < Date: Mon, 4 Apr 2022 15:56:00 +0200 Subject: [PATCH 2/2] partition: use `udevadm wait` --- meson.build | 45 ++++++++++++++++++------------------ src/partition/test-repart.sh | 7 +++--- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/meson.build b/meson.build index 311895db5e..0455d89b78 100644 --- a/meson.build +++ b/meson.build @@ -3076,27 +3076,6 @@ if conf.get('ENABLE_BINFMT') == 1 endif endif -if conf.get('ENABLE_REPART') == 1 - exe = executable( - 'systemd-repart', - systemd_repart_sources, - include_directories : includes, - link_with : [libshared], - dependencies : [threads, - libblkid, - libfdisk], - install_rpath : rootlibexecdir, - install : true, - install_dir : rootbindir) - public_programs += exe - - if want_tests != 'false' - test('test-repart', - test_repart_sh, - args : exe.full_path()) - endif -endif - if conf.get('ENABLE_SYSUPDATE') == 1 exe = executable( 'systemd-sysupdate', @@ -3517,7 +3496,7 @@ public_programs += executable( install : true, install_dir : rootlibexecdir) -public_programs += executable( +udevadm = executable( 'udevadm', udevadm_sources, include_directories : includes, @@ -3531,6 +3510,28 @@ public_programs += executable( install_rpath : udev_rpath, install : true, install_dir : rootbindir) +public_programs += udevadm + +if conf.get('ENABLE_REPART') == 1 + exe = executable( + 'systemd-repart', + systemd_repart_sources, + include_directories : includes, + link_with : [libshared], + dependencies : [threads, + libblkid, + libfdisk], + install_rpath : rootlibexecdir, + install : true, + install_dir : rootbindir) + public_programs += exe + + if want_tests != 'false' + test('test-repart', + test_repart_sh, + args : [exe.full_path(), udevadm.full_path()]) + endif +endif executable( 'systemd-shutdown', diff --git a/src/partition/test-repart.sh b/src/partition/test-repart.sh index 1783793127..88b696ba01 100755 --- a/src/partition/test-repart.sh +++ b/src/partition/test-repart.sh @@ -6,7 +6,9 @@ set -o pipefail [[ -e /dev/loop-control ]] || exit 77 repart="${1:?}" +udevadm="${2:?}" test -x "$repart" +test -x "$udevadm" PATH=$PATH:/sbin:/usr/sbin @@ -199,10 +201,7 @@ $D/zzz7 : start= 6291416, size= 98304, type=0FC63DAF-8483-4772-8E79-3D EOF LOOP="$(losetup -P --show --find "$D/zzz")" - while : ; do - test -e "$LOOP" && break - sleep .2 - done + "${udevadm:?}" wait --timeout 60 --initialized=yes --settle "${LOOP:?}" VOLUME="test-repart-$RANDOM"