-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.py
830 lines (758 loc) · 30.2 KB
/
runner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
import argparse
import textwrap
import json
import csv
import os
import glob
import subprocess
import stats as bench_stats
import pprint
import threading
from multiprocessing import Process, Pool
import multiprocessing
import shutil
import pickle
debug = True
"""
Tools
"""
JPF = "./jpf-travis/jpf-core/build/RunJPF.jar"
CBMC = "../cbmc/src/cbmc"
INFER = "infer"
#CPA = "./cpachecker/scripts/cpa.sh"
CPA = "./cpachecker/scripts/cpa.sh"
JAYHORN = "../jayhorn/jayhorn/build/libs/jayhorn.jar"
#JAYHORN = "./jayhorn.jar"
########
# UTILITIES
########
def stat (key, val): bench_stats.put (key, val)
def compile(prog, build_dir):
if debug: print "Compiling ... " + prog
d = build_dir + os.sep + ".." + os.sep
cmd = ['rm', '-rf', build_dir+os.sep+'*']
print " ".join(x for x in cmd)
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
cmd = ['javac', '-d', build_dir, '-sourcepath', d, prog]
p.communicate()
print " ".join(x for x in cmd)
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result, _ = p.communicate()
rc = p.returncode
return rc
def run_with_timeout(tool, command, timeout):
import time
import subprocess
if debug: print "Running .. " + " ".join(x for x in command)
p = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while timeout > 0:
if p.poll() is not None:
result, result2 = p.communicate()
if debug: print result, result2
return result
time.sleep(0.1)
timeout -= 0.1
else:
try:
p.kill()
except OSError as e:
if e.errno != 3:
raise
return None
def processResult(d, bench, raw_result, tool, total_time):
if debug:
if raw_result is None:
print "TIMEOUT"
else:
print raw_result
bench_ls = bench.split("_")
exp = bench_ls[len(bench_ls)-1]
expected = "UNKNOWN" if len(bench_ls)==1 else ("UNSAFE" if "false" in exp else "SAFE")
result = ""
if expected == "UNKNOWN":
if bench.startswith("Sat"):
expected = "SAFE"
elif bench.startswith("Unsat"):
expected = "UNSAFE"
stats = {"tool": tool, "result":result, "expected":expected,
"time":"", "mem":"",
"soot2cfg":"", "toHorn":"",
"logs": "",
"total-time":total_time}
if raw_result is None:
result = "TIMEOUT"
stats.update({"result":result, "logs": "Timeout"})
b = os.path.relpath(os.path.dirname(d))
bench = str(b)+"/"+bench
return {bench:stats}
else:
logs = ""
if "COMPILATION ERROR" in raw_result:
logs += "Compilation error<br>"
result = "COMPILATION ERROR"
stats.update({"result": result})
else:
for r in raw_result.splitlines():
#if "BRUNCH_STAT" not in r:
# logs += r +"<br>"
if "BRUNCH_STAT" in r:
goodLine = r.split()
if 'FinalResult' in goodLine:
result = goodLine[2]
stats.update({"result": result})
elif 'CheckSatTime' in goodLine :
stats.update({"time": "".join(x for x in goodLine[2:])})
elif 'SootToCFG' in goodLine :
stats.update({"soot2cfg": "".join(x for x in goodLine[2:])})
elif 'ToHorn' in goodLine :
stats.update({"toHorn": "".join(x for x in goodLine[2:])})
b = os.path.relpath(os.path.dirname(d))
bench = str(b)+"/"+bench
#stats.update({"logs":logs})
return {bench:stats}
####
# Run all benchmarks
####
def runBench(args):
dr = args.directory
stats = dict()
infer_stat, jayhorn_stat = dict(), dict()
if debug: print "Running on " + str(dr) + " ..."
for d in dr:
infer_stat, cpa_stat = dict(), dict()
if args.infer: infer_stat = runInfer(args, d)
if args.cpa: cpa_stat = runCpa(args, d)
print cpa_stat
# eldarica_result, spacer_result = runJayHorn(d,args)
# stats.update({str(d):{"infer":infer_stat,
# "jayhorn-eldarica":eldarica_result,
# "jayhorn-spacer": spacer_result,
# "cpa": cpa_stat}})
if args.plot:
scatterPlot(stats)
save_obj(stats, args.save_name)
if args.save:
save_obj(stats, args.save_name)
pprint.pprint(stats)
if stats and args.html:
generateHtml(args, stats)
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)
####
# Run Mine Pump with JayHorn
####
def minePump(dr, args):
all_dir = [os.path.join(dr, name)for name in os.listdir(dr) if os.path.isdir(os.path.join(dr, name)) ]
all_results = {}
eldarica_stats, spacer_stats = dict(), dict()
for d in sorted(all_dir):
if debug: print "Benchmark:\t " + str(d)
tmp = d.split("/")
bench = tmp[len(tmp)-1]
build_dir = d+os.sep+"build"
if not os.path.exists(build_dir):
os.mkdir(build_dir)
java_file = d + os.sep + "Main.java"
bench_name = os.path.basename(d)
try:
cresult = compile(java_file, build_dir)
except Exception as e:
print str(e)
if cresult == 0:
eldarica_result, spacer_result, eldarica_time, spacer_time = jayhorn(build_dir, args)
eldarica_st = processResult(d, bench_name, eldarica_result, 'Eldarica', eldarica_time)
eldarica_stats.update(eldarica_st)
spacer_st = processResult(d, bench_name, spacer_result, 'Spacer', spacer_time)
spacer_stats.update(spacer_st)
else:
st = processResult(d, bench_name, "COMPILATION ERROR", 'jayhorn', "")
eldarica_stats.update(st)
spacer_stats.update(st)
if debug: print "---------------------"
#pprint.pprint(stats)
return eldarica_stats, spacer_stats
####
# Run Infer
####
def inferAnalysis(infer_out):
stats = dict()
for out in infer_out:
bench_ls = out.split("_infer_out")[0]
bench_ls = bench_ls.split("_")
exp = bench_ls[len(bench_ls)-1]
expected = "UNKNOWN" if len(bench_ls)==1 else ("UNSAFE" if "false" in exp else "SAFE")
if expected == "UNKNOWN":
if bench.startswith("Sat"):
expected = "SAFE"
elif bench.startswith("Unsat"):
expected = "UNSAFE"
bench_name = out.split("_infer_out")[0]
result, logs = "", ""
try:
with open(out + os.sep + "bugs.txt", "r") as f:
issue = f.read()
result = "SAFE" if "No issues" in issue else "UNSAFE"
with open(out + os.sep + "toplevel.log", "r") as f:
for l in f.readlines():
logs += l + "<br>"
stat_json = json.load(open(out + os.sep + "stats.json"))
stat_times = stat_json['float']
st = {"result": result, "expected":expected, "logs": logs}
except Exception as e:
st = {"result": "ERROR", "expected":expected, "logs": str(e)}
stats.update({bench_name:dict(st.items() + stat_times.items())})
return stats
def runInfer(args, dr):
print "--- Running Infer --- "
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()
infer_out = "infer_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]
build_dir = os.path.splitext(d)[0]
bench_name = os.path.basename(d)
out = infer_out + os.sep + (bench_name.split(".java")[0])
all_build_dir.append(out)
cmd = [INFER, "-o", out, "-a", "checkers", "--", "javac", d+os.sep+"Main.java", "-cp", d]
try:
result = run_with_timeout('infer', cmd, args.timeout)
except Exception as e:
print str(e)
else:
print all_dir
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"
bench_name = os.path.basename(prog)
infer_out = (bench_name.split(".java")[0])+"_infer_out"
all_build_dir.append(infer_out)
if not os.path.exists(build_dir):
os.mkdir(build_dir)
cmd = [INFER, "-o", infer_out, "-a", "checkers", "--", "javac", prog, "-d", build_dir]
try:
result = run_with_timeout('infer', cmd, args.timeout)
except Exception as e:
print str(e)
if debug: print "---------------------"
stats = inferAnalysis(all_build_dir)
return stats
####
# Run CPA
####
def cpaAnalysis(cpa_out):
stats = dict()
for bench, values in cpa_out.iteritems():
bench_ls = bench.split("_")
exp = bench_ls[len(bench_ls)-1]
expected = "UNKNOWN" if len(bench_ls)==1 else ("UNSAFE" if "false" in exp else "SAFE")
if expected == "UNKNOWN":
if bench.startswith("Sat"):
expected = "SAFE"
elif bench.startswith("Unsat"):
expected = "UNSAFE"
st = dict()
try:
cpa_stats = (values["logs"]).split("Report.html")[0]
time = ""
with open(cpa_stats+os.sep+"Statistics.txt", 'r') as f:
for l in f.readlines():
if "Total CPU time for CPAchecker" in l:
time = (l.split(":")[1]).rstrip()
st = {"result": values["result"],
"expected":expected,
"time":time,
"logs": values["logs"],
"total-time":values["total-time"]}
except Exception as e:
st = {"result": "UNKNOWN",
"expected":expected,
"time":"",
"logs": str(e),
"total-time":values["total-time"]}
stats.update({bench:st})
return stats
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 runJayHorn(dr, args):
print "--- Running JayHorn with --- "
all_dir = [os.path.join(dr, name)for name in os.listdir(dr) if os.path.isdir(os.path.join(dr, name)) ]
all_results = {}
eldarica_stats, spacer_stats = dict(), dict()
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")
all_build_dir = list()
for prog in sorted(java_prog):
print "Java file: " + str(prog)
build_dir = os.path.splitext(prog)[0]+"_build"
all_build_dir.append(build_dir)
bench_name = os.path.basename(prog)
if not os.path.exists(build_dir):
os.mkdir(build_dir)
try:
cresult = compile(prog, build_dir)
except Exception as e:
print e
if cresult == 0:
eldarica_result, spacer_result, eldarica_time, spacer_time = jayhorn(build_dir, args)
eldarica_st = processResult(prog, bench_name, eldarica_result, "Eldarica", eldarica_time)
spacer_st = processResult(prog, bench_name, spacer_result, "Spacer", spacer_time)
eldarica_stats.update(eldarica_st)
spacer_stats.update(spacer_st)
else:
st = processResult(prog, bench_name, "COMPILATION ERROR", '', 'ERR')
eldarica_stats.update(st)
spacer_stats.update(st)
if debug: print "---------------------"
return eldarica_stats, spacer_stats
head="""
<div id="%s" class="tab-pane active">
<table class="table">
<tr class = "info">
<td><b>Benchmark</b></td>
<td><b>Result</b></td>
<td><b>Expected</b></td>
<td><b>Soot2Cfg (Time)</b></td>
<td><b>CheckSat (Time)</b></td>
<td><b>Hornify (Time)</b></td>
</tr>
"""
infer_head="""
<div id="%s" class="tab-pane">
<table class="table">
<tr class = "info">
<td><b>Benchmark</b></td>
<td><b>Result</b></td>
<td><b>Expected</b></td>
<td><b>Analysis (Time)</b></td>
<td><b> Capture (Time)</b></td>
<td><b> Reporting (Time)</b></td>
</tr>
"""
cpa_head="""
<div id="%s" class="tab-pane">
<table class="table">
<tr class = "info">
<td><b>Benchmark</a></td>
<td><b>Result</b></td>
<td><b>Expected</b></td>
<td><b>Analysis (Time)</b></td>
</tr>
"""
template="""
<tr class = "%s">
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>
"""
template2="""
<tr data-toggle="collapse" data-target="#%s" class="accordion-toggle %s">
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>
"""
template_cpa="""
<tr data-toggle="collapse" data-target="#%s" class="accordion-toggle %s">
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>
"""
template_hidden = """
<tr class = %s>
<td class="hiddenRow"><div class="accordian-body collapse" id="%s"> %s </div> </td>
</tr>
"""
template_hidden_cpa = """
<tr class = %s>
<td class="hiddenRow"><div class="accordian-body collapse" id="%s"> <a href=%s>CPAChecker Report</a> </div> </td>
</tr>
"""
foot_table = """
</table>
</div>
"""
def jayHornHtml(stats):
row = ""
id = 0
color = "active"
for bench, values in sorted(stats.items()):
id_s = "jayhorn"+str(id)
try:
if values["expected"] == "UNKNOWN":
color = "active"
else:
color = "danger" if values["result"] != values["expected"] else "success"
row += template2 % (id_s, color, bench, values["result"],\
values["expected"], str(values["soot2cfg"]),\
str(values["time"]), str(values["toHorn"])) + "\n"
row += template_hidden % (color, id_s, values["logs"]) + "\n"
except Exception as e:
print "Exception: " + str(e)
row += template2 % ("active", id_s, bench, " ", " ", " ", " ", " ") + "\n"
row += template_hidden % (color, id_s, values["logs"]) + "\n"
id +=1
jayhorn_head = head % "jayhorn"
table = jayhorn_head + row
return table
def inferHtml(stats):
row = ""
id = 0
color = "active"
for bench, values in sorted(stats.items()):
id_s = "infer"+str(id)
try:
if values["expected"] == "UNKNOWN":
color = "active"
else:
color = "danger" if values["result"] != values["expected"] else "success"
row += template2 % (id_s, color, bench, values["result"],\
values["expected"], str(values["analysis_time"]),\
str(values["capture_time"]), str(values["reporting_time"])) + "\n"
row += template_hidden % (color, id_s, values["logs"]) + "\n"
except Exception as e:
print "Exception: " + str(e)
row += template2 % ("active", id_s, bench, " ", " ", " ", " ", " ") + "\n"
row += template_hidden % (color, id_s, values["logs"]) + "\n"
id +=1
head_in = infer_head % "infer"
table = head_in + row
return table
def cpaHtml(stats):
row = ""
id = 0
color = "active"
for bench, values in sorted(stats.items()):
id_s = "cpa"+str(id)
try:
if values["expected"] == "UNKNOWN":
color = "active"
else:
color = "danger" if values["result"] != values["expected"] else "success"
row += template_cpa % (id_s, color, bench, values["result"],\
values["expected"], str(values["time"])) + "\n"
row += template_hidden_cpa % (color, id_s, values["logs"]) + "\n"
except Exception as e:
print "Exception: " + str(e)
row += template_cpa % ("active", id_s, bench, " ", " ", " ") + "\n"
row += template_hidden % (color, id_s, values["logs"]) + "\n"
id +=1
head_in = cpa_head % "cpa"
table = head_in + row
return table
def generateHtml(args, stats):
row = ""
id = 0
color = "active"
jayhorn_table, infer_table, cpa_table = "", "", ""
for d, v in stats.iteritems():
try:
jayhorn_table += jayHornHtml(v['jayhorn'])
except Exception as e:
print str(e)
try:
infer_table += inferHtml(v['infer'])
except Exception as e:
print str(e)
try:
cpa_table += cpaHtml(v['cpa'])
except Exception as e:
print str(e)
jayhorn_table = jayhorn_table + foot_table
infer_table = infer_table + foot_table
cpa_table = cpa_table + foot_table
header, footer = "", ""
with open("view_results/up.html") as h, open ("view_results/low.html") as l:
header = h.read()
footer = l.read()
out = "view_results" + os.sep + args.html_name
with open(out, 'w') as f:
f.write(header)
f.write(jayhorn_table)
f.write(infer_table)
f.write(cpa_table)
f.write(footer)
def generateMinePumpHtml(stats):
row = ""
id = 0
color = "active"
jayhorn_table, infer_table, cpa_table = "", "", ""
try:
jayhorn_table += jayHornHtml(stats['jayhorn'])
except Exception as e:
print str(e)
try:
infer_table += inferHtml(stats['infer'])
except Exception as e:
print str(e)
try:
cpa_table += cpaHtml(stats['cpa'])
except Exception as e:
print str(e)
jayhorn_table = jayhorn_table + foot_table
infer_table = infer_table + foot_table
cpa_table = cpa_table + foot_table
header, footer = "", ""
with open("view_results/up.html") as h, open ("view_results/low.html") as l:
header = h.read()
footer = l.read()
out = "view_results/minepump.html"
with open(out, 'w') as f:
f.write(header)
f.write(jayhorn_table)
f.write(infer_table)
f.write(cpa_table)
f.write(footer)
try:
shutil.move("cpachecker_out", "view_results")
except Exception as e:
print str(e)
def analysis(stats):
print "Analysis ..."
print pprint.pprint(stats)
el_safe, el_unsafe, sp_safe, sp_unsafe, total = 0, 0, 0, 0, 0
el_imprecise, el_unsound, sp_imprecise, sp_unsound = 0, 0, 0, 0
el_timeout, sp_timeout = 0, 0
error_case = ""
csv = "Benchmark, Expected, JayHorn-Eldarica-Answer, JayHorn-Spacer-Answer, JayHorn-Eldarica-Time, JayHorn-Spacer-Time\n"
for bench, results in stats.iteritems():
for (ek,ev), (sk,sv) in zip(results["jayhorn-eldarica"].items(), results["jayhorn-spacer"].items()):
total +=1
csv += ek + ", " + ev["expected"] + ", " + ev["result"] + ", " + ev["time"]
csv += ", " + sv["result"] + ", " + sv["time"] + "\n"
if ev["result"] == "SAFE" and ev["expected"] == "SAFE":
el_safe +=1 #correct case
elif ev["result"] == "UNSAFE" and ev["expected"] == "UNSAFE":
el_unsafe +=1 #correct case
elif ev["result"] == "SAFE" and ev["expected"] == "UNSAFE":
el_unsound +=1 # unsound case
elif ev["result"] == "UNSAFE" and ev["expected"] == "SAFE":
el_imprecise +=1 # imprecise case
elif ev["result"] == "TIMEOUT":
el_timeout +=1
else:
error_case += "Eldarica: " + sk + "\n"
if sv["result"] == "SAFE" and sv["expected"] == "SAFE":
sp_safe +=1 #correct case
elif sv["result"] == "UNSAFE" and sv["expected"] == "UNSAFE":
sp_unsafe +=1 #correct case
elif sv["result"] == "SAFE" and sv["expected"] == "UNSAFE":
sp_unsound +=1 # unsound case
elif sv["result"] == "UNSAFE" and sv["expected"] == "SAFE":
sp_imprecise +=1 # imprecise case
elif sv["result"] == "TIMEOUT":
sp_timeout +=1
else:
error_case += "SPACER: " + sk + "\n"
print csv
print "TOTAL ... " + str(total)
print "Eldarica SAFE ... " + str(el_safe)
print "Eldarica UNSAFE ... " + str(el_unsafe)
print "Eldarica UNSOUND ... " + str(el_unsound)
print "Eldarica IMPRECISE ... " + str(el_imprecise)
print "Eldarica TIMEOUT ... " + str(el_timeout)
print "Spacer SAFE ... " + str(sp_safe)
print "Spacer UNSAFE ... " + str(sp_unsafe)
print "Spacer UNSOUND ... " + str(sp_unsound)
print "Spacer IMPRECISE ... " + str(sp_imprecise)
print "Spacer TIMEOUT ... " + str(sp_timeout)
print " ---- TO BE CHECKED ----- "
print error_case
def scatterPlot(stats):
print "Making scatter Plot ... "
import numpy as np
import matplotlib.pyplot as plt, mpld3
import math
plottable = dict()
j, c = list(), list()
j_total, c_total = list(), list()
print stats
for bench, results in stats.iteritems():
for (jk, jv), (ck,cv) in zip(results["jayhorn-eldarica"].items(), results["cpa"].items()):
if jv["expected"] == jv["result"] == cv["result"]:
j.append((jv["time"].strip()).replace("s",""))
c.append((cv["time"].strip()).replace("s", ""))
j.append((jv["time"].strip()).replace("m",""))
c.append((cv["time"].strip()).replace("m", ""))
j_total.append((jv["total-time"].strip()).replace("s",""))
c_total.append((cv["total-time"].strip()).replace("s", ""))
j_total.append((jv["total-time"].strip()).replace("m",""))
c_total.append((cv["total-time"].strip()).replace("m", ""))
plottable.update({jk:[jv["time"], cv["time"]]})
print "\n\n======== PLOTTING ======="
fig = plt.figure()
print c, j
#plt.gca().set_aspect('equal', adjustable='box')
p0 = plt.subplot(211)
p0.scatter(j, c, s=80, c='red', marker=".", label='JayHorn vs CPAChecker -- Analsysis Time', lw=2)
#p0_p1.set_yscale('log', basey=2)
#p0_p1.set_xscale('log', basex=2)
plt.xlim(0, 60)
plt.ylim(0, 60)
x=np.linspace(0,60, 61)
plt.plot(x,x,'k-')
plt.legend(loc='upper left');
p1 = plt.subplot(212)
p1.scatter(j_total, c_total, s=80, c='red', marker=".", label='JayHorn vs CPAChecker -- Total Time', lw=2)
plt.xlim(0, 60)
plt.ylim(0, 60)
x=np.linspace(0,60, 61)
plt.plot(x,x,'k-')
plt.legend(loc='upper left');
plt.show()
def save_obj(obj, name ):
print "Saving stats ..... "
with open(name, 'wb') as f:
pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)
def load_obj(name ):
with open(name, 'rb') as f:
return pickle.load(f)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog='JAYHORN Bench Analysis Utils',
formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent('''\
JAYHORN Bench Analysis Utils
--------------------------------
'''))
#parser.add_argument ('file', metavar='BENCHMARK', help='Benchmark file')
parser.add_argument ('directory', help='Benchmark dirs', nargs='*')
parser.add_argument('-html', '--html', required=False, dest="html", action="store_true")
parser.add_argument('-html-fname', '--html-fname', required=False, dest="html_name", help = "html output name", default="results.html")
parser.add_argument('-save-fname', '--save-fname', required=False, dest="save_name", help = "save output name", default="results.pkl")
parser.add_argument('-load-stats', '--load-stats', required=False, dest="stats", help = "load stats", default="results.pkl")
parser.add_argument('-mp', '--mp', required=False, dest="mp", action="store_true", help = "Run Mine Pump benchmark")
parser.add_argument('-infer', '--infer', required=False, dest="infer", action="store_true")
parser.add_argument('-cpa', '--cpa', required=False, dest="cpa", action="store_true")
parser.add_argument('-spacer', '--spacer', required=False, dest="spacer", action="store_true")
parser.add_argument('-plot', '--plot', required=False, dest="plot", action="store_true")
parser.add_argument('-ana', '--ana', required=False, dest="ana", action="store_true")
parser.add_argument('-save', '--save', required=False, dest="save", action="store_true")
parser.add_argument('-load', '--load', required=False, dest="load", action="store_true", help = "Load pickled output and pretty print the stats")
parser.add_argument ('--timeout', help='Timeout', type=float, default=60.0, dest="timeout")
parser.add_argument('-mem', '--mem', required=False, dest="mem", help='Mem prec for JayHorn',
type=int, default=3)
parser.add_argument('-inline', '--inline', required=False, dest="inline", action="store_true")
args = parser.parse_args()
try:
if args.load:
stats = load_obj(args.stats)
#pprint.pprint(stats)
if args.ana:
analysis(stats)
elif args.mp:
cpa_stats = dict()
if args.cpa: cpa_stats = runCpa(args, args.directory[0])
#if args.infer: infer_stats = runInfer(args, args.directory[0])
eldarica_stats, spacer_stats = minePump(args.directory[0], args)
stats = {str(args.directory[0]):
{
"cpa":cpa_stats,
"jayhorn-eldarica":eldarica_stats,
"jayhorn-spacer":spacer_stats
}
}
if args.save: save_obj(stats, args.save_name)
if args.html: generateMinePumpHtml(stats)
else:
runBench(args)
except Exception as e:
print str(e)