fixing comparison in run_tests. moving all binary files to testfiles/
authorEli Bendersky <eliben@gmail.com>
Sat, 17 Sep 2011 11:07:57 +0000 (14:07 +0300)
committerEli Bendersky <eliben@gmail.com>
Sat, 17 Sep 2011 11:07:57 +0000 (14:07 +0300)
binfiles/z.elf [deleted file]
binfiles/z32.elf [deleted file]
tests/run_tests.py
tests/testfiles/z.elf [new file with mode: 0644]
tests/testfiles/zstrip.elf [new file with mode: 0644]

diff --git a/binfiles/z.elf b/binfiles/z.elf
deleted file mode 100644 (file)
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 (executable)
index d6b3cd1..0000000
Binary files a/binfiles/z32.elf and /dev/null differ
index f9169786f9c256fe5dc808879f1bf85dcdce4848..8a97701fbf60ea4f7c42c5fac9812c01c4a8864d 100755 (executable)
@@ -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 (file)
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 (file)
index 0000000..841b3f8
Binary files /dev/null and b/tests/testfiles/zstrip.elf differ