summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2023-09-18 13:38:36 +0100
committerSteve Sakoman <steve@sakoman.com>2023-10-18 05:25:19 -1000
commit5bad01b1befe38ce3e3e4dbf851a799be9f1b087 (patch)
tree874074aabf32f0d58e6fbcb560c898eaa6fa9581
parent629f043c8f1e066bf0e2c0548a0882b301a9a636 (diff)
downloadpoky-5bad01b1befe38ce3e3e4dbf851a799be9f1b087.tar.gz
oeqa/selftest/wic: Improve assertTrue calls
assertTrue is a problematic call use in test cases since when it fails, you just get an unhelpful "False is not True" message. Replace some uses with assertIn/assertNotIn which will give more helpful results and for the rest, add msg entries which given more helpful debugging. For example, this patch would help debugging of #15176. (From OE-Core rev: 52a2455ba7d91d404fc2c4568c805cf1fbe2b2ad) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 35d4c39e0df1a304f557471151a03d1e4b0f30c7) Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r--meta/lib/oeqa/selftest/cases/wic.py36
1 files changed, 18 insertions, 18 deletions
diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py
index b26b649c3a..760b1c67ce 100644
--- a/meta/lib/oeqa/selftest/cases/wic.py
+++ b/meta/lib/oeqa/selftest/cases/wic.py
@@ -729,7 +729,7 @@ part /etc --source rootfs --fstype=ext4 --change-directory=etc
729 wicout = glob(os.path.join(self.resultdir, "wictestdisk-*.direct")) 729 wicout = glob(os.path.join(self.resultdir, "wictestdisk-*.direct"))
730 self.assertEqual(1, len(wicout)) 730 self.assertEqual(1, len(wicout))
731 size = os.path.getsize(wicout[0]) 731 size = os.path.getsize(wicout[0])
732 self.assertTrue(size > extraspace) 732 self.assertTrue(size > extraspace, msg="Extra space not present (%s vs %s)" % (size, extraspace))
733 733
734class Wic2(WicTestCase): 734class Wic2(WicTestCase):
735 735
@@ -756,7 +756,7 @@ class Wic2(WicTestCase):
756 basename = bb_vars['IMAGE_BASENAME'] 756 basename = bb_vars['IMAGE_BASENAME']
757 self.assertEqual(basename, image) 757 self.assertEqual(basename, image)
758 path = os.path.join(imgdatadir, basename) + '.env' 758 path = os.path.join(imgdatadir, basename) + '.env'
759 self.assertTrue(os.path.isfile(path)) 759 self.assertTrue(os.path.isfile(path), msg="File %s wasn't generated as expected" % path)
760 760
761 wicvars = set(bb_vars['WICVARS'].split()) 761 wicvars = set(bb_vars['WICVARS'].split())
762 # filter out optional variables 762 # filter out optional variables
@@ -769,7 +769,7 @@ class Wic2(WicTestCase):
769 # test if variables used by wic present in the .env file 769 # test if variables used by wic present in the .env file
770 for var in wicvars: 770 for var in wicvars:
771 self.assertTrue(var in content, "%s is not in .env file" % var) 771 self.assertTrue(var in content, "%s is not in .env file" % var)
772 self.assertTrue(content[var]) 772 self.assertTrue(content[var], "%s doesn't have a value (%s)" % (var, content[var]))
773 773
774 def test_image_vars_dir_short(self): 774 def test_image_vars_dir_short(self):
775 """Test image vars directory selection -v option""" 775 """Test image vars directory selection -v option"""
@@ -816,8 +816,8 @@ class Wic2(WicTestCase):
816 # pointing to existing files 816 # pointing to existing files
817 for suffix in ('wic', 'manifest'): 817 for suffix in ('wic', 'manifest'):
818 path = prefix + suffix 818 path = prefix + suffix
819 self.assertTrue(os.path.islink(path)) 819 self.assertTrue(os.path.islink(path), msg="Link %s wasn't generated as expected" % path)
820 self.assertTrue(os.path.isfile(os.path.realpath(path))) 820 self.assertTrue(os.path.isfile(os.path.realpath(path)), msg="File linked to by %s wasn't generated as expected" % path)
821 821
822 # TODO this should work on aarch64 822 # TODO this should work on aarch64
823 @skipIfNotArch(['i586', 'i686', 'x86_64']) 823 @skipIfNotArch(['i586', 'i686', 'x86_64'])
@@ -1087,7 +1087,7 @@ class Wic2(WicTestCase):
1087 self.remove_config(config) 1087 self.remove_config(config)
1088 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'], image) 1088 bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'], image)
1089 image_path = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], '%s.wic' % bb_vars['IMAGE_LINK_NAME']) 1089 image_path = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], '%s.wic' % bb_vars['IMAGE_LINK_NAME'])
1090 self.assertTrue(os.path.exists(image_path)) 1090 self.assertTrue(os.path.exists(image_path), msg="Image file %s wasn't generated as expected" % image_path)
1091 1091
1092 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') 1092 sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
1093 1093
@@ -1328,11 +1328,11 @@ class Wic2(WicTestCase):
1328 orig_sizes = [int(line.split()[3]) for line in orig.output.split('\n')[1:]] 1328 orig_sizes = [int(line.split()[3]) for line in orig.output.split('\n')[1:]]
1329 exp_sizes = [int(line.split()[3]) for line in exp.output.split('\n')[1:]] 1329 exp_sizes = [int(line.split()[3]) for line in exp.output.split('\n')[1:]]
1330 self.assertEqual(orig_sizes[0], exp_sizes[0]) # first partition is not resized 1330 self.assertEqual(orig_sizes[0], exp_sizes[0]) # first partition is not resized
1331 self.assertTrue(orig_sizes[1] < exp_sizes[1]) 1331 self.assertTrue(orig_sizes[1] < exp_sizes[1], msg="Parition size wasn't enlarged (%s vs %s)" % (orig_sizes[1], exp_sizes[1]))
1332 1332
1333 # Check if all free space is partitioned 1333 # Check if all free space is partitioned
1334 result = runCmd("%s/usr/sbin/sfdisk -F %s" % (sysroot, new_image_path)) 1334 result = runCmd("%s/usr/sbin/sfdisk -F %s" % (sysroot, new_image_path))
1335 self.assertTrue("0 B, 0 bytes, 0 sectors" in result.output) 1335 self.assertIn("0 B, 0 bytes, 0 sectors", result.output)
1336 1336
1337 os.rename(image_path, image_path + '.bak') 1337 os.rename(image_path, image_path + '.bak')
1338 os.rename(new_image_path, image_path) 1338 os.rename(new_image_path, image_path)
@@ -1390,7 +1390,7 @@ class ModifyTests(WicTestCase):
1390 # check if file is there 1390 # check if file is there
1391 result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot)) 1391 result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot))
1392 self.assertEqual(7, len(result.output.split('\n'))) 1392 self.assertEqual(7, len(result.output.split('\n')))
1393 self.assertTrue(os.path.basename(testfile.name) in result.output) 1393 self.assertIn(os.path.basename(testfile.name), result.output)
1394 1394
1395 # prepare directory 1395 # prepare directory
1396 testdir = os.path.join(self.resultdir, 'wic-test-cp-dir') 1396 testdir = os.path.join(self.resultdir, 'wic-test-cp-dir')
@@ -1404,13 +1404,13 @@ class ModifyTests(WicTestCase):
1404 # check if directory is there 1404 # check if directory is there
1405 result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot)) 1405 result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot))
1406 self.assertEqual(8, len(result.output.split('\n'))) 1406 self.assertEqual(8, len(result.output.split('\n')))
1407 self.assertTrue(os.path.basename(testdir) in result.output) 1407 self.assertIn(os.path.basename(testdir), result.output)
1408 1408
1409 # copy the file from the partition and check if it success 1409 # copy the file from the partition and check if it success
1410 dest = '%s-cp' % testfile.name 1410 dest = '%s-cp' % testfile.name
1411 runCmd("wic cp %s:1/%s %s -n %s" % (images[0], 1411 runCmd("wic cp %s:1/%s %s -n %s" % (images[0],
1412 os.path.basename(testfile.name), dest, sysroot)) 1412 os.path.basename(testfile.name), dest, sysroot))
1413 self.assertTrue(os.path.exists(dest)) 1413 self.assertTrue(os.path.exists(dest), msg="File %s wasn't generated as expected" % dest)
1414 1414
1415 1415
1416 def test_wic_rm(self): 1416 def test_wic_rm(self):
@@ -1454,7 +1454,7 @@ class ModifyTests(WicTestCase):
1454 # list directory content of the second ext4 partition 1454 # list directory content of the second ext4 partition
1455 result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot)) 1455 result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot))
1456 self.assertTrue(set(['bin', 'home', 'proc', 'usr', 'var', 'dev', 'lib', 'sbin']).issubset( 1456 self.assertTrue(set(['bin', 'home', 'proc', 'usr', 'var', 'dev', 'lib', 'sbin']).issubset(
1457 set(line.split()[-1] for line in result.output.split('\n') if line))) 1457 set(line.split()[-1] for line in result.output.split('\n') if line)), msg="Expected directories not present %s" % result.output)
1458 1458
1459 def test_wic_cp_ext(self): 1459 def test_wic_cp_ext(self):
1460 """Test copy files and directories to the ext partition.""" 1460 """Test copy files and directories to the ext partition."""
@@ -1469,7 +1469,7 @@ class ModifyTests(WicTestCase):
1469 # list directory content of the ext4 partition 1469 # list directory content of the ext4 partition
1470 result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot)) 1470 result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot))
1471 dirs = set(line.split()[-1] for line in result.output.split('\n') if line) 1471 dirs = set(line.split()[-1] for line in result.output.split('\n') if line)
1472 self.assertTrue(set(['bin', 'home', 'proc', 'usr', 'var', 'dev', 'lib', 'sbin']).issubset(dirs)) 1472 self.assertTrue(set(['bin', 'home', 'proc', 'usr', 'var', 'dev', 'lib', 'sbin']).issubset(dirs), msg="Expected directories not present %s" % dirs)
1473 1473
1474 with NamedTemporaryFile("w", suffix=".wic-cp") as testfile: 1474 with NamedTemporaryFile("w", suffix=".wic-cp") as testfile:
1475 testfile.write("test") 1475 testfile.write("test")
@@ -1484,12 +1484,12 @@ class ModifyTests(WicTestCase):
1484 1484
1485 # check if the file to copy is in the partition 1485 # check if the file to copy is in the partition
1486 result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot)) 1486 result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot))
1487 self.assertTrue('fstab' in [line.split()[-1] for line in result.output.split('\n') if line]) 1487 self.assertIn('fstab', [line.split()[-1] for line in result.output.split('\n') if line])
1488 1488
1489 # copy file from the partition, replace the temporary file content with it and 1489 # copy file from the partition, replace the temporary file content with it and
1490 # check for the file size to validate the copy 1490 # check for the file size to validate the copy
1491 runCmd("wic cp %s:2/etc/fstab %s -n %s" % (images[0], testfile.name, sysroot)) 1491 runCmd("wic cp %s:2/etc/fstab %s -n %s" % (images[0], testfile.name, sysroot))
1492 self.assertTrue(os.stat(testfile.name).st_size > 0) 1492 self.assertTrue(os.stat(testfile.name).st_size > 0, msg="Filesize not as expected %s" % os.stat(testfile.name).st_size)
1493 1493
1494 1494
1495 def test_wic_rm_ext(self): 1495 def test_wic_rm_ext(self):
@@ -1504,18 +1504,18 @@ class ModifyTests(WicTestCase):
1504 1504
1505 # list directory content of the /etc directory on ext4 partition 1505 # list directory content of the /etc directory on ext4 partition
1506 result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot)) 1506 result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot))
1507 self.assertTrue('fstab' in [line.split()[-1] for line in result.output.split('\n') if line]) 1507 self.assertIn('fstab', [line.split()[-1] for line in result.output.split('\n') if line])
1508 1508
1509 # remove file 1509 # remove file
1510 runCmd("wic rm %s:2/etc/fstab -n %s" % (images[0], sysroot)) 1510 runCmd("wic rm %s:2/etc/fstab -n %s" % (images[0], sysroot))
1511 1511
1512 # check if it's removed 1512 # check if it's removed
1513 result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot)) 1513 result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot))
1514 self.assertTrue('fstab' not in [line.split()[-1] for line in result.output.split('\n') if line]) 1514 self.assertNotIn('fstab', [line.split()[-1] for line in result.output.split('\n') if line])
1515 1515
1516 # remove non-empty directory 1516 # remove non-empty directory
1517 runCmd("wic rm -r %s:2/etc/ -n %s" % (images[0], sysroot)) 1517 runCmd("wic rm -r %s:2/etc/ -n %s" % (images[0], sysroot))
1518 1518
1519 # check if it's removed 1519 # check if it's removed
1520 result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot)) 1520 result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot))
1521 self.assertTrue('etc' not in [line.split()[-1] for line in result.output.split('\n') if line]) 1521 self.assertNotIn('etc', [line.split()[-1] for line in result.output.split('\n') if line])