* renamed test files to be consistent
authorEli Bendersky <eliben@gmail.com>
Fri, 23 Sep 2011 09:03:48 +0000 (12:03 +0300)
committerEli Bendersky <eliben@gmail.com>
Fri, 23 Sep 2011 09:03:48 +0000 (12:03 +0300)
* 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

scripts/readelf.py
tests/run_tests.py
tests/testfiles/exe_simple32.elf [new file with mode: 0755]
tests/testfiles/exe_simple64.elf [new file with mode: 0644]
tests/testfiles/exe_stripped64.elf [new file with mode: 0644]
tests/testfiles/libelf0_8_13_32bit.so.elf [new file with mode: 0755]
tests/testfiles/obj_simple32.o.elf [new file with mode: 0644]
tests/testfiles/z.elf [deleted file]
tests/testfiles/z32.elf [deleted file]
tests/testfiles/z32.o.elf [deleted file]
tests/testfiles/zstrip.elf [deleted file]

index 69293cc6cf9ff8e2de46008a116860862bcc772c..8f1c27f074503f46cfc4ce277fe2d71b781229a8 100755 (executable)
@@ -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('.')
index a369b5ee0f4b50d4f82f1c3e5936eafa8b903abb..fda237175c24508e6a860bea53a2ce1fd1d0412c 100755 (executable)
@@ -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 (executable)
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 (file)
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 (file)
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 (executable)
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 (file)
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 (file)
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 (executable)
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 (file)
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 (file)
index 841b3f8..0000000
Binary files a/tests/testfiles/zstrip.elf and /dev/null differ