1 #-------------------------------------------------------------------------------
4 # Eli Bendersky (eliben@gmail.com)
5 # This code is in the public domain
6 #-------------------------------------------------------------------------------
10 from elftools
.elf
.elffile
import ELFFile
13 class TestARMSupport(unittest
.TestCase
):
15 with
open(os
.path
.join('test', 'testfiles_for_unittests',
16 'simple_gcc.elf.arm'), 'rb') as f
:
18 self
.assertEqual(elf
.get_machine_arch(), 'ARM')
20 # Check some other properties of this ELF file derived from readelf
21 self
.assertEqual(elf
['e_entry'], 0x8018)
22 self
.assertEqual(elf
.num_sections(), 14)
23 self
.assertEqual(elf
.num_segments(), 2)
25 def test_build_attributes(self
):
26 with
open(os
.path
.join('test', 'testfiles_for_unittests',
27 'simple_gcc.elf.arm'), 'rb') as f
:
30 sec
= elf
.get_section_by_name('.ARM.attributes')
31 self
.assertEqual(sec
['sh_type'], 'SHT_ARM_ATTRIBUTES')
32 self
.assertEqual(sec
.num_subsections
, 1)
34 subsec
= sec
.subsections
[0]
35 self
.assertEqual(subsec
.header
['vendor_name'], 'aeabi')
36 self
.assertEqual(subsec
.num_subsubsections
, 1)
38 subsubsec
= subsec
.subsubsections
[0]
39 self
.assertEqual(subsubsec
.header
.tag
, 'TAG_FILE')
41 for i
in subsubsec
.iter_attributes('TAG_CPU_NAME'):
42 self
.assertEqual(i
.value
, 'ARM7TDMI-S')
44 for i
in subsubsec
.iter_attributes('TAG_CPU_ARCH'):
45 self
.assertEqual(i
.value
, 2)
47 def test_DWARF_indirect_forms(self
):
48 # This file uses a lot of DW_FORM_indirect, and is also an ARM ELF
49 # with non-trivial DWARF info.
50 # So this is a simple sanity check that we can successfully parse it
51 # and extract the expected amount of CUs.
52 with
open(os
.path
.join('test', 'testfiles_for_unittests',
53 'arm_with_form_indirect.elf'), 'rb') as f
:
55 self
.assertTrue(elffile
.has_dwarf_info())
57 dwarfinfo
= elffile
.get_dwarf_info()
58 all_CUs
= list(dwarfinfo
.iter_CUs())
59 self
.assertEqual(len(all_CUs
), 9)
62 if __name__
== '__main__':