[OE-core] [PATCH v2 10/10] wic: selftest: add tests for --fixed-size partition flags
Maciej Borzecki
maciej.borzecki at rndity.com
Thu Nov 10 12:18:41 UTC 2016
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 <maciej.borzecki at rndity.com>
---
meta/lib/oeqa/selftest/wic.py | 65 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
diff --git a/meta/lib/oeqa/selftest/wic.py b/meta/lib/oeqa/selftest/wic.py
index 799886c164a734bcc3226baf97f20d789ae55b56..954f8911eff6da6880d25b4fcd2d82fe0a26c4ba 100644
--- a/meta/lib/oeqa/selftest/wic.py
+++ b/meta/lib/oeqa/selftest/wic.py
@@ -27,6 +27,7 @@ import os
from glob import glob
from shutil import rmtree
+from tempfile import NamedTemporaryFile
from oeqa.selftest.base import oeSelfTest
from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu
@@ -341,3 +342,67 @@ 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)
+ 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))
--
2.5.0
More information about the Openembedded-core
mailing list