def symbolic (filee, inputs, analysis, jalangi=util.DEFAULT_INSTALL): try: shutil.rmtree("jalangi_tmp") except: pass os.mkdir("jalangi_tmp") os.putenv("JALANGI_HOME", jalangi.get_home()) os.chdir("jalangi_tmp") (instrumented_f, out) = instrument(os.path.join(os.pardir,filee), jalangi=jalangi) i = 0 iters = 1 while i <= iters and i <= inputs: try: # Ignore failures on first iteration os.remove("inputs.js") except: pass if not os.path.isfile("inputs.js"): util.mkempty("inputs.js") util.run_node_script_std(jalangi.symbolic_script(), analysis, os.path.join(os.path.dirname(os.path.join(os.pardir,filee) + ".js"),instrumented_f), jalangi=jalangi, savestderr=True) try: iters = int(util.head("jalangi_tail",1)[0]) except: pass i = i + 1 if iters == inputs: print "{}.js passed".format(filee) with open("../jalangi_sym_test_results", 'a') as f: f.write("{}.js passed\n".format(filee)) else: print "{}.js failed".format(filee) with open("../jalangi_sym_test_results", 'a') as f: f.write("{}.js failed\n".format(filee)) print "Tests Generated = {}".format(iters)
def rerunall(filee, jalangi=util.DEFAULT_INSTALL): os.chdir("jalangi_tmp") try: shutil.rmtree(".coverage_data") os.remove("inputs.js") util.mkempty("inputs.js") except: pass print "---- Runing tests on {} ----".format(filee) util.run_node_script_std(os.path.join(os.pardir, filee + ".js"), jalangi=jalangi) for i in glob.glob("jalangi_inputs*"): print "Running {} on {}".format(filee, i) shutil.copy(i, "inputs.js") util.run_node_script_std(os.path.join(os.pardir, filee + ".js"), jalangi=jalangi, savestderr=True) if jalangi.coverage(): time.sleep(2) os.system("cover combine") os.system("cover report html") shutil.copy("cover_html/index.html", "../jalangi/out/out.html") for x in glob.glob("cover_html/*.*"): shutil.copy(x, "../jalangi/out/".format(x)) print "Test results are in {}".format("cover_html/index.html")
def testrr_helper (filee, jalangi, norm_fn, record_fn, instrument_fn=instrument): try: shutil.rmtree("jalangi_tmp") except: pass os.mkdir("jalangi_tmp") os.mkdir("jalangi_tmp/out") os.putenv("JALANGI_HOME", jalangi.get_home()) os.chdir("jalangi_tmp") (instrumented_f, out) = instrument_fn(os.path.join(os.pardir,filee), jalangi=jalangi) try: # Ignore failures on first iteration os.remove("inputs.js") shutil.copy("jalangi_inputs{}.js".format(i), "inputs.js") except: pass if not os.path.isfile("inputs.js"): util.mkempty("inputs.js") print "---- Running without instrumentation ----" try: os.remove("jalangi_trace") except: pass norm = norm_fn(os.path.join(os.pardir,filee + ".js"), jalangi=jalangi) with open("jalangi_normal", "w") as normfile: normfile.write(norm) print norm print "---- Recording execution of {} ----".format(filee) rec = record_fn(os.path.join(os.pardir,filee), instrumented_f) with open("jalangi_record", "w") as recfile: recfile.write(rec) print rec print "---- Replaying {} ----".format(filee) os.putenv("JALANGI_MODE", "replay") os.putenv("JALANGI_ANALYSIS", "none") rep = replay() with open("jalangi_replay", "w") as repfile: repfile.write(rep) print rep try: wcl = util.count_lines("jalangi_trace") with open("../jalangi_test_results", 'a') as f: f.write("# of lines in jalangi_trace for {}: {}".format(filee,str(wcl))) f.write("\n") except: pass if norm != rep: #TODO: Factor out this. print "{}.js failed".format(filee) import difflib with open("../jalangi_test_results", 'a') as f: f.write("\n") for line in difflib.unified_diff(norm.splitlines(1), rec.splitlines(1), fromfile='normal.{}'.format(filee), tofile='replay.{}'.format(filee)): f.write(line) if rec != rep: print "{}.js failed".format(filee) import difflib with open("../jalangi_test_results", 'a') as f: f.write("\n") for line in difflib.unified_diff(rec.splitlines(1), rep.splitlines(1), fromfile='record.{}'.format(filee), tofile='replay.{}'.format(filee)): f.write(line) util.move_coverage(jalangi)
def direct_analysis(analysis, filee, jalangi=util.DEFAULT_INSTALL): try: shutil.rmtree("jalangi_tmp") except: pass os.mkdir("jalangi_tmp") os.chdir("jalangi_tmp") #Instrument file first (instrumented_f,out) = instrument(filee, jalangi=jalangi) util.mkempty("inputs.js") print "---- Analyzing {} directly ----".format(filee) print direct(filee, instrumented_f, jalangi, analysis=analysis) util.move_coverage(jalangi)
def analysis(analysis, filee, jalangi=util.DEFAULT_INSTALL): temp_dir = mkdtemp() os.chdir(temp_dir) #Instrument file first (instrumented_f,out) = instrument(filee, jalangi=jalangi) util.mkempty("inputs.js") print "--- Recording execution of {} ----".format(filee) print record(filee,instrumented_f) print "---- Replaying {} with {}----".format(filee,analysis) os.putenv("JALANGI_MODE", "replay") os.putenv("JALANGI_ANALYSIS", analysis) print replay(jalangi) util.move_coverage(jalangi)
def concolic (filee, inputs, instrumented, line_range, jalangi=util.DEFAULT_INSTALL): try: shutil.rmtree("jalangi_tmp") except: pass os.mkdir("jalangi_tmp") os.mkdir("jalangi_tmp/out") os.putenv("JALANGI_HOME", jalangi.get_home()) os.chdir("jalangi_tmp") (instrumented_f, out) = instrument(os.path.join(os.pardir,filee), jalangi=jalangi) if (instrumented == "") else (instrumented, "") i = 0 iters = 0 while i <= iters and i <= inputs: try: # Ignore failures on first iteration os.remove("inputs.js") shutil.copy("jalangi_inputs{}.js".format(i), "inputs.js") except: pass if not os.path.isfile("inputs.js"): util.mkempty("inputs.js") print "==== Input {} ====".format(i) print "---- Recording execution of {} ----".format(filee) print record(os.path.join(os.pardir,filee),instrumented_f,jalangi=jalangi) print "---- Replaying {} ----".format(filee) print replay(jalangi=jalangi,analysis=[jalangi.concolic_analysis()]) print parse_stacktrace(str(iters),instrumented_f,line_range,jalangi=jalangi) with open(os.path.abspath(os.pardir) + '/jalangi_tmp/jalangi_stop', 'r') as myfile: data=myfile.read().replace('\n', '') if data == "true": break try: iters = int(util.head("jalangi_tail",1)[0]) except: pass i = i + 1 for i in glob.glob("jalangi_inputs*"): print "*** Generated (jalangi_tmp/{}:1:1) for ({}.js:1:1)".format(i,filee) iters = iters + 1 if iters == inputs: print "{}.js passed".format(filee) with open("../jalangi_sym_test_results", 'a') as f: f.write("{}.js passed\n".format(filee)) else: print "{}.js failed".format(filee) with open("../jalangi_sym_test_results", 'a') as f: f.write("{}.js failed\n".format(filee)) util.move_coverage(jalangi)
def concolic(filee, inputs, jalangi=util.DEFAULT_INSTALL): try: shutil.rmtree("jalangi_tmp") except: pass os.mkdir("jalangi_tmp") os.mkdir("jalangi_tmp/out") os.putenv("JALANGI_HOME", jalangi.get_home()) os.chdir("jalangi_tmp") (instrumented_f, out) = instrument(os.path.join(os.pardir, filee), jalangi=jalangi) i = 0 iters = 0 while i <= iters and i <= inputs: try: # Ignore failures on first iteration os.remove("inputs.js") shutil.copy("jalangi_inputs{}.js".format(i), "inputs.js") except: pass if not os.path.isfile("inputs.js"): util.mkempty("inputs.js") print "==== Input {} ====".format(i) print "---- Recording execution of {} ----".format(filee) print record(os.path.join(os.pardir, filee), instrumented_f, jalangi=jalangi) print "---- Replaying {} ----".format(filee) print replay(jalangi=jalangi, analysis=[jalangi.concolic_analysis()]) try: iters = int(util.head("jalangi_tail", 1)[0]) except: pass i = i + 1 for i in glob.glob("jalangi_inputs*"): print "*** Generated (jalangi_tmp/{}:1:1) for ({}.js:1:1)".format( i, filee) iters = iters + 1 if iters == inputs: print "{}.js passed".format(filee) with open("../jalangi_sym_test_results", 'a') as f: f.write("{}.js passed\n".format(filee)) else: print "{}.js failed".format(filee) with open("../jalangi_sym_test_results", 'a') as f: f.write("{}.js failed\n".format(filee)) util.move_coverage(jalangi)
def analysis(analysis, browser_rec, filee, jalangi=util.DEFAULT_INSTALL): try: shutil.rmtree("jalangi_tmp") except: pass os.mkdir("jalangi_tmp") os.chdir("jalangi_tmp") #Instrument file first (instrumented_f,out) = instrument(filee, jalangi=jalangi) util.mkempty("inputs.js") print "---- Recording execution of {} ----".format(filee) if browser_rec: selenium_browser_record(filee, instrumented_f,jalangi) else: print record(filee, instrumented_f, jalangi) print "---- Replaying {} ----".format(filee) print replay(analysis=analysis) util.move_coverage(jalangi)
def concolic (filee, inputs, jalangi=util.DEFAULT_INSTALL): try: shutil.rmtree("jalangi_tmp") except: pass os.mkdir("jalangi_tmp") os.mkdir("jalangi_tmp/out") os.putenv("JALANGI_HOME", jalangi.get_home()) os.chdir("jalangi_tmp") (instrumented_f, out) = instrument(os.path.join(os.pardir,filee), jalangi=jalangi) i = 0 iters = 0 while i <= iters and i <= inputs: try: # Ignore failures on first iteration os.remove("inputs.js") shutil.copy("jalangi_inputs{}.js".format(i), "inputs.js") except: pass if not os.path.isfile("inputs.js"): util.mkempty("inputs.js") print "==== Input {} ====".format(i) print "---- Recording execution of {} ----".format(filee) os.putenv("JALANGI_MODE", "record") os.putenv("JALANGI_ANALYSIS", "none") util.run_node_script_std(os.path.join(os.path.dirname(os.path.join(os.pardir,filee) + ".js"),instrumented_f), jalangi=jalangi) print "---- Replaying {} ----".format(filee) os.putenv("JALANGI_MODE", "replay") os.putenv("JALANGI_ANALYSIS", "analyses/concolic/SymbolicEngine") util.run_node_script_std(jalangi.replay_script(), jalangi=jalangi) try: iters = int(util.head("jalangi_tail",1)[0]) except: pass i = i + 1 for i in glob.glob("jalangi_inputs*"): print "*** Generated (jalangi_tmp/{}:1:1) for ({}.js:1:1)".format(i,filee) iters = iters + 1 if iters == inputs: print "{}.js passed".format(filee) with open("../jalangi_sym_test_results", 'a') as f: f.write("{}.js passed\n".format(filee)) else: print "{}.js failed".format(filee) with open("../jalangi_sym_test_results", 'a') as f: f.write("{}.js failed\n".format(filee)) util.move_coverage(jalangi)
def analysis(analysis, filee, jalangi=util.DEFAULT_INSTALL): try: shutil.rmtree("jalangi_tmp") except: pass os.mkdir("jalangi_tmp") os.chdir("jalangi_tmp") #Instrument file first (instrumented_f,out) = instrument(filee, jalangi=jalangi) util.mkempty("inputs.js") print "---- Recording execution of {} ----".format(filee) os.putenv("JALANGI_MODE", "record") os.putenv("JALANGI_ANALYSIS", "none") util.run_node_script_std(os.path.join(os.path.dirname(filee + ".js"),instrumented_f), jalangi=jalangi) print "---- Replaying {} ----".format(filee) os.putenv("JALANGI_MODE", "replay") os.putenv("JALANGI_ANALYSIS", analysis) util.run_node_script_std(jalangi.replay_script(), jalangi=jalangi) util.move_coverage(jalangi)
def rerunall(filee, jalangi=util.DEFAULT_INSTALL): os.chdir("jalangi_tmp") try: shutil.rmtree(".coverage_data") os.remove("inputs.js") util.mkempty("inputs.js") except: pass print "---- Runing tests on {} ----".format(filee) util.run_node_script(os.path.join(os.pardir, filee + ".js"), jalangi=jalangi) for i in glob.glob("jalangi_inputs*"): print "Running {} on {}".format(filee, i) shutil.copy(i, "inputs.js") util.run_node_script(os.path.join(os.pardir,filee +".js"), jalangi=jalangi) if jalangi.coverage(): time.sleep(2) os.system("cover combine") os.system("cover report") print "Test results are in {}".format("cover_html/index.html")
def symbolic(filee, inputs, analysis, jalangi=util.DEFAULT_INSTALL): try: shutil.rmtree("jalangi_tmp") except: pass os.mkdir("jalangi_tmp") os.putenv("JALANGI_HOME", jalangi.get_home()) os.chdir("jalangi_tmp") (instrumented_f, out) = instrument(os.path.join(os.pardir, filee), jalangi=jalangi) i = 0 iters = 1 while i <= iters and i <= inputs: try: # Ignore failures on first iteration os.remove("inputs.js") except: pass if not os.path.isfile("inputs.js"): util.mkempty("inputs.js") util.run_node_script_std( jalangi.symbolic_script(), analysis, os.path.join( os.path.dirname(os.path.join(os.pardir, filee) + ".js"), instrumented_f), jalangi=jalangi, savestderr=True) try: iters = int(util.head("jalangi_tail", 1)[0]) except: pass i = i + 1 if iters == inputs: print "{}.js passed".format(filee) with open("../jalangi_sym_test_results", 'a') as f: f.write("{}.js passed\n".format(filee)) else: print "{}.js failed".format(filee) with open("../jalangi_sym_test_results", 'a') as f: f.write("{}.js failed\n".format(filee)) print "Tests Generated = {}".format(iters)
def concolic_tgn (filee, inputs, jalangi=util.DEFAULT_INSTALL): print inputs try: shutil.rmtree("jalangi_tmp") except: pass os.mkdir("jalangi_tmp") os.mkdir("jalangi_tmp/out") os.putenv("JALANGI_HOME", jalangi.get_home()) os.chdir("jalangi_tmp") (instrumented_f, out) = instrument(os.path.join(os.pardir,filee), jalangi=jalangi) i = 0 iters = 0 while i <= iters and i <= inputs: try: # Ignore failures on first iteration os.remove("inputs.js") shutil.copy("jalangi_inputs{}.js".format(i), "inputs.js") except: pass if not os.path.isfile("inputs.js"): util.mkempty("inputs.js") print "==== Input {} ====".format(i) print "---- Recording execution of {} ----".format(filee) output = record(os.path.join(os.pardir,filee),instrumented_f,jalangi=jalangi) with open("jalangi_outputs{}.js".format(i), 'w') as output_f: output_f.write(output); print output print "---- Replaying {} ----".format(filee) print replay(jalangi=jalangi,analysis=[jalangi.concolic_analysis()]) try: iters = int(util.head("jalangi_tail",1)[0]) except: pass i = i + 1 for i in glob.glob("jalangi_inputs*"): print "*** Generated (jalangi_tmp/{}:1:1) for ({}.js:1:1)".format(i,filee) iters = iters + 1 util.move_coverage(jalangi)
def concolic (filee, inputs, jalangi=util.DEFAULT_INSTALL): try: shutil.rmtree("jalangi_tmp") except: pass os.mkdir("jalangi_tmp") os.mkdir("jalangi_tmp/out") os.putenv("JALANGI_HOME", jalangi.get_home()) os.chdir("jalangi_tmp") (instrumented_f, out) = instrument(os.path.join(os.pardir,filee), jalangi=jalangi) i = 0 iters = 0 mismatch = False while i <= iters and i <= inputs: try: # Ignore failures on first iteration os.remove("inputs.js") shutil.copy("jalangi_inputs{}.js".format(i), "inputs.js") except: pass if not os.path.isfile("inputs.js"): util.mkempty("inputs.js") print "==== Input {} ====".format(i) print "---- Runing without instrumentation ----" try: os.remove("jalangi_trace") except: pass norm = util.run_node_script(os.path.join(os.pardir,filee + ".js"), jalangi=jalangi, savestderr=True) #(open("jalangi_normal", "w")).write(norm) print "---- Recording execution of {} ----".format(filee) rec = record(os.path.join(os.pardir,filee), instrumented_f) print "---- Replaying {} ----".format(filee) os.putenv("JALANGI_MODE", "replay") os.putenv("JALANGI_ANALYSIS", "analyses/concolic/SymbolicEngine") rep = replay() (open("jalangi_replay", "w")).write(rep) print rep try: wcl = util.count_lines("jalangi_trace") with open("../jalangi_test_results", 'a') as f: f.write("# of lines in jalangi_trace for {}: {}".format(filee,str(wcl))) f.write("\n") except: pass if norm != rep: #TODO: Factor out this. import difflib with open("../jalangi_test_results", 'a') as f: f.write("\n") for line in difflib.unified_diff(norm.splitlines(1), rec.splitlines(1), fromfile='normal.{}'.format(filee), tofile='replay.{}'.format(filee)): f.write(line) if rec != rep: import difflib with open("../jalangi_test_results", 'a') as f: f.write("\n") for line in difflib.unified_diff(rec.splitlines(1), rep.splitlines(1), fromfile='replay.{}'.format(filee), tofile='record.{}'.format(filee)): f.write(line) try: iters = int(util.head("jalangi_tail",1)[0]) except: pass i = i + 1 for i in glob.glob("jalangi_inputs*"): print "*** Generated ({}:1:1) for ({}.js:1:1)".format(os.path.abspath(i),filee) iters = iters + 1 if iters == inputs: print "{}.js passed".format(filee) else: print "{}.js failed".format(filee) util.move_coverage(jalangi)
def testrr_helper(filee, jalangi, norm_fn, record_fn, instrument_fn=instrument): try: shutil.rmtree("jalangi_tmp") except: pass os.mkdir("jalangi_tmp") os.mkdir("jalangi_tmp/out") os.putenv("JALANGI_HOME", jalangi.get_home()) os.chdir("jalangi_tmp") (instrumented_f, out) = instrument_fn(os.path.join(os.pardir, filee), jalangi=jalangi) try: # Ignore failures on first iteration os.remove("inputs.js") shutil.copy("jalangi_inputs{}.js".format(i), "inputs.js") except: pass if not os.path.isfile("inputs.js"): util.mkempty("inputs.js") print "---- Running without instrumentation ----" try: os.remove("jalangi_trace") except: pass norm = norm_fn(os.path.join(os.pardir, filee + ".js"), jalangi=jalangi) with open("jalangi_normal", "w") as normfile: normfile.write(norm) print norm print "---- Recording execution of {} ----".format(filee) rec = record_fn(os.path.join(os.pardir, filee), instrumented_f) with open("jalangi_record", "w") as recfile: recfile.write(rec) print rec print "---- Replaying {} ----".format(filee) os.putenv("JALANGI_MODE", "replay") os.putenv("JALANGI_ANALYSIS", "none") rep = replay() with open("jalangi_replay", "w") as repfile: repfile.write(rep) print rep try: wcl = util.count_lines("jalangi_trace") with open("../jalangi_test_results", 'a') as f: f.write("# of lines in jalangi_trace for {}: {}".format( filee, str(wcl))) f.write("\n") except: pass if norm != rep: #TODO: Factor out this. print "{}.js failed".format(filee) import difflib with open("../jalangi_test_results", 'a') as f: f.write("\n") for line in difflib.unified_diff( norm.splitlines(1), rec.splitlines(1), fromfile='normal.{}'.format(filee), tofile='replay.{}'.format(filee)): f.write(line) if rec != rep: print "{}.js failed".format(filee) import difflib with open("../jalangi_test_results", 'a') as f: f.write("\n") for line in difflib.unified_diff( rec.splitlines(1), rep.splitlines(1), fromfile='record.{}'.format(filee), tofile='replay.{}'.format(filee)): f.write(line) util.move_coverage(jalangi)