From: Eli Bendersky Date: Fri, 23 Sep 2011 09:03:48 +0000 (+0300) Subject: * renamed test files to be consistent X-Git-Tag: v0.10~95 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=099d48f55112c92f4ee1800764f5b8f195025686;p=pyelftools.git * renamed test files to be consistent * added a real-life test file - the libelf SO on 32-bit * fixed a formatting difference in readelf.py * enabled selecting which test files to run on in run_tests.py --- diff --git a/scripts/readelf.py b/scripts/readelf.py index 69293cc..8f1c27f 100755 --- a/scripts/readelf.py +++ b/scripts/readelf.py @@ -289,21 +289,25 @@ class ReadElf(object): for rel in section.iter_relocations(): hexwidth = 8 if self.elffile.elfclass == 32 else 12 - symbol = symtable.get_symbol(rel['r_info_sym']) - self._emit('%s %s %-17.17s %s %s%s' % ( + self._emit('%s %s %-17.17s' % ( self._format_hex(rel['r_offset'], fieldsize=hexwidth, lead0x=False), self._format_hex(rel['r_info'], fieldsize=hexwidth, lead0x=False), describe_reloc_type( - rel['r_info_type'], self.elffile['e_machine']), + rel['r_info_type'], self.elffile['e_machine']))) + + if rel['r_info_sym'] == 0: + self._emitline() + continue + + symbol = symtable.get_symbol(rel['r_info_sym']) + self._emit(' %s %s%s' % ( self._format_hex( symbol['st_value'], fullhex=True, lead0x=False), ' ' if self.elffile.elfclass == 32 else '', - symbol.name, - )) - + symbol.name)) if section.is_RELA(): self._emit(' %s %x' % ( '+' if rel['r_addend'] >= 0 else '-', @@ -345,7 +349,7 @@ class ReadElf(object): for i in range(linebytes): c = data[dataptr + i] - if c >= ' ' and ord(c) <= 0x7f: + if c >= ' ' and ord(c) < 0x7f: self._emit(c) else: self._emit('.') diff --git a/tests/run_tests.py b/tests/run_tests.py index a369b5e..fda2371 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -64,8 +64,8 @@ def run_test_on_file(filename): return False stdouts.append(stdout) testlog.info('....comparing output...') - success, errmsg = compare_output(*stdouts) - if success: + rc, errmsg = compare_output(*stdouts) + if rc: testlog.info('.......................SUCCESS') else: success = False @@ -97,11 +97,12 @@ def compare_output(s1, s2): for i in range(len(lines1)): if 'Symbol table' in lines1[i]: flag_after_symtable = True + # Compare ignoring whitespace if lines1[i].split() != lines2[i].split(): + sm = SequenceMatcher() + sm.set_seqs(lines1[i], lines2[i]) if flag_after_symtable: - sm = SequenceMatcher() - sm.set_seqs(lines1[i], lines2[i]) # Detect readelf's adding @ with lib and version after # symbol name. changes = sm.get_opcodes() @@ -145,8 +146,16 @@ def main(): if not is_in_rootdir(): die('Please run me from the root dir of pyelftools!') + # If file names are given as command-line arguments, only these files + # are taken as inputs. Otherwise, autodiscovery is performed. + # + if len(sys.argv) > 1: + filenames = sys.argv[1:] + else: + filenames = list(discover_testfiles('tests/testfiles')) + success = True - for filename in discover_testfiles('tests/testfiles'): + for filename in filenames: success = success and run_test_on_file(filename) if success: diff --git a/tests/testfiles/exe_simple32.elf b/tests/testfiles/exe_simple32.elf new file mode 100755 index 0000000..d6b3cd1 Binary files /dev/null and b/tests/testfiles/exe_simple32.elf differ diff --git a/tests/testfiles/exe_simple64.elf b/tests/testfiles/exe_simple64.elf new file mode 100644 index 0000000..ccfa6ae Binary files /dev/null and b/tests/testfiles/exe_simple64.elf differ diff --git a/tests/testfiles/exe_stripped64.elf b/tests/testfiles/exe_stripped64.elf new file mode 100644 index 0000000..841b3f8 Binary files /dev/null and b/tests/testfiles/exe_stripped64.elf differ diff --git a/tests/testfiles/libelf0_8_13_32bit.so.elf b/tests/testfiles/libelf0_8_13_32bit.so.elf new file mode 100755 index 0000000..c236625 Binary files /dev/null and b/tests/testfiles/libelf0_8_13_32bit.so.elf differ diff --git a/tests/testfiles/obj_simple32.o.elf b/tests/testfiles/obj_simple32.o.elf new file mode 100644 index 0000000..5ce4182 Binary files /dev/null and b/tests/testfiles/obj_simple32.o.elf differ diff --git a/tests/testfiles/z.elf b/tests/testfiles/z.elf deleted file mode 100644 index ccfa6ae..0000000 Binary files a/tests/testfiles/z.elf and /dev/null differ diff --git a/tests/testfiles/z32.elf b/tests/testfiles/z32.elf deleted file mode 100755 index d6b3cd1..0000000 Binary files a/tests/testfiles/z32.elf and /dev/null differ diff --git a/tests/testfiles/z32.o.elf b/tests/testfiles/z32.o.elf deleted file mode 100644 index 5ce4182..0000000 Binary files a/tests/testfiles/z32.o.elf and /dev/null differ diff --git a/tests/testfiles/zstrip.elf b/tests/testfiles/zstrip.elf deleted file mode 100644 index 841b3f8..0000000 Binary files a/tests/testfiles/zstrip.elf and /dev/null differ