Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Side by Side Diff: appengine/findit/crash/test/findit_for_crash_test.py

Issue 2414523002: [Findit] Reorganizing findit_for_*.py (Closed)
Patch Set: trying to fix some tests Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 from collections import defaultdict
6
7 from common.blame import Region
8 from common.blame import Blame
9 from common.change_log import ChangeLog
10 from common.dependency import Dependency
11 from common.dependency import DependencyRoll
12 from common.git_repository import GitRepository
13 from crash import findit_for_crash
14 from crash.stacktrace import StackFrame
15 from crash.stacktrace import CallStack
16 from crash.stacktrace import Stacktrace
17 from crash.results import MatchResult
18 from crash.test.crash_test_suite import CrashTestSuite
19
20
21 DUMMY_CHANGELOG1 = ChangeLog.FromDict({
22 'author_name': 'r@chromium.org',
23 'message': 'dummy',
24 'committer_email': 'r@chromium.org',
25 'commit_position': 175900,
26 'author_email': 'r@chromium.org',
27 'touched_files': [
28 {
29 'change_type': 'add',
30 'new_path': 'a.cc',
31 'old_path': None,
32 },
33 ],
34 'author_time': 'Thu Mar 31 21:24:43 2016',
35 'committer_time': 'Thu Mar 31 21:28:39 2016',
36 'commit_url':
37 'https://repo.test/+/1',
38 'code_review_url': 'https://codereview.chromium.org/3281',
39 'committer_name': 'example@chromium.org',
40 'revision': '1',
41 'reverted_revision': None
42 })
43
44 DUMMY_CHANGELOG2 = ChangeLog.FromDict({
45 'author_name': 'example@chromium.org',
46 'message': 'dummy',
47 'committer_email': 'example@chromium.org',
48 'commit_position': 175976,
49 'author_email': 'example@chromium.org',
50 'touched_files': [
51 {
52 'change_type': 'add',
53 'new_path': 'f0.cc',
54 'old_path': 'b/f0.cc'
55 },
56 ],
57 'author_time': 'Thu Mar 31 21:24:43 2016',
58 'committer_time': 'Thu Mar 31 21:28:39 2016',
59 'commit_url':
60 'https://repo.test/+/2',
61 'code_review_url': 'https://codereview.chromium.org/3281',
62 'committer_name': 'example@chromium.org',
63 'revision': '2',
64 'reverted_revision': '1'
65 })
66
67 DUMMY_CHANGELOG3 = ChangeLog.FromDict({
68 'author_name': 'e@chromium.org',
69 'message': 'dummy',
70 'committer_email': 'e@chromium.org',
71 'commit_position': 176000,
72 'author_email': 'e@chromium.org',
73 'touched_files': [
74 {
75 'change_type': 'modify',
76 'new_path': 'f.cc',
77 'old_path': 'f.cc'
78 },
79 {
80 'change_type': 'delete',
81 'new_path': None,
82 'old_path': 'f1.cc'
83 },
84 ],
85 'author_time': 'Thu Apr 1 21:24:43 2016',
86 'committer_time': 'Thu Apr 1 21:28:39 2016',
87 'commit_url':
88 'https://repo.test/+/3',
89 'code_review_url': 'https://codereview.chromium.org/3281',
90 'committer_name': 'example@chromium.org',
91 'revision': '3',
92 'reverted_revision': None
93 })
94
95
96 class FinditForCrashTest(CrashTestSuite):
97
98 def testGetDepsInCrashStack(self):
99 crash_stack = CallStack(0)
100 crash_stack.extend([
101 StackFrame(0, 'src/', 'func0', 'f0.cc', 'src/f0.cc', [1]),
102 StackFrame(1, 'src/', 'func1', 'f1.cc', 'src/f1.cc', [2, 3]),
103 StackFrame(1, '', 'func2', 'f2.cc', 'src/f2.cc', [2, 3]),
104 ])
105 crash_deps = {'src/': Dependency('src/', 'https://chromium_repo', '1'),
106 'src/v8/': Dependency('src/v8/', 'https://v8_repo', '2')}
107
108 expected_stack_deps = {'src/': crash_deps['src/']}
109
110 self.assertEqual(
111 findit_for_crash.GetDepsInCrashStack(crash_stack, crash_deps),
112 expected_stack_deps)
113
114 def testGetChangeLogsForFilesGroupedByDeps(self):
115 regression_deps_rolls = {
116 'src/dep1': DependencyRoll('src/dep1', 'https://url_dep1', '7', '9'),
117 'src/dep2': DependencyRoll('src/dep2', 'repo_url', '3', None),
118 'src/': DependencyRoll('src/', ('https://chromium.googlesource.com/'
119 'chromium/src.git'), '4', '5')
120 }
121
122 stack_deps = {
123 'src/': Dependency('src/', 'https://url_src', 'rev1', 'DEPS'),
124 'src/new': Dependency('src/new', 'https://new', 'rev2', 'DEPS'),
125 }
126
127 def _MockGetChangeLogs(*_):
128 return [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2, DUMMY_CHANGELOG3]
129
130 self.mock(GitRepository, 'GetChangeLogs', _MockGetChangeLogs)
131
132 dep_file_to_changelogs, ignore_cls = (
133 findit_for_crash.GetChangeLogsForFilesGroupedByDeps(
134 regression_deps_rolls, stack_deps))
135 dep_file_to_changelogs_json = defaultdict(lambda: defaultdict(list))
136 for dep, file_to_changelogs in dep_file_to_changelogs.iteritems():
137 for file_path, changelogs in file_to_changelogs.iteritems():
138 for changelog in changelogs:
139 dep_file_to_changelogs_json[dep][file_path].append(changelog.ToDict())
140
141 expected_dep_file_to_changelogs_json = {
142 'src/': {
143 'a.cc': [DUMMY_CHANGELOG1.ToDict()],
144 'f.cc': [DUMMY_CHANGELOG3.ToDict()]
145 }
146 }
147 self.assertEqual(dep_file_to_changelogs_json,
148 expected_dep_file_to_changelogs_json)
149 self.assertEqual(ignore_cls, set(['1']))
150
151 def testGetStackInfosForFilesGroupedByDeps(self):
152
153 main_stack = CallStack(0)
154 main_stack.extend(
155 [StackFrame(0, 'src/', 'c(p* &d)', 'a.cc', 'src/a.cc', [177]),
156 StackFrame(1, 'src/', 'd(a* c)', 'a.cc', 'src/a.cc', [227, 228, 229]),
157 StackFrame(2, 'src/v8/', 'e(int)', 'b.cc', 'src/v8/b.cc', [89, 90])])
158
159 low_priority_stack = CallStack(1)
160 low_priority_stack.append(
161 StackFrame(0, 'src/dummy/', 'c(p* &d)', 'd.cc', 'src/dummy/d.cc', [17]))
162
163 stacktrace = Stacktrace()
164 stacktrace.extend([main_stack, low_priority_stack])
165
166 crashed_deps = {'src/': Dependency('src/', 'https//repo', '2'),
167 'src/v8/': Dependency('src/v8', 'https//repo', '1')}
168
169 expected_dep_file_to_stack_infos = {
170 'src/': {
171 'a.cc': [
172 (main_stack[0], 0),
173 (main_stack[1], 0),
174 ],
175 },
176 'src/v8/': {
177 'b.cc': [
178 (main_stack[2], 0),
179 ]
180 }
181 }
182
183 dep_file_to_stack_infos = (
184 findit_for_crash.GetStackInfosForFilesGroupedByDeps(
185 stacktrace, crashed_deps))
186
187 self.assertEqual(len(dep_file_to_stack_infos),
188 len(expected_dep_file_to_stack_infos))
189
190 for dep, file_to_stack_infos in dep_file_to_stack_infos.iteritems():
191 self.assertTrue(dep in expected_dep_file_to_stack_infos)
192 expected_file_to_stack_infos = expected_dep_file_to_stack_infos[dep]
193
194 for file_path, stack_infos in file_to_stack_infos.iteritems():
195 self.assertTrue(file_path in expected_file_to_stack_infos)
196 expected_stack_infos = expected_file_to_stack_infos[file_path]
197
198 self._VerifyTwoStackInfosEqual(stack_infos, expected_stack_infos)
199
200 def testFindMatchResults(self):
201 dep_file_to_changelogs = {
202 'src/': {
203 'a.cc': [
204 DUMMY_CHANGELOG1,
205 ]
206 }
207 }
208
209 dep_file_to_stack_infos = {
210 'src/': {
211 'a.cc': [
212 (StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [1]), 0),
213 (StackFrame(1, 'src/', 'func', 'a.cc', 'src/a.cc', [7]), 0),
214 ],
215 'b.cc': [
216 (StackFrame(2, 'src/', 'func', 'b.cc', 'src/b.cc', [36]), 0),
217 ]
218 }
219 }
220
221 dummy_blame = Blame('9', 'a.cc')
222 dummy_blame.AddRegion(
223 Region(1, 5, '6', 'a', 'a@chromium.org', 'Thu Mar 31 21:24:43 2016'))
224 dummy_blame.AddRegion(
225 Region(6, 10, '1', 'b', 'b@chromium.org', 'Thu Jun 19 12:11:40 2015'))
226
227 def _MockGetBlame(*_):
228 return dummy_blame
229
230 self.mock(GitRepository, 'GetBlame', _MockGetBlame)
231
232 stack_deps = {
233 'src/': Dependency('src/', 'https://url_src', 'rev1', 'DEPS'),
234 }
235
236 expected_match_results = [{
237 'url': 'https://repo.test/+/1',
238 'review_url': 'https://codereview.chromium.org/3281',
239 'revision': '1',
240 'project_path': 'src/',
241 'author': 'r@chromium.org',
242 'time': 'Thu Mar 31 21:24:43 2016',
243 'reasons': None,
244 'confidence': None,
245 'changed_files': None
246 }]
247
248 match_results = findit_for_crash.FindMatchResults(
249 dep_file_to_changelogs, dep_file_to_stack_infos, stack_deps)
250 self.assertEqual([result.ToDict() for result in match_results],
251 expected_match_results)
252
253 def testFindItForCrashNoRegressionRange(self):
254 self.assertEqual(
255 findit_for_crash.FindItForCrash(Stacktrace(), {}, {}, 7),
256 [])
257
258 def testFindItForCrashNoMatchFound(self):
259
260 def _MockFindMatchResults(*_):
261 return []
262
263 self.mock(findit_for_crash, 'FindMatchResults', _MockFindMatchResults)
264
265 regression_deps_rolls = {'src/': DependencyRoll('src/', 'https://repo',
266 '1', '2')}
267 self.assertEqual(findit_for_crash.FindItForCrash(
268 Stacktrace(), regression_deps_rolls, {}, 7), [])
269
270 def testFindItForCrash(self):
271
272 def _MockFindMatchResults(*_):
273 match_result1 = MatchResult(DUMMY_CHANGELOG1, 'src/', '')
274 frame1 = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [1])
275 frame2 = StackFrame(1, 'src/', 'func', 'a.cc', 'src/a.cc', [7])
276 match_result1.file_to_stack_infos = {
277 'a.cc': [(frame1, 0), (frame2, 0)]
278 }
279 match_result1.file_to_analysis_info = {
280 'a.cc': {'min_distance': 0, 'min_distance_frame': frame1}
281 }
282
283 match_result2 = MatchResult(DUMMY_CHANGELOG3, 'src/', '')
284 frame3 = StackFrame(5, 'src/', 'func', 'f.cc', 'src/f.cc', [1])
285 match_result2.file_to_stack_infos = {
286 'f.cc': [(frame3, 0)]
287 }
288 match_result2.file_to_analysis_info = {
289 'a.cc': {'min_distance': 20, 'min_distance_frame': frame3}
290 }
291
292 return [match_result1, match_result2]
293
294 self.mock(findit_for_crash, 'FindMatchResults', _MockFindMatchResults)
295
296 expected_match_results = [
297 {
298 'reasons': [('TopFrameIndex', 1.0, 'Top frame is #0'),
299 ('MinDistance', 1, 'Minimum distance is 0')],
300 'changed_files': [{'info': 'Minimum distance (LOC) 0, frame #0',
301 'blame_url': None, 'file': 'a.cc'}],
302 'time': 'Thu Mar 31 21:24:43 2016',
303 'author': 'r@chromium.org',
304 'url': 'https://repo.test/+/1',
305 'project_path': 'src/',
306 'review_url': 'https://codereview.chromium.org/3281',
307 'confidence': 1.0, 'revision': '1'
308 },
309 ]
310
311 regression_deps_rolls = {'src/': DependencyRoll('src/', 'https://repo',
312 '1', '2')}
313
314 results = findit_for_crash.FindItForCrash(Stacktrace(),
315 regression_deps_rolls, {}, 7)
316 self.assertEqual([result.ToDict() for result in results],
317 expected_match_results)
318
319 def testFinditForCrashFilterZeroConfidentResults(self):
320 def _MockFindMatchResults(*_):
321 match_result1 = MatchResult(DUMMY_CHANGELOG1, 'src/', '')
322 frame1 = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [1])
323 frame2 = StackFrame(1, 'src/', 'func', 'a.cc', 'src/a.cc', [7])
324 match_result1.file_to_stack_infos = {
325 'a.cc': [(frame1, 0), (frame2, 0)]
326 }
327 match_result1.file_to_analysis_info = {
328 'a.cc': {'min_distance': 1, 'min_distance_frame': frame1}
329 }
330
331 match_result2 = MatchResult(DUMMY_CHANGELOG3, 'src/', '')
332 frame3 = StackFrame(15, 'src/', 'func', 'f.cc', 'src/f.cc', [1])
333 match_result2.file_to_stack_infos = {
334 'f.cc': [(frame3, 0)]
335 }
336 match_result2.file_to_analysis_info = {
337 'f.cc': {'min_distance': 20, 'min_distance_frame': frame3}
338 }
339
340 match_result3 = MatchResult(DUMMY_CHANGELOG3, 'src/', '')
341 frame4 = StackFrame(3, 'src/', 'func', 'ff.cc', 'src/ff.cc', [1])
342 match_result3.file_to_stack_infos = {
343 'f.cc': [(frame4, 0)]
344 }
345 match_result3.file_to_analysis_info = {
346 'f.cc': {'min_distance': 60, 'min_distance_frame': frame4}
347 }
348
349 return [match_result1, match_result2, match_result3]
350
351 self.mock(findit_for_crash, 'FindMatchResults', _MockFindMatchResults)
352
353 expected_match_results = [
354 {
355 'author': 'r@chromium.org',
356 'changed_files': [
357 {
358 'blame_url': None,
359 'file': 'a.cc',
360 'info': 'Minimum distance (LOC) 1, frame #0'
361 }
362 ],
363 'confidence': 0.8,
364 'project_path': 'src/',
365 'reasons': [
366 ('TopFrameIndex', 1.0, 'Top frame is #0'),
367 ('MinDistance', 0.8, 'Minimum distance is 1')
368 ],
369 'review_url': 'https://codereview.chromium.org/3281',
370 'revision': '1',
371 'time': 'Thu Mar 31 21:24:43 2016',
372 'url': 'https://repo.test/+/1'
373 }
374 ]
375
376 regression_deps_rolls = {'src/': DependencyRoll('src/', 'https://repo',
377 '1', '2')}
378
379 results = findit_for_crash.FindItForCrash(Stacktrace(),
380 regression_deps_rolls, {}, 7)
381
382 self.assertEqual([result.ToDict() for result in results],
383 expected_match_results)
384
385 def testFinditForCrashAllMatchResultsWithZeroConfidences(self):
386 def _MockFindMatchResults(*_):
387 match_result1 = MatchResult(DUMMY_CHANGELOG1, 'src/', '')
388 frame1 = StackFrame(20, 'src/', '', 'func', 'a.cc', [1])
389 frame2 = StackFrame(21, 'src/', '', 'func', 'a.cc', [7])
390 match_result1.file_to_stack_infos = {
391 'a.cc': [(frame1, 0), (frame2, 0)]
392 }
393 match_result1.file_to_analysis_info = {
394 'a.cc': {'min_distance': 1, 'min_distance_frame': frame1}
395 }
396
397 match_result2 = MatchResult(DUMMY_CHANGELOG3, 'src/', '')
398 frame3 = StackFrame(15, 'src/', '', 'func', 'f.cc', [1])
399 match_result2.file_to_stack_infos = {
400 'f.cc': [(frame3, 0)]
401 }
402 match_result2.min_distance = 20
403 match_result2.file_to_analysis_info = {
404 'f.cc': {'min_distance': 20, 'min_distance_frame': frame3}
405 }
406
407 return [match_result1, match_result2]
408
409 self.mock(findit_for_crash, 'FindMatchResults', _MockFindMatchResults)
410
411 regression_deps_rolls = {'src/': DependencyRoll('src/', 'https://repo',
412 '1', '2')}
413
414 self.assertEqual(findit_for_crash.FindItForCrash(
415 Stacktrace(), regression_deps_rolls, {}, 7), [])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698