def run(program_text, func): global all_linear,forcing_ok,stack,directed,solutions,path_constraints all_linear,forcing_ok = True,True solutions = {} path_constraints = {} program = parseAST(program_text) program.body = [node for node in program.body if type(node) is FunctionDef and node.name==func.func_name] func_args = func.func_code.co_varnames[:func.func_code.co_argcount] import unparseAST print unparseAST.to_source(program) print print while True: stack = [] inputs = random_inputs(func_args) first = inputs directed = True while directed: try: inputs = execute_program(program,func,inputs) except KeyboardInterrupt: raise except: from sys import exc_info from traceback import print_tb print >> sys.stderr, exc_info() print_tb(exc_info()[-1]) if forcing_ok: print "Bug found" exit() else: forcing_ok = True if first: solutions[first] = get_solutions(path_constraints[first],first.keys()) solutions[first] = filter_inputs(solutions[first],first.keys()) if all_linear: break for key in solutions: print key for inputs in sorted(solutions[key]): print inputs print return solutions
def log(program_text, func, input_list): program = parseAST(program_text) program.body = [node for node in program.body if type(node) is FunctionDef and node.name==func.func_name] func_args = func.func_code.co_varnames[:func.func_code.co_argcount] instrumented = Instrument().visit(program) print "instrumented" import unparseAST print unparseAST.to_source(instrumented) trace = [] if input_list: for inputs in input_list: env = execute_func(instrumented,func,inputs) trace.append(env[Log.log_dict]) """ for point in env[Log.log_dict]: print point print env[Log.log_dict][point] print """ else: env = execute_func(instrumented,func,{}) trace.append(env[Log.log_dict]) """ print for trace_points in trace: for trace_point in trace_points: print str(trace_point) + ": " + str(trace_points[trace_point]) print """ return trace