Skip to content

Commit b18db06

Browse files
authored
Marking file types in the test binary corpus (#631)
* Housekeeping: marking ELF file type in name * Autotest for the naming convention * Typo * Negative test
1 parent 7121f11 commit b18db06

29 files changed

+51
-13
lines changed

test/test_corpus_naming.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#------------------------------------------------------------------------------
2+
# elftools tests
3+
#
4+
# Seva Alekseyev ([email protected])
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.segments import NoteSegment
12+
13+
class TestCorpusNaming(unittest.TestCase):
14+
def scan_under(self, subdir):
15+
dir = os.path.join('test', subdir)
16+
for filename in os.listdir(dir):
17+
name, ext = os.path.splitext(filename)
18+
if ext == '.elf':
19+
try:
20+
ef = ELFFile.load_from_path(os.path.join(dir, filename))
21+
22+
if ef.header.e_type == 'ET_DYN':
23+
self.assertTrue('.so.' in filename)
24+
elif ef.header.e_type == 'ET_REL':
25+
self.assertTrue('.o.' in filename)
26+
else: # Covers ET_EXEC, ET_CORE, ET_NONE
27+
self.assertFalse('.so.' in filename)
28+
self.assertFalse('.o.' in filename)
29+
except:
30+
pass
31+
32+
def test_corpus_naming(self):
33+
self.scan_under('testfiles_for_readelf')
34+
self.scan_under('testfiles_for_unittests')
35+
self.scan_under('testfiles_for_dwarfdump')
36+
37+
if __name__ == '__main__':
38+
unittest.main()

test/test_dbgfile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_dynamic_segment(self):
1212
""" Test that the degenerate case for the dynamic segment does not crash
1313
"""
1414
with open(os.path.join('test', 'testfiles_for_unittests',
15-
'debug_info.elf'), 'rb') as f:
15+
'debug_info.so.elf'), 'rb') as f:
1616
elf = ELFFile(f)
1717

1818
seen_dynamic_segment = False
@@ -28,7 +28,7 @@ def test_dynamic_section(self):
2828
""" Test that the degenerate case for the dynamic section does not crash
2929
"""
3030
with open(os.path.join('test', 'testfiles_for_unittests',
31-
'debug_info.elf'), 'rb') as f:
31+
'debug_info.so.elf'), 'rb') as f:
3232
elf = ELFFile(f)
3333
section = DynamicSection(elf.get_section_by_name('.dynamic').header, '.dynamic', elf)
3434

@@ -38,7 +38,7 @@ def test_eh_frame(self):
3838
""" Test that parsing .eh_frame with SHT_NOBITS does not crash
3939
"""
4040
with open(os.path.join('test', 'testfiles_for_unittests',
41-
'debug_info.elf'), 'rb') as f:
41+
'debug_info.so.elf'), 'rb') as f:
4242
elf = ELFFile(f)
4343
dwarf = elf.get_dwarf_info()
4444
eh_frame = list(dwarf.EH_CFI_entries())

test/test_dwarf_aranges.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
class TestRangeLists(unittest.TestCase):
1010
def test_arange_absent(self):
11-
with open(os.path.join('test', 'testfiles_for_unittests', 'aranges_absent.elf'), 'rb') as f:
11+
with open(os.path.join('test', 'testfiles_for_unittests', 'aranges_absent.so.elf'), 'rb') as f:
1212
elffile = ELFFile(f)
1313
self.assertTrue(elffile.has_dwarf_info())
1414
aranges = elffile.get_dwarf_info().get_aranges()
1515
self.assertIsNone(aranges)
1616

1717
def test_arange_partial(self):
18-
with open(os.path.join('test', 'testfiles_for_unittests', 'aranges_partial.elf'), 'rb') as f:
18+
with open(os.path.join('test', 'testfiles_for_unittests', 'aranges_partial.so.elf'), 'rb') as f:
1919
elffile = ELFFile(f)
2020
self.assertTrue(elffile.has_dwarf_info())
2121
aranges = elffile.get_dwarf_info().get_aranges()
@@ -24,7 +24,7 @@ def test_arange_partial(self):
2424
self.assertIsNotNone(aranges.cu_offset_at_addr(address_b))
2525

