diff options
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/wic.py')
-rw-r--r-- | meta/lib/oeqa/selftest/cases/wic.py | 124 |
1 files changed, 89 insertions, 35 deletions
diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py index b1c318bd4e..bb4ac23ebf 100644 --- a/meta/lib/oeqa/selftest/cases/wic.py +++ b/meta/lib/oeqa/selftest/cases/wic.py | |||
@@ -18,6 +18,7 @@ from glob import glob | |||
18 | from shutil import rmtree, copy | 18 | from shutil import rmtree, copy |
19 | from tempfile import NamedTemporaryFile | 19 | from tempfile import NamedTemporaryFile |
20 | from tempfile import TemporaryDirectory | 20 | from tempfile import TemporaryDirectory |
21 | from textwrap import dedent | ||
21 | 22 | ||
22 | from oeqa.selftest.case import OESelftestTestCase | 23 | from oeqa.selftest.case import OESelftestTestCase |
23 | from oeqa.core.decorator import OETestTag | 24 | from oeqa.core.decorator import OETestTag |
@@ -1021,7 +1022,7 @@ class Wic2(WicTestCase): | |||
1021 | wicvars = wicvars.difference(('DEPLOY_DIR_IMAGE', 'IMAGE_BOOT_FILES', | 1022 | wicvars = wicvars.difference(('DEPLOY_DIR_IMAGE', 'IMAGE_BOOT_FILES', |
1022 | 'INITRD', 'INITRD_LIVE', 'ISODIR','INITRAMFS_IMAGE', | 1023 | 'INITRD', 'INITRD_LIVE', 'ISODIR','INITRAMFS_IMAGE', |
1023 | 'INITRAMFS_IMAGE_BUNDLE', 'INITRAMFS_LINK_NAME', | 1024 | 'INITRAMFS_IMAGE_BUNDLE', 'INITRAMFS_LINK_NAME', |
1024 | 'APPEND', 'IMAGE_EFI_BOOT_FILES')) | 1025 | 'APPEND', 'IMAGE_EFI_BOOT_FILES', 'IMAGE_EXTRA_PARTITION_FILES')) |
1025 | with open(path) as envfile: | 1026 | with open(path) as envfile: |
1026 | content = dict(line.split("=", 1) for line in envfile) | 1027 | content = dict(line.split("=", 1) for line in envfile) |
1027 | # test if variables used by wic present in the .env file | 1028 | # test if variables used by wic present in the .env file |
@@ -1329,41 +1330,47 @@ run_wic_cmd() { | |||
1329 | def test_extra_partition_space(self): | 1330 | def test_extra_partition_space(self): |
1330 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools") | 1331 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools") |
1331 | 1332 | ||
1332 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | 1333 | oldpath = os.environ['PATH'] |
1333 | tempf.write("bootloader --ptable gpt\n" \ | 1334 | os.environ['PATH'] = get_bb_var("PATH", "wic-tools") |
1334 | "part --ondisk hda --size 10M --extra-partition-space 10M --fstype=ext4\n" \ | ||
1335 | "part --ondisk hda --fixed-size 20M --extra-partition-space 10M --fstype=ext4\n" \ | ||
1336 | "part --source rootfs --ondisk hda --extra-partition-space 10M --fstype=ext4\n" \ | ||
1337 | "part --source rootfs --ondisk hda --fixed-size 200M --extra-partition-space 10M --fstype=ext4\n") | ||
1338 | tempf.flush() | ||
1339 | |||
1340 | _, wicimg = self._get_wic(tempf.name) | ||
1341 | |||
1342 | res = runCmd("parted -m %s unit b p" % wicimg, | ||
1343 | native_sysroot=native_sysroot, stderr=subprocess.PIPE) | ||
1344 | |||
1345 | # parse parted output which looks like this: | ||
1346 | # BYT;\n | ||
1347 | # /var/tmp/wic/build/tmpfwvjjkf_-201611101222-hda.direct:200MiB:file:512:512:msdos::;\n | ||
1348 | # 1:0.00MiB:200MiB:200MiB:ext4::;\n | ||
1349 | partlns = res.output.splitlines()[2:] | ||
1350 | |||
1351 | self.assertEqual(4, len(partlns)) | ||
1352 | 1335 | ||
1353 | # Test for each partitions that the extra part space exists | 1336 | try: |
1354 | for part in range(0, len(partlns)): | 1337 | with NamedTemporaryFile("w", suffix=".wks") as tempf: |
1355 | part_file = os.path.join(self.resultdir, "selftest_img.part%d" % (part + 1)) | 1338 | tempf.write("bootloader --ptable gpt\n" \ |
1356 | partln = partlns[part].split(":") | 1339 | "part --ondisk hda --size 10M --extra-partition-space 10M --fstype=ext4\n" \ |
1357 | self.assertEqual(7, len(partln)) | 1340 | "part --ondisk hda --fixed-size 20M --extra-partition-space 10M --fstype=ext4\n" \ |
1358 | self.assertRegex(partln[3], r'^[0-9]+B$') | 1341 | "part --source rootfs --ondisk hda --extra-partition-space 10M --fstype=ext4\n" \ |
1359 | part_size = int(partln[3].rstrip("B")) | 1342 | "part --source rootfs --ondisk hda --fixed-size 200M --extra-partition-space 10M --fstype=ext4\n") |
1360 | start = int(partln[1].rstrip("B")) / 512 | 1343 | tempf.flush() |
1361 | length = part_size / 512 | 1344 | |
1362 | runCmd("dd if=%s of=%s skip=%d count=%d" % | 1345 | _, wicimg = self._get_wic(tempf.name) |
1363 | (wicimg, part_file, start, length)) | 1346 | |
1364 | res = runCmd("dumpe2fs %s -h | grep \"^Block count\"" % part_file) | 1347 | res = runCmd("parted -m %s unit b p" % wicimg, |
1365 | fs_size = int(res.output.split(":")[1].strip()) * 1024 | 1348 | native_sysroot=native_sysroot, stderr=subprocess.PIPE) |
1366 | self.assertLessEqual(fs_size + 10485760, part_size, "part file: %s" % part_file) | 1349 | |
1350 | # parse parted output which looks like this: | ||
1351 | # BYT;\n | ||
1352 | # /var/tmp/wic/build/tmpfwvjjkf_-201611101222-hda.direct:200MiB:file:512:512:msdos::;\n | ||
1353 | # 1:0.00MiB:200MiB:200MiB:ext4::;\n | ||
1354 | partlns = res.output.splitlines()[2:] | ||
1355 | |||
1356 | self.assertEqual(4, len(partlns)) | ||
1357 | |||
1358 | # Test for each partitions that the extra part space exists | ||
1359 | for part in range(0, len(partlns)): | ||
1360 | part_file = os.path.join(self.resultdir, "selftest_img.part%d" % (part + 1)) | ||
1361 | partln = partlns[part].split(":") | ||
1362 | self.assertEqual(7, len(partln)) | ||
1363 | self.assertRegex(partln[3], r'^[0-9]+B$') | ||
1364 | part_size = int(partln[3].rstrip("B")) | ||
1365 | start = int(partln[1].rstrip("B")) / 512 | ||
1366 | length = part_size / 512 | ||
1367 | runCmd("dd if=%s of=%s skip=%d count=%d" % | ||
1368 | (wicimg, part_file, start, length)) | ||
1369 | res = runCmd("dumpe2fs %s -h | grep \"^Block count\"" % part_file) | ||
1370 | fs_size = int(res.output.split(":")[1].strip()) * 1024 | ||
1371 | self.assertLessEqual(fs_size + 10485760, part_size, "part file: %s" % part_file) | ||
1372 | finally: | ||
1373 | os.environ['PATH'] = oldpath | ||
1367 | 1374 | ||
1368 | # TODO this test could also work on aarch64 | 1375 | # TODO this test could also work on aarch64 |
1369 | @skipIfNotArch(['i586', 'i686', 'x86_64']) | 1376 | @skipIfNotArch(['i586', 'i686', 'x86_64']) |
@@ -1647,6 +1654,53 @@ INITRAMFS_IMAGE = "core-image-initramfs-boot" | |||
1647 | status, output = qemu.run_serial(cmd) | 1654 | status, output = qemu.run_serial(cmd) |
1648 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) | 1655 | self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) |
1649 | 1656 | ||
1657 | def test_extra_partition_plugin(self): | ||
1658 | """Test extra partition plugin""" | ||
1659 | config = dedent("""\ | ||
1660 | IMAGE_EXTRA_PARTITION_FILES_label-foo = "bar.conf;foo.conf" | ||
1661 | IMAGE_EXTRA_PARTITION_FILES_uuid-e7d0824e-cda3-4bed-9f54-9ef5312d105d = "bar.conf;foobar.conf" | ||
1662 | IMAGE_EXTRA_PARTITION_FILES = "foo/*" | ||
1663 | WICVARS:append = "\ | ||
1664 | IMAGE_EXTRA_PARTITION_FILES_label-foo \ | ||
1665 | IMAGE_EXTRA_PARTITION_FILES_uuid-e7d0824e-cda3-4bed-9f54-9ef5312d105d \ | ||
1666 | " | ||
1667 | """) | ||
1668 | self.append_config(config) | ||
1669 | |||
1670 | deploy_dir = get_bb_var('DEPLOY_DIR_IMAGE') | ||
1671 | |||
1672 | testfile = open(os.path.join(deploy_dir, "bar.conf"), "w") | ||
1673 | testfile.write("test") | ||
1674 | testfile.close() | ||
1675 | |||
1676 | os.mkdir(os.path.join(deploy_dir, "foo")) | ||
1677 | testfile = open(os.path.join(deploy_dir, "foo", "bar.conf"), "w") | ||
1678 | testfile.write("test") | ||
1679 | testfile.close() | ||
1680 | |||
1681 | oldpath = os.environ['PATH'] | ||
1682 | os.environ['PATH'] = get_bb_var("PATH", "wic-tools") | ||
1683 | |||
1684 | try: | ||
1685 | with NamedTemporaryFile("w", suffix=".wks") as wks: | ||
1686 | wks.writelines(['part / --source extra_partition --ondisk sda --fstype=ext4 --label foo --align 4 --size 5M\n', | ||
1687 | 'part / --source extra_partition --ondisk sda --fstype=ext4 --uuid e7d0824e-cda3-4bed-9f54-9ef5312d105d --align 4 --size 5M\n', | ||
1688 | 'part / --source extra_partition --ondisk sda --fstype=ext4 --label bar --align 4 --size 5M\n']) | ||
1689 | wks.flush() | ||
1690 | _, wicimg = self._get_wic(wks.name) | ||
1691 | |||
1692 | result = runCmd("wic ls %s | wc -l" % wicimg) | ||
1693 | self.assertEqual('4', result.output, msg="Expect 3 partitions, not %s" % result.output) | ||
1694 | |||
1695 | for part, file in enumerate(["foo.conf", "foobar.conf", "bar.conf"]): | ||
1696 | result = runCmd("wic ls %s:%d | grep -q \"%s\"" % (wicimg, part + 1, file)) | ||
1697 | self.assertEqual(0, result.status, msg="File '%s' not found in the partition #%d" % (file, part)) | ||
1698 | |||
1699 | self.remove_config(config) | ||
1700 | |||
1701 | finally: | ||
1702 | os.environ['PATH'] = oldpath | ||
1703 | |||
1650 | def test_fs_types(self): | 1704 | def test_fs_types(self): |
1651 | """Test filesystem types for empty and not empty partitions""" | 1705 | """Test filesystem types for empty and not empty partitions""" |
1652 | img = 'core-image-minimal' | 1706 | img = 'core-image-minimal' |