-
Notifications
You must be signed in to change notification settings - Fork 50
/
pyexz3.py
executable file
·67 lines (50 loc) · 2.05 KB
/
pyexz3.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
# Copyright: see copyright.txt
import os
import sys
import logging
import traceback
from optparse import OptionParser
from symbolic.loader import *
from symbolic.explore import ExplorationEngine
print("PyExZ3 (Python Exploration with Z3)")
sys.path = [os.path.abspath(os.path.join(os.path.dirname(__file__)))] + sys.path
usage = "usage: %prog [options] <path to a *.py file>"
parser = OptionParser(usage=usage)
parser.add_option("-l", "--log", dest="logfile", action="store", help="Save log output to a file", default="")
parser.add_option("-s", "--start", dest="entry", action="store", help="Specify entry point", default="")
parser.add_option("-g", "--graph", dest="dot_graph", action="store_true", help="Generate a DOT graph of execution tree")
parser.add_option("-m", "--max-iters", dest="max_iters", type="int", help="Run specified number of iterations", default=0)
parser.add_option("--cvc", dest="cvc", action="store_true", help="Use the CVC SMT solver instead of Z3", default=False)
parser.add_option("--z3", dest="cvc", action="store_false", help="Use the Z3 SMT solver")
(options, args) = parser.parse_args()
if not (options.logfile == ""):
logging.basicConfig(filename=options.logfile,level=logging.DEBUG)
if len(args) == 0 or not os.path.exists(args[0]):
parser.error("Missing app to execute")
sys.exit(1)
solver = "cvc" if options.cvc else "z3"
filename = os.path.abspath(args[0])
# Get the object describing the application
app = loaderFactory(filename,options.entry)
if app == None:
sys.exit(1)
print ("Exploring " + app.getFile() + "." + app.getEntry())
result = None
try:
engine = ExplorationEngine(app.createInvocation(), solver=solver)
generatedInputs, returnVals, path = engine.explore(options.max_iters)
# check the result
result = app.executionComplete(returnVals)
# output DOT graph
if (options.dot_graph):
file = open(filename+".dot","w")
file.write(path.toDot())
file.close()
except ImportError as e:
# createInvocation can raise this
logging.error(e)
sys.exit(1)
if result == None or result == True:
sys.exit(0);
else:
sys.exit(1);