def parallelRun(self, smt2_file): """ Job spanner """ ctx = z3.Context() fp = z3.Fixedpoint(ctx=ctx) jobs = [] with stats.timer('Parse'): self.log.info('Parsing ... ' + str(smt2_file)) queries = fp.parse_file(smt2_file) stats.stop('Parse') self.log.info("Parsing time ... " + str(stats.get('Parse')) + " ms") n_function = len(queries) n_query = n_function if self.args.func < 0 or self.args.func > n_function else self.args.func self.log.info("Number of functions ... " + str(n_function)) self.log.info("Number of jobs ... " + str(n_query)) all_results = "" pool_jobs = Pool(processes=n_query) try: for q in range(n_query): query = queries[q] function_name = self.getFunctionName(query) self.log.info("Checking feasibility of ... " + str(function_name)) #job_result = pool_jobs.apply_async(jobStarter, (self.args, qi, smt2_file, ), callback=self.onReturn) job_result = pool_jobs.apply_async(jobStarter, ( self.args, q, smt2_file, )) job_result.wait(timeout=self.args.timeout) if job_result.ready(): out = "" try: out = job_result.get() if bench: print out except Exception as e: print str(e) continue all_results += out + "\n-----------------------\n" else: out = out_message % (function_name, "TIMEOUT", "", "", "", "", "") out = bcolors.WARNING + out + bcolors.ENDC if bench: print out all_results += out + "\n------- ----------------\n" pool_jobs.close() pool_jobs.terminate() pool_jobs.join() if self.args.save: f_name = ntpath.basename(smt2_file) + "_feas.txt" with open(f_name, "w") as f: f.write(all_results) else: print "\n\t ========= SUMMARY SEAHORN INCONSISTENCY CHECKS ========" print all_results except Exception as e: self.log.exception(str(e))
def Wolfinch_end(): log.info("Finalizing Wolfinch") exchanges.close_exchanges() # stop stats thread log.info("waiting to stop stats thread") stats.stop() ui.ui_mp_end() log.info("all cleanup done.")
def checkFeasibility(self, expr_query, function_name): done = False rounds = 0 # counter for feasibility check self.ee_idx = self.ee_vars(expr_query) if verbose: print "EE VARS INDEX:", self.ee_idx out = "" while not done: with stats.timer('Query'): res = self.fp.query( expr_query ) #if round == 0 else self.fp.query_from_lvl(12,expr_query) if res == z3.sat: msg = "ENTRY -> EXIT is FEASIBLE" if rounds == 0 else "STILL FEASIBLE: Continue checking ..." if verbose: print "( " + function_name + " ) " + msg expr_query, path = self.cex(expr_query) self.feasible_flag = self.ee_idx rounds += 1 if expr_query is None: result = "[%s], Feasible" % function_name stat('Result', result) stat('Rounds', str(rounds)) out += out_message % (function_name, "CONSISTENT", "", str(self.feasible_flag), str(self.non_feasible_flag)) out = bcolors.OKGREEN + out + bcolors.ENDC done = True elif res == z3.unsat: result = "[%s], Infeasible" % function_name stat('Result', result) stat('Rounds', str(rounds)) msg = "EXIT is not FEASIBLE" if rounds == 0 else "INFEASIBLE BLOCK FOUND" if rounds == 0: self.feasible_flag.append(self.ee_idx[0]) self.non_feasible_flag.append(self.ee_idx[1]) if verbose: print " ( " + function_name + " ) " + msg inv = "\n" for p in self.preds: lemmas = fp_get_cover_delta(self.fp, p) inv += "\tBasic Block: " + str(p.decl()) inv += "\n\tInvariant: " + str(lemmas) inv += "\n\t-----------\n" inv_info = inv if self.args.inv else "(set --inv to get invariants info)" out += out_message % (function_name, "INCONSISTENT", inv_info, str(self.feasible_flag), str(self.non_feasible_flag)) out = bcolors.FAIL + out + bcolors.ENDC done = True stats.stop('Query') # debugging purpose if self.args.stop != None: self.args.stop -= 1 done = self.args.stop == 0 return out
def parallelRun(self, smt2_file): """ Job spanner """ ctx = z3.Context () fp = z3.Fixedpoint (ctx=ctx) jobs = [] with stats.timer ('Parse'): self.log.info('Parsing ... ' + str(smt2_file)) queries = fp.parse_file (smt2_file) stats.stop('Parse') self.log.info("Parsing time ... " + str(stats.get('Parse')) + " ms") n_function = len(queries) n_query = n_function if self.args.func < 0 or self.args.func > n_function else self.args.func self.log.info("Number of functions ... " + str(n_function)) self.log.info("Number of jobs ... " + str(n_query)) all_results = "" pool_jobs = Pool(processes=n_query) try: for q in range(n_query): query = queries[q] function_name = self.getFunctionName(query) self.log.info("Checking feasibility of ... " + str(function_name)) #job_result = pool_jobs.apply_async(jobStarter, (self.args, qi, smt2_file, ), callback=self.onReturn) job_result = pool_jobs.apply_async(jobStarter, (self.args, q, smt2_file, )) job_result.wait(timeout=self.args.timeout) if job_result.ready(): out = "" try: out = job_result.get() if bench: print out except Exception as e: print str(e) continue all_results += out + "\n-----------------------\n" else: out = out_message % (function_name, "TIMEOUT", "", "", "", "", "") out = bcolors.WARNING + out + bcolors.ENDC if bench: print out all_results += out + "\n------- ----------------\n" pool_jobs.close() pool_jobs.terminate() pool_jobs.join() if self.args.save: f_name = ntpath.basename(smt2_file)+"_feas.txt" with open (f_name, "w") as f: f.write(all_results) else: print "\n\t ========= SUMMARY SEAHORN INCONSISTENCY CHECKS ========" print all_results except Exception as e: self.log.exception(str(e))
def jayhorn(build_dir, args): cmd = ["java", "-jar", JAYHORN, "-t", "60", "-stats", "-j", build_dir, '-mem-prec', "{}".format(args.mem)] if args.inline: cmd.extend(['-inline_size', '30', '-inline_count', '3']) cmd_spacer = cmd + ['-solver', 'spacer'] bench_stats.start('JayHorn-Eldarica-Time') eldarica_result = run_with_timeout("jayhorn-eldarica_{}_{}".format(args.mem, args.inline), cmd, args.timeout) bench_stats.stop('JayHorn-Eldarica-Time') bench_stats.start('JayHorn-Spacer-Time') spacer_result = run_with_timeout("jayhorn-spacer_{}_{}".format(args.mem, args.inline), cmd_spacer, args.timeout) bench_stats.stop('JayHorn-Spacer-Time') eldarica_time = bench_stats.get("JayHorn-Eldarica-Time") spacer_time = bench_stats.get("JayHorn-Spacer-Time") return eldarica_result, spacer_result, str(eldarica_time), str(spacer_time)
def singleRun(self, smt2_file): """ Single run """ ctx = z3.Context() fp = z3.Fixedpoint(ctx=ctx) with stats.timer('Parse'): self.log.info('Parsing ... ' + str(smt2_file)) queries = fp.parse_file(smt2_file) stats.stop('Parse') self.log.info("Parsing time ... " + str(stats.get('Parse')) + " ms") n_function = len(queries) n_query = n_function if self.args.func < 0 or self.args.func > n_function else self.args.func self.log.info("Number of functions ... " + str(n_function)) self.log.info("Number of jobs ... " + str(n_query)) all_results = "" try: for q in range(n_query): query = queries[q] function_name = self.getFunctionName(query) self.log.info("Checking feasibility of ... " + str(function_name)) out = "" try: p = multiprocessing.Process(target=checkFeas, args=( self.args, q, smt2_file, )) p.start() p.join(self.args.timeout) if p.is_alive(): out = out_message % (function_name, "TIMEOUT", "", "", "", "", "") out = bcolors.WARNING + out + bcolors.ENDC p.terminate() p.join() except Exception as e: self.log.exception(str(e)) continue all_results += out + "\n-----------------------\n" if self.args.save: f_name = ntpath.basename(smt2_file) + "_feas.txt" with open(f_name, "w") as f: f.write(all_results) except Exception as e: self.log.exception(str(e))
def checkFeasibility(self, expr_query, function_name): done = False rounds = 0 # counter for feasibility check self.ee_idx = self.ee_vars(expr_query) if verbose: print "EE VARS INDEX:", self.ee_idx out = "" while not done: with stats.timer ('Query'): res = self.fp.query (expr_query) #if round == 0 else self.fp.query_from_lvl(12,expr_query) if res == z3.sat: msg = "ENTRY -> EXIT is FEASIBLE" if rounds==0 else "STILL FEASIBLE: Continue checking ..." if verbose: print "( " + function_name + " ) " + msg expr_query, path = self.cex(expr_query) self.feasible_flag = self.ee_idx rounds += 1 if expr_query is None: result = "[%s], Feasible" % function_name stat('Result', result) stat('Rounds', str(rounds)) out += out_message % (function_name, "CONSISTENT", "", str(self.feasible_flag), str(self.non_feasible_flag)) out = bcolors.OKGREEN + out + bcolors.ENDC done = True elif res == z3.unsat: result = "[%s], Infeasible" % function_name stat('Result', result) stat('Rounds', str(rounds)) msg = "EXIT is not FEASIBLE" if rounds==0 else "INFEASIBLE BLOCK FOUND" if rounds == 0: self.feasible_flag.append(self.ee_idx[0]) self.non_feasible_flag.append(self.ee_idx[1]) if verbose: print " ( " + function_name + " ) " + msg inv = "\n" for p in self.preds: lemmas = fp_get_cover_delta (self.fp, p) inv += "\tBasic Block: " + str(p.decl()) inv += "\n\tInvariant: " + str(lemmas) inv += "\n\t-----------\n" inv_info = inv if self.args.inv else "(set --inv to get invariants info)" out += out_message % (function_name, "INCONSISTENT", inv_info, str(self.feasible_flag), str(self.non_feasible_flag)) out = bcolors.FAIL + out + bcolors.ENDC done = True stats.stop('Query') # debugging purpose if self.args.stop != None: self.args.stop -=1 done = self.args.stop==0 return out
def solve(self, smt2_file): """ Start solving """ self.fp.set(engine='spacer') if self.args.stat: self.fp.set('print_statistics', True) if self.args.z3_verbose: z3.set_option(verbose=1) self.fp.set('use_heavy_mev', True) self.fp.set('pdr.flexible_trace', True) self.fp.set('reset_obligation_queue', False) self.fp.set('spacer.elim_aux', False) if self.args.utvpi: self.fp.set('pdr.utvpi', False) if not self.args.pp: self.fp.set('xform.slice', False) self.fp.set('xform.inline_linear', False) self.fp.set('xform.inline_eager', False) with stats.timer('Parse'): queries = self.fp.parse_file(smt2_file) stats.stop('Parse') self.preds = get_preds(self.fp) n_function = len(queries) stat("Function_Numbers", n_function) # TODO: Put them in a multithreading function all_results = "" for q in queries: if z3.is_quantifier(q): decl = q.body().decl() function_name = str(decl).split("@")[0] try: out = self.checkFeasibility(q, function_name) all_results += out + "\n-----------------------\n" except Exception as e: print "Solving " + function_name else: function_name = str(q.decl()).split("@")[0] out = out_message % (function_name, "CONSISTENT", "", "Trivial", "") all_results += bcolors.OKGREEN + out + bcolors.ENDC print "\n\t ========= SEAHORN INCONSISTENCY RESULTS ========" print all_results
def solve(self, smt2_file): """ Start solving """ self.fp.set (engine='spacer') if self.args.stat: self.fp.set('print_statistics',True) if self.args.z3_verbose: z3.set_option (verbose=1) self.fp.set('use_heavy_mev',True) self.fp.set('pdr.flexible_trace',True) self.fp.set('reset_obligation_queue',False) self.fp.set('spacer.elim_aux',False) if self.args.utvpi: self.fp.set('pdr.utvpi', False) if not self.args.pp: self.fp.set ('xform.slice', False) self.fp.set ('xform.inline_linear',False) self.fp.set ('xform.inline_eager',False) with stats.timer ('Parse'): queries = self.fp.parse_file (smt2_file) stats.stop('Parse') self.preds = get_preds(self.fp) n_function = len(queries) stat("Function_Numbers", n_function) # TODO: Put them in a multithreading function all_results = "" for q in queries: if z3.is_quantifier(q): decl = q.body().decl() function_name = str(decl).split("@")[0] try: out = self.checkFeasibility(q, function_name) all_results += out + "\n-----------------------\n" except Exception as e: print "Solving " + function_name else: function_name = str(q.decl()).split("@")[0] out = out_message % (function_name, "CONSISTENT", "", "Trivial", "") all_results += bcolors.OKGREEN + out + bcolors.ENDC print "\n\t ========= SEAHORN INCONSISTENCY RESULTS ========" print all_results
def singleRun(self, smt2_file): """ Single run """ ctx = z3.Context () fp = z3.Fixedpoint (ctx=ctx) with stats.timer ('Parse'): self.log.info('Parsing ... ' + str(smt2_file)) queries = fp.parse_file (smt2_file) stats.stop('Parse') self.log.info("Parsing time ... " + str(stats.get('Parse')) + " ms") n_function = len(queries) n_query = n_function if self.args.func < 0 or self.args.func > n_function else self.args.func self.log.info("Number of functions ... " + str(n_function)) self.log.info("Number of jobs ... " + str(n_query)) all_results = "" try: for q in range(n_query): query = queries[q] function_name = self.getFunctionName(query) self.log.info("Checking feasibility of ... " + str(function_name)) out = "" try: p = multiprocessing.Process(target=checkFeas, args=(self.args, q, smt2_file, )) p.start() p.join(self.args.timeout) if p.is_alive(): out = out_message % (function_name, "TIMEOUT", "", "", "", "", "") out = bcolors.WARNING + out + bcolors.ENDC p.terminate() p.join() except Exception as e: self.log.exception(str(e)) continue all_results += out + "\n-----------------------\n" if self.args.save: f_name = ntpath.basename(smt2_file)+"_feas.txt" with open (f_name, "w") as f: f.write(all_results) except Exception as e: self.log.exception(str(e))
def jayhorn(build_dir, args): cmd = [ "java", "-jar", JAYHORN, "-t", "60", "-stats", "-j", build_dir, '-mem-prec', "{}".format(args.mem) ] if args.inline: cmd.extend(['-inline_size', '30', '-inline_count', '3']) cmd_spacer = cmd + ['-solver', 'spacer'] bench_stats.start('JayHorn-Eldarica-Time') eldarica_result = run_with_timeout( "jayhorn-eldarica_{}_{}".format(args.mem, args.inline), cmd, args.timeout) bench_stats.stop('JayHorn-Eldarica-Time') bench_stats.start('JayHorn-Spacer-Time') spacer_result = run_with_timeout( "jayhorn-spacer_{}_{}".format(args.mem, args.inline), cmd_spacer, args.timeout) bench_stats.stop('JayHorn-Spacer-Time') eldarica_time = bench_stats.get("JayHorn-Eldarica-Time") spacer_time = bench_stats.get("JayHorn-Spacer-Time") return eldarica_result, spacer_result, str(eldarica_time), str(spacer_time)
def run_test(setup, stats, output, speed, test, eta, sleep, coding=True, toggle_tq=False): verb = "with" if coding else "without" tq = "random tq" if toggle_tq else "network coding" iso_time = time.strftime("%H:%M:%S", time.gmtime(eta)) print("# {} kbps test {} {} {} (ETA: {})".format(speed, test, verb, tq, iso_time)) if not setup.set_coding_nodes(coding, toggle_tq): print("Setting coding failed. Sleeping") time.sleep(sleep) return False # Record stats from each node stats.start(test) # Start iperf on all slaves setup.signal_slaves(test) # Wait for iperf to finish ret = setup.wait_slaves() # Stop recording stats if not stats.stop(): print("Direct path detected. Sleeping") time.sleep(sleep) return False # Restart iperf server to avoid time skew setup.restart_iperf_slaves() if not ret: time.sleep(sleep) return False if not setup.check_slave_times(): print("Slave time differs; restarting") time.sleep(sleep) return False res = stats.results() for r in res: node = r[0] stat = r[1] append_output(output, coding, node, speed, stat) res = setup.result_slaves() for r in res: slave = r.pop('slave') append_output(output, coding, slave, speed, r) print("{:10s} {throughput:5.1f} kb/s | {jitter:4.1f} ms | {lost:4d}/{total:4d} ({pl:4.1f}%)".format(slave.name.title(), **r)) print time.sleep(sleep) return True
def runCpa(args, dr): print "--- Running CpaChecker --- " all_dir = [os.path.join(dr, name)for name in os.listdir(dr) if os.path.isdir(os.path.join(dr, name)) ] all_build_dir = list() raw_results = dict() cpa_out = "cpachecker_out" if not os.path.exists(cpa_out): os.mkdir(cpa_out) if args.mp: for d in sorted(all_dir): if debug: print "Benchmark:\t " + str(d) tmp = d.split("/") bench = tmp[len(tmp)-1] outputpath = cpa_out+os.sep+bench cmd = [CPA, "-valueAnalysis-java-with-RTT", "-cp", d, "-outputpath", outputpath, "Main"] result = "" try: bench_stats.start('Cpa-Time') result = run_with_timeout('cpa', cmd, args.timeout) bench_stats.stop('Cpa-Time') bench_stats.brunch_print() res = "" if result: for line in result.split("\n"): if "Verification result" in line: res = "UNSAFE" if "FALSE" in line else "SAFE" else: res = "UNKNOWN" raw_results.update({d:{"result":res, "total-time": str(bench_stats.get('Cpa-Time')), "logs": (outputpath + os.sep + "Report.html")}}) except Exception as e: raw_results.update({prog: {"result":"UNKNOWN", "total-time":"", "logs": result}}) else: for d in sorted(all_dir): if debug: print "Benchmark:\t " + str(d) tmp = d.split("/") bench = tmp[len(tmp)-1] java_prog = glob.glob(os.path.abspath(d) + os.sep + "*.java") for prog in sorted(java_prog): print "Java file: " + str(prog) build_dir = os.path.splitext(prog)[0] build_dir = os.path.dirname(build_dir) bench_name = os.path.basename(prog).split(".java")[0] outputpath = cpa_out+os.sep+bench_name cmd = [CPA, "-valueAnalysis-java-with-RTT", "-cp", build_dir, "-outputpath",outputpath, bench_name] result = "" try: bench_stats.start('Cpa-Time') result = run_with_timeout('cpa', cmd, args.timeout) bench_stats.stop('Cpa-Time') res = "" if result: for line in result.split("\n"): if "Verification result" in line: res = "UNSAFE" if "FALSE" in line else "SAFE" else: res = "UNKNOWN" raw_results.update({bench_name:{ "result":res, "total-time": str(bench_stats.get('Cpa-Time')), "logs":(outputpath + os.sep + "Report.html")}}) except Exception as e: raw_results.update({prog: {"result":"UNKNOWN", "total-time":str(bench_stats.get('Cpa-Time')), "logs": result}}) stats = cpaAnalysis(raw_results) return stats
def run_test(setup, stats, output, speed, test, eta, sleep, coding=True, toggle_tq=False): verb = "with" if coding else "without" tq = "random tq" if toggle_tq else "network coding" iso_time = time.strftime("%H:%M:%S", time.gmtime(eta)) print("# {} kbps test {} {} {} (ETA: {})".format(speed, test, verb, tq, iso_time)) if not setup.set_coding_nodes(coding, toggle_tq): print("Setting coding failed. Sleeping") time.sleep(sleep) return False # Record stats from each node stats.start(test) # Start iperf on all slaves setup.signal_slaves(test) # Wait for iperf to finish ret = setup.wait_slaves() # Stop recording stats if not stats.stop(): print("Direct path detected. Sleeping") time.sleep(sleep) return False # Restart iperf server to avoid time skew setup.restart_iperf_slaves() if not ret: time.sleep(sleep) return False if not setup.check_slave_times(): print("Slave time differs; restarting") time.sleep(sleep) return False res = stats.results() for r in res: node = r[0] stat = r[1] append_output(output, coding, node, speed, stat) res = setup.result_slaves() for r in res: slave = r.pop('slave') append_output(output, coding, slave, speed, r) print( "{:10s} {throughput:5.1f} kb/s | {jitter:4.1f} ms | {lost:4d}/{total:4d} ({pl:4.1f}%)" .format(slave.name.title(), **r)) print time.sleep(sleep) return True
def checkFeas(self, expr_query): done = False # flag to stop the feasibility checking rounds = 1 # counter for feasibility check self.ee_idx = self.ee_vars(expr_query) #entr/exit vars self.log.info("EE VARS INDEX ..." + str(self.ee_idx)) out = "" function_name = self.function_name while not done: with stats.timer ('Query'): #if round == 0 else self.fp.query_from_lvl(12, expr_query) res = self.fp.query (expr_query) stats.stop('Query') self.query_times.append(str(stats.get('Query'))) if bench: print "Query | Round [" + str(rounds) + "] | time [" + str(stats.get('Query')) + " ms]" if res == z3.sat: msg = "ENTRY -> EXIT is FEASIBLE" if rounds==1 else "STILL FEASIBLE: Continue checking ..." self.log.info("( " + function_name + " ) " + msg) self.feasible_flag |= set(self.ee_idx) expr_query, path = self.cex(expr_query) rounds += 1 if expr_query is None: feas = list(self.feasible_flag) infeas = ";".join([str(x) for x in list(self.non_feasible_flag)]) q_times = [float(x) for x in self.query_times] q_average = sum(q_times) / len(q_times) out += out_message % (function_name, "FEASIBLE", "", str(feas), infeas, str(rounds), str(q_average)) out = bcolors.OKGREEN + out + bcolors.ENDC done = True elif res == z3.unsat: inv = "\n-----------\n" for p in self.preds: lemmas = fp_get_cover_delta (self.fp, p) inv += "\tBasic Block: " + str(p.decl()) inv += "\n\tInvariant: " + str(lemmas) inv += "\n-----------\n" inv_info = inv if self.args.inv else "(set --inv to get invariants info)" if len(list(self.feasible_flag)) == self.flags: self.log.info(" ( " + function_name + " ) FEASIBLE") feas = list(self.feasible_flag) q_times = [float(x) for x in self.query_times] q_average = sum(q_times) / len(q_times) out += out_message % (function_name, "FEASIBLE", inv_info, str(feas), "", str(rounds), str(q_average)) out = bcolors.OKGREEN + out + bcolors.ENDC else: msg = "EXIT is not FEASIBLE" if rounds==1 else "INFEASIBLE BLOCK FOUND" self.feasOut() if rounds == 1: self.feasible_flag.add(self.ee_idx[0]) self.non_feasible_flag.add(self.ee_idx[1]) self.log.info(" ( " + function_name + " ) " + msg) feas, infeas = self.feasOut() q_times = [float(x) for x in self.query_times] q_average = sum(q_times) / len(q_times) infeas_str = ";".join([str(x) for x in infeas]) out += out_message % (function_name, "INFEASIBLE", inv_info, str(feas), infeas_str, str(rounds), str(q_average)) out = bcolors.FAIL + out + bcolors.ENDC done = True else: out += out_message % (function_name, "UNKNOWN", "", "", "", "", "") done = True return out
def checkFeas(self, expr_query): done = False # flag to stop the feasibility checking rounds = 1 # counter for feasibility check self.ee_idx = self.ee_vars(expr_query) #entr/exit vars self.log.info("EE VARS INDEX ..." + str(self.ee_idx)) out = "" function_name = self.function_name while not done: with stats.timer('Query'): #if round == 0 else self.fp.query_from_lvl(12, expr_query) res = self.fp.query(expr_query) stats.stop('Query') self.query_times.append(str(stats.get('Query'))) if bench: print "Query | Round [" + str( rounds) + "] | time [" + str( stats.get('Query')) + " ms]" if res == z3.sat: msg = "ENTRY -> EXIT is FEASIBLE" if rounds == 1 else "STILL FEASIBLE: Continue checking ..." self.log.info("( " + function_name + " ) " + msg) self.feasible_flag |= set(self.ee_idx) expr_query, path = self.cex(expr_query) rounds += 1 if expr_query is None: feas = list(self.feasible_flag) infeas = ";".join( [str(x) for x in list(self.non_feasible_flag)]) q_times = [float(x) for x in self.query_times] q_average = sum(q_times) / len(q_times) out += out_message % (function_name, "FEASIBLE", "", str(feas), infeas, str(rounds), str(q_average)) out = bcolors.OKGREEN + out + bcolors.ENDC done = True elif res == z3.unsat: inv = "\n-----------\n" for p in self.preds: lemmas = fp_get_cover_delta(self.fp, p) inv += "\tBasic Block: " + str(p.decl()) inv += "\n\tInvariant: " + str(lemmas) inv += "\n-----------\n" inv_info = inv if self.args.inv else "(set --inv to get invariants info)" if len(list(self.feasible_flag)) == self.flags: self.log.info(" ( " + function_name + " ) FEASIBLE") feas = list(self.feasible_flag) q_times = [float(x) for x in self.query_times] q_average = sum(q_times) / len(q_times) out += out_message % (function_name, "FEASIBLE", inv_info, str(feas), "", str(rounds), str(q_average)) out = bcolors.OKGREEN + out + bcolors.ENDC else: msg = "EXIT is not FEASIBLE" if rounds == 1 else "INFEASIBLE BLOCK FOUND" self.feasOut() if rounds == 1: self.feasible_flag.add(self.ee_idx[0]) self.non_feasible_flag.add(self.ee_idx[1]) self.log.info(" ( " + function_name + " ) " + msg) feas, infeas = self.feasOut() q_times = [float(x) for x in self.query_times] q_average = sum(q_times) / len(q_times) infeas_str = ";".join([str(x) for x in infeas]) out += out_message % (function_name, "INFEASIBLE", inv_info, str(feas), infeas_str, str(rounds), str(q_average)) out = bcolors.FAIL + out + bcolors.ENDC done = True else: out += out_message % (function_name, "UNKNOWN", "", "", "", "", "") done = True return out
def runCpa(args, dr): print "--- Running CpaChecker --- " all_dir = [ os.path.join(dr, name) for name in os.listdir(dr) if os.path.isdir(os.path.join(dr, name)) ] all_build_dir = list() raw_results = dict() cpa_out = "cpachecker_out" if not os.path.exists(cpa_out): os.mkdir(cpa_out) if args.mp: for d in sorted(all_dir): if debug: print "Benchmark:\t " + str(d) tmp = d.split("/") bench = tmp[len(tmp) - 1] outputpath = cpa_out + os.sep + bench cmd = [ CPA, "-valueAnalysis-java-with-RTT", "-cp", d, "-outputpath", outputpath, "Main" ] result = "" try: bench_stats.start('Cpa-Time') result = run_with_timeout('cpa', cmd, args.timeout) bench_stats.stop('Cpa-Time') bench_stats.brunch_print() res = "" if result: for line in result.split("\n"): if "Verification result" in line: res = "UNSAFE" if "FALSE" in line else "SAFE" else: res = "UNKNOWN" raw_results.update({ d: { "result": res, "total-time": str(bench_stats.get('Cpa-Time')), "logs": (outputpath + os.sep + "Report.html") } }) except Exception as e: raw_results.update({ prog: { "result": "UNKNOWN", "total-time": "", "logs": result } }) else: for d in sorted(all_dir): if debug: print "Benchmark:\t " + str(d) tmp = d.split("/") bench = tmp[len(tmp) - 1] java_prog = glob.glob(os.path.abspath(d) + os.sep + "*.java") for prog in sorted(java_prog): print "Java file: " + str(prog) build_dir = os.path.splitext(prog)[0] build_dir = os.path.dirname(build_dir) bench_name = os.path.basename(prog).split(".java")[0] outputpath = cpa_out + os.sep + bench_name cmd = [ CPA, "-valueAnalysis-java-with-RTT", "-cp", build_dir, "-outputpath", outputpath, bench_name ] result = "" try: bench_stats.start('Cpa-Time') result = run_with_timeout('cpa', cmd, args.timeout) bench_stats.stop('Cpa-Time') res = "" if result: for line in result.split("\n"): if "Verification result" in line: res = "UNSAFE" if "FALSE" in line else "SAFE" else: res = "UNKNOWN" raw_results.update({ bench_name: { "result": res, "total-time": str(bench_stats.get('Cpa-Time')), "logs": (outputpath + os.sep + "Report.html") } }) except Exception as e: raw_results.update({ prog: { "result": "UNKNOWN", "total-time": str(bench_stats.get('Cpa-Time')), "logs": result } }) stats = cpaAnalysis(raw_results) return stats