[PATCH] binman: Fix a test-coverage regression

Simon Glass sjg at chromium.org
Mon Jan 23 19:29:41 CET 2023


Unfortunately a recent patch snuck through without the require test
coverage. Fix it.

Signed-off-by: Simon Glass <sjg at chromium.org>
Fixes: 571bc4e67d3 ("binman: Support positioning an entry by and ELF symbol")
---

 tools/binman/elf_test.py       | 13 ++++++++++++-
 tools/binman/entry_test.py     | 19 +++++++++++++++++++
 tools/binman/test/embed_data.c |  1 +
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py
index 082a3e1d28c..8cb55ebb815 100644
--- a/tools/binman/elf_test.py
+++ b/tools/binman/elf_test.py
@@ -242,7 +242,7 @@ class TestElf(unittest.TestCase):
         end = offset['embed_end'].offset
         data = tools.read_file(fname)
         embed_data = data[start:end]
-        expect = struct.pack('<III', 0x1234, 0x5678, 0)
+        expect = struct.pack('<IIIII', 2, 3, 0x1234, 0x5678, 0)
         self.assertEqual(expect, embed_data)
 
     def testEmbedFail(self):
@@ -358,6 +358,17 @@ class TestElf(unittest.TestCase):
         self.assertEqual(True, elf.is_valid(data))
         self.assertEqual(False, elf.is_valid(data[4:]))
 
+    def test_get_symbol_offset(self):
+        fname = self.ElfTestFile('embed_data')
+        syms = elf.GetSymbols(fname, ['embed_start', 'embed'])
+        expected = syms['embed'].address - syms['embed_start'].address
+        val = elf.GetSymbolOffset(fname, 'embed', 'embed_start')
+        self.assertEqual(expected, val)
+
+        with self.assertRaises(KeyError) as e:
+            elf.GetSymbolOffset(fname, 'embed')
+        self.assertIn('__image_copy_start', str(e.exception))
+
 
 if __name__ == '__main__':
     unittest.main()
diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py
index aa470c58163..a6fbf62731f 100644
--- a/tools/binman/entry_test.py
+++ b/tools/binman/entry_test.py
@@ -114,6 +114,25 @@ class TestEntry(unittest.TestCase):
         self.assertEquals(tools.get_bytes(0, 1024), base.CompressData(b'abc'))
         self.assertEquals(tools.get_bytes(0, 1024), base.DecompressData(b'abc'))
 
+    def testLookupOffset(self):
+        """Test the lookup_offset() method of the base class"""
+        def MyFindEntryByNode(node):
+            return self.found
+
+        base = entry.Entry.Create(None, self.GetNode(), 'blob-dtb')
+        base.FindEntryByNode = MyFindEntryByNode
+        base.section = base
+        self.found = None
+        base.offset_from_elf = [self.GetNode(), 'start', 0]
+        with self.assertRaises(ValueError) as e:
+            base.lookup_offset()
+        self.assertIn("Cannot find entry for node 'u-boot'", str(e.exception))
+
+        self.found = base
+        with self.assertRaises(ValueError) as e:
+            base.lookup_offset()
+        self.assertIn("Need elf-fname property 'u-boot'", str(e.exception))
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/tools/binman/test/embed_data.c b/tools/binman/test/embed_data.c
index 47d8c38248c..08b68c550f6 100644
--- a/tools/binman/test/embed_data.c
+++ b/tools/binman/test/embed_data.c
@@ -7,6 +7,7 @@
  */
 
 int first[10] = {1};
+int before[2] __attribute__((section(".embed"))) = {2, 3};
 int embed[3] __attribute__((section(".embed"))) = {0x1234, 0x5678};
 int second[10] = {1};
 
-- 
2.39.0.246.g2a6d74b583-goog



More information about the U-Boot mailing list