From cb4eb99dbd562ed2207781f96a0a13762e626ba4 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Thu, 28 Nov 2013 09:54:41 -0800 Subject: [PATCH] All readelf tests are passing with python 2. some fails with 3 yet in readelf comparisons --- scripts/readelf.py | 35 ++++++++++++++++++++--------------- test/run_readelf_tests.py | 15 +++++++++++++-- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/scripts/readelf.py b/scripts/readelf.py index c3215b3..3263cfe 100755 --- a/scripts/readelf.py +++ b/scripts/readelf.py @@ -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 diff --git a/test/run_readelf_tests.py b/test/run_readelf_tests.py index afaf6c5..2c1d5f3 100755 --- a/test/run_readelf_tests.py +++ b/test/run_readelf_tests.py @@ -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, '' -- 2.30.2