-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstrument.py
47 lines (39 loc) · 1.88 KB
/
instrument.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
from os import path, system
from sys import argv
from getopt import getopt
NUM_PROBLEMS = 18 #19 even the professors provided pre-instrumented and pre-compiled files don't include 19
def main(argv):
options, arguments = getopt(argv[1:], "p:t:", ["problem=", "type="])
commandParts = ["java -Xmx6000m -cp target/aistr.jar nl.tudelft.instrumentation.Main",
"--type=", # + "fuzzing" or "symbol" or "patching"
"--file=problems/Problem", # + "1/Problem1.java"
"> instrumented/Problem"] # + "1.java"
instrumentAll = True
for option, argument in options:
if option in ("-p", "--problem"):
if str(argument) in [str(x) for x in range(1, NUM_PROBLEMS + 1)]:
instrumentAll = False
problemNumber = int(argument)
elif str(argument).lower() == "all":
pass
else:
raise RuntimeError("Unknown or too large argument " + argument)
elif option in ("-t", "--type"):
commandParts[1] += argument # could check if "fuzzing" or "symbol" or "patching" but w.e.
def adjustCommandAndExecute(commandParts, i):
commandParts[2] += str(i) + "/Problem" + str(i) + ".java"
commandParts[3] += str(i) + ".java"
print("\nExecuting: " + " ".join(commandParts))
system(" ".join(commandParts))
commandParts[2] = commandParts[2].replace(str(i) + "/Problem" + str(i) + ".java", "")
commandParts[3] = commandParts[3].replace(str(i) + ".java", "")
# Only instrument one file guard clause
if not instrumentAll:
adjustCommandAndExecute(commandParts, problemNumber)
return 0
# Instrument all files by default
for i in range(1, NUM_PROBLEMS + 1):
adjustCommandAndExecute(commandParts, i)
return 0
if __name__ == "__main__":
main(argv)