Add previously untested output file to test set
[pyelftools.git] / test / test_arm_support.py
1 #-------------------------------------------------------------------------------
2 # elftools tests
3 #
4 # Eli Bendersky (eliben@gmail.com)
5 # This code is in the public domain
6 #-------------------------------------------------------------------------------
7 import unittest
8 import os
9
10 from elftools.elf.elffile import ELFFile
11
12
13 class TestARMSupport(unittest.TestCase):
14 def test_hello(self):
15 with open(os.path.join('test', 'testfiles_for_unittests',
16 'simple_gcc.elf.arm'), 'rb') as f:
17 elf = ELFFile(f)
18 self.assertEqual(elf.get_machine_arch(), 'ARM')
19
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)
24
25 def test_build_attributes(self):
26 with open(os.path.join('test', 'testfiles_for_unittests',
27 'simple_gcc.elf.arm'), 'rb') as f:
28 elf = ELFFile(f)
29
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)
33
34 subsec = sec.subsections[0]
35 self.assertEqual(subsec.header['vendor_name'], 'aeabi')
36 self.assertEqual(subsec.num_subsubsections, 1)
37
38 subsubsec = subsec.subsubsections[0]
39 self.assertEqual(subsubsec.header.tag, 'TAG_FILE')
40
41 for i in subsubsec.iter_attributes('TAG_CPU_NAME'):
42 self.assertEqual(i.value, 'ARM7TDMI-S')
43
44 for i in subsubsec.iter_attributes('TAG_CPU_ARCH'):
45 self.assertEqual(i.value, 2)
46
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:
54 elffile = ELFFile(f)
55 self.assertTrue(elffile.has_dwarf_info())
56
57 dwarfinfo = elffile.get_dwarf_info()
58 all_CUs = list(dwarfinfo.iter_CUs())
59 self.assertEqual(len(all_CUs), 9)
60
61
62 if __name__ == '__main__':
63 unittest.main()