-
Notifications
You must be signed in to change notification settings - Fork 0
/
syminputBC.py
40 lines (31 loc) · 1.63 KB
/
syminputBC.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
import argparse
from tempfile import TemporaryDirectory
from subprocess import run, STDOUT
from os import path
# small config section
OPT = path.expanduser("~/build/llvm/Release/bin/opt")
MACKEOPT = path.expanduser("~/build/macke-opt-llvm/bin/libMackeOpt.so")
KLEE = path.expanduser("~/build/klee/Release+Asserts/bin/klee")
KTEST = path.expanduser("~/build/klee/Release+Asserts/bin/ktest-tool")
def run_KLEE(functionname, bcfile):
# Put all KLEE generated files into a temporary directory
with TemporaryDirectory() as tmpdir:
run([OPT, "-load", MACKEOPT,
"-encapsulatesymbolic", "--encapsulatedfunction=" + functionname,
bcfile, "-o", path.join(tmpdir, "prepared.bc")], check=True)
run([KLEE,
"--entry-point=macke_" + functionname + "_main", "--max-time=300", "-watchdog",
"--posix-runtime", "--libc=uclibc",
"--only-output-states-covering-new", path.join(tmpdir, "prepared.bc")
], check=True)
print()
# show the details of all test cases
run(["for ktest in "+ path.join(tmpdir, "klee-last") +"/*.ktest; do " + KTEST + " $ktest; echo ""; done"], shell=True)
# input("Press enter to delete " + tmpdir)
if __name__ == '__main__':
# Some argument parsing
parser = argparse.ArgumentParser(description='Get input for arbitrary functions')
parser.add_argument('functionname', help='name of the function to generate inputs for')
parser.add_argument('bcfile', type=argparse.FileType('r'), help='.bc-file containing the compiled bitcode')
args = parser.parse_args()
run_KLEE(args.functionname, args.bcfile.name)