summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2017-08-25 23:12:29 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-08-27 22:30:07 +0100
commit390dcbf2e14f212d81a8fe252cf3ae801b82ffa9 (patch)
tree806920bbb21509197125213fe09a140b03768740 /meta/lib/oeqa/selftest
parent7724e6fff7b9afd2e24b4f20139e99199d53f1ce (diff)
downloadpoky-390dcbf2e14f212d81a8fe252cf3ae801b82ffa9.tar.gz
wic: setlftest: test expanding MBR image
Added test_expand_mbr_image test case to the wic oe-selftest suite. The test expands directdisk wic image to 1Gb target, checks if it's expanded correctly and boots it in qemu to make sure the image is bootable, i.e. bootloader, kernel, boot and root partitions are still functional. (From OE-Core rev: 83739174be5b3fabd7df559a35ac6407d82a6280) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/selftest')
-rw-r--r--meta/lib/oeqa/selftest/cases/wic.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py
index aaefd4fde5..aa73ba4f7e 100644
--- a/meta/lib/oeqa/selftest/cases/wic.py
+++ b/meta/lib/oeqa/selftest/cases/wic.py
@@ -938,3 +938,56 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r
938 wksname = os.path.splitext(os.path.basename(wks.name))[0] 938 wksname = os.path.splitext(os.path.basename(wks.name))[0]
939 out = glob(self.resultdir + "%s-*direct" % wksname) 939 out = glob(self.resultdir + "%s-*direct" % wksname)
940 self.assertEqual(1, len(out)) 940 self.assertEqual(1, len(out))
941
942 def test_expand_mbr_image(self):
943 """Test wic write --expand command for mbr image"""
944 # build an image
945 config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "directdisk.wks"\n'
946 self.append_config(config)
947 self.assertEqual(0, bitbake('core-image-minimal').status)
948
949 # get path to the image
950 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'MACHINE'])
951 deploy_dir = bb_vars['DEPLOY_DIR_IMAGE']
952 machine = bb_vars['MACHINE']
953 image_path = os.path.join(deploy_dir, 'core-image-minimal-%s.wic' % machine)
954
955 self.remove_config(config)
956
957 try:
958 # expand image to 1G
959 new_image_path = None
960 with NamedTemporaryFile(mode='wb', suffix='.wic.exp',
961 dir=deploy_dir, delete=False) as sparse:
962 sparse.truncate(1024 ** 3)
963 new_image_path = sparse.name
964
965 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
966 cmd = "wic write -n %s --expand 1:0 %s %s" % (sysroot, image_path, new_image_path)
967 self.assertEqual(0, runCmd(cmd).status)
968
969 # check if partitions are expanded
970 orig = runCmd("wic ls %s -n %s" % (image_path, sysroot))
971 exp = runCmd("wic ls %s -n %s" % (new_image_path, sysroot))
972 orig_sizes = [int(line.split()[3]) for line in orig.output.split('\n')[1:]]
973 exp_sizes = [int(line.split()[3]) for line in exp.output.split('\n')[1:]]
974 self.assertEqual(orig_sizes[0], exp_sizes[0]) # first partition is not resized
975 self.assertTrue(orig_sizes[1] < exp_sizes[1])
976
977 # Check if all free space is partitioned
978 result = runCmd("%s/usr/sbin/sfdisk -F %s" % (sysroot, new_image_path))
979 self.assertTrue("0 B, 0 bytes, 0 sectors" in result.output)
980
981 os.rename(image_path, image_path + '.bak')
982 os.rename(new_image_path, image_path)
983
984 # Check if it boots in qemu
985 with runqemu('core-image-minimal', ssh=False) as qemu:
986 cmd = "ls /etc/"
987 status, output = qemu.run_serial('true')
988 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
989 finally:
990 if os.path.exists(new_image_path):
991 os.unlink(new_image_path)
992 if os.path.exists(image_path + '.bak'):
993 os.rename(image_path + '.bak', image_path)