From: Eli Bendersky Date: Sat, 17 Sep 2011 11:07:57 +0000 (+0300) Subject: fixing comparison in run_tests. moving all binary files to testfiles/ X-Git-Tag: v0.10~115 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=851cdb0bc36b365197bb32190a545a605ef6758d;p=pyelftools.git fixing comparison in run_tests. moving all binary files to testfiles/ --- diff --git a/binfiles/z.elf b/binfiles/z.elf deleted file mode 100644 index ccfa6ae..0000000 Binary files a/binfiles/z.elf and /dev/null differ diff --git a/binfiles/z32.elf b/binfiles/z32.elf deleted file mode 100755 index d6b3cd1..0000000 Binary files a/binfiles/z32.elf and /dev/null differ diff --git a/tests/run_tests.py b/tests/run_tests.py index f916978..8a97701 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -8,6 +8,7 @@ # This code is in the public domain #------------------------------------------------------------------------------- import os, sys +from difflib import SequenceMatcher import logging import subprocess import tempfile @@ -75,14 +76,35 @@ def compare_output(s1, s2): Return pair success, errmsg. If comparison succeeds, success is True and errmsg is empty. Otherwise success is False and errmsg holds a description of the mismatch. + + Note: this function contains some rather horrible hacks to ignore + differences which are not important for the verification of pyelftools. + This is due to some intricacies of binutils's readelf which pyelftools + doesn't currently implement. Read the documentation for more details. """ lines1 = s1.splitlines() lines2 = s2.splitlines() if len(lines1) != len(lines2): return False, 'Number of lines different: %s vs %s' % ( len(lines1), len(lines2)) + + flag_after_symtable = False + 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(): + 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() + if ( len(changes) == 2 and changes[1][0] == 'delete' and + lines1[i][changes[1][1]] == '@'): + continue + errmsg = 'Mismatch on line #%s:\n>>%s<<\n>>%s<<\n' % ( i, lines1[i], lines2[i]) return False, errmsg diff --git a/tests/testfiles/z.elf b/tests/testfiles/z.elf new file mode 100644 index 0000000..ccfa6ae Binary files /dev/null and b/tests/testfiles/z.elf differ diff --git a/tests/testfiles/zstrip.elf b/tests/testfiles/zstrip.elf new file mode 100644 index 0000000..841b3f8 Binary files /dev/null and b/tests/testfiles/zstrip.elf differ