summaryrefslogtreecommitdiff
path: root/tools/binman/ftest.py
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2021-11-13 21:14:51 -0500
committerTom Rini <trini@konsulko.com>2021-11-13 21:14:51 -0500
commite035ce4b3ba116016385e8d93ef448c710810286 (patch)
tree89cf25fb1c1cb99e18ca3ab1da98d70b9da0554f /tools/binman/ftest.py
parentb8a156f54ecd1e9a74f48a09a0735b4a41c90eba (diff)
parent89cc0520d7962358ca85464836112217c5b8eca2 (diff)
Merge tag 'dm-pull-13nov21' of https://source.denx.de/u-boot/custodians/u-boot-dm
env tidy-ups test fixes binman fixes and ELF enhancements
Diffstat (limited to 'tools/binman/ftest.py')
-rw-r--r--tools/binman/ftest.py88
1 files changed, 87 insertions, 1 deletions
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 8199a4fc7e0..6be003786e8 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -309,7 +309,7 @@ class TestFunctional(unittest.TestCase):
entry_args=None, images=None, use_real_dtb=False,
use_expanded=False, verbosity=None, allow_missing=False,
extra_indirs=None, threads=None,
- test_section_timeout=False):
+ test_section_timeout=False, update_fdt_in_elf=None):
"""Run binman with a given test file
Args:
@@ -334,6 +334,12 @@ class TestFunctional(unittest.TestCase):
extra_indirs: Extra input directories to add using -I
threads: Number of threads to use (None for default, 0 for
single-threaded)
+ test_section_timeout: True to force the first time to timeout, as
+ used in testThreadTimeout()
+ update_fdt_in_elf: Value to pass with --update-fdt-in-elf=xxx
+
+ Returns:
+ int return code, 0 on success
"""
args = []
if debug:
@@ -363,6 +369,8 @@ class TestFunctional(unittest.TestCase):
args.append('-a%s=%s' % (arg, value))
if allow_missing:
args.append('-M')
+ if update_fdt_in_elf:
+ args += ['--update-fdt-in-elf', update_fdt_in_elf]
if images:
for image in images:
args += ['-i', image]
@@ -4575,6 +4583,84 @@ class TestFunctional(unittest.TestCase):
self.assertIn('read:', stdout.getvalue())
self.assertIn('compress:', stdout.getvalue())
+ def testUpdateFdtInElf(self):
+ """Test that we can update the devicetree in an ELF file"""
+ infile = elf_fname = self.ElfTestFile('u_boot_binman_embed')
+ outfile = os.path.join(self._indir, 'u-boot.out')
+ begin_sym = 'dtb_embed_begin'
+ end_sym = 'dtb_embed_end'
+ retcode = self._DoTestFile(
+ '060_fdt_update.dts', update_dtb=True,
+ update_fdt_in_elf=','.join([infile,outfile,begin_sym,end_sym]))
+ self.assertEqual(0, retcode)
+
+ # Check that the output file does in fact contact a dtb with the binman
+ # definition in the correct place
+ syms = elf.GetSymbolFileOffset(infile,
+ ['dtb_embed_begin', 'dtb_embed_end'])
+ data = tools.ReadFile(outfile)
+ dtb_data = data[syms['dtb_embed_begin'].offset:
+ syms['dtb_embed_end'].offset]
+
+ dtb = fdt.Fdt.FromData(dtb_data)
+ dtb.Scan()
+ props = self._GetPropTree(dtb, BASE_DTB_PROPS + REPACK_DTB_PROPS)
+ self.assertEqual({
+ 'image-pos': 0,
+ 'offset': 0,
+ '_testing:offset': 32,
+ '_testing:size': 2,
+ '_testing:image-pos': 32,
+ 'section@0/u-boot:offset': 0,
+ 'section@0/u-boot:size': len(U_BOOT_DATA),
+ 'section@0/u-boot:image-pos': 0,
+ 'section@0:offset': 0,
+ 'section@0:size': 16,
+ 'section@0:image-pos': 0,
+
+ 'section@1/u-boot:offset': 0,
+ 'section@1/u-boot:size': len(U_BOOT_DATA),
+ 'section@1/u-boot:image-pos': 16,
+ 'section@1:offset': 16,
+ 'section@1:size': 16,
+ 'section@1:image-pos': 16,
+ 'size': 40
+ }, props)
+
+ def testUpdateFdtInElfInvalid(self):
+ """Test that invalid args are detected with --update-fdt-in-elf"""
+ with self.assertRaises(ValueError) as e:
+ self._DoTestFile('060_fdt_update.dts', update_fdt_in_elf='fred')
+ self.assertIn("Invalid args ['fred'] to --update-fdt-in-elf",
+ str(e.exception))
+
+ def testUpdateFdtInElfNoSyms(self):
+ """Test that missing symbols are detected with --update-fdt-in-elf"""
+ infile = elf_fname = self.ElfTestFile('u_boot_binman_embed')
+ outfile = ''
+ begin_sym = 'wrong_begin'
+ end_sym = 'wrong_end'
+ with self.assertRaises(ValueError) as e:
+ self._DoTestFile(
+ '060_fdt_update.dts',
+ update_fdt_in_elf=','.join([infile,outfile,begin_sym,end_sym]))
+ self.assertIn("Expected two symbols 'wrong_begin' and 'wrong_end': got 0:",
+ str(e.exception))
+
+ def testUpdateFdtInElfTooSmall(self):
+ """Test that an over-large dtb is detected with --update-fdt-in-elf"""
+ infile = elf_fname = self.ElfTestFile('u_boot_binman_embed_sm')
+ outfile = os.path.join(self._indir, 'u-boot.out')
+ begin_sym = 'dtb_embed_begin'
+ end_sym = 'dtb_embed_end'
+ with self.assertRaises(ValueError) as e:
+ self._DoTestFile(
+ '060_fdt_update.dts', update_dtb=True,
+ update_fdt_in_elf=','.join([infile,outfile,begin_sym,end_sym]))
+ self.assertRegex(
+ str(e.exception),
+ "Not enough space in '.*u_boot_binman_embed_sm' for data length.*")
+
if __name__ == "__main__":
unittest.main()