Remove unused import
[pyelftools.git] / test / test_double_dynstr_section.py
1 #------------------------------------------------------------------------------
2 # elftools tests
3 #
4 # Yann Rouillard (yann@pleiades.fr.eu.org)
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 from elftools.elf.dynamic import DynamicSection, DynamicTag
16
17
18 class TestDoubleDynstrSections(unittest.TestCase):
19 """ This test make sure than dynamic tags
20 are properly analyzed when two .dynstr
21 sections are present in an elf file
22 """
23
24 reference_data = [
25 b'libz.so.1',
26 b'libc.so.6',
27 b'lib_versioned.so.1',
28 ]
29
30 def _test_double_dynstr_section_generic(self, testfile):
31
32 with open(os.path.join('test', 'testfiles_for_unittests', testfile),
33 'rb') as f:
34 elf = ELFFile(f)
35 for section in elf.iter_sections():
36 if isinstance(section, DynamicSection):
37 d_tags = [getattr(x, x.entry.d_tag[3:].lower())
38 for x in section.iter_tags()
39 if x.entry.d_tag in DynamicTag._HANDLED_TAGS]
40 self.assertListEqual(
41 TestDoubleDynstrSections.reference_data,
42 d_tags)
43 return
44 self.fail('No dynamic section found !!')
45
46
47 def test_double_dynstr_section(self):
48 """ First test with the good dynstr section first
49 """
50 self._test_double_dynstr_section_generic(
51 'lib_with_two_dynstr_sections.so.1.elf')
52
53 def test_double_dynstr_section_reverse(self):
54 """ Second test with the good dynstr section last
55 """
56 self._test_double_dynstr_section_generic(
57 'lib_with_two_dynstr_sections_reversed.so.1.elf')
58
59
60 if __name__ == '__main__':
61 unittest.main()