-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexec_rerun.py
More file actions
executable file
·125 lines (104 loc) · 3.89 KB
/
Copy pathexec_rerun.py
File metadata and controls
executable file
·125 lines (104 loc) · 3.89 KB
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
# used to run ReRun and save the results in `results/{NAME_APP}_rerun.csv` format
from sys import argv
import random
import subprocess
from glob import glob
import os
import re
import copy
import time
REAL_DIR = glob(os.getcwd())[0]
OUT_DIR = REAL_DIR + '/reruns/'
shouldprint = False
showln = False
testsFound = {}
def save_fail_tests(dictFail):
os.chdir(REAL_DIR)
with open(f'results/{NAME_APP}_rerun.csv', 'w') as f:
f.write('name, count\n')
for test in dictFail:
f.write('%s, %d\n' % (test, dictFail[test]))
def parserTests(path):
testsFails = {}
allTests = {}
# change to dir
files = glob(path + f'/out.*.txt') # all log files
for file in files:
with open(file, "r") as reader:
ln = 0
for line in reader:
lastName = ''
ln = ln + 1
stripped_line = line.strip()
if stripped_line == 'INSTRUMENTATION_RESULT: stream=': # if is log for tests fails
count = 1
for line in reader:
ln = ln + 1
stripped_line = line.strip()
if stripped_line.startswith('INS'):
break # leaves the inner loop
failLine = f'{count}) '
if stripped_line.startswith(failLine):
count += 1
if showln:
print('line %d -> fail: %s' %
(ln, stripped_line))
test = line[3:] # retire the '1) '
test = test.strip() # for cases '10) '
position = test.index('(')
# remove the package for test name
test = test[:position]
if shouldprint:
print(f'new tst: {test}. line: {ln}')
try:
testsFails[test] += 1
except KeyError as _:
testsFails[test] = 1
# if is the name of test
if stripped_line.startswith('INSTRUMENTATION_STATUS: test='):
name = stripped_line[29:] # get only name
if name is not lastName: # for some logs followed in the same test name
lastName = name
allTests[name] = 1
return allTests, testsFails # now, de allTests is de passTests
# cont is the name of outuput file-> out.{count}.txt
def parserData(output, path):
global testsFound
path = OUT_DIR + path + '/' + f'{output}'
os.chdir(path)
if shouldprint:
print(path)
dictPass, dictFail = parserTests(path)
for test in dictFail.keys():
try:
testsFound[test] += dictFail[test]
except KeyError as _:
testsFound[test] = dictFail[test]
for t in testsFound:
print('%s - %d' % (t, testsFound[t]))
print('\n')
save_fail_tests(testsFound)
def runTests(folder, cont):
os.chdir(REAL_DIR)
test = f'./exec_rerun.sh {folder} {cont} {NAME_APP}'
print("runing %s" % test)
process = subprocess.Popen(test, stdout=subprocess.PIPE, shell=True)
stdout = process.communicate()[0].decode("utf-8")
if shouldprint:
print(stdout)
def main():
i = 4
for cont in range(13, 51): # out.{cont}.txt
print('-------------> RERUN in loop %s <-------------------' % (cont))
runTests(i, cont)
parserData(i, NAME_APP)
if __name__ == "__main__":
if len(argv) == 2:
#NUMBER_RANGE = int(argv[1])
NAME_APP = argv[1]
print('number of repetitions is 50\nname app is %s' %
(NAME_APP))
main()
else:
print("Error: please read the README.md")
exit(1)