-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-concolic-int.py
executable file
·87 lines (81 loc) · 3.29 KB
/
check-concolic-int.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
#!/usr/bin/python
import symex.fuzzy as fuzzy
import z3
import traceback
import sys
class MyException(Exception):
def __init__(self, *args):
super(MyException, self).__init__(*args)
try:
fuzzy.cur_path_constr = []
fuzzy.cur_path_constr_callers = []
fuzzy.concrete_values = {'x': 10}
x = fuzzy.mk_int('x')
y = x * 2
if not isinstance(y, fuzzy.concolic_int):
raise MyException("ERROR: lost concolic object after multiply")
if y != 20:
raise MyException("ERROR: wrong concrete value for concolic object")
if len(fuzzy.cur_path_constr) == 0:
raise MyException("ERROR: no path constraint from equality check")
if len(fuzzy.cur_path_constr) > 1:
raise MyException("ERROR: too many path constraints from equality check")
fuzzy.cur_path_constr = []
if y == 70:
raise MyException("ERROR: wrong concrete value for concolic object, take 2")
(ok, model) = fuzzy.fork_and_check(fuzzy.sym_not(fuzzy.cur_path_constr[0]))
if ok != z3.sat:
raise MyException("ERROR: unsolvable constraint")
if model['x'] != 35:
raise MyException("ERROR: wrong value in solved constraint")
print "Multiply works"
except MyException:
traceback.print_exc(None, sys.stdout)
try:
fuzzy.cur_path_constr = []
fuzzy.concrete_values = {'x': 10}
x = fuzzy.mk_int('x')
y = x / 2
if not isinstance(y, fuzzy.concolic_int):
raise MyException("ERROR: lost concolic object after divide")
if y != 5:
raise MyException("ERROR: wrong concrete value for concolic object")
if len(fuzzy.cur_path_constr) == 0:
raise MyException("ERROR: no path constraint from equality check")
if len(fuzzy.cur_path_constr) > 1:
raise MyException("ERROR: too many path constraints from equality check")
fuzzy.cur_path_constr = []
if y == 70:
raise MyException("ERROR: wrong concrete value for concolic object, take 2")
(ok, model) = fuzzy.fork_and_check(fuzzy.sym_not(fuzzy.cur_path_constr[0]))
if ok != z3.sat:
raise MyException("ERROR: unsolvable constraint")
if model['x'] != 140:
raise MyException("ERROR: wrong value in solved constraint")
print "Divide works"
except MyException:
traceback.print_exc(None, sys.stdout)
try:
fuzzy.cur_path_constr = []
concrete_values = {'x': 10}
x = fuzzy.mk_int('x')
y = (x / 2) * 4 + 3
if not isinstance(y, fuzzy.concolic_int):
raise MyException("ERROR: lost concolic object after divide+multiply+add")
if y != 23:
raise MyException("ERROR: wrong concrete value for concolic object")
if len(fuzzy.cur_path_constr) == 0:
raise MyException("ERROR: no path constraint from equality check")
if len(fuzzy.cur_path_constr) > 1:
raise MyException("ERROR: too many path constraints from equality check")
fuzzy.cur_path_constr = []
if y == 143:
raise MyException("ERROR: wrong concrete value for concolic object, take 2")
(ok, model) = fuzzy.fork_and_check(fuzzy.sym_not(fuzzy.cur_path_constr[0]))
if ok != z3.sat:
raise MyException("ERROR: unsolvable constraint")
if model['x'] != 70:
raise MyException("ERROR: wrong value in solved constraint")
print "Divide+multiply+add works"
except MyException:
traceback.print_exc(None, sys.stdout)