diff options
author | Simon Glass | 2021-04-03 11:05:09 +1300 |
---|---|---|
committer | Simon Glass | 2021-04-29 03:23:39 -0700 |
commit | c7722e84170a1b855da808c6e6aab4f871b15e0d (patch) | |
tree | e2df2f691e42dd88349badd8da78676ab535470f /tools/binman | |
parent | ec6db6c297afa8ef9f72c73c067d98e764aeae25 (diff) |
binman: Tweak implementation of fmap
Use an interator in two of the fmap tests so it is easier to add new
items. Also check the name first since that is the first indication
that something is wrong. Use a variable for the expected size of the
fmap to avoid repeating the code.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/binman')
-rw-r--r-- | tools/binman/ftest.py | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 4db25e43357..d0a1d99c0d0 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -1595,26 +1595,29 @@ class TestFunctional(unittest.TestCase): self.assertEqual(1, fhdr.ver_major) self.assertEqual(0, fhdr.ver_minor) self.assertEqual(0, fhdr.base) - self.assertEqual(16 + 16 + - fmap_util.FMAP_HEADER_LEN + - fmap_util.FMAP_AREA_LEN * 3, fhdr.image_size) + expect_size = fmap_util.FMAP_HEADER_LEN + fmap_util.FMAP_AREA_LEN * 3 + self.assertEqual(16 + 16 + expect_size, fhdr.image_size) self.assertEqual(b'FMAP', fhdr.name) self.assertEqual(3, fhdr.nareas) - for fentry in fentries: - self.assertEqual(0, fentry.flags) - - self.assertEqual(0, fentries[0].offset) - self.assertEqual(4, fentries[0].size) - self.assertEqual(b'RO_U_BOOT', fentries[0].name) - - self.assertEqual(16, fentries[1].offset) - self.assertEqual(4, fentries[1].size) - self.assertEqual(b'RW_U_BOOT', fentries[1].name) - - self.assertEqual(32, fentries[2].offset) - self.assertEqual(fmap_util.FMAP_HEADER_LEN + - fmap_util.FMAP_AREA_LEN * 3, fentries[2].size) - self.assertEqual(b'FMAP', fentries[2].name) + fiter = iter(fentries) + + fentry = next(fiter) + self.assertEqual(b'RO_U_BOOT', fentry.name) + self.assertEqual(0, fentry.offset) + self.assertEqual(4, fentry.size) + self.assertEqual(0, fentry.flags) + + fentry = next(fiter) + self.assertEqual(b'RW_U_BOOT', fentry.name) + self.assertEqual(16, fentry.offset) + self.assertEqual(4, fentry.size) + self.assertEqual(0, fentry.flags) + + fentry = next(fiter) + self.assertEqual(b'FMAP', fentry.name) + self.assertEqual(32, fentry.offset) + self.assertEqual(expect_size, fentry.size) + self.assertEqual(0, fentry.flags) def testBlobNamedByArg(self): """Test we can add a blob with the filename coming from an entry arg""" @@ -2065,19 +2068,23 @@ class TestFunctional(unittest.TestCase): fhdr, fentries = fmap_util.DecodeFmap(data[36:]) self.assertEqual(0x100, fhdr.image_size) - - self.assertEqual(0, fentries[0].offset) - self.assertEqual(4, fentries[0].size) - self.assertEqual(b'U_BOOT', fentries[0].name) - - self.assertEqual(4, fentries[1].offset) - self.assertEqual(3, fentries[1].size) - self.assertEqual(b'INTEL_MRC', fentries[1].name) - - self.assertEqual(36, fentries[2].offset) - self.assertEqual(fmap_util.FMAP_HEADER_LEN + - fmap_util.FMAP_AREA_LEN * 3, fentries[2].size) - self.assertEqual(b'FMAP', fentries[2].name) + expect_size = fmap_util.FMAP_HEADER_LEN + fmap_util.FMAP_AREA_LEN * 3 + fiter = iter(fentries) + + fentry = next(fiter) + self.assertEqual(b'U_BOOT', fentry.name) + self.assertEqual(0, fentry.offset) + self.assertEqual(4, fentry.size) + + fentry = next(fiter) + self.assertEqual(b'INTEL_MRC', fentry.name) + self.assertEqual(4, fentry.offset) + self.assertEqual(3, fentry.size) + + fentry = next(fiter) + self.assertEqual(b'FMAP', fentry.name) + self.assertEqual(36, fentry.offset) + self.assertEqual(expect_size, fentry.size) def testElf(self): """Basic test of ELF entries""" |