Fix for mixed version loclists, tests (#521)
[pyelftools.git] / test / test_dwarf_formdata16.py
1 #-------------------------------------------------------------------------------
2 # elftools tests
3 #
4 # Seva Alekseyev (sevaa@sprynet.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 class TestFormData16(unittest.TestCase):
13 def test_formdata16(self):
14 path = os.path.join('test', 'testfiles_for_unittests',
15 'dwarf_lineprog_data16.elf')
16 with open(path, 'rb') as f:
17 elffile = ELFFile(f)
18 dwarfinfo = elffile.get_dwarf_info(follow_links=False)
19 cu = next(dwarfinfo.iter_CUs())
20 # Without DW_FORM_data16, the following line errors out:
21 lp = dwarfinfo.line_program_for_CU(cu)
22 # Make sure the hashes come out right
23 self.assertEqual(lp.header.version, 5)
24 # The following interrogates the DWARFv5 specific header structures
25 self.assertEqual(lp.header.file_name_entry_format[2].content_type, 'DW_LNCT_MD5')
26 # The correct hash value was taken from llvm-dwarfdump output
27 hash = lp.header.file_names[0]['DW_LNCT_MD5']
28 hash = ''.join("%02x" % b for b in hash)
29 self.assertEqual(hash, '00dbc7f4edc56417c80f1aa512c4c051')
30
31
32
33 if __name__ == '__main__':
34 unittest.main()