-
Notifications
You must be signed in to change notification settings - Fork 308
/
Copy pathtest_bug_features.py
396 lines (339 loc) · 14.7 KB
/
test_bug_features.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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
import json
import os
import pytest
from bugbug.bug_features import (
BlockedBugsNumber,
BugExtractor,
BugReporter,
BugTypes,
CommentCount,
CommentLength,
Component,
DeltaNightlyRequestMerge,
FilePaths,
HasCrashSignature,
HasCVEInAlias,
HasGithubURL,
HasRegressionRange,
HasSTR,
HasURL,
HasW3CURL,
IsCoverityIssue,
IsMozillian,
Keywords,
Landings,
Patches,
Product,
Severity,
Whiteboard,
)
from bugbug.feature_cleanup import fileref, url
@pytest.fixture
def read(get_fixture_path):
def _read(path, feature_extractor_class, expected_results):
feature_extractor = feature_extractor_class()
path = get_fixture_path(os.path.join("bug_features", path))
with open(path, "r") as f:
results = (feature_extractor(json.loads(line)) for line in f)
for result, expected_result in zip(results, expected_results):
assert result == expected_result
return _read
def test_has_str(read):
read("has_str.json", HasSTR, ["yes", None, "no"])
def test_has_regression_range(read):
read("has_regression_range.json", HasRegressionRange, ["yes", None])
def test_has_crash_signature(read):
read("has_crash_signature.json", HasCrashSignature, [False, True])
def test_keywords(read):
read(
"keywords.json",
Keywords,
[
["crash", "intermittent-failure", "stale-bug"],
["bulk-close-intermittents", "crash", "intermittent-failure"],
],
)
def test_severity(read):
read("severity.json", Severity, ["major", "normal"])
def test_is_coverity_issue(read):
read("is_coverity_issue.json", IsCoverityIssue, [False, True])
def test_has_url(read):
read("has_url.json", HasURL, [True, False])
def test_has_w3c_url(read):
read("has_w3c_url.json", HasW3CURL, [True, False])
def test_has_github_url(read):
read("has_github_url.json", HasGithubURL, [True, False])
def test_whiteboard(read):
read(
"whiteboard.json",
Whiteboard,
[
["memshrink", "platform-rel-facebook"],
[],
["inj+", "av:quick heal", "av"],
["av:quick heal", "regressed sept 6th", "dll version is 3.0.1.*", "av"],
["av:quick heal", "inj+", "av"],
["av:quick heal", "inj+", "av"],
["inj+", "av:quick heal", "av"],
["inj+", "av:quick heal", "av"],
["inj+", "ux", "av:quick heal", "qf", "av"],
],
)
def test_patches(read):
read("patches.json", Patches, [1, 0])
def test_landings(read):
read("landings.json", Landings, [2, 1])
def test_product(read):
read("product.json", Product, ["Core", "Firefox for Android"])
def test_component(read):
read("component.json", Component, ["Graphics", "CSS Parsing and Computation"])
def test_is_mozillian(read):
read("is_mozillian.json", IsMozillian, [False, True, True])
def test_blocked_bugs_number(read):
read("blocked_bugs_number.json", BlockedBugsNumber, [2, 0])
def test_bug_reporter(read):
read(
"bug_reporter.json",
BugReporter,
[
],
)
def test_has_cve_in_alias(read):
read("has_cve_in_alias.json", HasCVEInAlias, [True, False])
def test_comment_count(read):
read("comment_count.json", CommentCount, [4, 28])
def test_comment_length(read):
read("comment_length.json", CommentLength, [566, 5291])
def test_delta_nightly_request_merge(read):
read(
"nightly_uplift.json",
DeltaNightlyRequestMerge,
[
pytest.approx(6.431805555555556),
pytest.approx(0.8732638888888888),
None,
None,
],
)
def test_BugExtractor():
BugExtractor([HasSTR(), HasURL()], [fileref(), url()])
with pytest.raises(AssertionError):
BugExtractor([HasSTR(), HasSTR()], [fileref(), url()])
with pytest.raises(AssertionError):
BugExtractor([HasSTR(), HasURL()], [fileref(), fileref()])
def test_BugTypes(read) -> None:
read(
"bug_types.json",
BugTypes,
[["performance"], ["memory"], ["power"], ["security"], ["crash"]],
)
def test_FilePaths(read):
inline_data = [
{
"summary": "<nsFrame.cpp> cleanup",
"comments": [
{
"text": "Fix for\n{{ <http://tinderbox.mozilla.org/SeaMonkey/warn1082809200.7591.html>\nanthonyd (2 warnings)\n1.\tlayout/html/base/src/nsFrame.cpp:3879 (See build log excerpt)\n\t`nsIFrame*thisBlock' might be used uninitialized in this function\n2.\tlayout/html/base/src/nsFrame.cpp:3908 (See build log excerpt)\n\t`nsIFrame*thisBlock' might be used uninitialized in this function\n}} (NB: lines should be lines - 2, due to checkin \"in progress\")\nwill be included."
}
],
},
{
"summary": "Spidermonkey regression causes treehydra trunk to fail 6 tests",
"comments": [
{
"text": 'Today I\'m trying to get callgraph stuff hooked into dxr, and I\'m unable to get a working treehydra. I\'ve updated tried updating just dehydra, then I updated gcc w/plugins using the new stuff in the patch queue, and it doesn\'t matter. Running make check_treehydra fails like this:\n\nTest Failure: \n Test command: /var/www/html/dxr/tools/gcc-dehydra/installed/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.3.0/cc1plus -quiet -fplugin=../gcc_treehydra.so -o /dev/null -fplugin-arg=test_locks_bad3.js locks_bad3.cc\n Failure msg: Expected \'locks_bad3.cc:10: error: precondition not met\' in error output; not found. stderr:../libs/treehydra.js:12: JS Exception: No case_val in this lazy object\n:0: #0: Error("No case_val in this lazy object")\n../libs/treehydra.js:12: #1: unhandledLazyProperty("case_val")\n../libs/unstable/esp.js:481: #2: ()\n./esp_lock.js:41: #3: process_tree([object GCCNode])\n\nTest Failure: \n Test command: /var/www/html/dxr/tools/gcc-dehydra/installed/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.3.0/cc1plus -quiet -fplugin=../gcc_treehydra.so -o /dev/null -fplugin-arg=test_locks_good.js locks_good.cc\n Failure msg: Expected no error output, got error output :../libs/treehydra.js:12: JS Exception: No case_val in this lazy object\n:0: #0: Error("No case_val in this lazy object")\n../libs/treehydra.js:12: #1: unhandledLazyProperty("case_val")\n../libs/unstable/esp.js:481: #2: ()\n./esp_lock.js:41: #3: process_tree([object GCCNode])\n\nTest Failure: \n Test command: /var/www/html/dxr/tools/gcc-dehydra/installed/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.3.0/cc1plus -quiet -fplugin=../gcc_treehydra.so -o /dev/null -fplugin-arg=test_locks_good2.js locks_good2.cc\n Failure msg: Expected no error output, got error output :../libs/treehydra.js:12: JS Exception: No case_val in this lazy object\n:0: #0: Error("No case_val in this lazy object")\n../libs/treehydra.js:12: #1: unhandledLazyProperty("case_val")\n../libs/unstable/esp.js:481: #2: ()\n./esp_lock.js:41: #3: process_tree([object GCCNode])\n\nTest Failure: \n Test command: /var/www/html/dxr/tools/gcc-dehydra/installed/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.3.0/cc1plus -quiet -fplugin=../gcc_treehydra.so -o /dev/null -fplugin-arg=test_locks_bad4.js locks_bad4.cc\n Failure msg: Expected \'locks_bad4.cc:13: error: precondition not met\' in error output; not found. stderr:../libs/treehydra.js:12: JS Exception: No case_val in this lazy object\n:0: #0: Error("No case_val in this lazy object")\n../libs/treehydra.js:12: #1: unhandledLazyProperty("case_val")\n../libs/unstable/esp.js:481: #2: ()\n./esp_lock.js:41: #3: process_tree([object GCCNode])\n\nTest Failure: \n Test command: /var/www/html/dxr/tools/gcc-dehydra/installed/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.3.0/cc1plus -quiet -fplugin=../gcc_treehydra.so -o /dev/null -fplugin-arg=test_locks_bad2.js locks_bad2.cc\n Failure msg: Expected \'locks_bad2.cc:12: error: precondition not met\' in error output; not found. stderr:../libs/treehydra.js:12: JS Exception: No case_val in this lazy object\n:0: #0: Error("No case_val in this lazy object")\n../libs/treehydra.js:12: #1: unhandledLazyProperty("case_val")\n../libs/unstable/esp.js:481: #2: ()\n./esp_lock.js:41: #3: process_tree([object GCCNode])\n\nTest Failure: \n Test command: /var/www/html/dxr/tools/gcc-dehydra/installed/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.3.0/cc1plus -quiet -fplugin=../gcc_treehydra.so -o /dev/null -fplugin-arg=test_locks_bad1.js locks_bad1.cc\n Failure msg: Expected \'locks_bad1.cc:11: error: precondition not met\' in error output; not found. stderr:../libs/treehydra.js:12: JS Exception: No case_val in this lazy object\n:0: #0: Error("No case_val in this lazy object")\n../libs/treehydra.js:12: #1: unhandledLazyProperty("case_val")\n../libs/unstable/esp.js:481: #2: ()\n./esp_lock.js:41: #3: process_tree([object GCCNode])\n\n\nUnit Test Suite Summary:\n 32 passed\n 6 failed\n 0 error(s)\nmake[1]: *** [check_treehydra] Error 1\nmake[1]: Leaving directory `/var/www/html/dxr/tools/gcc-dehydra/dehydra/test\'\nmake: *** [check] Error 2'
}
],
},
]
expected_results = [
[
"nsFrame.cpp",
"layout",
"html",
"base",
"src",
"nsFrame.cpp",
"layout/html/base/src/nsFrame.cpp",
"html/base/src/nsFrame.cpp",
"base/src/nsFrame.cpp",
"src/nsFrame.cpp",
"nsFrame.cpp",
"layout",
"html",
"base",
"src",
"nsFrame.cpp",
"layout/html/base/src/nsFrame.cpp",
"html/base/src/nsFrame.cpp",
"base/src/nsFrame.cpp",
"src/nsFrame.cpp",
"nsFrame.cpp",
],
[
"gcc_treehydra.so",
"/gcc_treehydra.so",
"gcc_treehydra.so",
"test_locks_bad3.js",
"locks_bad3.cc",
"locks_bad3.cc",
"libs",
"treehydra.js",
"/libs/treehydra.js",
"libs/treehydra.js",
"treehydra.js",
"libs",
"treehydra.js",
"/libs/treehydra.js",
"libs/treehydra.js",
"treehydra.js",
"libs",
"unstable",
"esp.js",
"/libs/unstable/esp.js",
"libs/unstable/esp.js",
"unstable/esp.js",
"esp.js",
"esp_lock.js",
"/esp_lock.js",
"esp_lock.js",
"gcc_treehydra.so",
"/gcc_treehydra.so",
"gcc_treehydra.so",
"test_locks_good.js",
"locks_good.cc",
"libs",
"treehydra.js",
"/libs/treehydra.js",
"libs/treehydra.js",
"treehydra.js",
"libs",
"treehydra.js",
"/libs/treehydra.js",
"libs/treehydra.js",
"treehydra.js",
"libs",
"unstable",
"esp.js",
"/libs/unstable/esp.js",
"libs/unstable/esp.js",
"unstable/esp.js",
"esp.js",
"esp_lock.js",
"/esp_lock.js",
"esp_lock.js",
"gcc_treehydra.so",
"/gcc_treehydra.so",
"gcc_treehydra.so",
"test_locks_good2.js",
"locks_good2.cc",
"libs",
"treehydra.js",
"/libs/treehydra.js",
"libs/treehydra.js",
"treehydra.js",
"libs",
"treehydra.js",
"/libs/treehydra.js",
"libs/treehydra.js",
"treehydra.js",
"libs",
"unstable",
"esp.js",
"/libs/unstable/esp.js",
"libs/unstable/esp.js",
"unstable/esp.js",
"esp.js",
"esp_lock.js",
"/esp_lock.js",
"esp_lock.js",
"gcc_treehydra.so",
"/gcc_treehydra.so",
"gcc_treehydra.so",
"test_locks_bad4.js",
"locks_bad4.cc",
"locks_bad4.cc",
"libs",
"treehydra.js",
"/libs/treehydra.js",
"libs/treehydra.js",
"treehydra.js",
"libs",
"treehydra.js",
"/libs/treehydra.js",
"libs/treehydra.js",
"treehydra.js",
"libs",
"unstable",
"esp.js",
"/libs/unstable/esp.js",
"libs/unstable/esp.js",
"unstable/esp.js",
"esp.js",
"esp_lock.js",
"/esp_lock.js",
"esp_lock.js",
"gcc_treehydra.so",
"/gcc_treehydra.so",
"gcc_treehydra.so",
"test_locks_bad2.js",
"locks_bad2.cc",
"locks_bad2.cc",
"libs",
"treehydra.js",
"/libs/treehydra.js",
"libs/treehydra.js",
"treehydra.js",
"libs",
"treehydra.js",
"/libs/treehydra.js",
"libs/treehydra.js",
"treehydra.js",
"libs",
"unstable",
"esp.js",
"/libs/unstable/esp.js",
"libs/unstable/esp.js",
"unstable/esp.js",
"esp.js",
"esp_lock.js",
"/esp_lock.js",
"esp_lock.js",
"gcc_treehydra.so",
"/gcc_treehydra.so",
"gcc_treehydra.so",
"test_locks_bad1.js",
"locks_bad1.cc",
"locks_bad1.cc",
"libs",
"treehydra.js",
"/libs/treehydra.js",
"libs/treehydra.js",
"treehydra.js",
"libs",
"treehydra.js",
"/libs/treehydra.js",
"libs/treehydra.js",
"treehydra.js",
"libs",
"unstable",
"esp.js",
"/libs/unstable/esp.js",
"libs/unstable/esp.js",
"unstable/esp.js",
"esp.js",
"esp_lock.js",
"/esp_lock.js",
"esp_lock.js",
],
]
feature_extractor = FilePaths()
results = [feature_extractor(item) for item in inline_data]
assert results == expected_results