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