wic: bugfixes & --fixed-size support, tests, oe-selftest: minor fixes
v4 cover wic: bugfixes & --fixed-size support, tests, oe-selftest: minor fixes
v4 of patch series previously posted here [1].
Some of the patches that were posted as part of v3 are already in master. This version contains only the patches that were not merged yet.
Changes since v3:
* Running wic tests on Ubuntu resulted in test_fixed_size to fail. The reason was that parted is not a part of the base system, but is needed for verification of wic-produced partition layout. Parted is built as part of wic dependencies, hence oeqa/utils/commands.py:runCmd() was extended to include a new paramter - native_sysroot. This allows runCmd() to run binaries from STAGING_DIR_NATIVE{/sbin,/usr/bin,/usr/sbin}.
[1]. http://lists.openembedded.org/pipermail/openembedded-core/2016-November/128785.html
Maciej Borzecki (7):
oe-selftest: enforce en_US.UTF-8 locale oeqa/utils/commands.py: allow use of binaries from native sysroot
wic: add --fixed-size wks option
wic: selftest: avoid COMPATIBLE_HOST issues
wic: selftest: do not repeat core-image-minimal
wic: selftest: do not assume bzImage kernel image
wic: selftest: add tests for --fixed-size partition flags
meta/lib/oeqa/selftest/wic.py | 234 +++++++++++++++++++++++++++------ meta/lib/oeqa/utils/commands.py | 9 +- scripts/lib/wic/help.py | 14 +- scripts/lib/wic/imager/direct.py | 2 +- scripts/lib/wic/ksparser.py | 41 +++++- scripts/lib/wic/partition.py | 88 ++++++++----- scripts/lib/wic/utils/partitionedfs.py | 2 +- scripts/oe-selftest | 3 + 8 files changed, 307 insertions(+), 86 deletions(-)
Signature · 1 line
2.5.0
PATCH v4 1/7 oe-selftest: enforce en_US.UTF-8 locale
Replicate bitbake and eforce en_US.UTF-8 locale so that ouptut of locale-aware tools remains stable.
--- scripts/oe-selftest | 3 +++ 1 file changed, 3 insertions(+)
scripts/oe-selftest +3 -0
@@ -468,6 +468,9 @@ def main(): sys.path.extend(layer_libdirs) imp.reload(oeqa.selftest) + # act like bitbake and enforce en_US.UTF-8 locale + os.environ["LC_ALL"] = "en_US.UTF-8" + if args.run_tests_by and len(args.run_tests_by) >= 2: valid_options = ['name', 'class', 'module', 'id', 'tag'] if args.run_tests_by[0] not in valid_options:
Signature · 1 line
2.5.0
PATCH v4 2/7 oeqa/utils/commands.py: allow use of binaries from native sysroot
In reply to Maciej BorzeckiTests may need to run a native tool that is not available on the host filesystem, but can be built using one of the *-native recipes. In such case, the tool will be available in native sysroot, and running in from that location will require adjustments to PATH.
runCmd() can now take a path to native sysroot as one of its arguments and setup PATH accordingly.
--- meta/lib/oeqa/utils/commands.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
meta/lib/oeqa/utils/commands.py +8 -1
@@ -97,9 +97,16 @@ class Result(object): pass -def runCmd(command, ignore_status=False, timeout=None, assert_error=True, **options): +def runCmd(command, ignore_status=False, timeout=None, assert_error=True, native_sysroot=None, **options): result = Result() + if native_sysroot: + extra_paths = "%s/sbin:%s/usr/sbin:%s/usr/bin" % \ + (native_sysroot, native_sysroot, native_sysroot) + nenv = dict(options.get('env', os.environ)) + nenv['PATH'] = extra_paths + ':' + nenv.get('PATH', '') + options['env'] = nenv + cmd = Command(command, timeout=timeout, **options) cmd.run()
Signature · 1 line
2.5.0
PATCH v4 3/7 wic: add --fixed-size wks option
In reply to Maciej BorzeckiAdded new option --fixed-size to wks. The option can be used to indicate the exact size of a partition. The option cannot be added together with --size, in which case an error will be raised. Other options that influence automatic partition size (--extra-space, --overhead-factor), if specifiec along with --fixed-size, will raise an error.
If it partition data is larger than the amount of space specified with --fixed-size option wic will raise an error.
--- scripts/lib/wic/help.py | 14 ++++-- scripts/lib/wic/imager/direct.py | 2 +- scripts/lib/wic/ksparser.py | 41 ++++++++++++++-- scripts/lib/wic/partition.py | 88 +++++++++++++++++++++------------- scripts/lib/wic/utils/partitionedfs.py | 2 +- 5 files changed, 105 insertions(+), 42 deletions(-)
scripts/lib/wic/help.py +11 -3
@@ -646,6 +646,12 @@ DESCRIPTION not specified, the size is in MB. You do not need this option if you use --source. + --fixed-size: Exact partition size. Value format is the same + as for --size option. This option cannot be + specified along with --size. If partition data + is larger than --fixed-size and error will be + raised when assembling disk image. + --source: This option is a wic-specific option that names the source of the data that will populate the partition. The most common value for this option
@@ -719,13 +725,15 @@ DESCRIPTION space after the space filled by the content of the partition. The final size can go beyond the size specified by --size. - By default, 10MB. + By default, 10MB. This option cannot be used + with --fixed-size option. --overhead-factor: This option is specific to wic. The size of the partition is multiplied by this factor. It has to be greater than or - equal to 1. - The default value is 1.3. + equal to 1. The default value is 1.3. + This option cannot be used with --fixed-size + option. --part-type: This option is specific to wic. It specifies partition type GUID for GPT partitions.
scripts/lib/wic/imager/direct.py +1 -1
@@ -290,7 +290,7 @@ class DirectImageCreator(BaseImageCreator): self.bootimg_dir, self.kernel_dir, self.native_sysroot) - self.__image.add_partition(int(part.size), + self.__image.add_partition(part.disk_size, part.disk, part.mountpoint, part.source_file,
scripts/lib/wic/ksparser.py +37 -4
70 lines not on this page · raw message
scripts/lib/wic/partition.py +55 -33
161 lines not on this page · raw message
scripts/lib/wic/utils/partitionedfs.py +1 -1
@@ -209,7 +209,7 @@ class Image(): msger.debug("Assigned %s to %s%d, sectors range %d-%d size %d " "sectors (%d bytes)." \ % (part['mountpoint'], part['disk_name'], part['num'], - part['start'], part['start'] + part['size'] - 1, + part['start'], disk['offset'] - 1, part['size'], part['size'] * self.sector_size)) # Once all the partitions have been layed out, we can calculate the
Signature · 1 line
2.5.0
PATCH v4 4/7 wic: selftest: avoid COMPATIBLE_HOST issues
In reply to Maciej Borzeckiwic tests will unconditionally attempt to build syslinux and add configuration options that may not be compatible with current machine.
Resolve this by consulting HOST_ARCH (which defaults to TARGET_ARCH) and build recipes, add configuration options or skip tests conditionally.
A convenience decorator onlyForArch() can be used to skip test cases for specific architectures.
--- meta/lib/oeqa/selftest/wic.py | 51 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-)
meta/lib/oeqa/selftest/wic.py +47 -4
@@ -24,15 +24,33 @@ """Test cases for wic.""" import os +import unittest from glob import glob from shutil import rmtree +from functools import wraps from oeqa.selftest.base import oeSelfTest from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu from oeqa.utils.decorators import testcase +class onlyForArch(object): + + def __init__(self, *args): + self.archs = args + + def __call__(self,f): + @wraps(f) + def wrapped_f(*args, **kwargs): + arch = get_bb_var('HOST_ARCH', 'core-image-minimal') + if self.archs and arch not in self.archs : + raise unittest.SkipTest("Testcase arch dependency not met: %s" % arch) + return f(*args, **kwargs) + wrapped_f.__name__ = f.__name__ + return wrapped_f + + class Wic(oeSelfTest): """Wic test class."""
@@ -41,15 +59,22 @@ class Wic(oeSelfTest): def setUpLocal(self): """This code is executed before each test method.""" - self.write_config('IMAGE_FSTYPES += " hddimg"\n' - 'MACHINE_FEATURES_append = " efi"\n') + arch = get_bb_var('HOST_ARCH', 'core-image-minimal') + is_x86 = arch in ['i586', 'i686', 'x86_64'] + if is_x86: + self.write_config('IMAGE_FSTYPES += " hddimg"\n' \ + 'MACHINE_FEATURES_append = " efi"\n') # Do this here instead of in setUpClass as the base setUp does some # clean up which can result in the native tools built earlier in # setUpClass being unavailable. if not Wic.image_is_ready: - bitbake('syslinux syslinux-native parted-native gptfdisk-native ' - 'dosfstools-native mtools-native bmap-tools-native') + tools = 'parted-native gptfdisk-native ' \ + 'dosfstools-native mtools-native bmap-tools-native' + if is_x86: + tools += ' syslinux syslinux-native' + bitbake(tools) + bitbake('core-image-minimal') Wic.image_is_ready = True
@@ -71,6 +96,7 @@ class Wic(oeSelfTest): self.assertEqual(0, runCmd('wic list --help').status) @testcase(1211) + @onlyForArch('i586', 'i686', 'x86_64') def test_build_image_name(self): """Test wic create directdisk --image-name core-image-minimal""" self.assertEqual(0, runCmd("wic create directdisk "
@@ -78,6 +104,7 @@ class Wic(oeSelfTest): self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct"))) @testcase(1212) + @onlyForArch('i586', 'i686', 'x86_64') def test_build_artifacts(self): """Test wic create directdisk providing all artifacts.""" bbvars = dict((var.lower(), get_bb_var(var, 'core-image-minimal')) \
@@ -92,6 +119,7 @@ class Wic(oeSelfTest): self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct"))) @testcase(1157) + @onlyForArch('i586', 'i686', 'x86_64') def test_gpt_image(self): """Test creation of core-image-minimal with gpt table and UUID boot""" self.assertEqual(0, runCmd("wic create directdisk-gpt "
@@ -125,6 +153,7 @@ class Wic(oeSelfTest): self.assertEqual(0, runCmd('wic help kickstart').status) @testcase(1264) + @onlyForArch('i586', 'i686', 'x86_64') def test_compress_gzip(self): """Test compressing an image with gzip""" self.assertEqual(0, runCmd("wic create directdisk "
@@ -134,6 +163,7 @@ class Wic(oeSelfTest): "directdisk-*.direct.gz"))) @testcase(1265) + @onlyForArch('i586', 'i686', 'x86_64') def test_compress_bzip2(self): """Test compressing an image with bzip2""" self.assertEqual(0, runCmd("wic create directdisk "
@@ -143,6 +173,7 @@ class Wic(oeSelfTest): "directdisk-*.direct.bz2"))) @testcase(1266) + @onlyForArch('i586', 'i686', 'x86_64') def test_compress_xz(self): """Test compressing an image with xz""" self.assertEqual(0, runCmd("wic create directdisk "
@@ -152,6 +183,7 @@ class Wic(oeSelfTest): "directdisk-*.direct.xz"))) @testcase(1267) + @onlyForArch('i586', 'i686', 'x86_64') def test_wrong_compressor(self): """Test how wic breaks if wrong compressor is provided""" self.assertEqual(2, runCmd("wic create directdisk "
@@ -159,6 +191,7 @@ class Wic(oeSelfTest): "-c wrong", ignore_status=True).status) @testcase(1268) + @onlyForArch('i586', 'i686', 'x86_64') def test_rootfs_indirect_recipes(self): """Test usage of rootfs plugin with rootfs recipes""" wks = "directdisk-multi-rootfs"
@@ -170,6 +203,7 @@ class Wic(oeSelfTest): self.assertEqual(1, len(glob(self.resultdir + "%s*.direct" % wks))) @testcase(1269) + @onlyForArch('i586', 'i686', 'x86_64') def test_rootfs_artifacts(self): """Test usage of rootfs plugin with rootfs paths""" bbvars = dict((var.lower(), get_bb_var(var, 'core-image-minimal')) \
@@ -188,6 +222,7 @@ class Wic(oeSelfTest): "%(wks)s-*.direct" % bbvars))) @testcase(1346) + @onlyForArch('i586', 'i686', 'x86_64') def test_iso_image(self): """Test creation of hybrid iso image with legacy and EFI boot""" self.assertEqual(0, runCmd("wic create mkhybridiso "
@@ -220,6 +255,7 @@ class Wic(oeSelfTest): self.assertTrue(content[var]) @testcase(1351) + @onlyForArch('i586', 'i686', 'x86_64') def test_wic_image_type(self): """Test building wic images by bitbake""" self.assertEqual(0, bitbake('wic-image-minimal').status)
@@ -235,6 +271,7 @@ class Wic(oeSelfTest): self.assertTrue(os.path.isfile(os.path.realpath(path))) @testcase(1348) + @onlyForArch('i586', 'i686', 'x86_64') def test_qemux86_directdisk(self): """Test creation of qemux-86-directdisk image""" image = "qemux86-directdisk"
@@ -243,6 +280,7 @@ class Wic(oeSelfTest): self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) @testcase(1349) + @onlyForArch('i586', 'i686', 'x86_64') def test_mkgummidisk(self): """Test creation of mkgummidisk image""" image = "mkgummidisk"
@@ -251,6 +289,7 @@ class Wic(oeSelfTest): self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) @testcase(1350) + @onlyForArch('i586', 'i686', 'x86_64') def test_mkefidisk(self): """Test creation of mkefidisk image""" image = "mkefidisk"
@@ -259,6 +298,7 @@ class Wic(oeSelfTest): self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) @testcase(1385) + @onlyForArch('i586', 'i686', 'x86_64') def test_directdisk_bootloader_config(self): """Test creation of directdisk-bootloader-config image""" image = "directdisk-bootloader-config"
@@ -267,6 +307,7 @@ class Wic(oeSelfTest): self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) @testcase(1422) + @onlyForArch('i586', 'i686', 'x86_64') def test_qemu(self): """Test wic-image-minimal under qemu""" self.assertEqual(0, bitbake('wic-image-minimal').status)
@@ -277,6 +318,7 @@ class Wic(oeSelfTest): self.assertEqual(1, status, 'Failed to run command "%s": %s' % (command, output)) self.assertEqual(output, '/dev/root /\r\n/dev/vda3 /mnt') + @onlyForArch('i586', 'i686', 'x86_64') def test_bmap(self): """Test generation of .bmap file""" image = "directdisk"
@@ -285,6 +327,7 @@ class Wic(oeSelfTest): self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct.bmap" % image))) + @onlyForArch('i586', 'i686', 'x86_64') def test_systemd_bootdisk(self): """Test creation of systemd-bootdisk image""" image = "systemd-bootdisk"
Signature · 1 line
2.5.0
PATCH v4 5/7 wic: selftest: do not repeat core-image-minimal
In reply to Maciej BorzeckiReplace repeated core-image-minimal with Wic class field.
--- meta/lib/oeqa/selftest/wic.py | 111 +++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 38 deletions(-)
meta/lib/oeqa/selftest/wic.py +73 -38
@@ -57,6 +57,8 @@ class Wic(oeSelfTest): resultdir = "/var/tmp/wic/build/" image_is_ready = False + OE_IMAGE = "core-image-minimal" + def setUpLocal(self): """This code is executed before each test method.""" arch = get_bb_var('HOST_ARCH', 'core-image-minimal')
@@ -75,7 +77,7 @@ class Wic(oeSelfTest): tools += ' syslinux syslinux-native' bitbake(tools) - bitbake('core-image-minimal') + bitbake(self.OE_IMAGE) Wic.image_is_ready = True rmtree(self.resultdir, ignore_errors=True)
@@ -100,14 +102,14 @@ class Wic(oeSelfTest): def test_build_image_name(self): """Test wic create directdisk --image-name core-image-minimal""" self.assertEqual(0, runCmd("wic create directdisk " - "--image-name core-image-minimal").status) + "--image-name %s" % self.OE_IMAGE).status) self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct"))) @testcase(1212) @onlyForArch('i586', 'i686', 'x86_64') def test_build_artifacts(self): """Test wic create directdisk providing all artifacts.""" - bbvars = dict((var.lower(), get_bb_var(var, 'core-image-minimal')) \ + bbvars = dict((var.lower(), get_bb_var(var, self.OE_IMAGE)) \ for var in ('STAGING_DATADIR', 'DEPLOY_DIR_IMAGE', 'STAGING_DIR_NATIVE', 'IMAGE_ROOTFS')) status = runCmd("wic create directdisk "
@@ -123,7 +125,7 @@ class Wic(oeSelfTest): def test_gpt_image(self): """Test creation of core-image-minimal with gpt table and UUID boot""" self.assertEqual(0, runCmd("wic create directdisk-gpt " - "--image-name core-image-minimal").status) + "--image-name %s" % self.OE_IMAGE).status) self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct"))) @testcase(1213)
@@ -157,8 +159,8 @@ class Wic(oeSelfTest): def test_compress_gzip(self): """Test compressing an image with gzip""" self.assertEqual(0, runCmd("wic create directdisk " - "--image-name core-image-minimal " - "-c gzip").status) + "--image-name %s " + "-c gzip" % self.OE_IMAGE).status) self.assertEqual(1, len(glob(self.resultdir + \ "directdisk-*.direct.gz")))
@@ -167,8 +169,8 @@ class Wic(oeSelfTest): def test_compress_bzip2(self): """Test compressing an image with bzip2""" self.assertEqual(0, runCmd("wic create directdisk " - "--image-name core-image-minimal " - "-c bzip2").status) + "--image-name %s " + "-c bzip2" % self.OE_IMAGE).status) self.assertEqual(1, len(glob(self.resultdir + \ "directdisk-*.direct.bz2")))
@@ -177,8 +179,8 @@ class Wic(oeSelfTest): def test_compress_xz(self): """Test compressing an image with xz""" self.assertEqual(0, runCmd("wic create directdisk " - "--image-name core-image-minimal " - "-c xz").status) + "--image-name %s " + "-c xz" % self.OE_IMAGE).status) self.assertEqual(1, len(glob(self.resultdir + \ "directdisk-*.direct.xz")))
@@ -187,26 +189,31 @@ class Wic(oeSelfTest): def test_wrong_compressor(self): """Test how wic breaks if wrong compressor is provided""" self.assertEqual(2, runCmd("wic create directdisk " - "--image-name core-image-minimal " - "-c wrong", ignore_status=True).status) + "--image-name %s " + "-c wrong" % self.OE_IMAGE, + ignore_status=True).status) @testcase(1268) @onlyForArch('i586', 'i686', 'x86_64') def test_rootfs_indirect_recipes(self): """Test usage of rootfs plugin with rootfs recipes""" wks = "directdisk-multi-rootfs" - self.assertEqual(0, runCmd("wic create %s " - "--image-name core-image-minimal " - "--rootfs rootfs1=core-image-minimal " - "--rootfs rootfs2=core-image-minimal" \ - % wks).status) + wic_cmd_vars = { + 'wks': wks, + 'image': self.OE_IMAGE, + } + self.assertEqual(0, runCmd("wic create %(wks)s " + "--image-name %(image)s " + "--rootfs rootfs1=%(image)s " + "--rootfs rootfs2=%(image)s" \ + % wic_cmd_vars).status) self.assertEqual(1, len(glob(self.resultdir + "%s*.direct" % wks))) @testcase(1269) @onlyForArch('i586', 'i686', 'x86_64') def test_rootfs_artifacts(self): """Test usage of rootfs plugin with rootfs paths""" - bbvars = dict((var.lower(), get_bb_var(var, 'core-image-minimal')) \ + bbvars = dict((var.lower(), get_bb_var(var, self.OE_IMAGE)) \ for var in ('STAGING_DATADIR', 'DEPLOY_DIR_IMAGE', 'STAGING_DIR_NATIVE', 'IMAGE_ROOTFS')) bbvars['wks'] = "directdisk-multi-rootfs"
@@ -226,24 +233,23 @@ class Wic(oeSelfTest): def test_iso_image(self): """Test creation of hybrid iso image with legacy and EFI boot""" self.assertEqual(0, runCmd("wic create mkhybridiso " - "--image-name core-image-minimal").status) + "--image-name %s" % self.OE_IMAGE).status) self.assertEqual(1, len(glob(self.resultdir + "HYBRID_ISO_IMG-*.direct"))) self.assertEqual(1, len(glob(self.resultdir + "HYBRID_ISO_IMG-*.iso"))) @testcase(1347) def test_image_env(self): """Test generation of <image>.env files.""" - image = 'core-image-minimal' - self.assertEqual(0, bitbake('%s -c do_rootfs_wicenv' % image).status) - stdir = get_bb_var('STAGING_DIR_TARGET', image) + self.assertEqual(0, bitbake('%s -c do_rootfs_wicenv' % self.OE_IMAGE).status) + stdir = get_bb_var('STAGING_DIR_TARGET', self.OE_IMAGE) imgdatadir = os.path.join(stdir, 'imgdata') - basename = get_bb_var('IMAGE_BASENAME', image) - self.assertEqual(basename, image) + basename = get_bb_var('IMAGE_BASENAME', self.OE_IMAGE) + self.assertEqual(basename, self.OE_IMAGE) path = os.path.join(imgdatadir, basename) + '.env' self.assertTrue(os.path.isfile(path)) - wicvars = set(get_bb_var('WICVARS', image).split()) + wicvars = set(get_bb_var('WICVARS', self.OE_IMAGE).split()) # filter out optional variables wicvars = wicvars.difference(('HDDDIR', 'IMAGE_BOOT_FILES', 'INITRD', 'ISODIR'))
@@ -275,8 +281,12 @@ class Wic(oeSelfTest): def test_qemux86_directdisk(self): """Test creation of qemux-86-directdisk image""" image = "qemux86-directdisk" - self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ - % image).status) + wic_cmd_vars = { + 'wks': image, + 'image': self.OE_IMAGE, + } + self.assertEqual(0, runCmd("wic create %(wks)s -e %(image)s" \ + % wic_cmd_vars).status) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) @testcase(1349)
@@ -284,8 +294,12 @@ class Wic(oeSelfTest): def test_mkgummidisk(self): """Test creation of mkgummidisk image""" image = "mkgummidisk" - self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ - % image).status) + wic_cmd_vars = { + 'wks': image, + 'image': self.OE_IMAGE, + } + self.assertEqual(0, runCmd("wic create %(wks)s -e %(image)s" \ + % wic_cmd_vars).status) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) @testcase(1350)
@@ -293,8 +307,12 @@ class Wic(oeSelfTest): def test_mkefidisk(self): """Test creation of mkefidisk image""" image = "mkefidisk" - self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ - % image).status) + wic_cmd_vars = { + 'wks': image, + 'image': self.OE_IMAGE, + } + self.assertEqual(0, runCmd("wic create %(wks)s -e %(image)s" \ + % wic_cmd_vars).status) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) @testcase(1385)
@@ -302,8 +320,12 @@ class Wic(oeSelfTest): def test_directdisk_bootloader_config(self): """Test creation of directdisk-bootloader-config image""" image = "directdisk-bootloader-config" - self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ - % image).status) + wic_cmd_vars = { + 'wks': image, + 'image': self.OE_IMAGE, + } + self.assertEqual(0, runCmd("wic create %(wks)s -e %(image)s" \ + % wic_cmd_vars).status) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) @testcase(1422)
@@ -322,7 +344,12 @@ class Wic(oeSelfTest): def test_bmap(self): """Test generation of .bmap file""" image = "directdisk" - status = runCmd("wic create %s -e core-image-minimal --bmap" % image).status + wic_cmd_vars = { + 'wks': image, + 'image': self.OE_IMAGE, + } + status = runCmd("wic create %(wks)s -e %(image)s --bmap" \ + % wic_cmd_vars).status self.assertEqual(0, status) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct.bmap" % image)))
@@ -331,14 +358,22 @@ class Wic(oeSelfTest): def test_systemd_bootdisk(self): """Test creation of systemd-bootdisk image""" image = "systemd-bootdisk" - self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ - % image).status) + wic_cmd_vars = { + 'wks': image, + 'image': self.OE_IMAGE, + } + self.assertEqual(0, runCmd("wic create %(wks)s -e %(image)s" \ + % wic_cmd_vars).status) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) def test_sdimage_bootpart(self): """Test creation of sdimage-bootpart image""" image = "sdimage-bootpart" self.write_config('IMAGE_BOOT_FILES = "bzImage"\n') - self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ - % image).status) + wic_cmd_vars = { + 'wks': image, + 'image': self.OE_IMAGE, + } + self.assertEqual(0, runCmd("wic create %(wks)s -e %(image)s" \ + % wic_cmd_vars).status) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image)))
Signature · 1 line
2.5.0
Re: [PATCH v4 5/7] wic: selftest: do not repeat core-image-minimal
Quoted 21 lines · Maciej Borzecki
Replace repeated core-image-minimal with Wic class field.
Signed-off-by Maciej Borzecki <[email protected]>--- meta/lib/oeqa/selftest/wic.py | 111 +++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 38 deletions(-)meta/lib/oeqa/selftest/wic.py +2
-0@@ -57,6 +57,8 @@ class Wic(oeSelfTest): resultdir = "/var/tmp/wic/build/" image_is_ready = False + OE_IMAGE = "core-image-minimal" + def setUpLocal(self): """This code is executed before each test method.""" arch = get_bb_var('HOST_ARCH', 'core-image-minimal')
meta/lib/oeqa/selftest/wic.py class Wic(oeSelfTest): · line 81
Quoted 6 lines
meta/lib/oeqa/selftest/wic.py +1
-1@@ -75,7 +77,7 @@ class Wic(oeSelfTest): tools += ' syslinux syslinux-native' bitbake(tools) - bitbake('core-image-minimal') + bitbake(self.OE_IMAGE) Wic.image_is_ready = True
I'd agree with Ross here - it looks less readable.
How it would look if we decide to add test case for another image?
Quoted 236 lines
meta/lib/oeqa/selftest/wic.py +70
-37rmtree(self.resultdir, ignore_errors=True)@@ -100,14 +102,14 @@ class Wic(oeSelfTest): def test_build_image_name(self): """Test wic create directdisk --image-name core-image-minimal""" self.assertEqual(0, runCmd("wic create directdisk " - "--image-name core-image-minimal").status) + "--image-name %s" % self.OE_IMAGE).status) self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct"))) @testcase(1212) @onlyForArch('i586', 'i686', 'x86_64') def test_build_artifacts(self): """Test wic create directdisk providing all artifacts.""" - bbvars = dict((var.lower(), get_bb_var(var, 'core-image-minimal')) \ + bbvars = dict((var.lower(), get_bb_var(var, self.OE_IMAGE)) \ for var in ('STAGING_DATADIR', 'DEPLOY_DIR_IMAGE', 'STAGING_DIR_NATIVE', 'IMAGE_ROOTFS')) status = runCmd("wic create directdisk "@@ -123,7 +125,7 @@ class Wic(oeSelfTest): def test_gpt_image(self): """Test creation of core-image-minimal with gpt table and UUID boot""" self.assertEqual(0, runCmd("wic create directdisk-gpt " - "--image-name core-image-minimal").status) + "--image-name %s" % self.OE_IMAGE).status) self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct"))) @testcase(1213)@@ -157,8 +159,8 @@ class Wic(oeSelfTest): def test_compress_gzip(self): """Test compressing an image with gzip""" self.assertEqual(0, runCmd("wic create directdisk " - "--image-name core-image-minimal " - "-c gzip").status) + "--image-name %s " + "-c gzip" % self.OE_IMAGE).status) self.assertEqual(1, len(glob(self.resultdir + \ "directdisk-*.direct.gz")))@@ -167,8 +169,8 @@ class Wic(oeSelfTest): def test_compress_bzip2(self): """Test compressing an image with bzip2""" self.assertEqual(0, runCmd("wic create directdisk " - "--image-name core-image-minimal " - "-c bzip2").status) + "--image-name %s " + "-c bzip2" % self.OE_IMAGE).status) self.assertEqual(1, len(glob(self.resultdir + \ "directdisk-*.direct.bz2")))@@ -177,8 +179,8 @@ class Wic(oeSelfTest): def test_compress_xz(self): """Test compressing an image with xz""" self.assertEqual(0, runCmd("wic create directdisk " - "--image-name core-image-minimal " - "-c xz").status) + "--image-name %s " + "-c xz" % self.OE_IMAGE).status) self.assertEqual(1, len(glob(self.resultdir + \ "directdisk-*.direct.xz")))@@ -187,26 +189,31 @@ class Wic(oeSelfTest): def test_wrong_compressor(self): """Test how wic breaks if wrong compressor is provided""" self.assertEqual(2, runCmd("wic create directdisk " - "--image-name core-image-minimal " - "-c wrong", ignore_status=True).status) + "--image-name %s " + "-c wrong" % self.OE_IMAGE, + ignore_status=True).status) @testcase(1268) @onlyForArch('i586', 'i686', 'x86_64') def test_rootfs_indirect_recipes(self): """Test usage of rootfs plugin with rootfs recipes""" wks = "directdisk-multi-rootfs" - self.assertEqual(0, runCmd("wic create %s " - "--image-name core-image-minimal " - "--rootfs rootfs1=core-image-minimal " - "--rootfs rootfs2=core-image-minimal" \ - % wks).status) + wic_cmd_vars = { + 'wks': wks, + 'image': self.OE_IMAGE, + } + self.assertEqual(0, runCmd("wic create %(wks)s " + "--image-name %(image)s " + "--rootfs rootfs1=%(image)s " + "--rootfs rootfs2=%(image)s" \ + % wic_cmd_vars).status) self.assertEqual(1, len(glob(self.resultdir + "%s*.direct" % wks))) @testcase(1269) @onlyForArch('i586', 'i686', 'x86_64') def test_rootfs_artifacts(self): """Test usage of rootfs plugin with rootfs paths""" - bbvars = dict((var.lower(), get_bb_var(var, 'core-image-minimal')) \ + bbvars = dict((var.lower(), get_bb_var(var, self.OE_IMAGE)) \ for var in ('STAGING_DATADIR', 'DEPLOY_DIR_IMAGE', 'STAGING_DIR_NATIVE', 'IMAGE_ROOTFS')) bbvars['wks'] = "directdisk-multi-rootfs"@@ -226,24 +233,23 @@ class Wic(oeSelfTest): def test_iso_image(self): """Test creation of hybrid iso image with legacy and EFI boot""" self.assertEqual(0, runCmd("wic create mkhybridiso " - "--image-name core-image-minimal").status) + "--image-name %s" % self.OE_IMAGE).status) self.assertEqual(1, len(glob(self.resultdir + "HYBRID_ISO_IMG-*.direct"))) self.assertEqual(1, len(glob(self.resultdir + "HYBRID_ISO_IMG-*.iso"))) @testcase(1347) def test_image_env(self): """Test generation of <image>.env files.""" - image = 'core-image-minimal' - self.assertEqual(0, bitbake('%s -c do_rootfs_wicenv' % image).status) - stdir = get_bb_var('STAGING_DIR_TARGET', image) + self.assertEqual(0, bitbake('%s -c do_rootfs_wicenv' % self.OE_IMAGE).status) + stdir = get_bb_var('STAGING_DIR_TARGET', self.OE_IMAGE) imgdatadir = os.path.join(stdir, 'imgdata') - basename = get_bb_var('IMAGE_BASENAME', image) - self.assertEqual(basename, image) + basename = get_bb_var('IMAGE_BASENAME', self.OE_IMAGE) + self.assertEqual(basename, self.OE_IMAGE) path = os.path.join(imgdatadir, basename) + '.env' self.assertTrue(os.path.isfile(path)) - wicvars = set(get_bb_var('WICVARS', image).split()) + wicvars = set(get_bb_var('WICVARS', self.OE_IMAGE).split()) # filter out optional variables wicvars = wicvars.difference(('HDDDIR', 'IMAGE_BOOT_FILES', 'INITRD', 'ISODIR'))@@ -275,8 +281,12 @@ class Wic(oeSelfTest): def test_qemux86_directdisk(self): """Test creation of qemux-86-directdisk image""" image = "qemux86-directdisk" - self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ - % image).status) + wic_cmd_vars = { + 'wks': image, + 'image': self.OE_IMAGE, + } + self.assertEqual(0, runCmd("wic create %(wks)s -e %(image)s" \ + % wic_cmd_vars).status) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) @testcase(1349)@@ -284,8 +294,12 @@ class Wic(oeSelfTest): def test_mkgummidisk(self): """Test creation of mkgummidisk image""" image = "mkgummidisk" - self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ - % image).status) + wic_cmd_vars = { + 'wks': image, + 'image': self.OE_IMAGE, + } + self.assertEqual(0, runCmd("wic create %(wks)s -e %(image)s" \ + % wic_cmd_vars).status) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) @testcase(1350)@@ -293,8 +307,12 @@ class Wic(oeSelfTest): def test_mkefidisk(self): """Test creation of mkefidisk image""" image = "mkefidisk" - self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ - % image).status) + wic_cmd_vars = { + 'wks': image, + 'image': self.OE_IMAGE, + } + self.assertEqual(0, runCmd("wic create %(wks)s -e %(image)s" \ + % wic_cmd_vars).status) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) @testcase(1385)@@ -302,8 +320,12 @@ class Wic(oeSelfTest): def test_directdisk_bootloader_config(self): """Test creation of directdisk-bootloader-config image""" image = "directdisk-bootloader-config" - self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ - % image).status) + wic_cmd_vars = { + 'wks': image, + 'image': self.OE_IMAGE, + } + self.assertEqual(0, runCmd("wic create %(wks)s -e %(image)s" \ + % wic_cmd_vars).status) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) @testcase(1422)@@ -322,7 +344,12 @@ class Wic(oeSelfTest): def test_bmap(self): """Test generation of .bmap file""" image = "directdisk" - status = runCmd("wic create %s -e core-image-minimal --bmap" % image).status + wic_cmd_vars = { + 'wks': image, + 'image': self.OE_IMAGE, + } + status = runCmd("wic create %(wks)s -e %(image)s --bmap" \ + % wic_cmd_vars).status self.assertEqual(0, status) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct.bmap" % image)))@@ -331,14 +358,22 @@ class Wic(oeSelfTest): def test_systemd_bootdisk(self): """Test creation of systemd-bootdisk image""" image = "systemd-bootdisk" - self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ - % image).status) + wic_cmd_vars = { + 'wks': image, + 'image': self.OE_IMAGE, + } + self.assertEqual(0, runCmd("wic create %(wks)s -e %(image)s" \ + % wic_cmd_vars).status) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) def test_sdimage_bootpart(self): """Test creation of sdimage-bootpart image""" image = "sdimage-bootpart" self.write_config('IMAGE_BOOT_FILES = "bzImage"\n') - self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ - % image).status) + wic_cmd_vars = { + 'wks': image, + 'image': self.OE_IMAGE, + } + self.assertEqual(0, runCmd("wic create %(wks)s -e %(image)s" \ + % wic_cmd_vars).status) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image)))Signature · 1 line
2.5.0
Signature · 3 lines
-- Regards, Ed
Re: [PATCH v4 5/7] wic: selftest: do not repeat core-image-minimal
Quoted 25 lines · Ed Bartosh
Quoted 24 lines · Maciej Borzecki
Replace repeated core-image-minimal with Wic class field.
Signed-off-by Maciej Borzecki <[email protected]>--- meta/lib/oeqa/selftest/wic.py | 111 +++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 38 deletions(-)meta/lib/oeqa/selftest/wic.py +2
-0@@ -57,6 +57,8 @@ class Wic(oeSelfTest): resultdir = "/var/tmp/wic/build/" image_is_ready = False + OE_IMAGE = "core-image-minimal" + def setUpLocal(self): """This code is executed before each test method.""" arch = get_bb_var('HOST_ARCH', 'core-image-minimal')@@ -75,7 +77,7 @@ class Wic(oeSelfTest): tools += ' syslinux syslinux-native' bitbake(tools)
Quoted 6 lines
meta/lib/oeqa/selftest/wic.py class Wic(oeSelfTest): · line 81
Quoted 3 lines
meta/lib/oeqa/selftest/wic.py +1
-1- bitbake('core-image-minimal') + bitbake(self.OE_IMAGE) Wic.image_is_ready = TrueI'd agree with Ross here - it looks less readable.
How it would look if we decide to add test case for another image?
The usual way would be to:
class WicSatoImage(Wic):
OE_IMAGE = "core-image-sato"
But I think you make a fair point. The patch introduces unnecessary complexity, and is not really needed right now. I'll drop this patch if next version will be necessary.
Can you take a look at the rest of the patchset as well?
Thanks,
Signature · 2 lines
Maciej Borzecki RnDity
Re: [PATCH v4 5/7] wic: selftest: do not repeat core-image-minimal
Quoted 35 lines · Maciej Borzęcki
Quoted 25 lines · Ed Bartosh
Quoted 24 lines · Maciej Borzecki
Replace repeated core-image-minimal with Wic class field.
Signed-off-by Maciej Borzecki <[email protected]>--- meta/lib/oeqa/selftest/wic.py | 111 +++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 38 deletions(-)meta/lib/oeqa/selftest/wic.py +2
-0@@ -57,6 +57,8 @@ class Wic(oeSelfTest): resultdir = "/var/tmp/wic/build/" image_is_ready = False + OE_IMAGE = "core-image-minimal" + def setUpLocal(self): """This code is executed before each test method.""" arch = get_bb_var('HOST_ARCH', 'core-image-minimal')@@ -75,7 +77,7 @@ class Wic(oeSelfTest): tools += ' syslinux syslinux-native' bitbake(tools)Quoted 6 lines
meta/lib/oeqa/selftest/wic.py class Wic(oeSelfTest): · line 81
Quoted 3 lines
meta/lib/oeqa/selftest/wic.py +1
-1- bitbake('core-image-minimal') + bitbake(self.OE_IMAGE) Wic.image_is_ready = TrueI'd agree with Ross here - it looks less readable.
How it would look if we decide to add test case for another image?The usual way would be to:
Quoted 9 lines
class WicSatoImage(Wic):
OE_IMAGE= "core-image-sato"But I think you make a fair point. The patch introduces unnecessary complexity, and is not really needed right now. I'll drop this patch if next version will be necessary.
Can you take a look at the rest of the patchset as well?
I already did. The patchset looks good to me. Thank you for your work! +1
--
Regards,
Ed
PATCH v4 6/7 wic: selftest: do not assume bzImage kernel image
In reply to Maciej BorzeckiInstead of assuming that bzImage is available, query bitbake enviroment for KERNEL_IMAGETYPE.
--- meta/lib/oeqa/selftest/wic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
meta/lib/oeqa/selftest/wic.py +2 -1
@@ -369,7 +369,8 @@ class Wic(oeSelfTest): def test_sdimage_bootpart(self): """Test creation of sdimage-bootpart image""" image = "sdimage-bootpart" - self.write_config('IMAGE_BOOT_FILES = "bzImage"\n') + kimgtype = get_bb_var('KERNEL_IMAGETYPE', self.OE_IMAGE) + self.write_config('IMAGE_BOOT_FILES = "%s"\n' % kimgtype) wic_cmd_vars = { 'wks': image, 'image': self.OE_IMAGE,
Signature · 1 line
2.5.0
PATCH v4 7/7 wic: selftest: add tests for --fixed-size partition flags
In reply to Maciej Borzeckiwic has a new flag for setting a fixed parition size --fixed-size. Add tests that verify if partition is indeed sized properly and that errors are signaled when there is not enough space to fit partition data.
--- meta/lib/oeqa/selftest/wic.py | 69 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+)
meta/lib/oeqa/selftest/wic.py +69 -0
@@ -29,6 +29,7 @@ import unittest from glob import glob from shutil import rmtree from functools import wraps +from tempfile import NamedTemporaryFile from oeqa.selftest.base import oeSelfTest from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu
@@ -61,6 +62,8 @@ class Wic(oeSelfTest): def setUpLocal(self): """This code is executed before each test method.""" + self.native_sysroot = get_bb_var('STAGING_DIR_NATIVE', 'core-image-minimal') + arch = get_bb_var('HOST_ARCH', 'core-image-minimal') is_x86 = arch in ['i586', 'i686', 'x86_64'] if is_x86:
@@ -378,3 +381,69 @@ class Wic(oeSelfTest): self.assertEqual(0, runCmd("wic create %(wks)s -e %(image)s" \ % wic_cmd_vars).status) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) + + def _make_fixed_size_wks(self, size): + """ + Create a wks of an image with a single partition. Size of the partition is set + using --fixed-size flag. Returns a tuple: (path to wks file, wks image name) + """ + with NamedTemporaryFile("w", suffix=".wks", delete=False) as tf: + wkspath = tf.name + tf.write("part " \ + "--source rootfs --ondisk hda --align 4 --fixed-size %d " + "--fstype=ext4\n" % size) + wksname = os.path.splitext(os.path.basename(wkspath))[0] + + return (wkspath, wksname) + + def test_fixed_size(self): + """ + Test creation of a simple image with partition size controlled through + --fixed-size flag + """ + wkspath, wksname = self._make_fixed_size_wks(200) + + wic_cmd_vars = { + 'wks': wkspath, + 'image': self.OE_IMAGE, + } + self.assertEqual(0, runCmd("wic create %(wks)s -e %(image)s" \ + % wic_cmd_vars).status) + os.remove(wkspath) + wicout = glob(self.resultdir + "%s-*direct" % wksname) + self.assertEqual(1, len(wicout)) + + wicimg = wicout[0] + + # verify partition size with wic + res = runCmd("parted -m %s unit mib p 2>/dev/null" % wicimg, + ignore_status=True, + native_sysroot=self.native_sysroot) + self.assertEqual(0, res.status) + + # 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:] + + self.assertEqual(1, len(partlns)) + self.assertEqual("1:0.00MiB:200MiB:200MiB:ext4::;", partlns[0]) + + def test_fixed_size_error(self): + """ + Test creation of a simple image with partition size controlled through + --fixed-size flag. The size of partition is intentionally set to 1MiB + in order to trigger an error in wic. + """ + wkspath, wksname = self._make_fixed_size_wks(1) + + wic_cmd_vars = { + 'wks': wkspath, + 'image': self.OE_IMAGE, + } + self.assertEqual(1, runCmd("wic create %(wks)s -e %(image)s" \ + % wic_cmd_vars, ignore_status=True).status) + os.remove(wkspath) + wicout = glob(self.resultdir + "%s-*direct" % wksname) + self.assertEqual(0, len(wicout))
Signature · 1 line
2.5.0
Re: [PATCH v4 7/7] wic: selftest: add tests for --fixed-size partition flags
Hi Maciej,
Thank you for the patchset!
The changes and the tests look good to me.
I have little suggestions, but most of them just a matter of taste, so feel free to ignore them.
Quoted 38 lines · Maciej Borzecki
wic has a new flag for setting a fixed parition size --fixed-size. Add tests that verify if partition is indeed sized properly and that errors are signaled when there is not enough space to fit partition data.
Signed-off-by Maciej Borzecki <[email protected]>--- meta/lib/oeqa/selftest/wic.py | 69 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+)meta/lib/oeqa/selftest/wic.py +7
-0@@ -29,6 +29,7 @@ import unittest from glob import glob from shutil import rmtree from functools import wraps +from tempfile import NamedTemporaryFile from oeqa.selftest.base import oeSelfTest from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu@@ -61,6 +62,8 @@ class Wic(oeSelfTest): def setUpLocal(self): """This code is executed before each test method.""" + self.native_sysroot = get_bb_var('STAGING_DIR_NATIVE', 'core-image-minimal') + arch = get_bb_var('HOST_ARCH', 'core-image-minimal') is_x86 = arch in ['i586', 'i686', 'x86_64'] if is_x86:@@ -378,3 +381,69 @@ class Wic(oeSelfTest): self.assertEqual(0, runCmd("wic create %(wks)s -e %(image)s" \ % wic_cmd_vars).status) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) + + def _make_fixed_size_wks(self, size): + """ + Create a wks of an image with a single partition. Size of the partition is set
meta/lib/oeqa/selftest/wic.py class Wic(oeSelfTest): · line 397
Quoted 10 lines
meta/lib/oeqa/selftest/wic.py +10
-0+ using --fixed-size flag. Returns a tuple: (path to wks file, wks image name) + """ + with NamedTemporaryFile("w", suffix=".wks", delete=False) as tf: + wkspath = tf.name + tf.write("part " \ + "--source rootfs --ondisk hda --align 4 --fixed-size %d " + "--fstype=ext4\n" % size) + wksname = os.path.splitext(os.path.basename(wkspath))[0] + + return (wkspath, wksname)
Would 'return wkspath, wksname' be a bit more readable?
Quoted 42 lines
meta/lib/oeqa/selftest/wic.py +42
-0+ + def test_fixed_size(self): + """ + Test creation of a simple image with partition size controlled through + --fixed-size flag + """ + wkspath, wksname = self._make_fixed_size_wks(200) + + wic_cmd_vars = { + 'wks': wkspath, + 'image': self.OE_IMAGE, + } + self.assertEqual(0, runCmd("wic create %(wks)s -e %(image)s" \ + % wic_cmd_vars).status) + os.remove(wkspath) + wicout = glob(self.resultdir + "%s-*direct" % wksname) + self.assertEqual(1, len(wicout)) + + wicimg = wicout[0] + + # verify partition size with wic + res = runCmd("parted -m %s unit mib p 2>/dev/null" % wicimg, + ignore_status=True, + native_sysroot=self.native_sysroot) + self.assertEqual(0, res.status) + + # 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:] + + self.assertEqual(1, len(partlns)) + self.assertEqual("1:0.00MiB:200MiB:200MiB:ext4::;", partlns[0]) + + def test_fixed_size_error(self): + """ + Test creation of a simple image with partition size controlled through + --fixed-size flag. The size of partition is intentionally set to 1MiB + in order to trigger an error in wic. + """ + wkspath, wksname = self._make_fixed_size_wks(1)
meta/lib/oeqa/selftest/wic.py class Wic(oeSelfTest): · line 449
Quoted 10 lines
meta/lib/oeqa/selftest/wic.py +10
-0+ + wic_cmd_vars = { + 'wks': wkspath, + 'image': self.OE_IMAGE, + } + self.assertEqual(1, runCmd("wic create %(wks)s -e %(image)s" \ + % wic_cmd_vars, ignore_status=True).status) + os.remove(wkspath) + wicout = glob(self.resultdir + "%s-*direct" % wksname) + self.assertEqual(0, len(wicout))
--
Regards,
Ed
Re: [PATCH v4 7/7] wic: selftest: add tests for --fixed-size partition flags
Quoted 49 lines · Ed Bartosh
Hi Maciej,
Thank you for the patchset!
The changes and the tests look good to me.
I have little suggestions, but most of them just a matter of taste, so feel free to ignore them.Quoted 41 lines · Maciej Borzecki
wic has a new flag for setting a fixed parition size --fixed-size. Add tests that verify if partition is indeed sized properly and that errors are signaled when there is not enough space to fit partition data.
Signed-off-by Maciej Borzecki <[email protected]>--- meta/lib/oeqa/selftest/wic.py | 69 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+)meta/lib/oeqa/selftest/wic.py +10
-0@@ -29,6 +29,7 @@ import unittest from glob import glob from shutil import rmtree from functools import wraps +from tempfile import NamedTemporaryFile from oeqa.selftest.base import oeSelfTest from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu@@ -61,6 +62,8 @@ class Wic(oeSelfTest): def setUpLocal(self): """This code is executed before each test method.""" + self.native_sysroot = get_bb_var('STAGING_DIR_NATIVE', 'core-image-minimal') + arch = get_bb_var('HOST_ARCH', 'core-image-minimal') is_x86 = arch in ['i586', 'i686', 'x86_64'] if is_x86:@@ -378,3 +381,69 @@ class Wic(oeSelfTest): self.assertEqual(0, runCmd("wic create %(wks)s -e %(image)s" \ % wic_cmd_vars).status) self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) + + def _make_fixed_size_wks(self, size): + """ + Create a wks of an image with a single partition. Size of the partition is set + using --fixed-size flag. Returns a tuple: (path to wks file, wks image name) + """ + with NamedTemporaryFile("w", suffix=".wks", delete=False) as tf:
Quoted 8 lines
meta/lib/oeqa/selftest/wic.py class Wic(oeSelfTest): · line 397
Quoted 7 lines
meta/lib/oeqa/selftest/wic.py +7
-0+ wkspath = tf.name + tf.write("part " \ + "--source rootfs --ondisk hda --align 4 --fixed-size %d " + "--fstype=ext4\n" % size) + wksname = os.path.splitext(os.path.basename(wkspath))[0] + + return (wkspath, wksname)Would 'return wkspath, wksname' be a bit more readable?
Agreed.
Signature · 2 lines
Maciej Borzecki RnDity