forked from rohanpadhye/JQF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
80 lines (66 loc) · 2.55 KB
/
test.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
import subprocess
import concurrent.futures
import time
def timer(seconds :int):
start_time = time.time()
while True:
elapsed_time = time.time() - start_time
print(f"Elapsed Time: {elapsed_time:.2f} seconds", end="\r")
if elapsed_time >= seconds:
break
time.sleep(0.1) # Adjust the sleep duration as needed for accuracy and performance
print("\nTimer finished!")
def run_command(command:list,args:list):
# complete command with arguments for test cases
for arg in args:
if arg == 'r':
command.insert(1,'-r')
else:
command.append(arg)
try:
process = subprocess.run(command, check=True, text=True, capture_output=True, timeout=600)
print("Subprocess completed successfully.")
print("Output:", process.stdout)
# this only hides the errors caused by the forced timeout in guidance
except subprocess.TimeoutExpired:
print("Subprocess timed out after 600 seconds.")
except subprocess.CalledProcessError as e:
print("Subprocess failed with return code:", e.returncode)
print("Error:", e.stderr)
def bash_test():
# command without test method (for spezialization)
test_all_1 = False
test_1_5 = True
method = 'fuzzJSONParser_nomut'
target_direct = 'plot_tests/'
command =[
'bin/jqf-zest',
'-f',
'-c',
subprocess.check_output(['scripts/examples_classpath.sh'], text=True).strip(),
'edu.berkeley.cs.jqf.examples.jackson.jackson_test'
]
if test_all_1:
test_methods = [['fuzzJSONParser_mut','result-full'],
['fuzzJSONParser_nomut','result-nomut'],
['fuzzJSONParser_ascii','result-ascii-full'],
['fuzzJSONdeser_mut','result-mut-deser'],
['fuzzJSONmin_ascii','result-ascii-min'],
['fuzzJSONmin_mut','result-mut-min'],
['fuzzJSONParser_mut','result-full-random','r']
]
elif test_1_5:
command.append(method)
test_methods = []
for i in range(1):
test_methods.append([target_direct+ 'jackson/results_nomut/result'+str(i+9)])
with concurrent.futures.ProcessPoolExecutor(max_workers=len(test_methods)) as executor:
futures = {executor.submit(run_command,command,arg): arg for arg in test_methods}
timer(600)
concurrent.futures.wait(futures)
def main():
bash_test()
pass
if __name__ == "__main__":
print("hello")
main()