2626
def test_arange_complete(self):
27-
with open(os.path.join('test', 'testfiles_for_unittests', 'aranges_complete.elf'), 'rb') as f:
27+
with open(os.path.join('test', 'testfiles_for_unittests', 'aranges_complete.so.elf'), 'rb') as f:
2828
elffile = ELFFile(f)
2929
self.assertTrue(elffile.has_dwarf_info())
3030
aranges = elffile.get_dwarf_info().get_aranges()

test/test_dwarf_formdata16.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class TestFormData16(unittest.TestCase):
1313
def test_formdata16(self):
1414
path = os.path.join('test', 'testfiles_for_unittests',
15-
'dwarf_lineprog_data16.elf')
15+
'dwarf_lineprog_data16.so.elf')
1616
with open(path, 'rb') as f:
1717
elffile = ELFFile(f)
1818
dwarfinfo = elffile.get_dwarf_info(follow_links=False)

test/test_dwarf_llpair.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class TestLocListsPair(unittest.TestCase):
1313
def test_llpair(self):
1414
path = os.path.join('test', 'testfiles_for_unittests',
15-
'dwarf_llpair.elf')
15+
'dwarf_llpair.so.elf')
1616
with open(path, 'rb') as f:
1717
elffile = ELFFile(f)
1818
dwarfinfo = elffile.get_dwarf_info(follow_links=False)

test/test_dynamic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def test_reading_symbols_gnu_hash(self):
7878
""" Verify we can read symbol table without SymbolTableSection but with
7979
a GNU symbol hash table"""
8080
with open(os.path.join('test', 'testfiles_for_unittests',
81-
'android_dyntags.elf'), 'rb') as f:
81+
'android_dyntags.so.elf'), 'rb') as f:
8282
elf = ELFFile(f)
8383
for segment in elf.iter_segments():
8484
if segment.header.p_type != 'PT_DYNAMIC':
@@ -114,7 +114,7 @@ def extract_sunw(filename):
114114
f1 = extract_sunw(os.path.join('test', 'testfiles_for_unittests',
115115
'exe_solaris32_cc.sparc.elf'))
116116
f2 = extract_sunw(os.path.join('test', 'testfiles_for_unittests',
117-
'android_dyntags.elf'))
117+
'android_dyntags.so.elf'))
118118
self.assertEqual(f1, {'DT_SUNW_STRPAD', 'DT_SUNW_LDMACH'})
119119
self.assertEqual(f2, set())
120120

test/test_ehabi_elf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_parse_shared_library(self):
5757
self.assertNotIsInstance(info.get_entry(i), CorruptEHABIEntry)
5858

5959
def test_parse_executable(self):
60-
fname = os.path.join('test', 'testfiles_for_unittests', 'arm_exidx_test.elf')
60+
fname = os.path.join('test', 'testfiles_for_unittests', 'arm_exidx_test.so.elf')
6161
with open(fname, 'rb') as f:
6262
elf = ELFFile(f)
6363
self.assertTrue(elf.has_ehabi_info())

test/test_stab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_stab(self):
1818
("label", 0x95, 0xc8, 0x4072, 0xdeadbeef),
1919
("another label", 0x41, 0x66, 0xf9b1, 0xcafebabe)]
2020
with open(os.path.join('test', 'testfiles_for_unittests',
21-
'obj_stabs.elf'), 'rb') as f:
21+
'obj_stabs.o.elf'), 'rb') as f:
2222
elf = ELFFile(f)
2323

2424
# using correct type?

test/test_tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class TestTree(unittest.TestCase):
1818
def test_tree(self):
19-
self.run_test_on('dwarf_llpair.elf', 0, True)
19+
self.run_test_on('dwarf_llpair.so.elf', 0, True)
2020
self.run_test_on('test_debugsup1.debug', 2, False)
2121

2222
def run_test_on(self, file_name, cu_index, test_cached):

test/testfiles_for_dwarfdump/dwarf_cpptype_volatile.elf renamed to test/testfiles_for_dwarfdump/dwarf_cpptype_volatile.so.elf

File renamed without changes.

0 commit comments

Comments
 (0)