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

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

Issue 2588513002: [Predator] renamed "Result" to "Suspect" (Closed)
Patch Set: Removing redundant import Created 4 years 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
« no previous file with comments | « appengine/findit/crash/test/results_test.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 crash.results import AnalysisInfo
6 from crash.results import MatchResult
7 from crash.results import MatchResults
8 from crash.results import Result
9 from crash.results import StackInfo
10 from crash.stacktrace import StackFrame 5 from crash.stacktrace import StackFrame
6 from crash.suspect import AnalysisInfo
7 from crash.suspect import StackInfo
8 from crash.suspect import Suspect
9 from crash.suspect import Suspects
10 from crash.suspect import _UpdateSuspect
11 from crash.test.crash_test_suite import CrashTestSuite 11 from crash.test.crash_test_suite import CrashTestSuite
12 from libs.gitiles.blame import Blame 12 from libs.gitiles.blame import Blame
13 from libs.gitiles.blame import Region 13 from libs.gitiles.blame import Region
14 from libs.gitiles.change_log import ChangeLog 14 from libs.gitiles.change_log import ChangeLog
15 15
16 DUMMY_CHANGELOG1 = ChangeLog.FromDict({ 16 DUMMY_CHANGELOG1 = ChangeLog.FromDict({
17 'author_name': 'r@chromium.org', 17 'author_name': 'r@chromium.org',
18 'message': 'dummy', 18 'message': 'dummy',
19 'committer_email': 'r@chromium.org', 19 'committer_email': 'r@chromium.org',
20 'commit_position': 175900, 20 'commit_position': 175900,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 DUMMY_BLAME.AddRegion( 72 DUMMY_BLAME.AddRegion(
73 Region(9, 2, '3', 'k', 'k@chromium.org', 'Thu Apr 1 21:24:43 2016')) 73 Region(9, 2, '3', 'k', 'k@chromium.org', 'Thu Apr 1 21:24:43 2016'))
74 74
75 DUMMY_BLAME2 = Blame('4', 'b.cc') 75 DUMMY_BLAME2 = Blame('4', 'b.cc')
76 DUMMY_BLAME2.AddRegion( 76 DUMMY_BLAME2.AddRegion(
77 Region(1, 5, '2', 'r', 'r@chromium.org', 'Thu Mar 25 21:24:43 2016')) 77 Region(1, 5, '2', 'r', 'r@chromium.org', 'Thu Mar 25 21:24:43 2016'))
78 DUMMY_BLAME2.AddRegion( 78 DUMMY_BLAME2.AddRegion(
79 Region(6, 3, '1', 'e', 'e@chromium.org', 'Thu Mar 31 21:24:43 2016')) 79 Region(6, 3, '1', 'e', 'e@chromium.org', 'Thu Mar 31 21:24:43 2016'))
80 80
81 81
82 class ResultsTest(CrashTestSuite): 82 class SuspectTest(CrashTestSuite):
83 83
84 def testResultToDict(self): 84 def testSuspectToDict(self):
85 85
86 result = Result(DUMMY_CHANGELOG1, 'src/', 86 suspect = Suspect(DUMMY_CHANGELOG1, 'src/',
87 confidence=1, reasons=['MinDistance', 0.5, 'some reason'], 87 confidence=1, reasons=['MinDistance', 0.5, 'some reason'],
88 changed_files={'file': 'f', 'blame_url': 'http://b', 88 changed_files={'file': 'f', 'blame_url': 'http://b',
89 'info': 'min distance (LOC) 5'}) 89 'info': 'min distance (LOC) 5'})
90 90
91 expected_result_json = { 91 expected_suspect_json = {
92 'url': DUMMY_CHANGELOG1.commit_url, 92 'url': DUMMY_CHANGELOG1.commit_url,
93 'review_url': DUMMY_CHANGELOG1.code_review_url, 93 'review_url': DUMMY_CHANGELOG1.code_review_url,
94 'revision': DUMMY_CHANGELOG1.revision, 94 'revision': DUMMY_CHANGELOG1.revision,
95 'project_path': 'src/', 95 'project_path': 'src/',
96 'author': DUMMY_CHANGELOG1.author_email, 96 'author': DUMMY_CHANGELOG1.author_email,
97 'time': str(DUMMY_CHANGELOG1.author_time), 97 'time': str(DUMMY_CHANGELOG1.author_time),
98 'reasons': ['MinDistance', 0.5, 'some reason'], 98 'reasons': ['MinDistance', 0.5, 'some reason'],
99 'changed_files': {'file': 'f', 'blame_url': 'http://b', 99 'changed_files': {'file': 'f', 'blame_url': 'http://b',
100 'info': 'min distance (LOC) 5'}, 100 'info': 'min distance (LOC) 5'},
101 'confidence': 1, 101 'confidence': 1,
102 } 102 }
103 103
104 self.assertEqual(result.ToDict(), expected_result_json) 104 self.assertEqual(suspect.ToDict(), expected_suspect_json)
105 105
106 def testResultToString(self): 106 def testSuspectToString(self):
107 107
108 result = Result(DUMMY_CHANGELOG1, 'src/', confidence=1) 108 suspect = Suspect(DUMMY_CHANGELOG1, 'src/', confidence=1)
109 109
110 expected_result_str = '' 110 expected_str = ''
111 self.assertEqual(result.ToString(), expected_result_str) 111 self.assertEqual(suspect.ToString(), expected_str)
112 112
113 result.file_to_stack_infos = { 113 suspect.file_to_stack_infos = {
114 'a.cc': [StackInfo( 114 'a.cc': [StackInfo(
115 frame = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', []), 115 frame = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', []),
116 priority = 0)] 116 priority = 0)]
117 } 117 }
118 expected_result_str = 'Changed file a.cc crashed in frame #0' 118 expected_str = 'Changed file a.cc crashed in frame #0'
119 119
120 self.assertEqual(str(result), expected_result_str) 120 self.assertEqual(str(suspect), expected_str)
121 121
122 def testMatchResultUpdate(self): 122 def testSuspectUpdate(self):
123 # Touched lines have intersection with crashed lines. 123 # Touched lines have intersection with crashed lines.
124 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1) 124 suspect = Suspect(DUMMY_CHANGELOG1, 'src/', confidence=1)
125 stack_infos = [StackInfo( 125 stack_infos = [StackInfo(
126 frame = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]), 126 frame = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]),
127 priority = 0)] 127 priority = 0)]
128 128
129 result.Update('a.cc', stack_infos, DUMMY_BLAME) 129 _UpdateSuspect(suspect, 'a.cc', stack_infos, DUMMY_BLAME)
130 self.assertEqual(result.file_to_analysis_info['a.cc'].min_distance, 0) 130 self.assertEqual(suspect.file_to_analysis_info['a.cc'].min_distance, 0)
131 131
132 # Touched lines are before crashed lines. 132 # Touched lines are before crashed lines.
133 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1) 133 suspect = Suspect(DUMMY_CHANGELOG1, 'src/', confidence=1)
134 134
135 stack_infos = [StackInfo( 135 stack_infos = [StackInfo(
136 frame = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [3]), 136 frame = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [3]),
137 priority = 0)] 137 priority = 0)]
138 138
139 result.Update('a.cc', stack_infos, DUMMY_BLAME) 139 _UpdateSuspect(suspect, 'a.cc', stack_infos, DUMMY_BLAME)
140 self.assertEqual(result.file_to_analysis_info['a.cc'].min_distance, 3) 140 self.assertEqual(suspect.file_to_analysis_info['a.cc'].min_distance, 3)
141 141
142 # Touched lines are after crashed lines. 142 # Touched lines are after crashed lines.
143 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1) 143 suspect = Suspect(DUMMY_CHANGELOG1, 'src/', confidence=1)
144 144
145 stack_infos = [StackInfo( 145 stack_infos = [StackInfo(
146 frame = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [10]), 146 frame = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [10]),
147 priority = 0)] 147 priority = 0)]
148 148
149 result.Update('a.cc', stack_infos, DUMMY_BLAME) 149 _UpdateSuspect(suspect, 'a.cc', stack_infos, DUMMY_BLAME)
150 self.assertEqual(result.file_to_analysis_info['a.cc'].min_distance, 2) 150 self.assertEqual(suspect.file_to_analysis_info['a.cc'].min_distance, 2)
151 151
152 def testMatchResultUpdateWithEmptyBlame(self): 152 def testSuspectUpdateWithEmptyBlame(self):
153 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1) 153 suspect = Suspect(DUMMY_CHANGELOG1, 'src/', confidence=1)
154 stack_infos = [StackInfo( 154 stack_infos = [StackInfo(
155 frame = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]), 155 frame = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]),
156 priority = 0)] 156 priority = 0)]
157 157
158 result.Update('a.cc', stack_infos, None) 158 _UpdateSuspect(suspect, 'a.cc', stack_infos, None)
159 self.assertEqual(result.file_to_stack_infos['a.cc'], stack_infos) 159 self.assertEqual(suspect.file_to_stack_infos['a.cc'], stack_infos)
160 self.assertEqual(result.file_to_analysis_info, {}) 160 self.assertEqual(suspect.file_to_analysis_info, {})
161 161
162 def testMatchResultUpdateMinimumDistance(self): 162 def testSuspectUpdateMinimumDistance(self):
163 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1) 163 suspect = Suspect(DUMMY_CHANGELOG1, 'src/', confidence=1)
164 frame1 = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]) 164 frame1 = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7])
165 frame2 = StackFrame(2, 'src/', 'func', 'a.cc', 'src/a.cc', [20]) 165 frame2 = StackFrame(2, 'src/', 'func', 'a.cc', 'src/a.cc', [20])
166 stack_infos = [StackInfo(frame1, 0), StackInfo(frame2, 0)] 166 stack_infos = [StackInfo(frame1, 0), StackInfo(frame2, 0)]
167 167
168 result.Update('a.cc', stack_infos, DUMMY_BLAME) 168 _UpdateSuspect(suspect, 'a.cc', stack_infos, DUMMY_BLAME)
169 self.assertEqual(result.file_to_stack_infos['a.cc'], stack_infos) 169 self.assertEqual(suspect.file_to_stack_infos['a.cc'], stack_infos)
170 self.assertEqual(result.file_to_analysis_info, 170 self.assertEqual(suspect.file_to_analysis_info,
171 {'a.cc': AnalysisInfo(min_distance = 0, min_distance_frame = frame1)}) 171 {'a.cc': AnalysisInfo(min_distance = 0, min_distance_frame = frame1)})
172 172
173 def testMatchResultsGenerateMatchResults(self): 173 def testSuspectsGenerateSuspects(self):
174 match_results = MatchResults(ignore_cls=set(['2'])) 174 suspects = Suspects(ignore_cls=set(['2']))
175 frame1 = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]) 175 frame1 = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7])
176 frame2 = StackFrame(1, 'src/', 'func', 'b.cc', 'src/b.cc', [11]) 176 frame2 = StackFrame(1, 'src/', 'func', 'b.cc', 'src/b.cc', [11])
177 stack_infos1 = [StackInfo(frame1, 0)] 177 stack_infos1 = [StackInfo(frame1, 0)]
178 stack_infos2 = [StackInfo(frame2, 0)] 178 stack_infos2 = [StackInfo(frame2, 0)]
179 match_results.GenerateMatchResults('a.cc', 'src/', stack_infos1, 179 suspects.GenerateSuspects('a.cc', 'src/', stack_infos1,
180 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2], 180 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2],
181 DUMMY_BLAME) 181 DUMMY_BLAME)
182 182
183 match_results.GenerateMatchResults('b.cc', 'src/', stack_infos2, 183 suspects.GenerateSuspects('b.cc', 'src/', stack_infos2,
184 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2], 184 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2],
185 DUMMY_BLAME2) 185 DUMMY_BLAME2)
186 186
187 expected_match_result = MatchResult(DUMMY_CHANGELOG1, 'src/') 187 expected_suspect = Suspect(DUMMY_CHANGELOG1, 'src/')
188 expected_match_result.file_to_stack_infos = { 188 expected_suspect.file_to_stack_infos = {
189 'a.cc': stack_infos1, 189 'a.cc': stack_infos1,
190 'b.cc': stack_infos2, 190 'b.cc': stack_infos2,
191 } 191 }
192 expected_match_result.file_to_analysis_info = { 192 expected_suspect.file_to_analysis_info = {
193 'a.cc': AnalysisInfo(min_distance = 0, min_distance_frame = frame1), 193 'a.cc': AnalysisInfo(min_distance = 0, min_distance_frame = frame1),
194 'b.cc': AnalysisInfo(min_distance = 3, min_distance_frame = frame2), 194 'b.cc': AnalysisInfo(min_distance = 3, min_distance_frame = frame2),
195 } 195 }
196 196
197 expected_match_results = MatchResults(ignore_cls=set(['2'])) 197 expected_suspects = Suspects(ignore_cls=set(['2']))
198 expected_match_results['1'] = expected_match_result 198 expected_suspects['1'] = expected_suspect
199 199
200 self._VerifyTwoMatchResultsEqual(match_results, expected_match_results) 200 self._VerifyTwoSuspectsEqual(suspects, expected_suspects)
OLDNEW
« no previous file with comments | « appengine/findit/crash/test/results_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698