Merge pull request #32 from vadmium/tuples
[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 try:
8 import unittest2 as unittest
9 except ImportError:
10 import unittest
11 import os
12
13 from utils import setup_syspath; setup_syspath()
14 from elftools.elf.elffile import ELFFile
15
16 class TestARMSupport(unittest.TestCase):
17 def test_hello(self):
18 with open(os.path.join('test', 'testfiles_for_unittests',
19 'simple_gcc.elf.arm'), 'rb') as f:
20 elf = ELFFile(f)
21 self.assertEqual(elf.get_machine_arch(), 'ARM')
22
23 # Check some other properties of this ELF file derived from readelf
24 self.assertEqual(elf['e_entry'], 0x8018)
25 self.assertEqual(elf.num_sections(), 14)
26 self.assertEqual(elf.num_segments(), 2)
27
28 def test_DWARF_indirect_forms(self):
29 # This file uses a lot of DW_FORM_indirect, and is also an ARM ELF
30 # with non-trivial DWARF info.
31 # So this is a simple sanity check that we can successfully parse it
32 # and extract the expected amount of CUs.
33 with open(os.path.join('test', 'testfiles_for_unittests',
34 'arm_with_form_indirect.elf'), 'rb') as f:
35 elffile = ELFFile(f)
36 self.assertTrue(elffile.has_dwarf_info())
37
38 dwarfinfo = elffile.get_dwarf_info()
39 all_CUs = list(dwarfinfo.iter_CUs())
40 self.assertEqual(len(all_CUs), 9)
41
42 if __name__ == '__main__':
43 unittest.main()
44