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

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

Issue 2414523002: [Findit] Reorganizing findit_for_*.py (Closed)
Patch Set: Fixing call to ScheduleNewAnalysis in handlers/crash/crash_handler.py 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
1 # Copyright 2016 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from common import chromium_deps 5 from common import chromium_deps
6 from common.dependency import DependencyRoll 6 from common.dependency import DependencyRoll
7 from crash import changelist_classifier
7 from crash import detect_regression_range 8 from crash import detect_regression_range
8 from crash import findit_for_chromecrash 9 from crash import findit
10 from crash.findit_for_chromecrash import FinditForChromeCrash
9 from crash import chromecrash_parser 11 from crash import chromecrash_parser
10 from crash import findit_for_crash
11 from crash.component_classifier import ComponentClassifier 12 from crash.component_classifier import ComponentClassifier
12 from crash.project_classifier import ProjectClassifier 13 from crash.project_classifier import ProjectClassifier
14 from crash.changelist_classifier import ChangelistClassifier
13 from crash.results import MatchResult 15 from crash.results import MatchResult
14 from crash.stacktrace import CallStack 16 from crash.stacktrace import CallStack
15 from crash.stacktrace import Stacktrace 17 from crash.stacktrace import Stacktrace
16 from crash.test.crash_testcase import CrashTestCase 18 from crash.test.crash_testcase import CrashTestCase
19 from model.crash.crash_analysis import CrashAnalysis
17 20
18 21
19 class FinditForChromeCrashTest(CrashTestCase): 22 class FinditForChromeCrashTest(CrashTestCase):
20 23
21 def testFindCulpritForChromeCrashEmptyStacktrace(self): 24 def testFindCulpritForChromeCrashEmptyStacktrace(self):
22 def _MockGetChromeDependency(*_): 25 self.mock(chromium_deps, 'GetChromeDependency', lambda *_: {})
23 return {} 26 self.mock(chromecrash_parser.ChromeCrashParser, 'Parse',
24 27 lambda *_: Stacktrace())
25 def _MockParse(*_):
26 return Stacktrace()
27
28 self.mock(chromium_deps, 'GetChromeDependency', _MockGetChromeDependency)
29 self.mock(chromecrash_parser.ChromeCrashParser, 'Parse', _MockParse)
30 28
31 expected_results = {'found': False} 29 expected_results = {'found': False}
32 expected_tag = {'found_suspects': False, 30 expected_tag = {'found_suspects': False,
33 'has_regression_range': False} 31 'has_regression_range': False}
34 32
35 results, tag = findit_for_chromecrash.FinditForChromeCrash().FindCulprit( 33 analysis = CrashAnalysis()
36 'signature', 'win', 'frame1\nframe2', '50.0.1234.0', 34 analysis.signature = 'signature'
37 [{'chrome_version': '50.0.1234.0', 'cpm': 0.6}]).ToDicts() 35 analysis.platform = 'win'
36 analysis.stack_trace = 'frame1\nframe2'
37 analysis.crashed_version = '50.0.1234.0'
38 analysis.historical_metadata = [{'chrome_version': '51.0.1234.0', 'cpm': 0.6 }]
39 results, tag = FinditForChromeCrash().FindCulprit(analysis).ToDicts()
38 40
39 self.assertEqual(expected_results, results) 41 self.assertDictEqual(expected_results, results)
40 self.assertEqual(expected_tag, tag) 42 self.assertDictEqual(expected_tag, tag)
41 43
42 def testFindCulpritForChromeCrash(self): 44 def testFindCulpritForChromeCrash(self):
43 def _MockGetChromeDependency(*_): 45 self.mock(chromium_deps, 'GetChromeDependency', lambda *_: {})
44 return {}
45 46
46 def _MockParse(*_): 47 self.mock(chromecrash_parser.ChromeCrashParser, 'Parse',
47 stack = Stacktrace() 48 lambda *_: Stacktrace([CallStack(0)]))
48 stack.append(CallStack(0))
49 return stack
50 49
51 def _MockGetDEPSRollsDict(*_): 50 self.mock(detect_regression_range, 'DetectRegressionRange',
52 return {'src/': DependencyRoll('src/', 'https://repo', '1', '2'), 51 lambda historic_metadata:
53 'src/add': DependencyRoll('src/add', 'https://repo1', None, '2'), 52 ('50.0.1233.0', '50.0.1234.0') if historic_metadata else None)
54 'src/delete': DependencyRoll('src/delete', 'https://repo2', 53
55 '2', None)} 54 self.mock(chromium_deps, 'GetDEPSRollsDict', lambda *_: {
55 'src/': DependencyRoll('src/', 'https://repo', '1', '2'),
56 'src/add': DependencyRoll('src/add', 'https://repo1', None, '2'),
57 'src/delete': DependencyRoll('src/delete', 'https://repo2', '2', None)
58 })
56 59
57 dummy_match_result = MatchResult(self.GetDummyChangeLog(), 'src/') 60 dummy_match_result = MatchResult(self.GetDummyChangeLog(), 'src/')
58 def _MockFindItForCrash(*args): 61 self.mock(changelist_classifier.ChangelistClassifier, '__call__',
59 regression_deps_rolls = args[1] 62 lambda _self, regression_deps_rolls, *args:
60 if regression_deps_rolls: 63 [dummy_match_result] if regression_deps_rolls else [])
61 return [dummy_match_result]
62 64
63 return [] 65 self.mock(ComponentClassifier, 'Classify', lambda *_: [])
64 66 self.mock(ProjectClassifier, 'Classify', lambda *_: '')
65 def _MockComponentClassify(*_):
66 return []
67
68 def _MockProjectClassify(*_):
69 return ''
70
71 self.mock(chromium_deps, 'GetChromeDependency', _MockGetChromeDependency)
72 self.mock(chromecrash_parser.ChromeCrashParser, 'Parse', _MockParse)
73 self.mock(chromium_deps, 'GetDEPSRollsDict', _MockGetDEPSRollsDict)
74 self.mock(findit_for_crash, 'FindItForCrash', _MockFindItForCrash)
75
76 self.mock(ComponentClassifier, 'Classify', _MockComponentClassify)
77 self.mock(ProjectClassifier, 'Classify', _MockProjectClassify)
78 67
79 expected_results = {'found': False} 68 expected_results = {'found': False}
80 expected_tag = {'found_suspects': False} 69 expected_tag = {'found_suspects': False}
81 70
82 results, tag = findit_for_chromecrash.FinditForChromeCrash().FindCulprit( 71 analysis = CrashAnalysis()
83 'signature', 'win', 'frame1\nframe2', '50.0.1234.0', 72 analysis.signature = 'signature'
84 ['50.0.1233.0', '50.0.1234.0']).ToDicts() 73 analysis.platform = 'win'
74 analysis.stack_trace = 'frame1\nframe2'
75 analysis.crashed_version = '50.0.1234.0'
76 analysis.historical_metadata = ['50.0.1233.0', '50.0.1234.0']
Sharu Jiang 2016/10/19 00:20:06 This should be analysis.regression_range = ['50.0.
wrengr 2016/10/19 18:05:16 Done. Thanks
77 results, tag = FinditForChromeCrash().FindCulprit(analysis).ToDicts()
85 78
86 # TODO(wrengr): compare the Culprit object directly to these values, 79 # TODO(wrengr): compare the Culprit object directly to these values,
87 # rather than converting to dicts first. We can make a different 80 # rather than converting to dicts first. We can make a different
88 # unit test for comparing the dicts, if we actually need/want to. 81 # unit test for comparing the dicts, if we actually need/want to.
89 expected_results = { 82 expected_results = {
90 'found': True, 83 'found': True,
91 'suspected_project': '', 84 'suspected_project': '',
92 'suspected_components': [], 85 'suspected_components': [],
93 'suspected_cls': [dummy_match_result.ToDict()], 86 'suspected_cls': [dummy_match_result.ToDict()],
94 'regression_range': ['50.0.1233.0', '50.0.1234.0'] 87 'regression_range': ['50.0.1233.0', '50.0.1234.0']
95 } 88 }
96 expected_tag = { 89 expected_tag = {
97 'found_suspects': True, 90 'found_suspects': True,
98 'found_project': False, 91 'found_project': False,
99 'found_components': False, 92 'found_components': False,
100 'has_regression_range': True, 93 'has_regression_range': True,
101 'solution': 'core_algorithm', 94 'solution': 'core_algorithm',
102 } 95 }
103 96
104 self.assertEqual(expected_results, results) 97 # TODO(wrengr): our _MockDetectRegressionRange isn't working here...
105 self.assertEqual(expected_tag, tag) 98 self.assertDictEqual(expected_results, results)
wrengr 2016/10/18 23:28:10 The mocking of DetectRegressionRange doesn't work
99 self.assertDictEqual(expected_tag, tag)
106 100
107 results, tag = findit_for_chromecrash.FinditForChromeCrash().FindCulprit( 101 # TODO(wrengr): why isn't this one broken out as a separate unittest?
108 'signature', 'win', 'frame1\nframe2', '50.0.1234.0', None).ToDicts() 102 analysis = CrashAnalysis()
103 analysis.signature = 'signature'
104 analysis.platform = 'win'
105 analysis.stack_trace = 'frame1\nframe2'
106 analysis.crashed_version = '50.0.1234.0'
107 analysis.historical_metadata = []
108 results, tag = FinditForChromeCrash().FindCulprit(analysis).ToDicts()
109 109
110 expected_results = { 110 expected_results = {
111 'found': False, 111 'found': False,
112 'suspected_project': '', 112 'suspected_project': '',
113 'suspected_components': [], 113 'suspected_components': [],
114 'suspected_cls': [], 114 'suspected_cls': [],
115 'regression_range': None 115 'regression_range': None
116 } 116 }
117 expected_tag = { 117 expected_tag = {
118 'found_suspects': False, 118 'found_suspects': False,
119 'found_project': False, 119 'found_project': False,
120 'found_components': False, 120 'found_components': False,
121 'has_regression_range': False, 121 'has_regression_range': False,
122 'solution': 'core_algorithm', 122 'solution': 'core_algorithm',
123 } 123 }
124 124
125 self.assertEqual(expected_results, results) 125 self.assertDictEqual(expected_results, results)
126 self.assertEqual(expected_tag, tag) 126 self.assertDictEqual(expected_tag, tag)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698