forked from pyvypr/VyPRAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_main.py
140 lines (118 loc) · 4.83 KB
/
test_main.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from datetime import datetime
import pickle
import argparse
import sys
sys.path.append("..")
import VyPRAnalysis as analysis
def plot_severity_vs_time(f,severity_function=analysis.utils.verdict_severity):
#get a function call of the given function such that there was a failure during the call
call=f.get_calls_with_verdict(0)[0]
#find the first observation wrt verdicts that caused the failure
failed_observation=call.get_falsifying_observation()
#find the instrumentation point at which the failed observation failed
inst_point=failed_observation.get_instrumentation_point()
#get all the observations of that instrumentation point, whether they failed or not
observations=inst_point.get_observations()
ids=[] #will contain IDs of assignments
t=[]
s=[]
#grouping observations by the assignments they are paired with
#t and s are lists, they have as many elements as there are groups (assignments)
#their elements are lists of time points and verdict severity values
valuations=[]
for obs in observations:
assignments=obs.get_assignments()
print(obs.id)
final_dict=dict()
for a in assignments:
a=vars(a)
a["value"]=pickle.loads(a["value"])
print(a)
final_dict[a["variable"]]=a["value"]
if final_dict not in valuations:
valuations.append(final_dict)
t.append([])
s.append([])
time=analysis.verdict(obs.verdict).time_obtained
t[valuations.index(final_dict)].append(datetime.strptime(time,'%Y-%m-%dT%H:%M:%S.%f'))
s[valuations.index(final_dict)].append(severity_function(obs))
for v in valuations:
ind=valuations.index(v)
plt.plot(t[ind],s[ind],'ob')
plt.xlabel('time verdict was obtained')
plt.ylabel('verdict severity')
plt.margins(0.05)
plt.savefig('plot_%d.pdf'%ind)
plt.close() #move after loop to get a plot of all dots on the same graph (coloured by assignment)
def plot_failed_verdicts_vs_function(function_ids=None):
verdicts=[]
if function_ids!=None:
for id in function_ids:
verdicts.append(len(analysis.function(id).get_verdicts(0)))
else:
f_list=analysis.list_functions()
function_ids=[]
for f in f_list:
function_ids.append(f.id)
verdicts.append(len(f.get_verdicts(0)))
plt.bar(function_ids,verdicts,width=0.3)
plt.xticks(function_ids)
plt.xlabel('Function/Property pair ID')
plt.ylabel('Violations generated')
plt.savefig('plot_verdicts.pdf')
plt.close()
return
def main():
parse = argparse.ArgumentParser(description="Testing script for VyPRAnalysis.")
parse.add_argument('--port', type=int, help='The port number on which to connect to the verdict server.')
parse.add_argument('--service-dir', type=str, help='The absolute directory in which to find the monitored service locally.')
args = parse.parse_args()
analysis.set_server("http://127.0.0.1:%i/" % args.port)
"""f=analysis.function(99)
verdicts=f.get_verdicts(0)
print(len(analysis.list_functions()))
#plot_failed_verdicts_vs_function([100,103])
plot_failed_verdicts_vs_function()"""
#print(analysis.get_parametric_path([6,7,8],1))
print(analysis.get_intersection_from_observations('app.routes.paths_branching_test',[6,7,8],1))
"""f1=analysis.function(fully_qualified_name='app.routes.paths_branching_test')
f2=analysis.function(id=1)
function_calls1=f1.get_calls()
function_calls2=f2.get_calls(http_request(1))
print(len(function_calls1))
print(len(function_calls2))
req=analysis.http_request(id=1)
print(req.time_of_request)
req1=analysis.http_request(time_of_request=req.time_of_request)
print(req1.id)
function_calls3=f2.get_calls(req1)
print(function_calls3[0].http_request)
verdict1=analysis.verdict(1)
atom1s=verdict1.get_collapsing_atom().get_structure()
print(atom1s)
obs=analysis.observation(id=1)
print(obs.verdict_severity())
true_verdicts=analysis.list_verdicts_dict_with_value(1)
print(true_verdicts)
for v in true_verdicts:
print(v)
print("function id=",v["function"])
print("verdict time:",v["time_obtained"])
print(len(analysis.get_atom_list(1)))
call1=analysis.function_call(1)
obs_fail=call1.get_falsifying_observation()
if obs_fail!=None:
print(obs_fail.id)
pp=analysis.instrumentation_point(id=1)
print(pp.serialised_condition_sequence)
#ppp=analysis.assignment(id=1)
#print(ppp.variable)
graphfile=open("graph_file","w+")
analysis.write_scfg(f1.get_graph(),"graph_file")
graphfile.close()
plot_severity_vs_time(analysis.function(1))"""
if __name__ == "__main__":
main()