-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpeer.py
182 lines (155 loc) · 6.03 KB
/
peer.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
import os, copy, glob, re
import parsing_utils
from constant import *
from pinput import *
PROJECT = pinput["project"]
def testresult_files():
return glob.glob(os.path.join(TESTRESULT_DIR.format(PROJECT), TR_PATTERN))
def splited_tests(file):
return [x.strip("\n").split("\t") for x in open(file)]
def pf_all():
# pf(failed test t) is determined by #files t failed on
freq = {}
failures, misconfs = parsing_utils.failure_map()
for img in failures:
for t, misconfs in failures[img][C_EFFECTIVE].items():
if t not in freq:
freq[t] = set()
freq[t].add(img)
# remove each file from its failure frequency
pf = {}
for file in testresult_files():
tests = [t[0] for t in splited_tests(file)]
img = re.findall(TR_REGEX, file)[0]
pf[img] = {}
for t in tests:
pf[img][t] = set()
if t in freq:
pf[img][t] = freq[t] - set([img])
return pf
def pf_dp():
# pf(failed test t) is determined by all params in the change where t failed on
# load peer config failure frequency
freq = {}
failures, misconfs = parsing_utils.failure_map()
for img in failures:
for t, misconfs in failures[img][C_EFFECTIVE].items():
params = set([k for k in parsing_utils.get_file_params(img).keys()])
if t not in freq:
freq[t] = {}
# failed test -> param in change -> change that failed the test
for p in params:
if p not in freq[t]:
freq[t][p] = set()
freq[t][p].add(img)
return build_pf(freq)
def pf_pc():
# pf(failed test t) is determined by all param get by t in the change where t failed on
readparams = parsing_utils.param_coverage(change_aware=False, use_pid=False)
# load peer config failure frequency
freq = {}
failures, misconfs = parsing_utils.failure_map()
for img in failures:
for t, misconfs in failures[img][C_EFFECTIVE].items():
params = set([k for k in parsing_utils.get_file_params(img).keys()])
if t not in freq:
freq[t] = {}
# failed test -> param get (in change) -> changes where t fails
for p in params.intersection(readparams[t]):
if p not in freq[t]:
freq[t][p] = set()
freq[t][p].add(img)
return build_pf(freq)
def pf_rc():
"""
pf(failed test t) is determined by the root cause param in the change where t fails
root cause is localized through manual inspection
"""
freq = {}
failures, misconfs = parsing_utils.failure_map()
for img in failures:
for t, rootcauses in failures[img][C_EFFECTIVE].items():
if t not in freq:
freq[t] = {}
for p in rootcauses:
if p not in freq[t]:
freq[t][p] = set()
freq[t][p].add(img)
return build_pf(freq)
def build_pf(freq):
# remove each file from its failure frequency
pf = {}
for file in testresult_files():
tests = [t[0] for t in splited_tests(file)]
img = re.findall(TR_REGEX, file)[0]
params = set([k for k in parsing_utils.get_file_params(img).keys()])
pf[img] = {}
for t in tests:
pf[img][t] = {}
if t in freq:
# ignore params not in the current change
for p in params.intersection(freq[t].keys()):
# exclude current change from its own peer failures
pf[img][t][p] = freq[t][p] - set([img])
# convert to failed test -> #peer failures
for img in pf:
for t in pf[img]:
failed_imgs = set()
for p in pf[img][t]:
failed_imgs = failed_imgs.union(pf[img][t][p])
# pf[img][t] = len(failed_imgs)
pf[img][t] = failed_imgs
return pf
def pf_pcc():
# pf(failed test t) is determined by all param get by t in the change where t failed on
readparams = parsing_utils.param_coverage(change_aware=False, use_pid=False)
# load peer config failure frequency
freq = {}
failures, misconfs = parsing_utils.failure_map()
for img in failures:
for t, misconfs in failures[img][C_EFFECTIVE].items():
params = set([k for k in parsing_utils.get_file_params(img).keys()])
if t not in freq:
freq[t] = {}
# failed test -> param get (in change) -> changes where t fails
for p in params.intersection(readparams[t]):
if p not in freq[t]:
freq[t][p] = set()
freq[t][p].add(img)
return build_pf_cov(freq)
def pf_rcc():
"""
pf(failed test t) is determined by the root cause param in the change where t fails
root cause is localized through manual inspection
"""
freq = {}
failures, misconfs = parsing_utils.failure_map()
for img in failures:
for t, rootcauses in failures[img][C_EFFECTIVE].items():
if t not in freq:
freq[t] = {}
for p in rootcauses:
if p not in freq[t]:
freq[t][p] = set()
freq[t][p].add(img)
return build_pf_cov(freq)
def build_pf_cov(freq):
# remove each file from its failure frequency
pf = {}
for file in testresult_files():
tests = [t[0] for t in splited_tests(file)]
img = re.findall(TR_REGEX, file)[0]
params = set([k for k in parsing_utils.get_file_params(img).keys()])
pf[img] = {}
for t in tests:
pf[img][t] = {}
if t in freq:
# ignore params not in the current change
for p in params.intersection(freq[t].keys()):
# exclude current change from its own peer failures
pf[img][t][p] = freq[t][p] - set([img])
# convert to failed test -> #peer failures
for img in pf:
for t in pf[img]:
pf[img][t] = set([x for x in pf[img][t].keys()])
return pf