-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·240 lines (207 loc) · 7.9 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/bin/python
import os
import subprocess as sp
import time
import csv
import pydot
import networkx as nx
def load_graph_from_dot(file_path):
graph = pydot.graph_from_dot_file(file_path)[0]
G = nx.DiGraph()
for node in graph.get_nodes():
node_id = node.get_name()
label = node.get_label()
G.add_node(node_id, label=label)
for edge in graph.get_edges():
source = edge.get_source()
destination = edge.get_destination()
label = edge.get_label()
G.add_edge(source, destination, label=label)
return G
def are_graphs_equivalent(G1, G2):
# check that the nodes are the same
if set(G1.nodes) != set(G2.nodes):
return False
# check that the edges are the same
if set(G1.edges) != set(G2.edges):
return False
# for each nodes in the first graph
for node in G1.nodes:
# if the labels are different then they are not equal
if G1.nodes[node].get("label") != G2.nodes[node].get("label"):
return False
# for each edges in the first graph
for edge in G1.edges:
# if the labels are different then they are not equal
if G1[edge[0]][edge[1]].get("label") != G2[edge[0]][edge[1]].get("label"):
return False
return True
def check_correctness(file1, file2):
G1 = load_graph_from_dot(file1)
try:
G2 = load_graph_from_dot(file2)
return str(are_graphs_equivalent(G1, G2))
except Exception as e:
return "Not present"
def read_csv_file(filepath):
data = {}
with open(filepath, mode="r") as csvfile:
reader = csv.reader(csvfile)
for row in reader:
key, value = row
data[key] = value
return data
def lv_number(csvdata):
c = 0
for k in csvdata.keys():
if "lv" in k:
c += 1
return str(int(c / 2)) # every lv is double counted
def generate_latex_table(columns, rows, caption, label):
headers = " & ".join(columns)
table = (
"\\begin{table}[!ht]\n\\centering\n\\begin{tabular}{|"
+ "c|" * len(columns)
+ "}\n\\hline\n"
)
table += headers + " \\\\ \n\\hline\n"
for row in rows:
# print(row)
table += " & ".join(row) + " \\\\ \n"
table += (
"\\hline\n\\end{tabular}\n\\caption{"
+ caption
+ "}\n\\label{"
+ label
+ "}\n\\end{table}"
)
return table
# default: minimize global views
test_list = [
["./examples/account/account.erl", "main/0", "examples/account", "true"],
["./examples/dining/dining.erl", "main/0", "examples/dining", "true"],
["./examples/hello/hello.erl", "main/0", "examples/hello", "true"],
["./examples/async/async.erl", "main/0", "examples/async", "true"],
["./examples/ticktackstop/tictacstop.erl","start/0","examples/ticktackstop", "true"],
["./examples/ticktackloop/tictacloop.erl","start/0","examples/ticktackloop", "true"],
["./examples/customer/customer.erl","main/0","examples/customer", "true"],
["./examples/serverclient/serverclient.erl","main/0","examples/serverclient", "true"],
["./examples/trick/trick.erl","main/0","examples/trick", "true"],
["./examples/airline/airline.erl","main/0","examples/airline", "true"],
["./examples/conditional/conditional.erl","main/0","examples/conditional", "true"],
["./examples/forloop/forloop.erl","main/0","examples/forloop", "true"],
["./examples/funcall/funcall.erl","main/0","examples/funcall", "true"],
["./examples/hof/hof.erl","greet/0","examples/hof", "true"],
["./examples/if-cases/ifcases.erl","main/0","examples/if-cases", "true"],
["./examples/pass/pass.erl","main/0","examples/pass", "true"],
["./examples/producer/producer.erl","main/0","examples/producer", "true"],
["./examples/spawn/spawn.erl","main/0","examples/spawn", "true"],
["./examples/unknown/unknown.erl","main/0","examples/unknown", "true"],
["./examples/test/foo1/foo1.erl","test/0","examples/test/foo1", "true"],
["./examples/test/foo2/foo2.erl","test/0","examples/test/foo2", "true"],
["./examples/test/foo3/foo3.erl","test/0","examples/test/foo3", "true"],
["./examples/test/foo4/foo4.erl","test/0","examples/test/foo4", "true"],
["./examples/test/foo5/foo5.erl","test/0","examples/test/foo5", "true"],
["./examples/test/foo6/foo6.erl","test/0","examples/test/foo6", "true"],
["./examples/test/foo7/foo7.erl","main/0","examples/test/foo7", "true"],
["./examples/test/foo8/foo8.erl","main/0","examples/test/foo8", "true"],
["./examples/test/foo9/foo9.erl","main/0","examples/test/foo9", "true"],
["./examples/test/foo9b/foo9b.erl","main/0","examples/test/foo9b", "true"],
["./examples/test/foo9c/foo9c.erl","main/0","examples/test/foo9c", "true"],
["./examples/test/foo9d/foo9d.erl","main/0","examples/test/foo9d", "true"],
["./examples/test/foo9e/foo9e.erl","main/0","examples/test/foo9e", "true"],
["./examples/test/foo9f/foo9f.erl","main/0","examples/test/foo9f", "true"],
["./examples/test/foo9g/foo9g.erl","main/0","examples/test/foo9g", "true"],
["./examples/test/foo9h/foo9h.erl","main/0","examples/test/foo9h", "true"],
["./examples/test/ping/ping.erl","start/0","examples/test/ping", "true"],
["./examples/cauder_suite/airline/airline.erl","main/0","examples/cauder_suite/airline", "true"],
["./examples/cauder_suite/meViolation/meViolation.erl","main/0","examples/cauder_suite/meViolation", "true"],
["./examples/cauder_suite/purchase/purchase.erl","main/0","examples/cauder_suite/purchase", "true"],
# ["./examples/cauder_suite/barber/barber.erl","main/0","examples/cauder_suite/barber", "true"],
]
# compile the tool
os.system("rebar3 escriptize")
csvs = []
add_data = {}
# run the tool on each test
for item in test_list:
item = ["./_build/default/bin/chorer"] + item[:-1] # remove minimize of global view
csvfile = item[3] + "/output.csv"
gvfile = item[3] + "/global_view.dot"
correct_gvfile = item[3] + "/correct_gv.dot"
csvs.append(csvfile)
print("Executing", " ".join(item))
# get time
start_time = time.time()
output = sp.check_output(item).decode("utf-8")
runtime = time.time() - start_time
# get some additional data
warns = output.count("WARNING")
errs = output.count("ERROR")
add_data[item[3].rsplit("/", 1)[-1]] = {
"warns": str(warns),
"errs": str(errs),
"runtime": "{:.3f}s".format(runtime),
"correct": check_correctness(gvfile, correct_gvfile),
}
# print(f"{output}\ntime {runtime}\nwarns {warns}\nerrs {errs}")
# time.sleep(1)
# collect data from csv
datas = []
for c in csvs:
data = read_csv_file(c)
filetmp = c.rsplit("/", 1)[0] if "/" in c else c
file = filetmp.rsplit("/", 1)[-1] if "/" in c else c
# merge the 2 dictionaries with data
datas.append((file, data | add_data[file]))
# sort by number of lines
sorted_data = sorted(datas, key=lambda x: x[1]["line"])
# generate global view table
columns = [
"Example",
"Lines",
"Tot LV",
"GV Nodes",
"GV Edges",
"Warns",
"Errors",
"Time",
# "Check",
]
rows = [
[
file,
data["line"],
lv_number(data),
data["gv_nodes"],
data["gv_edges"],
data["warns"],
data["errs"],
data["runtime"],
# data["correct"],
]
for (file, data) in sorted_data
]
gv_table_code = generate_latex_table(
columns, rows, "Global view empirical data", "tab:gvbench"
)
with open("assets/table.tex", "w", encoding="utf-8") as f:
f.write(gv_table_code)
# generate correctness view table
columns = [
"Example",
"Check",
]
rows = [
[
file,
data["correct"],
]
for (file, data) in sorted_data
if "Not present" != data["correct"]
]
correct_table_code = generate_latex_table(
columns, rows, "Global view correctness data", "tab:corrbench"
)
with open("assets/correct.tex", "w", encoding="utf-8") as f:
f.write(correct_table_code)