Merge https://gitlab.denx.de/u-boot/custodians/u-boot-sh
[oweals/u-boot.git] / tools / binman / elf_test.py
index c7f51bb86aaa743357533b702987143169b52e41..37e1b423cf61cd9743ee1f8474c842fdcaf651ff 100644 (file)
@@ -10,11 +10,11 @@ import sys
 import tempfile
 import unittest
 
-import command
-import elf
-import test_util
-import tools
-import tout
+from binman import elf
+from patman import command
+from patman import test_util
+from patman import tools
+from patman import tout
 
 binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
 
@@ -45,7 +45,7 @@ class FakeSection:
     def GetPath(self):
         return 'section_path'
 
-    def LookupSymbol(self, name, weak, msg):
+    def LookupSymbol(self, name, weak, msg, base_addr):
         """Fake implementation which returns the same value for all symbols"""
         return self.sym_value
 
@@ -69,8 +69,7 @@ def BuildElfTestFiles(target_dir):
     if 'MAKEFLAGS' in os.environ:
         del os.environ['MAKEFLAGS']
     tools.Run('make', '-C', target_dir, '-f',
-              os.path.join(testdir, 'Makefile'), 'SRC=%s/' % testdir,
-              'bss_data', 'u_boot_ucode_ptr', 'u_boot_no_ucode_ptr')
+              os.path.join(testdir, 'Makefile'), 'SRC=%s/' % testdir)
 
 
 class TestElf(unittest.TestCase):
@@ -118,7 +117,7 @@ class TestElf(unittest.TestCase):
         """Test a symbol which extends outside the entry area is detected"""
         entry = FakeEntry(10)
         section = FakeSection()
-        elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms')
+        elf_fname = self.ElfTestFile('u_boot_binman_syms')
         with self.assertRaises(ValueError) as e:
             syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
         self.assertIn('entry_path has offset 4 (size 8) but the contents size '
@@ -132,7 +131,7 @@ class TestElf(unittest.TestCase):
         """
         entry = FakeEntry(10)
         section = FakeSection()
-        elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms_bad')
+        elf_fname = self.ElfTestFile('u_boot_binman_syms_bad')
         self.assertEqual(elf.LookupAndWriteSymbols(elf_fname, entry, section),
                          None)
 
@@ -144,7 +143,7 @@ class TestElf(unittest.TestCase):
         """
         entry = FakeEntry(10)
         section = FakeSection()
-        elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms_size')
+        elf_fname =self.ElfTestFile('u_boot_binman_syms_size')
         with self.assertRaises(ValueError) as e:
             syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
         self.assertIn('has size 1: only 4 and 8 are supported',
@@ -156,11 +155,11 @@ class TestElf(unittest.TestCase):
         This should produce -1 values for all thress symbols, taking up the
         first 16 bytes of the image.
         """
-        entry = FakeEntry(20)
+        entry = FakeEntry(24)
         section = FakeSection(sym_value=None)
-        elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms')
+        elf_fname = self.ElfTestFile('u_boot_binman_syms')
         syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
-        self.assertEqual(tools.GetBytes(255, 16) + tools.GetBytes(ord('a'), 4),
+        self.assertEqual(tools.GetBytes(255, 20) + tools.GetBytes(ord('a'), 4),
                                                                   entry.data)
 
     def testDebug(self):
@@ -169,7 +168,7 @@ class TestElf(unittest.TestCase):
             tout.Init(tout.DEBUG)
             entry = FakeEntry(20)
             section = FakeSection()
-            elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms')
+            elf_fname = self.ElfTestFile('u_boot_binman_syms')
             with test_util.capture_sys_output() as (stdout, stderr):
                 syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
             self.assertTrue(len(stdout.getvalue()) > 0)