diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-09-18 13:38:36 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-09-20 08:57:26 +0100 |
commit | 2564f3a432f8a6200d26c9ff91f82e0a51a268f8 (patch) | |
tree | 9f984e780749cf2f6d9501965669fdc2e42bd3e2 | |
parent | e1a3d10aaafffbfdd0cdd7258618c84e9ace238b (diff) | |
download | poky-2564f3a432f8a6200d26c9ff91f82e0a51a268f8.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: 35d4c39e0df1a304f557471151a03d1e4b0f30c7)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/lib/oeqa/selftest/cases/wic.py | 36 |
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 aa61349ed1..b4866bcb32 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 | ||
734 | def test_no_table(self): | 734 | def test_no_table(self): |
735 | """Test --no-table wks option.""" | 735 | """Test --no-table wks option.""" |
@@ -773,7 +773,7 @@ class Wic2(WicTestCase): | |||
773 | basename = bb_vars['IMAGE_BASENAME'] | 773 | basename = bb_vars['IMAGE_BASENAME'] |
774 | self.assertEqual(basename, image) | 774 | self.assertEqual(basename, image) |
775 | path = os.path.join(imgdatadir, basename) + '.env' | 775 | path = os.path.join(imgdatadir, basename) + '.env' |
776 | self.assertTrue(os.path.isfile(path)) | 776 | self.assertTrue(os.path.isfile(path), msg="File %s wasn't generated as expected" % path) |
777 | 777 | ||
778 | wicvars = set(bb_vars['WICVARS'].split()) | 778 | wicvars = set(bb_vars['WICVARS'].split()) |
779 | # filter out optional variables | 779 | # filter out optional variables |
@@ -786,7 +786,7 @@ class Wic2(WicTestCase): | |||
786 | # test if variables used by wic present in the .env file | 786 | # test if variables used by wic present in the .env file |
787 | for var in wicvars: | 787 | for var in wicvars: |
788 | self.assertTrue(var in content, "%s is not in .env file" % var) | 788 | self.assertTrue(var in content, "%s is not in .env file" % var) |
789 | self.assertTrue(content[var]) | 789 | self.assertTrue(content[var], "%s doesn't have a value (%s)" % (var, content[var])) |
790 | 790 | ||
791 | def test_image_vars_dir_short(self): | 791 | def test_image_vars_dir_short(self): |
792 | """Test image vars directory selection -v option""" | 792 | """Test image vars directory selection -v option""" |
@@ -833,8 +833,8 @@ class Wic2(WicTestCase): | |||
833 | # pointing to existing files | 833 | # pointing to existing files |
834 | for suffix in ('wic', 'manifest'): | 834 | for suffix in ('wic', 'manifest'): |
835 | path = prefix + suffix | 835 | path = prefix + suffix |
836 | self.assertTrue(os.path.islink(path)) | 836 | self.assertTrue(os.path.islink(path), msg="Link %s wasn't generated as expected" % path) |
837 | self.assertTrue(os.path.isfile(os.path.realpath(path))) | 837 | self.assertTrue(os.path.isfile(os.path.realpath(path)), msg="File linked to by %s wasn't generated as expected" % path) |
838 | 838 | ||
839 | # TODO this should work on aarch64 | 839 | # TODO this should work on aarch64 |
840 | @skipIfNotArch(['i586', 'i686', 'x86_64']) | 840 | @skipIfNotArch(['i586', 'i686', 'x86_64']) |
@@ -1104,7 +1104,7 @@ class Wic2(WicTestCase): | |||
1104 | self.remove_config(config) | 1104 | self.remove_config(config) |
1105 | bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'], image) | 1105 | bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_LINK_NAME'], image) |
1106 | image_path = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], '%s.wic' % bb_vars['IMAGE_LINK_NAME']) | 1106 | image_path = os.path.join(bb_vars['DEPLOY_DIR_IMAGE'], '%s.wic' % bb_vars['IMAGE_LINK_NAME']) |
1107 | self.assertTrue(os.path.exists(image_path)) | 1107 | self.assertTrue(os.path.exists(image_path), msg="Image file %s wasn't generated as expected" % image_path) |
1108 | 1108 | ||
1109 | sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') | 1109 | sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') |
1110 | 1110 | ||
@@ -1345,11 +1345,11 @@ class Wic2(WicTestCase): | |||
1345 | orig_sizes = [int(line.split()[3]) for line in orig.output.split('\n')[1:]] | 1345 | orig_sizes = [int(line.split()[3]) for line in orig.output.split('\n')[1:]] |
1346 | exp_sizes = [int(line.split()[3]) for line in exp.output.split('\n')[1:]] | 1346 | exp_sizes = [int(line.split()[3]) for line in exp.output.split('\n')[1:]] |
1347 | self.assertEqual(orig_sizes[0], exp_sizes[0]) # first partition is not resized | 1347 | self.assertEqual(orig_sizes[0], exp_sizes[0]) # first partition is not resized |
1348 | self.assertTrue(orig_sizes[1] < exp_sizes[1]) | 1348 | self.assertTrue(orig_sizes[1] < exp_sizes[1], msg="Parition size wasn't enlarged (%s vs %s)" % (orig_sizes[1], exp_sizes[1])) |
1349 | 1349 | ||
1350 | # Check if all free space is partitioned | 1350 | # Check if all free space is partitioned |
1351 | result = runCmd("%s/usr/sbin/sfdisk -F %s" % (sysroot, new_image_path)) | 1351 | result = runCmd("%s/usr/sbin/sfdisk -F %s" % (sysroot, new_image_path)) |
1352 | self.assertTrue("0 B, 0 bytes, 0 sectors" in result.output) | 1352 | self.assertIn("0 B, 0 bytes, 0 sectors", result.output) |
1353 | 1353 | ||
1354 | os.rename(image_path, image_path + '.bak') | 1354 | os.rename(image_path, image_path + '.bak') |
1355 | os.rename(new_image_path, image_path) | 1355 | os.rename(new_image_path, image_path) |
@@ -1433,7 +1433,7 @@ class ModifyTests(WicTestCase): | |||
1433 | # check if file is there | 1433 | # check if file is there |
1434 | result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot)) | 1434 | result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot)) |
1435 | self.assertEqual(7, len(result.output.split('\n'))) | 1435 | self.assertEqual(7, len(result.output.split('\n'))) |
1436 | self.assertTrue(os.path.basename(testfile.name) in result.output) | 1436 | self.assertIn(os.path.basename(testfile.name), result.output) |
1437 | 1437 | ||
1438 | # prepare directory | 1438 | # prepare directory |
1439 | testdir = os.path.join(self.resultdir, 'wic-test-cp-dir') | 1439 | testdir = os.path.join(self.resultdir, 'wic-test-cp-dir') |
@@ -1447,13 +1447,13 @@ class ModifyTests(WicTestCase): | |||
1447 | # check if directory is there | 1447 | # check if directory is there |
1448 | result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot)) | 1448 | result = runCmd("wic ls %s:1/ -n %s" % (images[0], sysroot)) |
1449 | self.assertEqual(8, len(result.output.split('\n'))) | 1449 | self.assertEqual(8, len(result.output.split('\n'))) |
1450 | self.assertTrue(os.path.basename(testdir) in result.output) | 1450 | self.assertIn(os.path.basename(testdir), result.output) |
1451 | 1451 | ||
1452 | # copy the file from the partition and check if it success | 1452 | # copy the file from the partition and check if it success |
1453 | dest = '%s-cp' % testfile.name | 1453 | dest = '%s-cp' % testfile.name |
1454 | runCmd("wic cp %s:1/%s %s -n %s" % (images[0], | 1454 | runCmd("wic cp %s:1/%s %s -n %s" % (images[0], |
1455 | os.path.basename(testfile.name), dest, sysroot)) | 1455 | os.path.basename(testfile.name), dest, sysroot)) |
1456 | self.assertTrue(os.path.exists(dest)) | 1456 | self.assertTrue(os.path.exists(dest), msg="File %s wasn't generated as expected" % dest) |
1457 | 1457 | ||
1458 | 1458 | ||
1459 | def test_wic_rm(self): | 1459 | def test_wic_rm(self): |
@@ -1497,7 +1497,7 @@ class ModifyTests(WicTestCase): | |||
1497 | # list directory content of the second ext4 partition | 1497 | # list directory content of the second ext4 partition |
1498 | result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot)) | 1498 | result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot)) |
1499 | self.assertTrue(set(['bin', 'home', 'proc', 'usr', 'var', 'dev', 'lib', 'sbin']).issubset( | 1499 | self.assertTrue(set(['bin', 'home', 'proc', 'usr', 'var', 'dev', 'lib', 'sbin']).issubset( |
1500 | set(line.split()[-1] for line in result.output.split('\n') if line))) | 1500 | set(line.split()[-1] for line in result.output.split('\n') if line)), msg="Expected directories not present %s" % result.output) |
1501 | 1501 | ||
1502 | def test_wic_cp_ext(self): | 1502 | def test_wic_cp_ext(self): |
1503 | """Test copy files and directories to the ext partition.""" | 1503 | """Test copy files and directories to the ext partition.""" |
@@ -1512,7 +1512,7 @@ class ModifyTests(WicTestCase): | |||
1512 | # list directory content of the ext4 partition | 1512 | # list directory content of the ext4 partition |
1513 | result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot)) | 1513 | result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot)) |
1514 | dirs = set(line.split()[-1] for line in result.output.split('\n') if line) | 1514 | dirs = set(line.split()[-1] for line in result.output.split('\n') if line) |
1515 | self.assertTrue(set(['bin', 'home', 'proc', 'usr', 'var', 'dev', 'lib', 'sbin']).issubset(dirs)) | 1515 | self.assertTrue(set(['bin', 'home', 'proc', 'usr', 'var', 'dev', 'lib', 'sbin']).issubset(dirs), msg="Expected directories not present %s" % dirs) |
1516 | 1516 | ||
1517 | with NamedTemporaryFile("w", suffix=".wic-cp") as testfile: | 1517 | with NamedTemporaryFile("w", suffix=".wic-cp") as testfile: |
1518 | testfile.write("test") | 1518 | testfile.write("test") |
@@ -1527,12 +1527,12 @@ class ModifyTests(WicTestCase): | |||
1527 | 1527 | ||
1528 | # check if the file to copy is in the partition | 1528 | # check if the file to copy is in the partition |
1529 | result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot)) | 1529 | result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot)) |
1530 | self.assertTrue('fstab' in [line.split()[-1] for line in result.output.split('\n') if line]) | 1530 | self.assertIn('fstab', [line.split()[-1] for line in result.output.split('\n') if line]) |
1531 | 1531 | ||
1532 | # copy file from the partition, replace the temporary file content with it and | 1532 | # copy file from the partition, replace the temporary file content with it and |
1533 | # check for the file size to validate the copy | 1533 | # check for the file size to validate the copy |
1534 | runCmd("wic cp %s:2/etc/fstab %s -n %s" % (images[0], testfile.name, sysroot)) | 1534 | runCmd("wic cp %s:2/etc/fstab %s -n %s" % (images[0], testfile.name, sysroot)) |
1535 | self.assertTrue(os.stat(testfile.name).st_size > 0) | 1535 | self.assertTrue(os.stat(testfile.name).st_size > 0, msg="Filesize not as expected %s" % os.stat(testfile.name).st_size) |
1536 | 1536 | ||
1537 | 1537 | ||
1538 | def test_wic_rm_ext(self): | 1538 | def test_wic_rm_ext(self): |
@@ -1547,18 +1547,18 @@ class ModifyTests(WicTestCase): | |||
1547 | 1547 | ||
1548 | # list directory content of the /etc directory on ext4 partition | 1548 | # list directory content of the /etc directory on ext4 partition |
1549 | result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot)) | 1549 | result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot)) |
1550 | self.assertTrue('fstab' in [line.split()[-1] for line in result.output.split('\n') if line]) | 1550 | self.assertIn('fstab', [line.split()[-1] for line in result.output.split('\n') if line]) |
1551 | 1551 | ||
1552 | # remove file | 1552 | # remove file |
1553 | runCmd("wic rm %s:2/etc/fstab -n %s" % (images[0], sysroot)) | 1553 | runCmd("wic rm %s:2/etc/fstab -n %s" % (images[0], sysroot)) |
1554 | 1554 | ||
1555 | # check if it's removed | 1555 | # check if it's removed |
1556 | result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot)) | 1556 | result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot)) |
1557 | self.assertTrue('fstab' not in [line.split()[-1] for line in result.output.split('\n') if line]) | 1557 | self.assertNotIn('fstab', [line.split()[-1] for line in result.output.split('\n') if line]) |
1558 | 1558 | ||
1559 | # remove non-empty directory | 1559 | # remove non-empty directory |
1560 | runCmd("wic rm -r %s:2/etc/ -n %s" % (images[0], sysroot)) | 1560 | runCmd("wic rm -r %s:2/etc/ -n %s" % (images[0], sysroot)) |
1561 | 1561 | ||
1562 | # check if it's removed | 1562 | # check if it's removed |
1563 | result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot)) | 1563 | result = runCmd("wic ls %s:2/ -n %s" % (images[0], sysroot)) |
1564 | self.assertTrue('etc' not in [line.split()[-1] for line in result.output.split('\n') if line]) | 1564 | self.assertNotIn('etc', [line.split()[-1] for line in result.output.split('\n') if line]) |