| 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.changelist_classifier import ChangelistClassifier |
| 8 from crash import findit_for_chromecrash | 8 from crash.chromecrash_parser import ChromeCrashParser |
| 9 from crash import chromecrash_parser | |
| 10 from crash import findit_for_crash | |
| 11 from crash.component_classifier import ComponentClassifier | 9 from crash.component_classifier import ComponentClassifier |
| 10 from crash.crash_pipeline import CrashWrapperPipeline |
| 11 from crash.findit_for_chromecrash import FinditForChromeCrash |
| 12 from crash.project_classifier import ProjectClassifier | 12 from crash.project_classifier import ProjectClassifier |
| 13 from crash.results import MatchResult | 13 from crash.results import MatchResult |
| 14 from crash.stacktrace import CallStack | 14 from crash.stacktrace import CallStack |
| 15 from crash.stacktrace import Stacktrace | 15 from crash.stacktrace import Stacktrace |
| 16 from crash.test.crash_testcase import CrashTestCase | 16 from crash.test.crash_testcase import CrashTestCase |
| 17 from model.crash.crash_analysis import CrashAnalysis |
| 17 | 18 |
| 19 def _FinditForChromeCrash(): |
| 20 return FinditForChromeCrash(CrashWrapperPipeline) |
| 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(ChromeCrashParser, 'Parse', lambda *_: Stacktrace()) |
| 24 | |
| 25 def _MockParse(*_): | |
| 26 return Stacktrace() | |
| 27 | |
| 28 self.mock(chromium_deps, 'GetChromeDependency', _MockGetChromeDependency) | |
| 29 self.mock(chromecrash_parser.ChromeCrashParser, 'Parse', _MockParse) | |
| 30 | 27 |
| 31 expected_results = {'found': False} | 28 expected_results = {'found': False} |
| 32 expected_tag = {'found_suspects': False, | 29 expected_tag = {'found_suspects': False, |
| 33 'has_regression_range': False} | 30 'has_regression_range': False} |
| 34 | 31 |
| 35 results, tag = findit_for_chromecrash.FinditForChromeCrash().FindCulprit( | 32 analysis = CrashAnalysis() |
| 36 'signature', 'win', 'frame1\nframe2', '50.0.1234.0', | 33 analysis.signature = 'signature' |
| 37 [{'chrome_version': '50.0.1234.0', 'cpm': 0.6}]).ToDicts() | 34 analysis.platform = 'win' |
| 35 analysis.stack_trace = 'frame1\nframe2' |
| 36 analysis.crashed_version = '50.0.1234.0' |
| 37 analysis.historical_metadata = [ |
| 38 {'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 {} | 46 self.mock(ChromeCrashParser, 'Parse', lambda *_: Stacktrace([CallStack(0)])) |
| 45 | 47 self.mock(chromium_deps, 'GetDEPSRollsDict', lambda *_: { |
| 46 def _MockParse(*_): | 48 'src/': DependencyRoll('src/', 'https://repo', '1', '2'), |
| 47 stack = Stacktrace() | 49 'src/add': DependencyRoll('src/add', 'https://repo1', None, '2'), |
| 48 stack.append(CallStack(0)) | 50 'src/delete': DependencyRoll('src/delete', 'https://repo2', '2', None) |
| 49 return stack | 51 }) |
| 50 | |
| 51 def _MockGetDEPSRollsDict(*_): | |
| 52 return {'src/': DependencyRoll('src/', 'https://repo', '1', '2'), | |
| 53 'src/add': DependencyRoll('src/add', 'https://repo1', None, '2'), | |
| 54 'src/delete': DependencyRoll('src/delete', 'https://repo2', | |
| 55 '2', None)} | |
| 56 | 52 |
| 57 dummy_match_result = MatchResult(self.GetDummyChangeLog(), 'src/') | 53 dummy_match_result = MatchResult(self.GetDummyChangeLog(), 'src/') |
| 58 def _MockFindItForCrash(*args): | 54 self.mock(ChangelistClassifier, '__call__', |
| 59 regression_deps_rolls = args[1] | 55 lambda _self, report: |
| 60 if regression_deps_rolls: | 56 [dummy_match_result] if report.regression_range else []) |
| 61 return [dummy_match_result] | |
| 62 | 57 |
| 63 return [] | 58 self.mock(ComponentClassifier, 'Classify', lambda *_: []) |
| 59 self.mock(ProjectClassifier, 'Classify', lambda *_: '') |
| 64 | 60 |
| 65 def _MockComponentClassify(*_): | 61 # TODO(wrengr): for both these tests, we should compare Culprit |
| 66 return [] | 62 # objects directly rather than calling ToDicts and comparing the |
| 63 # dictionaries. |
| 64 self._testFindCulpritForChromeCrashSucceeds(dummy_match_result) |
| 65 self._testFindCulpritForChromeCrashFails() |
| 67 | 66 |
| 68 def _MockProjectClassify(*_): | 67 def _testFindCulpritForChromeCrashSucceeds(self, dummy_match_result): |
| 69 return '' | 68 analysis = CrashAnalysis() |
| 69 analysis.signature = 'signature' |
| 70 analysis.platform = 'win' |
| 71 analysis.stack_trace = 'frame1\nframe2' |
| 72 analysis.crashed_version = '50.0.1234.0' |
| 73 dummy_regression_range = ['50.0.1233.0', '50.0.1234.0'] |
| 74 analysis.regression_range = dummy_regression_range |
| 75 results, tag = _FinditForChromeCrash().FindCulprit(analysis).ToDicts() |
| 70 | 76 |
| 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 = { | 77 expected_results = { |
| 90 'found': True, | 78 'found': True, |
| 91 'suspected_project': '', | 79 'suspected_project': '', |
| 92 'suspected_components': [], | 80 'suspected_components': [], |
| 93 'suspected_cls': [dummy_match_result.ToDict()], | 81 'suspected_cls': [dummy_match_result.ToDict()], |
| 94 'regression_range': ['50.0.1233.0', '50.0.1234.0'] | 82 'regression_range': dummy_regression_range |
| 95 } | 83 } |
| 96 expected_tag = { | 84 expected_tag = { |
| 97 'found_suspects': True, | 85 'found_suspects': True, |
| 98 'found_project': False, | 86 'found_project': False, |
| 99 'found_components': False, | 87 'found_components': False, |
| 100 'has_regression_range': True, | 88 'has_regression_range': True, |
| 101 'solution': 'core_algorithm', | 89 'solution': 'core_algorithm', |
| 102 } | 90 } |
| 103 | 91 |
| 104 self.assertEqual(expected_results, results) | 92 self.assertDictEqual(expected_results, results) |
| 105 self.assertEqual(expected_tag, tag) | 93 self.assertDictEqual(expected_tag, tag) |
| 106 | 94 |
| 107 results, tag = findit_for_chromecrash.FinditForChromeCrash().FindCulprit( | 95 def _testFindCulpritForChromeCrashFails(self): |
| 108 'signature', 'win', 'frame1\nframe2', '50.0.1234.0', None).ToDicts() | 96 analysis = CrashAnalysis() |
| 97 analysis.signature = 'signature' |
| 98 analysis.platform = 'win' |
| 99 analysis.stack_trace = 'frame1\nframe2' |
| 100 analysis.crashed_version = '50.0.1234.0' |
| 101 #analysis.historical_metadata = [] |
| 102 #analysis.regression_range = None |
| 103 results, tag = _FinditForChromeCrash().FindCulprit(analysis).ToDicts() |
| 109 | 104 |
| 110 expected_results = { | 105 expected_results = { |
| 111 'found': False, | 106 'found': False, |
| 112 'suspected_project': '', | 107 'suspected_project': '', |
| 113 'suspected_components': [], | 108 'suspected_components': [], |
| 114 'suspected_cls': [], | 109 'suspected_cls': [], |
| 115 'regression_range': None | 110 'regression_range': None |
| 116 } | 111 } |
| 117 expected_tag = { | 112 expected_tag = { |
| 118 'found_suspects': False, | 113 'found_suspects': False, |
| 119 'found_project': False, | 114 'found_project': False, |
| 120 'found_components': False, | 115 'found_components': False, |
| 121 'has_regression_range': False, | 116 'has_regression_range': False, |
| 122 'solution': 'core_algorithm', | 117 'solution': 'core_algorithm', |
| 123 } | 118 } |
| 124 | 119 |
| 125 self.assertEqual(expected_results, results) | 120 self.assertDictEqual(expected_results, results) |
| 126 self.assertEqual(expected_tag, tag) | 121 self.assertDictEqual(expected_tag, tag) |
| OLD | NEW |