mirror of https://github.com/geohot/qira
update static tests for python3
This commit is contained in:
parent
e1b0c65d1b
commit
b30b2e9efd
|
@ -10,7 +10,7 @@ import struct
|
|||
try:
|
||||
from static2 import *
|
||||
except ImportError as e:
|
||||
print "Couldn't import static2 with error `{}'. Are you in the virtualenv?".format(e)
|
||||
print("Couldn't import static2 with error `{}'. Are you in the virtualenv?".format(e))
|
||||
sys.exit()
|
||||
import subprocess
|
||||
import argparse
|
||||
|
@ -56,19 +56,19 @@ def test_files(fns,quiet=False,profile=False,runtime=False):
|
|||
short_fn = fn.split("/")[-1] if "/" in fn else fn
|
||||
if os.path.isdir(fn):
|
||||
if not quiet:
|
||||
print "{} {}: skipping directory".format(notice, short_fn)
|
||||
print("{} {}: skipping directory".format(notice, short_fn))
|
||||
continue
|
||||
try:
|
||||
elf = ELFFile(open(fn))
|
||||
elf = ELFFile(open(fn, "rb"))
|
||||
except ELFError:
|
||||
if not quiet:
|
||||
print "{} {}: skipping non-ELF file".format(notice, short_fn)
|
||||
print("{} {}: skipping non-ELF file".format(notice, short_fn))
|
||||
continue
|
||||
|
||||
arch = elf['e_machine']
|
||||
if arch not in SUPPORTED:
|
||||
if not quiet:
|
||||
print "{} {}: skipping ELF with unsupported architecture `{}`".format(notice, short_fn, arch)
|
||||
print("{} {}: skipping ELF with unsupported architecture `{}`".format(notice, short_fn, arch))
|
||||
continue
|
||||
|
||||
engine_functions = {}
|
||||
|
@ -87,17 +87,17 @@ def test_files(fns,quiet=False,profile=False,runtime=False):
|
|||
this_engine.process()
|
||||
engine_functions[engine] = {x.start for x in this_engine['functions']}
|
||||
except KeyboardInterrupt:
|
||||
print "{} User stopped processing test cases.".format(notice)
|
||||
print("{} User stopped processing test cases.".format(notice))
|
||||
sys.exit()
|
||||
except MemoryError:
|
||||
#print "{} {}: bap encountered a memory error.".format(fail, short_fn, engine)
|
||||
#print("{} {}: bap encountered a memory error.".format(fail, short_fn, engine)
|
||||
continue
|
||||
except Exception as e:
|
||||
print "{} {}: {} engine failed to process file with `{}'".format(fail, short_fn, engine, e)
|
||||
print("{} {}: {} engine failed to process file with `{}'".format(fail, short_fn, engine, e))
|
||||
continue
|
||||
if runtime:
|
||||
if not quiet:
|
||||
print "{} {}: {} ran without exceptions".format(ok_green, short_fn, engine)
|
||||
print("{} {}: {} ran without exceptions".format(ok_green, short_fn, engine))
|
||||
continue
|
||||
|
||||
if runtime:
|
||||
|
@ -106,29 +106,29 @@ def test_files(fns,quiet=False,profile=False,runtime=False):
|
|||
if elf.has_dwarf_info():
|
||||
dwarfinfo = elf.get_dwarf_info()
|
||||
dwarf_functions = get_functions(dwarfinfo)
|
||||
for engine,functions in engine_functions.iteritems():
|
||||
for engine,functions in engine_functions.items():
|
||||
missed = dwarf_functions - functions
|
||||
total_fxns = len(dwarf_functions)
|
||||
if len(missed) == 0:
|
||||
print "{} {}: {} engine found all {} function(s)".format(ok_green,
|
||||
print("{} {}: {} engine found all {} function(s)".format(ok_green,
|
||||
short_fn,
|
||||
engine,
|
||||
total_fxns)
|
||||
total_fxns))
|
||||
else:
|
||||
status = fail if len(missed) == total_fxns else warn
|
||||
if args.verbose:
|
||||
fmt = "{} {}: {} engine missed {}/{} function(s): {}"
|
||||
missed_s = ", ".join(hex(fxn) for fxn in missed)
|
||||
print fmt.format(status, short_fn, engine,
|
||||
len(missed), total_fxns, missed_s)
|
||||
print(fmt.format(status, short_fn, engine,
|
||||
len(missed), total_fxns, missed_s))
|
||||
else:
|
||||
fmt = "{} {}: {} engine missed {}/{} function(s)"
|
||||
print fmt.format(status, short_fn, engine,
|
||||
len(missed), total_fxns)
|
||||
print(fmt.format(status, short_fn, engine,
|
||||
len(missed), total_fxns))
|
||||
else:
|
||||
for engine,functions in engine_functions.iteritems():
|
||||
for engine,functions in engine_functions.items():
|
||||
status = fail if len(functions) == 0 else ok_blue
|
||||
print "{} {}: {} engine found {} function(s). (dwarf info unavailable)".format(status, short_fn, engine, len(functions))
|
||||
print("{} {}: {} engine found {} function(s). (dwarf info unavailable)".format(status, short_fn, engine, len(functions)))
|
||||
|
||||
def get_file_list(location, recursive=False):
|
||||
fns = []
|
||||
|
@ -146,7 +146,7 @@ def get_file_list(location, recursive=False):
|
|||
if not os.path.isdir(fn):
|
||||
fns.append(fn)
|
||||
if fns == []:
|
||||
print "No files found. Try running with -r."
|
||||
print("No files found. Try running with -r.")
|
||||
return fns
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -171,9 +171,9 @@ if __name__ == "__main__":
|
|||
fns = get_file_list(args.files, args.recursive)
|
||||
else:
|
||||
if args.profile:
|
||||
print "Profiling over entire test suite. Are you sure that's what you wanted?"
|
||||
print("Profiling over entire test suite. Are you sure that's what you wanted?")
|
||||
fns = get_file_list([TEST_PATH], args.recursive)
|
||||
if len(fns) == 0:
|
||||
print "No files found in {}. Try running python autogen.py --dwarf in the tests directory.".format(TEST_PATH)
|
||||
print("No files found in {}. Try running python autogen.py --dwarf in the tests directory.".format(TEST_PATH))
|
||||
|
||||
test_files(fns, args.quiet, args.profile, args.runtime)
|
||||
|
|
|
@ -46,7 +46,7 @@ def compiler_command(path,filename,this_arch,args):
|
|||
if args.clang:
|
||||
if this_arch not in [arch.x86,arch.x86_64]:
|
||||
#todo: fix this, clang should support all archs pretty easily
|
||||
print "clang doesn't support arch"
|
||||
print("clang doesn't support arch")
|
||||
return []
|
||||
compiler = "clang"
|
||||
raw_filename += "_clang"
|
||||
|
@ -75,7 +75,7 @@ def compiler_command(path,filename,this_arch,args):
|
|||
command += [PPC64_GCC]
|
||||
raw_filename += "_ppc64"
|
||||
else:
|
||||
print "Invalid archicture"
|
||||
print("Invalid arch")
|
||||
return []
|
||||
|
||||
if args.static:
|
||||
|
@ -185,21 +185,21 @@ def process_files(archs,files,args):
|
|||
if cmd == []:
|
||||
continue #failed to get command
|
||||
if args.print_only:
|
||||
print " ".join(cmd)
|
||||
print(" ".join(cmd))
|
||||
else:
|
||||
print "{} [{}/{}] {}".format(green_plus,
|
||||
progress,to_compile," ".join(cmd))
|
||||
print("{} [{}/{}] {}".format(green_plus,
|
||||
progress,to_compile," ".join(cmd)))
|
||||
#don't show warnings
|
||||
status = subprocess.call(cmd,stdout=FNULL,stderr=FNULL)
|
||||
if status != 0:
|
||||
any_failed = True
|
||||
fail_path = os.path.join(path,fn)
|
||||
print "{} Compilation failed for {}.".format(fail_minus,fail_path)
|
||||
print("{} Compilation failed for {}.".format(fail_minus,fail_path))
|
||||
progress += 1
|
||||
if any_failed:
|
||||
print "At least one test failed."
|
||||
print "Install ./autogen-extras.sh if necessary."
|
||||
print "Otherwise, it's a bug and we're working on it."
|
||||
print("At least one test failed.")
|
||||
print("Install ./autogen-extras.sh if necessary.")
|
||||
print("Otherwise, it's a bug and we're working on it.")
|
||||
|
||||
def generate_binaries():
|
||||
args = argument_parse()
|
||||
|
@ -210,7 +210,7 @@ def generate_binaries():
|
|||
sys.exit()
|
||||
|
||||
if args.strip and args.dwarf:
|
||||
print "Both --strip and --dwarf seleted. Was that intended?"
|
||||
print("Both --strip and --dwarf seleted. Was that intended?")
|
||||
|
||||
archs = get_archs(args)
|
||||
files = get_files(args)
|
||||
|
|
Loading…
Reference in New Issue