-
Notifications
You must be signed in to change notification settings - Fork 13
/
report.py
282 lines (264 loc) · 11.9 KB
/
report.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
import os
import sys
import json
import subprocess
from os import listdir
from os.path import isfile, join
curdir = os.getcwd()
services = ["features-service", "languagetool", "ncs", "news", "ocvn", "proxyprint", "restcountries", "scout-api",
"scs", "erc20-rest-service", "genome-nexus", "person-controller", "problem-controller", "rest-study",
"spring-batch-rest", "spring-boot-sample-app", "user-management", "cwa-verification", "market",
"project-tracking-system"]
tools = ["evomaster-whitebox_data", "restler_data", "resttestgen_data", "restest_data", "bboxrt_data", "schemathesis_data", "tcases_data", "dredd_data", "evomaster-blackbox_data", "apifuzzer_data"]
class_name = ["app.coronawarn", "com.giassi.microservice", "com.test.sampleapp", "com.github.chrisgleissner", "org.restscs", "se.devscout.scoutapi", "com.in28minutes.rest.webservices.restfulwebservices", "eu.fayder.restcountries", "io.github.proxyprint.kitchen", "com.pfa.pack", "com.sw.project", "com.mongodb.starter", "org.devgateway", "org.tsdes.spring.examples.news", "org.restncs", "market", "org.languagetool", "org.cbioportal.genome_nexus", "org.javiermf.features", "io.blk.erc20"]
paths = [
"services/evo_jdk8/cs/rest/original/features-service",
"services/evo_jdk8/cs/rest/original/languagetool",
"services/evo_jdk8/cs/rest/artificial/ncs",
"services/evo_jdk8/cs/rest/artificial/news",
"services/evo_jdk8/cs/rest-gui/ocvn",
"services/evo_jdk8/cs/rest/original/proxyprint",
"services/evo_jdk8/cs/rest/original/restcountries",
"services/evo_jdk8/cs/rest/original/scout-api",
"services/evo_jdk8/cs/rest/artificial/scs",
"services/jdk8/erc20-rest-service",
"services/jdk8/genome-nexus",
"services/jdk8/person-controller",
"services/jdk8/problem-controller",
"services/jdk8/rest-study",
"services/jdk8/spring-batch-rest",
"services/jdk8/spring-boot-sample-app",
"services/jdk8/user-management",
"services/jdk11/cwa-verification",
"services/jdk11/market",
"services/jdk11/project-tracking-system",
]
port = sys.argv[1]
path = sys.argv[2]
# name = sys.argv[2]
# k = 0
# for i in range(len(services)):
# if name == services[i]:
# k = i
#
# path = paths[k]
print("Generating report")
subdirs = [x[0] for x in os.walk(path)]
class_files = []
jacoco_command2 = ''
for subdir in subdirs:
if path in subdir and '/target/classes/' in subdir:
target_dir = subdir[:subdir.rfind('/target/classes/') + 15]
if target_dir not in class_files:
class_files.append(target_dir)
jacoco_command2 = jacoco_command2 + ' --classfiles ' + target_dir
if path in subdir and '/build/classes/' in subdir:
target_dir = subdir[:subdir.rfind('/build/classes/') + 14]
if target_dir not in class_files:
class_files.append(target_dir)
jacoco_command2 = jacoco_command2 + ' --classfiles ' + target_dir
jacoco_command2 = jacoco_command2 + ' --csv '
jacoco_command1 = 'java -jar org.jacoco.cli-0.8.7-nodeps.jar report '
files = [f for f in os.listdir(curdir)]
files.sort()
count = 0
errors = []
time = []
start_time = True
error_start = False
error_msg = ''
error_time = ''
for f in files:
if str(port) in f:
if count == 6:
count = 0
if 'jacoco' in f and '.exec' in f:
count = count + 1
jacoco_file = 'jacoco_' + str(count) + '.csv'
subprocess.run(jacoco_command1 + f + jacoco_command2 + jacoco_file, shell=True)
elif 'log' in f:
subprocess.call('split -l 10000000 ' + f, shell=True)
ffs = [ff for ff in os.listdir('.') if os.path.isfile(ff)]
ffs.sort()
for ff in ffs:
if ff[0] == 'x':
with open(ff, 'r') as log_file:
data = log_file.readlines()
for line in data:
if 'ERROR ' in line:
error_start = True
error_time = line[:line.rfind(':')]
elif error_start and 'java.lang.Thread.run' in line:
error_start = False
if error_msg not in errors:
errors.append(error_msg)
time.append(error_time)
error_msg = ''
error_time = ''
elif error_start and 'at ' in line:
error_msg = error_msg + line
print(len(errors))
with open('error.json', 'w', encoding='UTF-8') as f:
json.dump(errors, f)
with open('time.json', 'w', encoding='UTF-8') as f:
json.dump(time, f)
subprocess.run("rm -rf x*", shell=True)
curdir = os.getcwd()
res = ""
t_line = [0, 0, 0, 0, 0, 0]
c_line = [0, 0, 0, 0, 0, 0]
t_branch = [0, 0, 0, 0, 0, 0]
c_branch = [0, 0, 0, 0, 0, 0]
t_method = [0, 0, 0, 0, 0, 0]
c_method = [0, 0, 0, 0, 0, 0]
error = 0
unique_err = 0
crucial = 0
mypath = os.path.join(curdir, "result")
if os.path.isdir(mypath):
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
for dir_file in onlyfiles:
if '_1.csv' in dir_file:
with open(os.path.join(mypath, dir_file)) as f:
lines = f.readlines()
start = False
for line in lines:
if not start:
start = True
continue
element = line.split(',')
if "EMDriver" in element[2] or "EmbeddedControl" in element[2]:
continue
c_branch[0] = c_branch[0] + int(element[6])
t_branch[0] = t_branch[0] + int(element[5]) + int(element[6])
c_line[0] = c_line[0] + int(element[8])
t_line[0] = t_line[0] + int(element[7]) + int(element[8])
c_method[0] = c_method[0] + int(element[12])
t_method[0] = t_method[0] + int(element[12]) + int(element[11])
elif '_2.csv' in dir_file:
with open(os.path.join(mypath, dir_file)) as f:
lines = f.readlines()
start = False
for line in lines:
if not start:
start = True
continue
element = line.split(',')
if "EMDriver" in element[2] or "EmbeddedControl" in element[2]:
continue
c_branch[1] = c_branch[1] + int(element[6])
t_branch[1] = t_branch[1] + int(element[5]) + int(element[6])
c_line[1] = c_line[1] + int(element[8])
t_line[1] = t_line[1] + int(element[7]) + int(element[8])
c_method[1] = c_method[1] + int(element[12])
t_method[1] = t_method[1] + int(element[11]) + int(element[12])
elif '_3.csv' in dir_file:
with open(os.path.join(mypath, dir_file)) as f:
lines = f.readlines()
start = False
for line in lines:
if not start:
start = True
continue
element = line.split(',')
if "EMDriver" in element[2] or "EmbeddedControl" in element[2]:
continue
c_branch[2] = c_branch[2] + int(element[6])
t_branch[2] = t_branch[2] + int(element[5]) + int(element[6])
c_line[2] = c_line[2] + int(element[8])
t_line[2] = t_line[2] + int(element[7]) + int(element[8])
c_method[2] = c_method[2] + int(element[12])
t_method[2] = t_method[2] + int(element[11]) + int(element[12])
elif '_4.csv' in dir_file:
with open(os.path.join(mypath, dir_file)) as f:
lines = f.readlines()
start = False
for line in lines:
if not start:
start = True
continue
element = line.split(',')
if "EMDriver" in element[2] or "EmbeddedControl" in element[2]:
continue
c_branch[3] = c_branch[3] + int(element[6])
t_branch[3] = t_branch[3] + int(element[5]) + int(element[6])
c_line[3] = c_line[3] + int(element[8])
t_line[3] = t_line[3] + int(element[7]) + int(element[8])
c_method[3] = c_method[3] + int(element[12])
t_method[3] = t_method[3] + int(element[11]) + int(element[12])
elif '_5.csv' in dir_file:
with open(os.path.join(mypath, dir_file)) as f:
lines = f.readlines()
start = False
for line in lines:
if not start:
start = True
continue
element = line.split(',')
if "EMDriver" in element[2] or "EmbeddedControl" in element[2]:
continue
c_branch[4] = c_branch[4] + int(element[6])
t_branch[4] = t_branch[4] + int(element[5]) + int(element[6])
c_line[4] = c_line[4] + int(element[8])
t_line[4] = t_line[4] + int(element[7]) + int(element[8])
c_method[4] = c_method[4] + int(element[12])
t_method[4] = t_method[4] + int(element[11]) + int(element[12])
elif '_6.csv' in dir_file:
with open(os.path.join(mypath, dir_file)) as f:
lines = f.readlines()
start = False
for line in lines:
if not start:
start = True
continue
element = line.split(',')
if "EMDriver" in element[2] or "EmbeddedControl" in element[2]:
continue
c_branch[5] = c_branch[5] + int(element[6])
t_branch[5] = t_branch[5] + int(element[5]) + int(element[6])
c_line[5] = c_line[5] + int(element[8])
t_line[5] = t_line[5] + int(element[7]) + int(element[8])
c_method[5] = c_method[5] + int(element[12])
t_method[5] = t_method[5] + int(element[11]) + int(element[12])
elif 'error' in dir_file:
with open(os.path.join(mypath, dir_file), 'r') as f:
data = json.load(f)
unique = []
for d in data:
uniq = d[:d.find('\n')]
if uniq not in unique:
unique.append(uniq)
error = error + len(data)
unique_err = unique_err + len(unique)
for uni in unique:
flag = True
for n in class_name:
if n in uni:
flag = False
if flag:
crucial = crucial + 1
res = ""
for k in range(6):
if t_line[k] != 0:
line = c_line[k]/t_line[k]
else:
line = 0
if t_branch[k] != 0:
branch = c_branch[k]/t_branch[k]
else:
branch = 0
if t_method[k] != 0:
method = c_method[k]/t_method[k]
else:
method = 0
res = res + str(line*100) + '%,' + str(branch*100) + '%,' + str(method*100) + '%\n'
res = res + str(error) + ',' + str(unique_err) + ',' + str(crucial) + '\n'
with open('res.csv', 'w') as f:
f.write(res)
subprocess.run("mkdir -p " + "result", shell=True)
subprocess.call('mv res.csv ' + "result", shell=True)
subprocess.call('mv *.csv ' + "result", shell=True)
subprocess.call('mv error.json ' + "result", shell=True)
subprocess.call('mv time.json ' + "result", shell=True)
subprocess.call('mv jacoco*.exec ' + "result", shell=True)
subprocess.call('mv log* ' + "result", shell=True)