File: test_die_size.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 (32 lines) | stat: -rw-r--r-- 1,333 bytes parent folder | download | duplicates (2)
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
#------------------------------------------------------------------------------
# elftools tests
#
# Anders Dellien (anders@andersdellien.se)
# This code is in the public domain
#------------------------------------------------------------------------------
import unittest
import os

from elftools.elf.elffile import ELFFile

class TestDieSize(unittest.TestCase):
    """ This test verifies that null DIEs are treated correctly - i.e.
        removed when we 'unflatten' the linear list and build a tree.
        The test file contains a CU with two non-null DIEs (both three bytes big),
        where the second one is followed by three null DIEs.
        We verify that the null DIEs are discarded and that the length of the second DIE
        does not include the null entries that follow it.
    """
    def test_die_size(self):
        with open(os.path.join('test',
                               'testfiles_for_unittests', 'trailing_null_dies.elf'),
                  'rb') as f:
            elffile = ELFFile(f)
            self.assertTrue(elffile.has_dwarf_info())
            dwarfinfo = elffile.get_dwarf_info()
            for CU in dwarfinfo.iter_CUs():
                 for child in CU.get_top_DIE().iter_children():
                     self.assertEqual(child.size, 3)

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