| OLD | NEW |
| 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 | 5 from crash.results import AnalysisInfo |
| 6 from crash.results import MatchResult | 6 from crash.results import MatchResult |
| 7 from crash.results import MatchResults | 7 from crash.results import MatchResults |
| 8 from crash.results import Result | 8 from crash.results import Result |
| 9 from crash.results import StackInfo |
| 9 from crash.stacktrace import StackFrame | 10 from crash.stacktrace import StackFrame |
| 10 from crash.test.crash_test_suite import CrashTestSuite | 11 from crash.test.crash_test_suite import CrashTestSuite |
| 11 from lib.gitiles.blame import Blame | 12 from lib.gitiles.blame import Blame |
| 12 from lib.gitiles.blame import Region | 13 from lib.gitiles.blame import Region |
| 13 from lib.gitiles.change_log import ChangeLog | 14 from lib.gitiles.change_log import ChangeLog |
| 14 | 15 |
| 15 DUMMY_CHANGELOG1 = ChangeLog.FromDict({ | 16 DUMMY_CHANGELOG1 = ChangeLog.FromDict({ |
| 16 'author_name': 'r@chromium.org', | 17 'author_name': 'r@chromium.org', |
| 17 'message': 'dummy', | 18 'message': 'dummy', |
| 18 'committer_email': 'r@chromium.org', | 19 'committer_email': 'r@chromium.org', |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 self.assertEqual(result.ToDict(), expected_result_json) | 104 self.assertEqual(result.ToDict(), expected_result_json) |
| 104 | 105 |
| 105 def testResultToString(self): | 106 def testResultToString(self): |
| 106 | 107 |
| 107 result = Result(DUMMY_CHANGELOG1, 'src/', confidence=1) | 108 result = Result(DUMMY_CHANGELOG1, 'src/', confidence=1) |
| 108 | 109 |
| 109 expected_result_str = '' | 110 expected_result_str = '' |
| 110 self.assertEqual(result.ToString(), expected_result_str) | 111 self.assertEqual(result.ToString(), expected_result_str) |
| 111 | 112 |
| 112 result.file_to_stack_infos = { | 113 result.file_to_stack_infos = { |
| 113 'a.cc': [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', []), 0)] | 114 'a.cc': [StackInfo( |
| 115 frame = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', []), |
| 116 priority = 0)] |
| 114 } | 117 } |
| 115 expected_result_str = 'Changed file a.cc crashed in frame #0' | 118 expected_result_str = 'Changed file a.cc crashed in frame #0' |
| 116 | 119 |
| 117 self.assertEqual(str(result), expected_result_str) | 120 self.assertEqual(str(result), expected_result_str) |
| 118 | 121 |
| 119 def testMatchResultUpdate(self): | 122 def testMatchResultUpdate(self): |
| 120 # Touched lines have intersection with crashed lines. | 123 # Touched lines have intersection with crashed lines. |
| 121 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1) | 124 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1) |
| 122 stack_infos = [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]), 0)] | 125 stack_infos = [StackInfo( |
| 126 frame = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]), |
| 127 priority = 0)] |
| 123 | 128 |
| 124 result.Update('a.cc', stack_infos, DUMMY_BLAME) | 129 result.Update('a.cc', stack_infos, DUMMY_BLAME) |
| 125 self.assertEqual(result.file_to_analysis_info['a.cc'].min_distance, 0) | 130 self.assertEqual(result.file_to_analysis_info['a.cc'].min_distance, 0) |
| 126 | 131 |
| 127 # Touched lines are before crashed lines. | 132 # Touched lines are before crashed lines. |
| 128 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1) | 133 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1) |
| 129 | 134 |
| 130 stack_infos = [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [3]), 0)] | 135 stack_infos = [StackInfo( |
| 136 frame = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [3]), |
| 137 priority = 0)] |
| 131 | 138 |
| 132 result.Update('a.cc', stack_infos, DUMMY_BLAME) | 139 result.Update('a.cc', stack_infos, DUMMY_BLAME) |
| 133 self.assertEqual(result.file_to_analysis_info['a.cc'].min_distance, 3) | 140 self.assertEqual(result.file_to_analysis_info['a.cc'].min_distance, 3) |
| 134 | 141 |
| 135 # Touched lines are after crashed lines. | 142 # Touched lines are after crashed lines. |
| 136 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1) | 143 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1) |
| 137 | 144 |
| 138 stack_infos = [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [10]), 0)] | 145 stack_infos = [StackInfo( |
| 146 frame = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [10]), |
| 147 priority = 0)] |
| 139 | 148 |
| 140 result.Update('a.cc', stack_infos, DUMMY_BLAME) | 149 result.Update('a.cc', stack_infos, DUMMY_BLAME) |
| 141 self.assertEqual(result.file_to_analysis_info['a.cc'].min_distance, 2) | 150 self.assertEqual(result.file_to_analysis_info['a.cc'].min_distance, 2) |
| 142 | 151 |
| 143 def testMatchResultUpdateWithEmptyBlame(self): | 152 def testMatchResultUpdateWithEmptyBlame(self): |
| 144 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1) | 153 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1) |
| 145 stack_infos = [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]), 0)] | 154 stack_infos = [StackInfo( |
| 155 frame = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]), |
| 156 priority = 0)] |
| 146 | 157 |
| 147 result.Update('a.cc', stack_infos, None) | 158 result.Update('a.cc', stack_infos, None) |
| 148 self.assertEqual(result.file_to_stack_infos['a.cc'], stack_infos) | 159 self.assertEqual(result.file_to_stack_infos['a.cc'], stack_infos) |
| 149 self.assertEqual(result.file_to_analysis_info, {}) | 160 self.assertEqual(result.file_to_analysis_info, {}) |
| 150 | 161 |
| 151 def testMatchResultUpdateMinimumDistance(self): | 162 def testMatchResultUpdateMinimumDistance(self): |
| 152 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1) | 163 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1) |
| 153 frame1 = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]) | 164 frame1 = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]) |
| 154 frame2 = StackFrame(2, 'src/', 'func', 'a.cc', 'src/a.cc', [20]) | 165 frame2 = StackFrame(2, 'src/', 'func', 'a.cc', 'src/a.cc', [20]) |
| 155 stack_infos = [(frame1, 0), (frame2, 0)] | 166 stack_infos = [StackInfo(frame1, 0), StackInfo(frame2, 0)] |
| 156 | 167 |
| 157 result.Update('a.cc', stack_infos, DUMMY_BLAME) | 168 result.Update('a.cc', stack_infos, DUMMY_BLAME) |
| 158 self.assertEqual(result.file_to_stack_infos['a.cc'], stack_infos) | 169 self.assertEqual(result.file_to_stack_infos['a.cc'], stack_infos) |
| 159 self.assertEqual(result.file_to_analysis_info, | 170 self.assertEqual(result.file_to_analysis_info, |
| 160 {'a.cc': AnalysisInfo(min_distance = 0, min_distance_frame = frame1)}) | 171 {'a.cc': AnalysisInfo(min_distance = 0, min_distance_frame = frame1)}) |
| 161 | 172 |
| 162 def testMatchResultsGenerateMatchResults(self): | 173 def testMatchResultsGenerateMatchResults(self): |
| 163 match_results = MatchResults(ignore_cls=set(['2'])) | 174 match_results = MatchResults(ignore_cls=set(['2'])) |
| 164 frame1 = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]) | 175 frame1 = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]) |
| 165 frame2 = StackFrame(1, 'src/', 'func', 'b.cc', 'src/b.cc', [11]) | 176 frame2 = StackFrame(1, 'src/', 'func', 'b.cc', 'src/b.cc', [11]) |
| 166 stack_infos1 = [(frame1, 0)] | 177 stack_infos1 = [StackInfo(frame1, 0)] |
| 167 stack_infos2 = [(frame2, 0)] | 178 stack_infos2 = [StackInfo(frame2, 0)] |
| 168 match_results.GenerateMatchResults('a.cc', 'src/', stack_infos1, | 179 match_results.GenerateMatchResults('a.cc', 'src/', stack_infos1, |
| 169 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2], | 180 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2], |
| 170 DUMMY_BLAME) | 181 DUMMY_BLAME) |
| 171 | 182 |
| 172 match_results.GenerateMatchResults('b.cc', 'src/', stack_infos2, | 183 match_results.GenerateMatchResults('b.cc', 'src/', stack_infos2, |
| 173 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2], | 184 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2], |
| 174 DUMMY_BLAME2) | 185 DUMMY_BLAME2) |
| 175 | 186 |
| 176 expected_match_result = MatchResult(DUMMY_CHANGELOG1, 'src/') | 187 expected_match_result = MatchResult(DUMMY_CHANGELOG1, 'src/') |
| 177 expected_match_result.file_to_stack_infos = { | 188 expected_match_result.file_to_stack_infos = { |
| 178 'a.cc': stack_infos1, | 189 'a.cc': stack_infos1, |
| 179 'b.cc': stack_infos2, | 190 'b.cc': stack_infos2, |
| 180 } | 191 } |
| 181 expected_match_result.file_to_analysis_info = { | 192 expected_match_result.file_to_analysis_info = { |
| 182 'a.cc': AnalysisInfo(min_distance = 0, min_distance_frame = frame1), | 193 'a.cc': AnalysisInfo(min_distance = 0, min_distance_frame = frame1), |
| 183 'b.cc': AnalysisInfo(min_distance = 3, min_distance_frame = frame2), | 194 'b.cc': AnalysisInfo(min_distance = 3, min_distance_frame = frame2), |
| 184 } | 195 } |
| 185 | 196 |
| 186 expected_match_results = MatchResults(ignore_cls=set(['2'])) | 197 expected_match_results = MatchResults(ignore_cls=set(['2'])) |
| 187 expected_match_results['1'] = expected_match_result | 198 expected_match_results['1'] = expected_match_result |
| 188 | 199 |
| 189 self._VerifyTwoMatchResultsEqual(match_results, expected_match_results) | 200 self._VerifyTwoMatchResultsEqual(match_results, expected_match_results) |
| OLD | NEW |