diff options
author | Tom Rini <trini@konsulko.com> | 2022-02-23 12:28:54 -0500 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2022-02-23 13:34:08 -0500 |
commit | 4cb9bd834e6a63ab56797b362a288709e867ccfb (patch) | |
tree | d4bfbd7d8ad58b103d8d2e9e3f54b7f18589da2f /tools/binman/elf_test.py | |
parent | 17a0dc6abfdbf392f6a27074f2633608038c4221 (diff) | |
parent | 70f42e720c90faa2fa27836288559e0d647862b7 (diff) |
Merge tag 'dm-pull-22222' of https://gitlab.denx.de/u-boot/custodians/u-boot-dm
binman fixes/improvements to FIT generator
binman SPL fixes
moveconfig support regex matches
Diffstat (limited to 'tools/binman/elf_test.py')
-rw-r--r-- | tools/binman/elf_test.py | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py index 47ebfbac4a6..a67915bda63 100644 --- a/tools/binman/elf_test.py +++ b/tools/binman/elf_test.py @@ -56,8 +56,8 @@ class FakeSection: def BuildElfTestFiles(target_dir): """Build ELF files used for testing in binman - This compiles and links the test files into the specified directory. It the - Makefile and source files in the binman test/ directory. + This compiles and links the test files into the specified directory. It uses + the Makefile and source files in the binman test/ directory. Args: target_dir: Directory to put the files into @@ -258,6 +258,33 @@ class TestElf(unittest.TestCase): offset = elf.GetSymbolFileOffset(fname, ['missing_sym']) self.assertEqual({}, offset) + def test_read_segments(self): + """Test for read_segments()""" + if not elf.ELF_TOOLS: + self.skipTest('Python elftools not available') + fname = self.ElfTestFile('embed_data') + segments, entry = elf.read_segments(tools.read_file(fname)) + + def test_read_segments_fail(self): + """Test for read_segments() without elftools""" + try: + old_val = elf.ELF_TOOLS + elf.ELF_TOOLS = False + fname = self.ElfTestFile('embed_data') + with self.assertRaises(ValueError) as e: + elf.read_segments(tools.read_file(fname)) + self.assertIn('Python elftools package is not available', + str(e.exception)) + finally: + elf.ELF_TOOLS = old_val + + def test_read_segments_bad_data(self): + """Test for read_segments() with an invalid ELF file""" + fname = self.ElfTestFile('embed_data') + with self.assertRaises(ValueError) as e: + elf.read_segments(tools.get_bytes(100, 100)) + self.assertIn('Magic number does not match', str(e.exception)) + if __name__ == '__main__': unittest.main() |