From 851cdb0bc36b365197bb32190a545a605ef6758d Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Sat, 17 Sep 2011 14:07:57 +0300 Subject: [PATCH] fixing comparison in run_tests. moving all binary files to testfiles/ --- binfiles/z32.elf | Bin 5492 -> 0 bytes tests/run_tests.py | 22 ++++++++++++++++++++++ {binfiles => tests/testfiles}/z.elf | Bin tests/testfiles/zstrip.elf | Bin 0 -> 6440 bytes 4 files changed, 22 insertions(+) delete mode 100755 binfiles/z32.elf rename {binfiles => tests/testfiles}/z.elf (100%) create mode 100644 tests/testfiles/zstrip.elf diff --git a/binfiles/z32.elf b/binfiles/z32.elf deleted file mode 100755 index d6b3cd1ff7e422d1845ec7887ccb1e0cb1db058c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5492 zcmeHLUuauZ7(Z!mw^S=;Tg2kxh?;8q(7SHS#41i**R{p5zqTr+%hD!o?#Q2!d!rk4 z*e(`Y(n`T8eOrqUzNic)B6JTe8SCa#6ofrUndl&;Rr^rKz|rgPcW+L~Y6tq@TR!;C z_kHL4o$q|-JLiU+^Fi~WgARv7NGcQM!m`qe(~nN~7Te<&Uf~qA!XvheP3WS}KL8Ba z8h}9+=u^Pu^uhKI!VlgCn@k^LlP%&{@I^St94}n9zv^)zsxB!`vVs9sV9rZ_8H5*p zFMQ-2Y%=|vgWL*yE9NF2fK8UZV|R=Y%zuy^e;oee`B#7>b3Ak38P&RXMnm;cEuK27 z>IrqX?L%sozvXZ{G&@hmM5@+UHzaFAfA$a8v#noG_Vq6Gee%=!^Ap+HeM|JoIk-mJ z>q+)A5362Y;U$LHFW>xShI%m(C&>$?P8yI~!B2rlKSYfox3IW@Kwm5o59mfPX#@fS zOYPwjUlf71Bj^oj@jyxshk&E2fQtpSxM(@lw!bN`TWvrnP?=Q=2U^yJOmb=3WAwdZ zn_?OJw~0wkD$dQ23MCfVK62+odP&I>);X9x`m_+4kMEnNIrM{3k>7#d{P%47G3K4l zn^|-3Jw!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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/binfiles/z.elf b/tests/testfiles/z.elf similarity index 100% rename from binfiles/z.elf rename to tests/testfiles/z.elf diff --git a/tests/testfiles/zstrip.elf b/tests/testfiles/zstrip.elf new file mode 100644 index 0000000000000000000000000000000000000000..841b3f854170d691a7016cdf59a6d1a2385a480c GIT binary patch literal 6440 zcmeHLZ){Ul6u*7#MhAmU91(%Irzr_U`WP^dpr7y?kq-=p!V)zaNhE0EGF?*nm-z?X2cVvF-#J@(f`4NCw%fdW z?)me(=iGDeyS?x3Z4N!JxLksZBAyYF^XO7!*FwY}U<)C15fBwn*NR6(If%>PVLP2# zOed&ore5mC4b%fqK(Pe@MVAexi)^uA$`K+(e^W)LrcKXbKv0+pp-LWcsG2`VvOu@X z22&5kF`p>okVTwMIGu1zk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