Fix for mixed version loclists, tests (#521)
[pyelftools.git] / test / test_stab.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 from elftools.elf.sections import StabSection
12
13
14 class TestStab(unittest.TestCase):
15 def test_stab(self):
16 expected = [
17 ("obj_stabs.S", 0, 0, 0x2, 33), # generated by compiler
18 ("label", 0x95, 0xc8, 0x4072, 0xdeadbeef),
19 ("another label", 0x41, 0x66, 0xf9b1, 0xcafebabe)]
20 with open(os.path.join('test', 'testfiles_for_unittests',
21 'obj_stabs.elf'), 'rb') as f:
22 elf = ELFFile(f)
23
24 # using correct type?
25 for s in elf.iter_sections():
26 if s.name == '.stab':
27 self.assertIsInstance(s, StabSection)
28
29 # check section contents
30 stab = elf.get_section_by_name('.stab')
31 stabstr = elf.get_section_by_name('.stabstr')
32 for entry, golden in zip(stab.iter_stabs(), expected):
33 self.assertEqual(stabstr.get_string(entry.n_strx), golden[0])
34 self.assertEqual(entry.n_type, golden[1])
35 self.assertEqual(entry.n_other, golden[2])
36 self.assertEqual(entry.n_desc, golden[3])
37 self.assertEqual(entry.n_value, golden[4])
38
39
40 if __name__ == '__main__':
41 unittest.main()