summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest/cases/wic.py
diff options
context:
space:
mode:
authorRoss Burton <ross@burtonini.com>2022-03-31 19:29:12 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-04-01 23:11:38 +0100
commitada2cbb6829013edd3846e0fe361a236fcfce373 (patch)
tree589d7d9d2ca83a979ae8797b38fcd5555e2c9003 /meta/lib/oeqa/selftest/cases/wic.py
parent443d557ba0b111fbf616da9f314518d6a86f0386 (diff)
downloadpoky-ada2cbb6829013edd3846e0fe361a236fcfce373.tar.gz
oeqa/selftest/wic: rearrange tests
Split the tests into further classes: one which exercises the CLI and doesn't need to build images at all, and another which is just the tests that manipulate existing images. (From OE-Core rev: c9bc4def71325dba7b7ad93001f7fe1acced0bea) Signed-off-by: Ross Burton <ross.burton@arm.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/wic.py')
-rw-r--r--meta/lib/oeqa/selftest/cases/wic.py154
1 files changed, 77 insertions, 77 deletions
diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py
index 6da70b8c28..c2496486bc 100644
--- a/meta/lib/oeqa/selftest/cases/wic.py
+++ b/meta/lib/oeqa/selftest/cases/wic.py
@@ -104,8 +104,7 @@ class WicTestCase(OESelftestTestCase):
104 WicTestCase.wicenv_cache[image] = os.path.join(stdir, machine, 'imgdata') 104 WicTestCase.wicenv_cache[image] = os.path.join(stdir, machine, 'imgdata')
105 return WicTestCase.wicenv_cache[image] 105 return WicTestCase.wicenv_cache[image]
106 106
107class Wic(WicTestCase): 107class CLITests(OESelftestTestCase):
108
109 def test_version(self): 108 def test_version(self):
110 """Test wic --version""" 109 """Test wic --version"""
111 runCmd('wic --version') 110 runCmd('wic --version')
@@ -166,6 +165,7 @@ class Wic(WicTestCase):
166 """Test wic without command""" 165 """Test wic without command"""
167 self.assertEqual(1, runCmd('wic', ignore_status=True).status) 166 self.assertEqual(1, runCmd('wic', ignore_status=True).status)
168 167
168class Wic(WicTestCase):
169 def test_build_image_name(self): 169 def test_build_image_name(self):
170 """Test wic create wictestdisk --image-name=core-image-minimal""" 170 """Test wic create wictestdisk --image-name=core-image-minimal"""
171 cmd = "wic create wictestdisk --image-name=core-image-minimal -o %s" % self.resultdir 171 cmd = "wic create wictestdisk --image-name=core-image-minimal -o %s" % self.resultdir
@@ -1271,6 +1271,81 @@ class Wic2(WicTestCase):
1271 self.assertEqual(dest_stat.st_blocks, 8) 1271 self.assertEqual(dest_stat.st_blocks, 8)
1272 os.unlink(dest) 1272 os.unlink(dest)
1273 1273
1274 def test_mkfs_extraopts(self):
1275 """Test wks option --mkfs-extraopts for empty and not empty partitions"""
1276 img = 'core-image-minimal'
1277 with NamedTemporaryFile("w", suffix=".wks") as wks:
1278 wks.writelines(
1279 ['part ext2 --fstype ext2 --source rootfs --mkfs-extraopts "-D -F -i 8192"\n',
1280 "part btrfs --fstype btrfs --source rootfs --size 40M --mkfs-extraopts='--quiet'\n",
1281 'part squash --fstype squashfs --source rootfs --mkfs-extraopts "-no-sparse -b 4096"\n',
1282 'part emptyvfat --fstype vfat --size 1M --mkfs-extraopts "-S 1024 -s 64"\n',
1283 'part emptymsdos --fstype msdos --size 1M --mkfs-extraopts "-S 1024 -s 64"\n',
1284 'part emptyext2 --fstype ext2 --size 1M --mkfs-extraopts "-D -F -i 8192"\n',
1285 'part emptybtrfs --fstype btrfs --size 100M --mkfs-extraopts "--mixed -K"\n'])
1286 wks.flush()
1287 cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir)
1288 runCmd(cmd)
1289 wksname = os.path.splitext(os.path.basename(wks.name))[0]
1290 out = glob(self.resultdir + "%s-*direct" % wksname)
1291 self.assertEqual(1, len(out))
1292
1293 @only_for_arch(['i586', 'i686', 'x86_64'])
1294 @OETestTag("runqemu")
1295 def test_expand_mbr_image(self):
1296 """Test wic write --expand command for mbr image"""
1297 # build an image
1298 config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "directdisk.wks"\n'
1299 self.append_config(config)
1300 bitbake('core-image-minimal')
1301
1302 # get path to the image
1303 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'MACHINE'])
1304 deploy_dir = bb_vars['DEPLOY_DIR_IMAGE']
1305 machine = bb_vars['MACHINE']
1306 image_path = os.path.join(deploy_dir, 'core-image-minimal-%s.wic' % machine)
1307
1308 self.remove_config(config)
1309
1310 try:
1311 # expand image to 1G
1312 new_image_path = None
1313 with NamedTemporaryFile(mode='wb', suffix='.wic.exp',
1314 dir=deploy_dir, delete=False) as sparse:
1315 sparse.truncate(1024 ** 3)
1316 new_image_path = sparse.name
1317
1318 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
1319 cmd = "wic write -n %s --expand 1:0 %s %s" % (sysroot, image_path, new_image_path)
1320 runCmd(cmd)
1321
1322 # check if partitions are expanded
1323 orig = runCmd("wic ls %s -n %s" % (image_path, sysroot))
1324 exp = runCmd("wic ls %s -n %s" % (new_image_path, sysroot))
1325 orig_sizes = [int(line.split()[3]) for line in orig.output.split('\n')[1:]]
1326 exp_sizes = [int(line.split()[3]) for line in exp.output.split('\n')[1:]]
1327 self.assertEqual(orig_sizes[0], exp_sizes[0]) # first partition is not resized
1328 self.assertTrue(orig_sizes[1] < exp_sizes[1])
1329
1330 # Check if all free space is partitioned
1331 result = runCmd("%s/usr/sbin/sfdisk -F %s" % (sysroot, new_image_path))
1332 self.assertTrue("0 B, 0 bytes, 0 sectors" in result.output)
1333
1334 os.rename(image_path, image_path + '.bak')
1335 os.rename(new_image_path, image_path)
1336
1337 # Check if it boots in qemu
1338 with runqemu('core-image-minimal', ssh=False, runqemuparams='nographic') as qemu:
1339 cmd = "ls /etc/"
1340 status, output = qemu.run_serial('true')
1341 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
1342 finally:
1343 if os.path.exists(new_image_path):
1344 os.unlink(new_image_path)
1345 if os.path.exists(image_path + '.bak'):
1346 os.rename(image_path + '.bak', image_path)
1347
1348class ModifyTests(WicTestCase):
1274 def test_wic_ls(self): 1349 def test_wic_ls(self):
1275 """Test listing image content using 'wic ls'""" 1350 """Test listing image content using 'wic ls'"""
1276 runCmd("wic create wictestdisk " 1351 runCmd("wic create wictestdisk "
@@ -1363,81 +1438,6 @@ class Wic2(WicTestCase):
1363 self.assertNotIn('\n%s ' % kerneltype.upper(), result.output) 1438 self.assertNotIn('\n%s ' % kerneltype.upper(), result.output)
1364 self.assertNotIn('\nEFI <DIR> ', result.output) 1439 self.assertNotIn('\nEFI <DIR> ', result.output)
1365 1440
1366 def test_mkfs_extraopts(self):
1367 """Test wks option --mkfs-extraopts for empty and not empty partitions"""
1368 img = 'core-image-minimal'
1369 with NamedTemporaryFile("w", suffix=".wks") as wks:
1370 wks.writelines(
1371 ['part ext2 --fstype ext2 --source rootfs --mkfs-extraopts "-D -F -i 8192"\n',
1372 "part btrfs --fstype btrfs --source rootfs --size 40M --mkfs-extraopts='--quiet'\n",
1373 'part squash --fstype squashfs --source rootfs --mkfs-extraopts "-no-sparse -b 4096"\n',
1374 'part emptyvfat --fstype vfat --size 1M --mkfs-extraopts "-S 1024 -s 64"\n',
1375 'part emptymsdos --fstype msdos --size 1M --mkfs-extraopts "-S 1024 -s 64"\n',
1376 'part emptyext2 --fstype ext2 --size 1M --mkfs-extraopts "-D -F -i 8192"\n',
1377 'part emptybtrfs --fstype btrfs --size 100M --mkfs-extraopts "--mixed -K"\n'])
1378 wks.flush()
1379 cmd = "wic create %s -e %s -o %s" % (wks.name, img, self.resultdir)
1380 runCmd(cmd)
1381 wksname = os.path.splitext(os.path.basename(wks.name))[0]
1382 out = glob(self.resultdir + "%s-*direct" % wksname)
1383 self.assertEqual(1, len(out))
1384
1385 @only_for_arch(['i586', 'i686', 'x86_64'])
1386 @OETestTag("runqemu")
1387 def test_expand_mbr_image(self):
1388 """Test wic write --expand command for mbr image"""
1389 # build an image
1390 config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "directdisk.wks"\n'
1391 self.append_config(config)
1392 bitbake('core-image-minimal')
1393
1394 # get path to the image
1395 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'MACHINE'])
1396 deploy_dir = bb_vars['DEPLOY_DIR_IMAGE']
1397 machine = bb_vars['MACHINE']
1398 image_path = os.path.join(deploy_dir, 'core-image-minimal-%s.wic' % machine)
1399
1400 self.remove_config(config)
1401
1402 try:
1403 # expand image to 1G
1404 new_image_path = None
1405 with NamedTemporaryFile(mode='wb', suffix='.wic.exp',
1406 dir=deploy_dir, delete=False) as sparse:
1407 sparse.truncate(1024 ** 3)
1408 new_image_path = sparse.name
1409
1410 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
1411 cmd = "wic write -n %s --expand 1:0 %s %s" % (sysroot, image_path, new_image_path)
1412 runCmd(cmd)
1413
1414 # check if partitions are expanded
1415 orig = runCmd("wic ls %s -n %s" % (image_path, sysroot))
1416 exp = runCmd("wic ls %s -n %s" % (new_image_path, sysroot))
1417 orig_sizes = [int(line.split()[3]) for line in orig.output.split('\n')[1:]]
1418 exp_sizes = [int(line.split()[3]) for line in exp.output.split('\n')[1:]]
1419 self.assertEqual(orig_sizes[0], exp_sizes[0]) # first partition is not resized
1420 self.assertTrue(orig_sizes[1] < exp_sizes[1])
1421
1422 # Check if all free space is partitioned
1423 result = runCmd("%s/usr/sbin/sfdisk -F %s" % (sysroot, new_image_path))
1424 self.assertTrue("0 B, 0 bytes, 0 sectors" in result.output)
1425
1426 os.rename(image_path, image_path + '.bak')
1427 os.rename(new_image_path, image_path)
1428
1429 # Check if it boots in qemu
1430 with runqemu('core-image-minimal', ssh=False, runqemuparams='nographic') as qemu:
1431 cmd = "ls /etc/"
1432 status, output = qemu.run_serial('true')
1433 self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
1434 finally:
1435 if os.path.exists(new_image_path):
1436 os.unlink(new_image_path)
1437 if os.path.exists(image_path + '.bak'):
1438 os.rename(image_path + '.bak', image_path)
1439
1440
1441 def test_wic_ls_ext(self): 1441 def test_wic_ls_ext(self):
1442 """Test listing content of the ext partition using 'wic ls'""" 1442 """Test listing content of the ext partition using 'wic ls'"""
1443 runCmd("wic create wictestdisk " 1443 runCmd("wic create wictestdisk "