On Wed, Dec 14, 2016 at 05:28:54PM +0100, Kristian Amlie wrote: > Based partially on an earlier patch by Maciej Borzecki. > > Signed-off-by: Kristian Amlie <kristian.am...@mender.io> > --- > meta/lib/oeqa/selftest/wic.py | 106 > +++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 105 insertions(+), 1 deletion(-) > > diff --git a/meta/lib/oeqa/selftest/wic.py b/meta/lib/oeqa/selftest/wic.py > index faac11e..b2b0fe8 100644 > --- a/meta/lib/oeqa/selftest/wic.py > +++ b/meta/lib/oeqa/selftest/wic.py > @@ -49,7 +49,8 @@ class Wic(oeSelfTest): > # setUpClass being unavailable. > if not Wic.image_is_ready: > bitbake('syslinux syslinux-native parted-native gptfdisk-native ' > - 'dosfstools-native mtools-native bmap-tools-native') > + 'dosfstools-native mtools-native bmap-tools-native ' > + 'e2tools-native') > bitbake('core-image-minimal') > Wic.image_is_ready = True > > @@ -299,3 +300,106 @@ class Wic(oeSelfTest): > self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ > % image).status) > self.assertEqual(1, len(glob(self.resultdir + "%s-*direct" % image))) > + > + def test_exclude_path(self): > + """Test --exclude-path wks option.""" > + > + # For using 'e2ls'. > + old_path = os.environ['PATH'] > + os.environ['PATH'] = get_bb_var('PATH', 'core-image-minimal') > + > + wks_file = 'temp.wks' > + ks = open(wks_file, 'w') I'd use more pythonic 'with open(wks_file, 'w') as wks:' here.
> + rootfs_dir = get_bb_var('IMAGE_ROOTFS', 'core-image-minimal') > + ks.write("""part / --source rootfs --ondisk mmcblk0 --fstype=ext4 > --exclude-path usr > +part /usr --source rootfs --ondisk mmcblk0 --fstype=ext4 --rootfs-dir %s/usr > +part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ > --rootfs-dir %s/usr""" > + % (rootfs_dir, rootfs_dir)) > + ks.close() > + self.assertEqual(0, runCmd("wic create %s -e core-image-minimal" \ > + % wks_file).status) > + > + os.remove(wks_file) > + wicout = glob(self.resultdir + "%s-*direct" % 'temp') > + self.assertEqual(1, len(wicout)) > + > + wicimg = wicout[0] > + > + # verify partition size with wic > + res = runCmd("parted -m %s unit b p 2>/dev/null" % wicimg) > + 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(3, len(partlns)) > + > + for part in [1, 2, 3]: > + part_file = os.path.join(self.resultdir, "selftest_img.part%d" % > part) > + partln = partlns[part-1].split(":") > + self.assertEqual(7, len(partln)) > + start = int(partln[1].rstrip("B")) / 512 > + length = int(partln[3].rstrip("B")) / 512 > + self.assertEqual(0, runCmd("dd if=%s of=%s skip=%d count=%d" % > + (wicimg, part_file, start, > length)).status) > + > + # Test partition 1, should contain the normal root directories, > except > + # /usr. > + res = runCmd("e2ls %s" % os.path.join(self.resultdir, > "selftest_img.part1")) > + self.assertEqual(0, res.status) > + files = res.output.split() > + self.assertIn("etc", files) > + self.assertNotIn("usr", files) > + > + # Partition 2, should contain common directories for /usr, not root > + # directories. > + res = runCmd("e2ls %s" % os.path.join(self.resultdir, > "selftest_img.part2")) > + self.assertEqual(0, res.status) > + files = res.output.split() > + self.assertNotIn("etc", files) > + self.assertNotIn("usr", files) > + self.assertIn("share", files) > + > + # Partition 3, should contain the same as partition 2, including the > bin > + # directory, but not the files inside it. > + res = runCmd("e2ls %s" % os.path.join(self.resultdir, > "selftest_img.part3")) > + self.assertEqual(0, res.status) > + files = res.output.split() > + self.assertNotIn("etc", files) > + self.assertNotIn("usr", files) > + self.assertIn("share", files) > + self.assertIn("bin", files) > + res = runCmd("e2ls %s:bin" % os.path.join(self.resultdir, > "selftest_img.part3")) > + self.assertEqual(0, res.status) > + self.assertEqual("No files found!", res.output.strip()) > + > + for part in [1, 2, 3]: > + part_file = os.path.join(self.resultdir, "selftest_img.part%d" % > part) > + os.remove(part_file) > + > + os.environ['PATH'] = old_path > + > + def test_exclude_path_errors(self): > + """Test --exclude-path wks option error handling.""" > + wks_file = 'temp.wks' > + > + rootfs_dir = get_bb_var('IMAGE_ROOTFS', 'core-image-minimal') > + > + # Absolute argument. > + ks = open(wks_file, 'w') and here > + ks.write("part / --source rootfs --ondisk mmcblk0 --fstype=ext4 > --exclude-path /usr") > + ks.close() > + self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal" \ > + % wks_file, ignore_status=True).status) > + os.remove(wks_file) > + > + # Argument pointing to parent directory. > + ks = open(wks_file, 'w') and here > + ks.write("part / --source rootfs --ondisk mmcblk0 --fstype=ext4 > --exclude-path ././..") > + ks.close() > + self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal" \ > + % wks_file, ignore_status=True).status) > + os.remove(wks_file) -- Regards, Ed -- _______________________________________________ Openembedded-core mailing list Openembedded-core@lists.openembedded.org http://lists.openembedded.org/mailman/listinfo/openembedded-core