File: test_dwarf_formdata16.py

package info (click to toggle)
python-pyelftools 0.32-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 68,964 kB
  • sloc: python: 15,903; ansic: 298; asm: 86; makefile: 24; cpp: 18; sh: 4
file content (34 lines) | stat: -rw-r--r-- 1,396 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#-------------------------------------------------------------------------------
# elftools tests
#
# Seva Alekseyev (sevaa@sprynet.com)
# This code is in the public domain
#-------------------------------------------------------------------------------
import unittest
import os

from elftools.elf.elffile import ELFFile

class TestFormData16(unittest.TestCase):
    def test_formdata16(self):
        path = os.path.join('test', 'testfiles_for_unittests',
                            'dwarf_lineprog_data16.elf')
        with open(path, 'rb') as f:
            elffile = ELFFile(f)
            dwarfinfo = elffile.get_dwarf_info(follow_links=False)
            cu = next(dwarfinfo.iter_CUs())
            # Without DW_FORM_data16, the following line errors out:
            lp = dwarfinfo.line_program_for_CU(cu)
            # Make sure the hashes come out right
            self.assertEqual(lp.header.version, 5)
            # The following interrogates the DWARFv5 specific header structures
            self.assertEqual(lp.header.file_name_entry_format[2].content_type, 'DW_LNCT_MD5')
            # The correct hash value was taken from llvm-dwarfdump output
            hash = lp.header.file_names[0]['DW_LNCT_MD5']
            hash = ''.join("%02x" % b for b in hash)
            self.assertEqual(hash, '00dbc7f4edc56417c80f1aa512c4c051')



if __name__ == '__main__':
    unittest.main()