From: Eli Bendersky Date: Sat, 23 Mar 2013 13:33:09 +0000 (-0700) Subject: Added license snippet to all files in the code. Whitespace cleanup. X-Git-Tag: v0.21~23 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=db51f265f88ba1ead12da3d819eacba523d785d7;p=pyelftools.git Added license snippet to all files in the code. Whitespace cleanup. --- diff --git a/elftools/__init__.py b/elftools/__init__.py index 4f6eb32..4bec384 100644 --- a/elftools/__init__.py +++ b/elftools/__init__.py @@ -1,3 +1,9 @@ +#------------------------------------------------------------------------------- +# elftools +# +# Eli Bendersky (eliben@gmail.com) +# This code is in the public domain +#------------------------------------------------------------------------------- __version__ = '0.21' diff --git a/elftools/common/ordereddict.py b/elftools/common/ordereddict.py index 5e0f142..e1589be 100644 --- a/elftools/common/ordereddict.py +++ b/elftools/common/ordereddict.py @@ -1,11 +1,9 @@ -# http://code.activestate.com/recipes/576693/ (r9) -# Created by Raymond Hettinger on Wed, 18 Mar 2009 (MIT) +#------------------------------------------------------------------------------- +# elftools: port of OrderedDict to work on Python < 2.7 # -# Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 -# and pypy. -# Passes Python2.7's test suite and incorporates all the latest updates. -# - +# Taken from http://code.activestate.com/recipes/576693/ , revision 9 +# Code by Raymond Hettinger. License: MIT +#------------------------------------------------------------------------------- try: from thread import get_ident as _get_ident except ImportError: diff --git a/test/run_readelf_tests.py b/test/run_readelf_tests.py index 1adec09..32fc40f 100755 --- a/test/run_readelf_tests.py +++ b/test/run_readelf_tests.py @@ -23,6 +23,11 @@ testlog = logging.getLogger('run_tests') testlog.setLevel(logging.DEBUG) testlog.addHandler(logging.StreamHandler(sys.stdout)) +# Set the path for calling readelf. By default this is the system readelf. +# +READELF_PATH = 'readelf' +READELF_PATH = '/home/eliben/test/binutils-2.23.52/binutils/readelf' + def discover_testfiles(rootdir): """ Discover test files in the given directory. Yield them one by one. @@ -44,10 +49,10 @@ def run_test_on_file(filename, verbose=False): '--debug-dump=info', '--debug-dump=decodedline', '--debug-dump=frames', '--debug-dump=frames-interp']: if verbose: testlog.info("..option='%s'" % option) - # stdouts will be a 2-element list: output of readelf and output + # stdouts will be a 2-element list: output of readelf and output # of scripts/readelf.py stdouts = [] - for exe_path in ['readelf', 'scripts/readelf.py']: + for exe_path in [READELF_PATH, 'scripts/readelf.py']: args = [option, filename] if verbose: testlog.info("....executing: '%s %s'" % ( exe_path, ' '.join(args))) @@ -64,6 +69,7 @@ def run_test_on_file(filename, verbose=False): success = False testlog.info('.......................FAIL') testlog.info('....for option "%s"' % option) + testlog.info('....Output #1 is readelf, Output #2 is pyelftools') testlog.info('@@ ' + errmsg) dump_output_to_temp_files(testlog, *stdouts) return success @@ -95,7 +101,7 @@ def compare_output(s1, s2): if not filter_out: if not line.startswith('unknown: length'): yield line - + lines1 = prepare_lines(s1) lines2 = prepare_lines(s2) @@ -120,7 +126,7 @@ def compare_output(s1, s2): sm.set_seqs(lines1[i], lines2[i]) changes = sm.get_opcodes() if flag_after_symtable: - # Detect readelf's adding @ with lib and version after + # Detect readelf's adding @ with lib and version after # symbol name. if ( len(changes) == 2 and changes[1][0] == 'delete' and lines1[i][changes[1][1]] == '@'): @@ -134,7 +140,7 @@ def compare_output(s1, s2): elif 'os/abi' in lines1[i]: if 'unix - gnu' in lines1[i] and 'unix - linux' in lines2[i]: ok = True - else: + else: for s in ('t (tls)', 'l (large)'): if s in lines1[i] or s in lines2[i]: ok = True @@ -175,7 +181,7 @@ def main(): for filename in filenames: if success: success = success and run_test_on_file( - filename, + filename, verbose=options.verbose) if success: diff --git a/test/test_arm_support.py b/test/test_arm_support.py index 71d8fc6..804e1df 100644 --- a/test/test_arm_support.py +++ b/test/test_arm_support.py @@ -1,3 +1,9 @@ +#------------------------------------------------------------------------------- +# elftools tests +# +# Eli Bendersky (eliben@gmail.com) +# This code is in the public domain +#------------------------------------------------------------------------------- try: import unittest2 as unittest except ImportError: diff --git a/test/test_callframe.py b/test/test_callframe.py index 33fb1e7..6ea0aeb 100644 --- a/test/test_callframe.py +++ b/test/test_callframe.py @@ -1,3 +1,9 @@ +#------------------------------------------------------------------------------- +# elftools tests +# +# Eli Bendersky (eliben@gmail.com) +# This code is in the public domain +#------------------------------------------------------------------------------- try: import unittest2 as unittest except ImportError: @@ -19,7 +25,7 @@ class TestCallFrame(unittest.TestCase): self.assertIsInstance(instr, CallFrameInstruction) self.assertEqual(instruction_name(instr.opcode), name) self.assertEqual(instr.args, args) - + def test_spec_sample_d6(self): # D.6 sample in DWARFv3 s = BytesIO() @@ -40,7 +46,7 @@ class TestCallFrame(unittest.TestCase): b'\x08\x07' + b'\x09\x08\x01' + b'\x00' + - + # then comes the FDE b'\x28\x00\x00\x00' + # length b'\x00\x00\x00\x00' + # CIE_pointer (to CIE at 0) @@ -125,7 +131,7 @@ class TestCallFrame(unittest.TestCase): self.assertEqual(decoded_FDE.table[9]['pc'], 0x11223344 + 76) def test_describe_CFI_instructions(self): - # The data here represents a single CIE + # The data here represents a single CIE data = (b'' + b'\x16\x00\x00\x00' + # length b'\xff\xff\xff\xff' + # CIE_id @@ -141,7 +147,7 @@ class TestCallFrame(unittest.TestCase): set_global_machine_arch('x86') self.assertEqual(describe_CFI_instructions(entries[0]), - ( ' DW_CFA_def_cfa: r7 (edi) ofs 2\n' + + ( ' DW_CFA_def_cfa: r7 (edi) ofs 2\n' + ' DW_CFA_expression: r2 (edx) (DW_OP_addr: 201; DW_OP_deref; DW_OP_deref)\n')) diff --git a/test/test_dwarf_expr.py b/test/test_dwarf_expr.py index 0efface..7c81ab3 100644 --- a/test/test_dwarf_expr.py +++ b/test/test_dwarf_expr.py @@ -1,3 +1,9 @@ +#------------------------------------------------------------------------------- +# elftools tests +# +# Eli Bendersky (eliben@gmail.com) +# This code is in the public domain +#------------------------------------------------------------------------------- try: import unittest2 as unittest except ImportError: @@ -23,12 +29,12 @@ class TestExprDumper(unittest.TestCase): self.visitor.process_expr([0x1b]) self.assertEqual(self.visitor.get_str(), 'DW_OP_div') - + self.setUp() self.visitor.process_expr([0x74, 0x82, 0x01]) self.assertEqual(self.visitor.get_str(), 'DW_OP_breg4 (rsi): 130') - + self.setUp() self.visitor.process_expr([0x91, 0x82, 0x01]) self.assertEqual(self.visitor.get_str(), diff --git a/test/test_dwarf_lineprogram.py b/test/test_dwarf_lineprogram.py index 75c88c8..2a88972 100644 --- a/test/test_dwarf_lineprogram.py +++ b/test/test_dwarf_lineprogram.py @@ -1,3 +1,9 @@ +#------------------------------------------------------------------------------- +# elftools tests +# +# Eli Bendersky (eliben@gmail.com) +# This code is in the public domain +#------------------------------------------------------------------------------- try: import unittest2 as unittest except ImportError: @@ -24,9 +30,9 @@ class TestLineProgram(unittest.TestCase): b'\x0A' + # opcode_base b'\x00\x01\x04\x08\x0C\x01\x01\x01\x00' + # standard_opcode_lengths # 2 dir names followed by a NULL - b'\x61\x62\x00\x70\x00\x00' + + b'\x61\x62\x00\x70\x00\x00' + # a file entry - b'\x61\x72\x00\x0C\x0D\x0F' + + b'\x61\x72\x00\x0C\x0D\x0F' + # and another entry b'\x45\x50\x51\x00\x86\x12\x07\x08' + # followed by NULL @@ -34,14 +40,14 @@ class TestLineProgram(unittest.TestCase): lp = LineProgram(header, stream, ds, 0, len(stream.getvalue())) return lp - + def assertLineState(self, state, **kwargs): """ Assert that the state attributes specified in kwargs have the given values (the rest are default). """ for k, v in iteritems(kwargs): self.assertEqual(getattr(state, k), v) - + def test_spec_sample_59(self): # Sample in figure 59 of DWARFv3 s = BytesIO() diff --git a/test/test_dwarf_structs.py b/test/test_dwarf_structs.py index eaf972c..9f6926a 100644 --- a/test/test_dwarf_structs.py +++ b/test/test_dwarf_structs.py @@ -1,3 +1,9 @@ +#------------------------------------------------------------------------------- +# elftools tests +# +# Eli Bendersky (eliben@gmail.com) +# This code is in the public domain +#------------------------------------------------------------------------------- try: import unittest2 as unittest except ImportError: @@ -20,9 +26,9 @@ class TestDWARFStructs(unittest.TestCase): b'\x06' + # opcode_base b'\x00\x01\x04\x08\x0C' + # standard_opcode_lengths # 2 dir names followed by a NULL - b'\x61\x62\x00\x70\x00\x00' + + b'\x61\x62\x00\x70\x00\x00' + # a file entry - b'\x61\x72\x00\x0C\x0D\x0F' + + b'\x61\x72\x00\x0C\x0D\x0F' + # and another entry b'\x45\x50\x51\x00\x86\x12\x07\x08' + # followed by NULL diff --git a/test/test_utils.py b/test/test_utils.py index f0142d8..bc54780 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -1,3 +1,9 @@ +#------------------------------------------------------------------------------- +# elftools tests +# +# Eli Bendersky (eliben@gmail.com) +# This code is in the public domain +#------------------------------------------------------------------------------- try: import unittest2 as unittest except ImportError: @@ -14,7 +20,7 @@ from elftools.common.utils import (parse_cstring_from_stream, class Test_parse_cstring_from_stream(unittest.TestCase): def _make_random_bytes(self, n): return b''.join(int2byte(randint(32, 127)) for i in range(n)) - + def test_small1(self): sio = BytesIO(b'abcdefgh\x0012345') self.assertEqual(parse_cstring_from_stream(sio), b'abcdefgh') diff --git a/z.py b/z.py index d30feb3..18f7d35 100644 --- a/z.py +++ b/z.py @@ -1,3 +1,10 @@ +#------------------------------------------------------------------------------- +# elftools +# +# Eli Bendersky (eliben@gmail.com) +# This code is in the public domain +#------------------------------------------------------------------------------- + # Just a script for playing around with pyelftools during testing # please ignore it! #