summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaciej Borzecki <maciej.borzecki@rndity.com>2017-03-21 12:35:05 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-03-22 11:35:22 +0000
commit19090446da4184ef5cdd442c5c640593e1bc46e1 (patch)
tree2b15389f26c452b8267d9dfbd8ead01a11c60b86
parent17fe3eb453a4fda54eb320e3c69a3dbf3f306e87 (diff)
downloadpoky-19090446da4184ef5cdd442c5c640593e1bc46e1.tar.gz
wic: selftest: add tests for --fixed-size partition flags
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. (From OE-Core rev: 84c2184546779ece3eb23c5628e4c9d177568043) Signed-off-by: Maciej Borzecki <maciej.borzecki@rndity.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oeqa/selftest/wic.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/wic.py b/meta/lib/oeqa/selftest/wic.py
index 776e44aac4..4aacd86085 100644
--- a/meta/lib/oeqa/selftest/wic.py
+++ b/meta/lib/oeqa/selftest/wic.py
@@ -29,6 +29,7 @@ import unittest
29from glob import glob 29from glob import glob
30from shutil import rmtree 30from shutil import rmtree
31from functools import wraps, lru_cache 31from functools import wraps, lru_cache
32from tempfile import NamedTemporaryFile
32 33
33from oeqa.selftest.base import oeSelfTest 34from oeqa.selftest.base import oeSelfTest
34from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars, runqemu 35from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars, runqemu
@@ -64,10 +65,13 @@ class Wic(oeSelfTest):
64 65
65 resultdir = "/var/tmp/wic.oe-selftest/" 66 resultdir = "/var/tmp/wic.oe-selftest/"
66 image_is_ready = False 67 image_is_ready = False
68 native_sysroot = None
67 wicenv_cache = {} 69 wicenv_cache = {}
68 70
69 def setUpLocal(self): 71 def setUpLocal(self):
70 """This code is executed before each test method.""" 72 """This code is executed before each test method."""
73 if not self.native_sysroot:
74 Wic.native_sysroot = get_bb_var('STAGING_DIR_NATIVE', 'wic-tools')
71 75
72 # Do this here instead of in setUpClass as the base setUp does some 76 # Do this here instead of in setUpClass as the base setUp does some
73 # clean up which can result in the native tools built earlier in 77 # clean up which can result in the native tools built earlier in
@@ -618,3 +622,62 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r
618 status, output = qemu.run_serial(cmd) 622 status, output = qemu.run_serial(cmd)
619 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) 623 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
620 self.assertEqual(output, '3') 624 self.assertEqual(output, '3')
625
626 @staticmethod
627 def _make_fixed_size_wks(size):
628 """
629 Create a wks of an image with a single partition. Size of the partition is set
630 using --fixed-size flag. Returns a tuple: (path to wks file, wks image name)
631 """
632 with NamedTemporaryFile("w", suffix=".wks", delete=False) as tempf:
633 wkspath = tempf.name
634 tempf.write("part " \
635 "--source rootfs --ondisk hda --align 4 --fixed-size %d "
636 "--fstype=ext4\n" % size)
637 wksname = os.path.splitext(os.path.basename(wkspath))[0]
638
639 return wkspath, wksname
640
641 def test_fixed_size(self):
642 """
643 Test creation of a simple image with partition size controlled through
644 --fixed-size flag
645 """
646 wkspath, wksname = Wic._make_fixed_size_wks(200)
647
648 self.assertEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \
649 % (wkspath, self.resultdir)).status)
650 os.remove(wkspath)
651 wicout = glob(self.resultdir + "%s-*direct" % wksname)
652 self.assertEqual(1, len(wicout))
653
654 wicimg = wicout[0]
655
656 # verify partition size with wic
657 res = runCmd("parted -m %s unit mib p 2>/dev/null" % wicimg,
658 ignore_status=True,
659 native_sysroot=self.native_sysroot)
660 self.assertEqual(0, res.status)
661
662 # parse parted output which looks like this:
663 # BYT;\n
664 # /var/tmp/wic/build/tmpfwvjjkf_-201611101222-hda.direct:200MiB:file:512:512:msdos::;\n
665 # 1:0.00MiB:200MiB:200MiB:ext4::;\n
666 partlns = res.output.splitlines()[2:]
667
668 self.assertEqual(1, len(partlns))
669 self.assertEqual("1:0.00MiB:200MiB:200MiB:ext4::;", partlns[0])
670
671 def test_fixed_size_error(self):
672 """
673 Test creation of a simple image with partition size controlled through
674 --fixed-size flag. The size of partition is intentionally set to 1MiB
675 in order to trigger an error in wic.
676 """
677 wkspath, wksname = Wic._make_fixed_size_wks(1)
678
679 self.assertEqual(1, runCmd("wic create %s -e core-image-minimal -o %s" \
680 % (wkspath, self.resultdir), ignore_status=True).status)
681 os.remove(wkspath)
682 wicout = glob(self.resultdir + "%s-*direct" % wksname)
683 self.assertEqual(0, len(wicout))