| 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 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 detect_regression_range | 7 from crash import changelist_classifier |
| 8 from crash import findit_for_chromecrash | 8 from crash import findit |
| 9 from crash.findit_for_chromecrash import FinditForChromeCrash |
| 9 from crash import chromecrash_parser | 10 from crash import chromecrash_parser |
| 10 from crash import findit_for_crash | |
| 11 from crash.component_classifier import ComponentClassifier | 11 from crash.component_classifier import ComponentClassifier |
| 12 from crash.project_classifier import ProjectClassifier | 12 from crash.project_classifier import ProjectClassifier |
| 13 from crash.changelist_classifier import ChangelistClassifier |
| 13 from crash.results import MatchResult | 14 from crash.results import MatchResult |
| 14 from crash.stacktrace import CallStack | 15 from crash.stacktrace import CallStack |
| 15 from crash.stacktrace import Stacktrace | 16 from crash.stacktrace import Stacktrace |
| 17 from crash.culprit import NullCulprit |
| 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(chromium_deps, 'GetDEPSRollsDict', lambda *_: { |
| 52 return {'src/': DependencyRoll('src/', 'https://repo', '1', '2'), | 51 'src/': DependencyRoll('src/', 'https://repo', '1', '2'), |
| 53 'src/add': DependencyRoll('src/add', 'https://repo1', None, '2'), | 52 'src/add': DependencyRoll('src/add', 'https://repo1', None, '2'), |
| 54 'src/delete': DependencyRoll('src/delete', 'https://repo2', | 53 'src/delete': DependencyRoll('src/delete', 'https://repo2', '2', None) |
| 55 '2', None)} | 54 }) |
| 56 | 55 |
| 57 dummy_match_result = MatchResult(self.GetDummyChangeLog(), 'src/') | 56 dummy_match_result = MatchResult(self.GetDummyChangeLog(), 'src/') |
| 58 def _MockFindItForCrash(*args): | 57 self.mock(changelist_classifier.ChangelistClassifier, '__call__', |
| 59 regression_deps_rolls = args[1] | 58 lambda _self, regression_deps_rolls, *args: |
| 60 if regression_deps_rolls: | 59 [dummy_match_result] if regression_deps_rolls else []) |
| 61 return [dummy_match_result] | |
| 62 | 60 |
| 63 return [] | 61 self.mock(ComponentClassifier, 'Classify', lambda *_: []) |
| 62 self.mock(ProjectClassifier, 'Classify', lambda *_: '') |
| 64 | 63 |
| 65 def _MockComponentClassify(*_): | 64 # TODO(wrengr): for both these tests, we should compare Culprit |
| 66 return [] | 65 # objects directly rather than calling ToDicts and comparing the |
| 66 # dictionaries. |
| 67 self._testFindCulpritForChromeCrashSucceeds(dummy_match_result) |
| 68 self._testFindCulpritForChromeCrashFails() |
| 67 | 69 |
| 68 def _MockProjectClassify(*_): | 70 def _testFindCulpritForChromeCrashSucceeds(self, dummy_match_result): |
| 69 return '' | 71 analysis = CrashAnalysis() |
| 72 analysis.signature = 'signature' |
| 73 analysis.platform = 'win' |
| 74 analysis.stack_trace = 'frame1\nframe2' |
| 75 analysis.crashed_version = '50.0.1234.0' |
| 76 dummy_regression_range = ['50.0.1233.0', '50.0.1234.0'] |
| 77 analysis.regression_range = dummy_regression_range |
| 78 results, tag = FinditForChromeCrash().FindCulprit(analysis).ToDicts() |
| 70 | 79 |
| 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 | |
| 79 expected_results = {'found': False} | |
| 80 expected_tag = {'found_suspects': False} | |
| 81 | |
| 82 results, tag = findit_for_chromecrash.FinditForChromeCrash().FindCulprit( | |
| 83 'signature', 'win', 'frame1\nframe2', '50.0.1234.0', | |
| 84 ['50.0.1233.0', '50.0.1234.0']).ToDicts() | |
| 85 | |
| 86 # TODO(wrengr): compare the Culprit object directly to these values, | |
| 87 # rather than converting to dicts first. We can make a different | |
| 88 # unit test for comparing the dicts, if we actually need/want to. | |
| 89 expected_results = { | 80 expected_results = { |
| 90 'found': True, | 81 'found': True, |
| 91 'suspected_project': '', | 82 'suspected_project': '', |
| 92 'suspected_components': [], | 83 'suspected_components': [], |
| 93 'suspected_cls': [dummy_match_result.ToDict()], | 84 'suspected_cls': [dummy_match_result.ToDict()], |
| 94 'regression_range': ['50.0.1233.0', '50.0.1234.0'] | 85 'regression_range': dummy_regression_range |
| 95 } | 86 } |
| 96 expected_tag = { | 87 expected_tag = { |
| 97 'found_suspects': True, | 88 'found_suspects': True, |
| 98 'found_project': False, | 89 'found_project': False, |
| 99 'found_components': False, | 90 'found_components': False, |
| 100 'has_regression_range': True, | 91 'has_regression_range': True, |
| 101 'solution': 'core_algorithm', | 92 'solution': 'core_algorithm', |
| 102 } | 93 } |
| 103 | 94 |
| 104 self.assertEqual(expected_results, results) | 95 self.assertDictEqual(expected_results, results) |
| 105 self.assertEqual(expected_tag, tag) | 96 self.assertDictEqual(expected_tag, tag) |
| 106 | 97 |
| 107 results, tag = findit_for_chromecrash.FinditForChromeCrash().FindCulprit( | 98 def _testFindCulpritForChromeCrashFails(self): |
| 108 'signature', 'win', 'frame1\nframe2', '50.0.1234.0', None).ToDicts() | 99 analysis = CrashAnalysis() |
| 100 analysis.signature = 'signature' |
| 101 analysis.platform = 'win' |
| 102 analysis.stack_trace = 'frame1\nframe2' |
| 103 analysis.crashed_version = '50.0.1234.0' |
| 104 analysis.historical_metadata = [] |
| 105 results, tag = FinditForChromeCrash().FindCulprit(analysis).ToDicts() |
| 109 | 106 |
| 110 expected_results = { | 107 expected_results, expected_tag = NullCulprit().ToDicts() |
| 111 'found': False, | |
| 112 'suspected_project': '', | |
| 113 'suspected_components': [], | |
| 114 'suspected_cls': [], | |
| 115 'regression_range': None | |
| 116 } | |
| 117 expected_tag = { | |
| 118 'found_suspects': False, | |
| 119 'found_project': False, | |
| 120 'found_components': False, | |
| 121 'has_regression_range': False, | |
| 122 'solution': 'core_algorithm', | |
| 123 } | |
| 124 | 108 |
| 125 self.assertEqual(expected_results, results) | 109 self.assertDictEqual(expected_results, results) |
| 126 self.assertEqual(expected_tag, tag) | 110 self.assertDictEqual(expected_tag, tag) |
| OLD | NEW |