All readelf tests are passing with python 2. some fails with 3 yet in readelf comparisons
authorEli Bendersky <eliben@gmail.com>
Thu, 28 Nov 2013 17:54:41 +0000 (09:54 -0800)
committerEli Bendersky <eliben@gmail.com>
Thu, 28 Nov 2013 17:54:41 +0000 (09:54 -0800)
scripts/readelf.py
test/run_readelf_tests.py

index c3215b3c22219eb88d06e2b018d2315b46209ea1..3263cfe5c1e8ad60495faacdb6381718f9a077cc 100755 (executable)
@@ -923,8 +923,10 @@ class ReadElf(object):
 
         for entry in self._dwarfinfo.CFI_entries():
             if isinstance(entry, CIE):
-                self._emitline('\n%08x %016x %016x CIE' % (
-                    entry.offset, entry['length'], entry['CIE_id']))
+                self._emitline('\n%08x %s %s CIE' % (
+                    entry.offset,
+                    self._format_hex(entry['length'], fullhex=True, lead0x=False),
+                    self._format_hex(entry['CIE_id'], fullhex=True, lead0x=False)))
                 self._emitline('  Version:               %d' % entry['version'])
                 self._emitline('  Augmentation:          "%s"' % bytes2str(entry['augmentation']))
                 self._emitline('  Code alignment factor: %u' % entry['code_alignment_factor'])
@@ -932,13 +934,15 @@ class ReadElf(object):
                 self._emitline('  Return address column: %d' % entry['return_address_register'])
                 self._emitline()
             else: # FDE
-                self._emitline('\n%08x %016x %016x FDE cie=%08x pc=%016x..%016x' % (
+                self._emitline('\n%08x %s %s FDE cie=%08x pc=%s..%s' % (
                     entry.offset,
-                    entry['length'],
-                    entry['CIE_pointer'],
+                    self._format_hex(entry['length'], fullhex=True, lead0x=False),
+                    self._format_hex(entry['CIE_pointer'], fullhex=True, lead0x=False),
                     entry.cie.offset,
-                    entry['initial_location'],
-                    entry['initial_location'] + entry['address_range']))
+                    self._format_hex(entry['initial_location'], fullhex=True, lead0x=False),
+                    self._format_hex(
+                        entry['initial_location'] + entry['address_range'],
+                        fullhex=True, lead0x=False)))
 
             self._emit(describe_CFI_instructions(entry))
         self._emitline()
@@ -953,23 +957,24 @@ class ReadElf(object):
 
         for entry in self._dwarfinfo.CFI_entries():
             if isinstance(entry, CIE):
-                self._emitline('\n%08x %016x %016x CIE "%s" cf=%d df=%d ra=%d' % (
+                self._emitline('\n%08x %s %s CIE "%s" cf=%d df=%d ra=%d' % (
                     entry.offset,
-                    entry['length'],
-                    entry['CIE_id'],
+                    self._format_hex(entry['length'], fullhex=True, lead0x=False),
+                    self._format_hex(entry['CIE_id'], fullhex=True, lead0x=False),
                     bytes2str(entry['augmentation']),
                     entry['code_alignment_factor'],
                     entry['data_alignment_factor'],
                     entry['return_address_register']))
                 ra_regnum = entry['return_address_register']
             else: # FDE
-                self._emitline('\n%08x %016x %016x FDE cie=%08x pc=%016x..%016x' % (
+                self._emitline('\n%08x %s %s FDE cie=%08x pc=%s..%s' % (
                     entry.offset,
-                    entry['length'],
-                    entry['CIE_pointer'],
+                    self._format_hex(entry['length'], fullhex=True, lead0x=False),
+                    self._format_hex(entry['CIE_pointer'], fullhex=True, lead0x=False),
                     entry.cie.offset,
-                    entry['initial_location'],
-                    entry['initial_location'] + entry['address_range']))
+                    self._format_hex(entry['initial_location'], fullhex=True, lead0x=False),
+                    self._format_hex(entry['initial_location'] + entry['address_range'],
+                        fullhex=True, lead0x=False)))
                 ra_regnum = entry.cie['return_address_register']
 
             # Print the heading row for the decoded table
index afaf6c5fbad861603ad736448a5b552bda4976de..2c1d5f3992db203772b5cf860452f39c49c7fbaf 100755 (executable)
@@ -121,8 +121,19 @@ def compare_output(s1, s2):
         # Compare ignoring whitespace
         lines1_parts = lines1[i].split()
         lines2_parts = lines2[i].split()
+
         if ''.join(lines1_parts) != ''.join(lines2_parts):
             ok = False
+
+            try:
+                # Ignore difference in precision of hex representation in the
+                # last part (i.e. 008f3b vs 8f3b)
+                if (''.join(lines1_parts[:-1]) == ''.join(lines2_parts[:-1]) and
+                    int(lines1_parts[-1], 16) == int(lines2_parts[-1], 16)):
+                    ok = True
+            except ValueError:
+                pass
+
             sm = SequenceMatcher()
             sm.set_seqs(lines1[i], lines2[i])
             changes = sm.get_opcodes()
@@ -151,8 +162,8 @@ def compare_output(s1, s2):
                         ok = True
                         break
             if not ok:
-                errmsg = 'Mismatch on line #%s:\n>>%s<<\n>>%s<<\n' % (
-                    i, lines1[i], lines2[i])
+                errmsg = 'Mismatch on line #%s:\n>>%s<<\n>>%s<<\n (%r)' % (
+                    i, lines1[i], lines2[i], changes)
                 return False, errmsg
     return True, ''