1
0
mirror of https://git.yoctoproject.org/poky synced 2026-06-10 16:10:04 +00:00

oeqa/selftest/wic: fix PATH for wic.Wic2.test_extra_partition_space

Without importing PATH from the wic-tools recipes, the build host PATH
is used and this test may fail depending on tools (parted, dumpe2fs,
...) availability. This triggers build faillure on AB (e.g. [0])

To fix this, import PATH from wic-tools and ensure the original
environment is restored after.

Since this indent a block of code into a try/finally block, here is the
diff ignoring white spaces change:
  diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py
  index b1c318bd4e..34d844b90b 100644
  --- a/meta/lib/oeqa/selftest/cases/wic.py
  +++ b/meta/lib/oeqa/selftest/cases/wic.py
  @@ -1331,0 +1332,4 @@
  +        oldpath = os.environ['PATH']
  +        os.environ['PATH'] = get_bb_var("PATH", "wic-tools")
  +
  +        try:
  @@ -1366,0 +1371,2 @@
  +        finally:
  +            os.environ['PATH'] = oldpath

[0]: https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/2456

(From OE-Core rev: a6278a199807f1ad7ed1e27ec352af46e03e8b67)

Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Yoann Congal
2025-10-03 23:12:47 +02:00
committed by Richard Purdie
parent 107da7da4b
commit 82eb9a0c36
+36 -30
View File
@@ -1330,41 +1330,47 @@ run_wic_cmd() {
def test_extra_partition_space(self):
native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools")
with NamedTemporaryFile("w", suffix=".wks") as tempf:
tempf.write("bootloader --ptable gpt\n" \
"part --ondisk hda --size 10M --extra-partition-space 10M --fstype=ext4\n" \
"part --ondisk hda --fixed-size 20M --extra-partition-space 10M --fstype=ext4\n" \
"part --source rootfs --ondisk hda --extra-partition-space 10M --fstype=ext4\n" \
"part --source rootfs --ondisk hda --fixed-size 200M --extra-partition-space 10M --fstype=ext4\n")
tempf.flush()
oldpath = os.environ['PATH']
os.environ['PATH'] = get_bb_var("PATH", "wic-tools")
_, wicimg = self._get_wic(tempf.name)
try:
with NamedTemporaryFile("w", suffix=".wks") as tempf:
tempf.write("bootloader --ptable gpt\n" \
"part --ondisk hda --size 10M --extra-partition-space 10M --fstype=ext4\n" \
"part --ondisk hda --fixed-size 20M --extra-partition-space 10M --fstype=ext4\n" \
"part --source rootfs --ondisk hda --extra-partition-space 10M --fstype=ext4\n" \
"part --source rootfs --ondisk hda --fixed-size 200M --extra-partition-space 10M --fstype=ext4\n")
tempf.flush()
res = runCmd("parted -m %s unit b p" % wicimg,
native_sysroot=native_sysroot, stderr=subprocess.PIPE)
_, wicimg = self._get_wic(tempf.name)
# parse parted output which looks like this:
# BYT;\n
# /var/tmp/wic/build/tmpfwvjjkf_-201611101222-hda.direct:200MiB:file:512:512:msdos::;\n
# 1:0.00MiB:200MiB:200MiB:ext4::;\n
partlns = res.output.splitlines()[2:]
res = runCmd("parted -m %s unit b p" % wicimg,
native_sysroot=native_sysroot, stderr=subprocess.PIPE)
self.assertEqual(4, len(partlns))
# parse parted output which looks like this:
# BYT;\n
# /var/tmp/wic/build/tmpfwvjjkf_-201611101222-hda.direct:200MiB:file:512:512:msdos::;\n
# 1:0.00MiB:200MiB:200MiB:ext4::;\n
partlns = res.output.splitlines()[2:]
# Test for each partitions that the extra part space exists
for part in range(0, len(partlns)):
part_file = os.path.join(self.resultdir, "selftest_img.part%d" % (part + 1))
partln = partlns[part].split(":")
self.assertEqual(7, len(partln))
self.assertRegex(partln[3], r'^[0-9]+B$')
part_size = int(partln[3].rstrip("B"))
start = int(partln[1].rstrip("B")) / 512
length = part_size / 512
runCmd("dd if=%s of=%s skip=%d count=%d" %
(wicimg, part_file, start, length))
res = runCmd("dumpe2fs %s -h | grep \"^Block count\"" % part_file)
fs_size = int(res.output.split(":")[1].strip()) * 1024
self.assertLessEqual(fs_size + 10485760, part_size, "part file: %s" % part_file)
self.assertEqual(4, len(partlns))
# Test for each partitions that the extra part space exists
for part in range(0, len(partlns)):
part_file = os.path.join(self.resultdir, "selftest_img.part%d" % (part + 1))
partln = partlns[part].split(":")
self.assertEqual(7, len(partln))
self.assertRegex(partln[3], r'^[0-9]+B$')
part_size = int(partln[3].rstrip("B"))
start = int(partln[1].rstrip("B")) / 512
length = part_size / 512
runCmd("dd if=%s of=%s skip=%d count=%d" %
(wicimg, part_file, start, length))
res = runCmd("dumpe2fs %s -h | grep \"^Block count\"" % part_file)
fs_size = int(res.output.split(":")[1].strip()) * 1024
self.assertLessEqual(fs_size + 10485760, part_size, "part file: %s" % part_file)
finally:
os.environ['PATH'] = oldpath
# TODO this test could also work on aarch64
@skipIfNotArch(['i586', 'i686', 'x86_64'])