-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdypybench.py
367 lines (322 loc) · 18.8 KB
/
dypybench.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
import argparse
import subprocess
import csv
import os
parser = argparse.ArgumentParser()
parser.add_argument(
"--list", "-l", action="store_true", help="List all the projects DyPyBench supports"
)
parser.add_argument(
"--timeout", type=int, help="Specify timeout to be used in seconds for execution of subprocesses", default=(60*60)
)
parser.add_argument(
"--test", "-t", type=int, nargs='+', help="Specify the project number to run the test suite"
)
parser.add_argument(
"--test_original", "-to", action="store_true", help="Run tests on original code"
)
parser.add_argument(
"--save", "-s", type=str, help="Specify file name to save the stdout and stderr combined"
)
parser.add_argument(
"--update_dynapyt_source", action="store_true", help="get dynapyt source code"
)
parser.add_argument(
"--update_lex_source", action="store_true", help="get LExecutor source code"
)
parser.add_argument(
"--dynapyt_instrument", "-di", type=int, nargs='+', help="Specify the project no. to run DynaPyt instrumentation"
)
parser.add_argument(
"--dynapyt_file", "-df", type=str, help="Specify the path to file containing the includes.txt file to run the instrumentation"
)
parser.add_argument(
"--dynapyt_analysis", "-da", help="Specify DynaPyt analysis to run"
)
parser.add_argument(
"--dynapyt_run", "-dr", type=int, nargs='+', help="Specify the project no. to run DynaPyt Analysis"
)
parser.add_argument(
"--lex_instrument", "-li", type=int, nargs='+', help="Specify the project no. to run LExecutor instrumentation"
)
parser.add_argument(
"--lex_file", "-lf", type=str, help="Specify the path to file containing the includes.txt file to run the instrumentation"
)
parser.add_argument(
"--lex_test", "-lt", type=int, nargs='+', help="Specify the project no. to run test suite for LExecutor"
)
parser.add_argument(
"--pycg", "-scg", type=int, nargs='+', help="Specify the project no. to run PyCG for static call graph generation"
)
def printAllProjects():
print("{:<8} {:<20} {:<50}".format("Number", "Project Name", "Repository URL"))
print("{:<8} {:<20} {:<50}".format("-------", "--------------", "---------------------------------"))
for value in data:
no, name, url = value
print("{:<8} {:<20} {:<50}".format(no, name, url))
def setupProjects():
global data
global original_data
data = []
original_data = []
with open("/DyPyBench/text/github-url.txt", "r") as csv_file:
csvReader = csv.reader(csv_file, delimiter=" ")
for index, row in enumerate(csvReader):
temp=[]
temp.append(index + 1)
temp.append(row[0].split("/")[-1].split(".git")[0])
temp.append(row[0])
data.append(temp)
original_data.append(row)
def get_project_name(proj_no):
for value in data:
no, name, url = value
if(proj_no == no):
return name
def get_project_no(proj_name):
for value in data:
no, name, url = value
if(proj_name == name):
return str(no)
if __name__ == '__main__':
bench_size = 50
args = parser.parse_args()
setupProjects()
if args.list:
printAllProjects()
if args.update_dynapyt_source:
# print("Downloading the dynapyt source from git")
if args.save:
output = subprocess.run(["/DyPyBench/scripts/setup-DynaPyt-src.sh"
], shell=True, stdout=open(args.save,'a+',1), stderr=subprocess.STDOUT)
else:
output = subprocess.run(["/DyPyBench/scripts/setup-DynaPyt-src.sh"
], shell=True, capture_output=True)
#if output needs to be printed on the console then comment above and uncomment below
"""output = subprocess.run(["/DyPyBench/scripts/setup-DynaPyt-src.sh"
], shell=True, stderr=subprocess.STDOUT)"""
if args.update_lex_source:
# print("Downloading the LExecutor source from git")
if args.save:
output = subprocess.run(["/DyPyBench/scripts/setup-LExecutor-src.sh"
], shell=True, stdout=open(args.save,'a+',1), stderr=subprocess.STDOUT)
else:
output = subprocess.run(["/DyPyBench/scripts/setup-LExecutor-src.sh"
], shell=True, capture_output=True)
#if output needs to be printed on the console then comment above and uncomment below
"""output = subprocess.run(["/DyPyBench/scripts/setup-LExecutor-src.sh"
], shell=True, stderr=subprocess.STDOUT)"""
if args.test:
projects = args.test
if 0 in projects:
projects = [x for x in range(1, bench_size + 1)]
for project in projects:
if(project < 0 or project > bench_size):
print("Project number should be between 1 and {}".format(bench_size))
else:
print("WE HERE IN PY SCRIPT")
proj_name = str(data[project - 1][1])
proj_no = str(data[project - 1][0])
proj_flags = str(original_data[project - 1][1])
copy_folder = args.test_original
if(proj_flags == "rt"):
proj_test_folder = str(original_data[project - 1][3])
elif(proj_flags == "t"):
proj_test_folder = str(original_data[project - 1][2])
elif(proj_flags == "r"):
proj_test_folder = ""
if args.save:
print("WE HERE IN PY SCRIPT 2")
output = subprocess.run(["/DyPyBench/scripts/run-test.sh %s %s %s %s %s" %(proj_name, proj_no, proj_test_folder, copy_folder, args.timeout)
], shell=True, stdout=open(args.save,'a+',1), stderr=subprocess.STDOUT, timeout=args.timeout)
else:
print("WE HERE IN PY SCRIPT 3")
print("/DyPyBench/scripts/run-test.sh %s %s %s %s %s" %(proj_name, proj_no, proj_test_folder, copy_folder, args.timeout))
output = subprocess.run(["/DyPyBench/scripts/run-test.sh %s %s %s %s %s" %(proj_name, proj_no, proj_test_folder, copy_folder, args.timeout)
], shell=True, capture_output=True, timeout=args.timeout)
#if output needs to be printed on the console then comment above and uncomment below
"""output = subprocess.run(["/DyPyBench/scripts/run-test.sh %s %s %s %s %s" %(proj_name, proj_no, proj_test_folder, copy_folder, args.timeout)
], shell=True, stderr=subprocess.STDOUT, timeout=args.timeout)"""
if args.dynapyt_instrument:
projects = args.dynapyt_instrument
if 0 in projects:
projects = [x for x in range(1, bench_size + 1)]
for project in projects:
if(project < 0 or project > bench_size):
print("Project number should be between 1 and {}".format(bench_size))
else:
proj_name = str(data[project - 1][1])
proj_no = str(data[project - 1][0])
instr_file = args.dynapyt_file
analysis = args.dynapyt_analysis
with open(instr_file, 'r') as inst_file:
csvReader = csv.reader(inst_file, delimiter=" ")
instr_details = {}
for row in csvReader:
project_name, flag, path = row
project_no = get_project_no(project_name)
if project_no in instr_details.keys():
temp = instr_details[project_no]
temp.append((project_no, flag, path))
instr_details[project_no] = temp
else:
instr_details[project_no] = [(project_no, flag, path)]
if args.save:
output = subprocess.run(["/DyPyBench/scripts/clear-project.sh %s %s" %(proj_name, proj_no)
], shell=True, stdout=open(args.save,'a+',1), stderr=subprocess.STDOUT, timeout=args.timeout)
else:
output = subprocess.run(["/DyPyBench/scripts/clear-project.sh %s %s" %(proj_name, proj_no)
], shell=True, capture_output=True, timeout=args.timeout)
#if output needs to be printed on the console then comment above and uncomment below
"""output = subprocess.run(["/DyPyBench/scripts/clear-project.sh %s %s" %(proj_name, proj_no)
], shell=True, stderr=subprocess.STDOUT, timeout=args.timeout)"""
for line in instr_details[proj_no]:
project_no, flag, path = line
if args.save:
output = subprocess.run(["/DyPyBench/scripts/run-dynapyt-instrumentation.sh %s %s %s %s %s %s" %(proj_name, proj_no, path, analysis, flag, args.timeout)
], shell=True, stdout=open(args.save,'a+',1), stderr=subprocess.STDOUT, timeout=args.timeout)
else:
output = subprocess.run(["/DyPyBench/scripts/run-dynapyt-instrumentation.sh %s %s %s %s %s %s" %(proj_name, proj_no, path, analysis, flag, args.timeout)
], shell=True, capture_output=True, timeout=args.timeout)
#if output needs to be printed on the console then comment above and uncomment below
"""output = subprocess.run(["/DyPyBench/scripts/run-dynapyt-instrumentation.sh %s %s %s %s %s %s" %(proj_name, proj_no, path, analysis, flag, args.timeout)
], shell=True, stderr=subprocess.STDOUT, timeout=args.timeout)"""
if args.dynapyt_run:
projects = args.dynapyt_run
if 0 in projects:
projects = [x for x in range(1, bench_size + 1)]
for project in projects:
if(project < 0 or project > bench_size):
print("Project number should be between 1 and {}".format(bench_size))
else:
proj_name = str(data[project - 1][1])
proj_no = str(data[project - 1][0])
analysis = args.dynapyt_analysis
proj_flags = str(original_data[project - 1][1])
if(proj_flags == "rt"):
proj_test_folder = str(original_data[project - 1][3])
elif(proj_flags == "t"):
proj_test_folder = str(original_data[project - 1][2])
elif(proj_flags == "r"):
proj_test_folder = ""
if args.save:
# os.system("/DyPyBench/scripts/run-dynapyt-analysis.sh %s %s %s %s >> %s 2>&1" %(proj_name, proj_no, analysis, proj_test_folder, args.save))
output = subprocess.run(["/DyPyBench/scripts/run-dynapyt-analysis.sh %s %s %s %s %s" %(proj_name, proj_no, analysis, proj_test_folder, args.timeout)
], shell=True, stdout=open(args.save,'a+',1), stderr=subprocess.STDOUT, timeout=args.timeout)
else:
# os.system("/DyPyBench/scripts/run-dynapyt-analysis.sh %s %s %s %s" %(proj_name, proj_no, analysis, proj_test_folder))
output = subprocess.run(["/DyPyBench/scripts/run-dynapyt-analysis.sh %s %s %s %s %s" %(proj_name, proj_no, analysis, proj_test_folder, args.timeout)
], shell=True, capture_output=True, timeout=args.timeout)
#if output needs to be printed on the console then comment above and uncomment below
"""output = subprocess.run(["/DyPyBench/scripts/run-dynapyt-analysis.sh %s %s %s %s %s" %(proj_name, proj_no, analysis, proj_test_folder, args.timeout)
], shell=True, stderr=subprocess.STDOUT, timeout=args.timeout)"""
if args.lex_instrument:
projects = args.lex_instrument
if 0 in projects:
projects = [x for x in range(1, bench_size + 1)]
for project in projects:
if(project < 0 or project > bench_size):
print("Project number should be between 1 and {}".format(bench_size))
else:
proj_name = str(data[project - 1][1])
proj_no = str(data[project - 1][0])
instr_file = args.lex_file
with open(instr_file, 'r') as inst_file:
csvReader = csv.reader(inst_file, delimiter=" ")
instr_details = {}
for row in csvReader:
project_name, path = row
project_no = get_project_no(project_name)
if project_no in instr_details.keys():
temp = instr_details[project_no]
temp.append((project_no, path))
instr_details[project_no] = temp
else:
instr_details[project_no] = [(project_no, path)]
if args.save:
output = subprocess.run(["/DyPyBench/scripts/clear-project.sh %s %s" %(proj_name, proj_no)
], shell=True, stdout=open(args.save,'a+',1), stderr=subprocess.STDOUT, timeout=args.timeout)
else:
output = subprocess.run(["/DyPyBench/scripts/clear-project.sh %s %s" %(proj_name, proj_no)
], shell=True, capture_output=True, timeout=args.timeout)
#if output needs to be printed on the console then comment above and uncomment below
"""output = subprocess.run(["/DyPyBench/scripts/clear-project.sh %s %s" %(proj_name, proj_no)
], shell=True, stderr=subprocess.STDOUT, timeout=args.timeout)"""
files = []
for line in instr_details[proj_no]:
project_no, file_path = line
files.append(file_path)
path = ' '.join([str(path) for path in files])
if args.save:
output = subprocess.run(["/DyPyBench/scripts/run-lex-instrumentation.sh %s %s %s %s" %(proj_name, proj_no, args.timeout, path)
], shell=True, stdout=open(args.save,'a+',1), stderr=subprocess.STDOUT, timeout=args.timeout)
else:
output = subprocess.run(["/DyPyBench/scripts/run-lex-instrumentation.sh %s %s %s %s" %(proj_name, proj_no, args.timeout, path)
], shell=True, capture_output=True, timeout=args.timeout)
#if output needs to be printed on the console then comment above and uncomment below
"""output = subprocess.run(["/DyPyBench/scripts/run-lex-instrumentation.sh %s %s %s %s" %(proj_name, proj_no, args.timeout, path)
], shell=True, stderr=subprocess.STDOUT, timeout=args.timeout)"""
if args.lex_test:
projects = args.lex_test
if 0 in projects:
projects = [x for x in range(1, bench_size + 1)]
for project in projects:
if(project < 0 or project > bench_size):
print("Project number should be between 1 and {}".format(bench_size))
else:
proj_name = str(data[project - 1][1])
proj_no = str(data[project - 1][0])
proj_flags = str(original_data[project - 1][1])
if(proj_flags == "rt"):
proj_test_folder = str(original_data[project - 1][3])
elif(proj_flags == "t"):
proj_test_folder = str(original_data[project - 1][2])
elif(proj_flags == "r"):
proj_test_folder = ""
if args.save:
print("/DyPyBench/scripts/run-lex-test.sh %s %s %s %s" %(proj_name, proj_no, proj_test_folder, args.timeout))
# os.system("/DyPyBench/scripts/run-test-lexecutor.sh %s %s %s %s >> %s 2>&1" %(proj_name, proj_no, proj_test_folder, args.save))
output = subprocess.run(["/DyPyBench/scripts/run-lex-test.sh %s %s %s %s" %(proj_name, proj_no, proj_test_folder, args.timeout)
], shell=True, stdout=open(args.save,'a+',1), stderr=subprocess.STDOUT, timeout=args.timeout)
else:
# os.system("/DyPyBench/scripts/run-test-lexecutor.sh %s %s %s %s" %(proj_name, proj_no, proj_test_folder))
output = subprocess.run(["/DyPyBench/scripts/run-lex-test.sh %s %s %s %s" %(proj_name, proj_no, proj_test_folder, args.timeout)
], shell=True, capture_output=True, timeout=args.timeout)
#if output needs to be printed on the console then comment above and uncomment below
"""output = subprocess.run(["/DyPyBench/scripts/run-lex-test.sh %s %s %s %s" %(proj_name, proj_no, proj_test_folder, args.timeout)
], shell=True, stderr=subprocess.STDOUT, timeout=args.timeout)"""
if args.pycg:
projects = args.pycg
if 0 in projects:
projects = [x for x in range(1, bench_size + 1)]
for project in projects:
if(project < 0 or project > bench_size):
print("Project number should be between 1 and {}".format(bench_size))
else:
proj_name = str(data[project - 1][1])
proj_no = str(data[project - 1][0])
proj_flags = str(original_data[project - 1][1])
if(proj_flags == "rt"):
proj_test_folder = str(original_data[project - 1][3])
elif(proj_flags == "t"):
proj_test_folder = str(original_data[project - 1][2])
elif(proj_flags == "r"):
proj_test_folder = ""
# add files from test folders to path for entry in pycg
# files = []
# for line in original_data[proj_no]:
# project_no, file_path = line
# files.append(file_path)
# path = ' '.join([str(path) for path in files])
flag = "folder"
if proj_test_folder.__contains__(".py"):
flag = "file"
if args.save:
output = subprocess.run(["/DyPyBench/scripts/run-pycg.sh %s %s %s %s %s" %(proj_name, proj_no, proj_test_folder, flag, args.timeout)
], shell=True, stdout=open(args.save,'a+',1), stderr=subprocess.STDOUT, timeout=args.timeout)
else:
output = subprocess.run(["/DyPyBench/scripts/run-pycg.sh %s %s %s %s %s" %(proj_name, proj_no, proj_test_folder, flag, args.timeout)
], shell=True, capture_output=True, timeout=args.timeout)
#if output needs to be printed on the console then comment above and uncomment below
"""output = subprocess.run(["/DyPyBench/scripts/run-pycg.sh %s %s %s %s %s" %(proj_name, proj_no, proj_test_folder, flag, args.timeout)
], shell=True, stderr=subprocess.STDOUT, timeout=args.timeout)"""