| 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 import copy | 4 import copy |
| 5 import json | 5 import json |
| 6 | 6 |
| 7 from google.appengine.api import app_identity | 7 from google.appengine.api import app_identity |
| 8 from webtest.app import AppError |
| 8 | 9 |
| 9 from common.pipeline_wrapper import pipeline_handlers | 10 from common.pipeline_wrapper import pipeline_handlers |
| 10 from crash import crash_pipeline | 11 from crash import crash_pipeline |
| 11 from crash import findit_for_chromecrash | 12 from crash import findit_for_chromecrash |
| 13 from crash.culprit import Culprit |
| 14 from crash.crash_report import CrashReport |
| 15 from crash.findit_for_chromecrash import FinditForFracas |
| 16 from crash.stacktrace import Stacktrace |
| 12 from crash.test.crash_testcase import CrashTestCase | 17 from crash.test.crash_testcase import CrashTestCase |
| 18 from crash.type_enums import CrashClient |
| 13 from model import analysis_status | 19 from model import analysis_status |
| 14 from model.crash.fracas_crash_analysis import FracasCrashAnalysis | 20 from model.crash.fracas_crash_analysis import FracasCrashAnalysis |
| 15 | 21 |
| 16 | 22 |
| 23 def DummyCrashData( |
| 24 version='1', |
| 25 signature='signature', |
| 26 platform='win', |
| 27 stack_trace=None, |
| 28 regression_range=None, |
| 29 channel='canary', |
| 30 historical_metadata=None, |
| 31 crash_identifiers=True, |
| 32 process_type='browser'): |
| 33 if crash_identifiers is True: |
| 34 crash_identifiers = { |
| 35 'chrome_version': version, |
| 36 'signature': signature, |
| 37 'channel': channel, |
| 38 'platform': platform, |
| 39 'process_type': process_type, |
| 40 } |
| 41 return { |
| 42 'crashed_version': version, |
| 43 'signature': signature, |
| 44 'platform': platform, |
| 45 'stack_trace': stack_trace, |
| 46 'regression_range': regression_range, |
| 47 'crash_identifiers': crash_identifiers, |
| 48 'customized_data': { |
| 49 'historical_metadata': None, |
| 50 'channel': channel, |
| 51 }, |
| 52 } |
| 53 |
| 54 |
| 17 class CrashPipelineTest(CrashTestCase): | 55 class CrashPipelineTest(CrashTestCase): |
| 18 app_module = pipeline_handlers._APP | 56 app_module = pipeline_handlers._APP |
| 19 | 57 |
| 20 def testNoAnalysisIfLastOneIsNotFailed(self): | 58 def testNoAnalysisIfLastOneIsNotFailed(self): |
| 21 chrome_version = '1' | 59 crash_data = DummyCrashData() |
| 22 signature = 'signature' | 60 crash_identifiers = crash_data['crash_identifiers'] |
| 23 platform = 'win' | |
| 24 crash_identifiers = { | |
| 25 'chrome_version': chrome_version, | |
| 26 'signature': signature, | |
| 27 'channel': 'canary', | |
| 28 'platform': platform, | |
| 29 'process_type': 'browser', | |
| 30 } | |
| 31 for status in (analysis_status.PENDING, analysis_status.RUNNING, | 61 for status in (analysis_status.PENDING, analysis_status.RUNNING, |
| 32 analysis_status.COMPLETED, analysis_status.SKIPPED): | 62 analysis_status.COMPLETED, analysis_status.SKIPPED): |
| 33 analysis = FracasCrashAnalysis.Create(crash_identifiers) | 63 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 34 analysis.status = status | 64 analysis.status = status |
| 35 analysis.put() | 65 analysis.put() |
| 36 self.assertFalse(crash_pipeline._NeedsNewAnalysis( | 66 self.assertFalse(FinditForFracas()._NeedsNewAnalysis(crash_data)) |
| 37 crash_identifiers, chrome_version, signature, 'fracas', | |
| 38 platform, None, {'channel': 'canary'})) | |
| 39 | 67 |
| 40 def testAnalysisNeededIfLastOneFailed(self): | 68 def testAnalysisNeededIfLastOneFailed(self): |
| 41 chrome_version = '1' | 69 crash_data = DummyCrashData() |
| 42 signature = 'signature' | 70 crash_identifiers = crash_data['crash_identifiers'] |
| 43 platform = 'win' | |
| 44 crash_identifiers = { | |
| 45 'chrome_version': chrome_version, | |
| 46 'signature': signature, | |
| 47 'channel': 'canary', | |
| 48 'platform': platform, | |
| 49 'process_type': 'browser', | |
| 50 } | |
| 51 analysis = FracasCrashAnalysis.Create(crash_identifiers) | 71 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 52 analysis.status = analysis_status.ERROR | 72 analysis.status = analysis_status.ERROR |
| 53 analysis.put() | 73 analysis.put() |
| 54 self.assertTrue(crash_pipeline._NeedsNewAnalysis( | 74 self.assertTrue(FinditForFracas()._NeedsNewAnalysis(crash_data)) |
| 55 crash_identifiers, chrome_version, signature, 'fracas', | |
| 56 platform, None, {'channel': 'canary'})) | |
| 57 | 75 |
| 58 def testAnalysisNeededIfNoAnalysisYet(self): | 76 def testAnalysisNeededIfNoAnalysisYet(self): |
| 59 chrome_version = '1' | 77 crash_data = DummyCrashData() |
| 60 signature = 'signature' | 78 self.assertTrue(FinditForFracas()._NeedsNewAnalysis(crash_data)) |
| 61 platform = 'win' | |
| 62 crash_identifiers = { | |
| 63 'chrome_version': chrome_version, | |
| 64 'signature': signature, | |
| 65 'channel': 'canary', | |
| 66 'platform': platform, | |
| 67 'process_type': 'browser', | |
| 68 } | |
| 69 self.assertTrue(crash_pipeline._NeedsNewAnalysis( | |
| 70 crash_identifiers, chrome_version, signature, 'fracas', | |
| 71 platform, None, {'channel': 'canary'})) | |
| 72 | 79 |
| 73 def testUnsupportedChannelOrPlatformSkipped(self): | 80 def testUnsupportedChannelOrPlatformSkipped(self): |
| 74 self.assertFalse( | 81 crash_data = DummyCrashData( |
| 75 crash_pipeline.ScheduleNewAnalysisForCrash( | 82 version = None, |
| 76 {}, None, None, 'fracas', 'win', | 83 signature = None, |
| 77 None, {'channel': 'unsupported_channel', | 84 crash_identifiers = {}, |
| 78 'historical_metadata': None})) | 85 channel = 'unsupported_channel') |
| 79 self.assertFalse( | 86 self.assertFalse(FinditForFracas().ScheduleNewAnalysis(crash_data)) |
| 80 crash_pipeline.ScheduleNewAnalysisForCrash( | 87 crash_data['platform'] = 'unsupported_platform' |
| 81 {}, None, None, 'fracas', 'unsupported_platform', | 88 self.assertFalse(FinditForFracas().ScheduleNewAnalysis(crash_data)) |
| 82 None, {'channel': 'unsupported_channel', | |
| 83 'historical_metadata': None})) | |
| 84 | 89 |
| 85 def testBlackListSignatureSipped(self): | 90 def testBlackListSignatureSkipped(self): |
| 86 self.assertFalse( | 91 crash_data = DummyCrashData( |
| 87 crash_pipeline.ScheduleNewAnalysisForCrash( | 92 version = None, |
| 88 {}, None, 'Blacklist marker signature', 'fracas', 'win', | 93 signature = 'Blacklist marker signature', |
| 89 None, {'channel': 'canary', | 94 crash_identifiers = {}) |
| 90 'historical_metadata': None})) | 95 self.assertFalse(FinditForFracas().ScheduleNewAnalysis(crash_data)) |
| 91 | 96 |
| 92 def testPlatformRename(self): | 97 def testPlatformRename(self): |
| 93 def _MockNeedsNewAnalysis(*args): | 98 old_crash_data = DummyCrashData( |
| 94 self.assertEqual(args, | 99 version = None, |
| 95 ({}, None, 'signature', 'fracas', 'unix', None, | 100 platform = 'unix', |
| 96 {'channel': 'canary'})) | 101 crash_identifiers = {}) |
| 97 return False | 102 del old_crash_data['customized_data']['historical_metadata'] |
| 98 | 103 |
| 99 self.mock(crash_pipeline, '_NeedsNewAnalysis', _MockNeedsNewAnalysis) | 104 testcase = self |
| 105 class _MockFinditForFracas(FinditForFracas): |
| 106 def _NeedsNewAnalysis(self, new_crash_data): |
| 107 testcase.assertEqual(self.client_id, CrashClient.FRACAS) |
| 108 testcase.assertDictEqual(new_crash_data, old_crash_data) |
| 109 return False |
| 100 | 110 |
| 101 crash_pipeline.ScheduleNewAnalysisForCrash( | 111 new_crash_data = copy.deepcopy(old_crash_data) |
| 102 {}, None, 'signature', 'fracas', 'linux', | 112 new_crash_data['platform'] = 'linux' |
| 103 None, {'channel': 'canary'}) | 113 _MockFinditForFracas().ScheduleNewAnalysis(new_crash_data) |
| 104 | 114 |
| 105 def testNoAnalysisNeeded(self): | 115 def testNoAnalysisNeeded(self): |
| 106 chrome_version = '1' | 116 crash_data = DummyCrashData() |
| 107 signature = 'signature' | 117 crash_identifiers = crash_data['crash_identifiers'] |
| 108 platform = 'win' | |
| 109 channel = 'canary' | |
| 110 crash_identifiers = { | |
| 111 'chrome_version': chrome_version, | |
| 112 'signature': signature, | |
| 113 'channel': channel, | |
| 114 'platform': platform, | |
| 115 'process_type': 'browser', | |
| 116 } | |
| 117 analysis = FracasCrashAnalysis.Create(crash_identifiers) | 118 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 118 analysis.status = analysis_status.COMPLETED | 119 analysis.status = analysis_status.COMPLETED |
| 119 analysis.put() | 120 analysis.put() |
| 120 | 121 self.assertFalse(FinditForFracas().ScheduleNewAnalysis(crash_data)) |
| 121 self.assertFalse( | |
| 122 crash_pipeline.ScheduleNewAnalysisForCrash( | |
| 123 crash_identifiers, chrome_version, signature, 'fracas', | |
| 124 platform, None, {'channel': channel, | |
| 125 'historical_metadata': None})) | |
| 126 | 122 |
| 127 def _TestRunningAnalysisForResult(self, analysis_result, analysis_tags): | 123 def _TestRunningAnalysisForResult(self, analysis_result, analysis_tags): |
| 124 # Reconstruct the culprit that gives rise to the analysis_{result,tags} |
| 125 mock_culprit = Culprit( |
| 126 project = analysis_result.get('suspected_project', None), |
| 127 components = analysis_result.get('suspected_components', None), |
| 128 cls = analysis_result.get('suspected_cls', None), |
| 129 regression_range = analysis_result.get('regression_range', (None, None))
, |
| 130 algorithm = analysis_tags.get('solution', None), |
| 131 ) |
| 132 |
| 128 pubsub_publish_requests = [] | 133 pubsub_publish_requests = [] |
| 129 def Mocked_PublishMessagesToTopic(messages_data, topic): | 134 def Mocked_PublishMessagesToTopic(messages_data, topic): |
| 130 pubsub_publish_requests.append((messages_data, topic)) | 135 pubsub_publish_requests.append((messages_data, topic)) |
| 131 self.mock(crash_pipeline.pubsub_util, 'PublishMessagesToTopic', | 136 self.mock(crash_pipeline.pubsub_util, 'PublishMessagesToTopic', |
| 132 Mocked_PublishMessagesToTopic) | 137 Mocked_PublishMessagesToTopic) |
| 133 | 138 |
| 134 analyzed_crashes = [] | 139 analyzed_crashes = [] |
| 135 class Mocked_FinditForChromeCrash(object): | 140 class _MockFinditForFracas(FinditForFracas): |
| 136 def __init__(self, *_): | |
| 137 pass | |
| 138 def FindCulprit(self, *args): | 141 def FindCulprit(self, *args): |
| 139 analyzed_crashes.append(args) | 142 analyzed_crashes.append(args) |
| 140 return analysis_result, analysis_tags | 143 return mock_culprit |
| 141 self.mock(findit_for_chromecrash, 'FinditForChromeCrash', | |
| 142 Mocked_FinditForChromeCrash) | |
| 143 | |
| 144 chrome_version = '1' | |
| 145 signature = 'signature' | |
| 146 platform = 'win' | |
| 147 channel = 'canary' | |
| 148 crash_identifiers = { | |
| 149 'chrome_version': chrome_version, | |
| 150 'signature': signature, | |
| 151 'channel': channel, | |
| 152 'platform': platform, | |
| 153 'process_type': 'browser', | |
| 154 } | |
| 155 stack_trace = 'frame1\nframe2\nframe3' | |
| 156 chrome_version = '50.2500.0.1' | |
| 157 historical_metadata = None | |
| 158 | 144 |
| 159 mock_host = 'https://host.com' | 145 mock_host = 'https://host.com' |
| 160 self.mock(app_identity, 'get_default_version_hostname', lambda: mock_host) | 146 self.mock(app_identity, 'get_default_version_hostname', lambda: mock_host) |
| 161 | 147 |
| 162 self.assertTrue( | 148 crash_data = DummyCrashData( |
| 163 crash_pipeline.ScheduleNewAnalysisForCrash( | 149 version = '50.2500.0.1', |
| 164 crash_identifiers, chrome_version, signature, 'fracas', | 150 stack_trace = 'frame1\nframe2\nframe3') |
| 165 platform, stack_trace, | 151 self.assertTrue(_MockFinditForFracas().ScheduleNewAnalysis(crash_data)) |
| 166 {'channel': channel, 'historical_metadata': historical_metadata})) | |
| 167 | 152 |
| 168 self.execute_queued_tasks() | 153 # We catch and re-raise to clean up the callstack that's reported. |
| 154 try: |
| 155 self.execute_queued_tasks() |
| 156 except AppError, e: |
| 157 raise e |
| 169 | 158 |
| 170 self.assertEqual(1, len(pubsub_publish_requests)) | 159 self.assertEqual(1, len(pubsub_publish_requests)) |
| 171 | 160 |
| 172 processed_analysis_result = copy.deepcopy(analysis_result) | 161 processed_analysis_result = copy.deepcopy(analysis_result) |
| 173 processed_analysis_result['feedback_url'] = ( | 162 processed_analysis_result['feedback_url'] = ( |
| 174 mock_host + '/crash/fracas-result-feedback?' | 163 mock_host + '/crash/fracas-result-feedback?' |
| 175 'key=agx0ZXN0YmVkLXRlc3RyQQsSE0ZyYWNhc0NyYXNoQW5hbHlzaXMiKGU2ZWIyNj' | 164 'key=agx0ZXN0YmVkLXRlc3RyQQsSE0ZyYWNhc0NyYXNoQW5hbHlzaXMiKGU2ZWIyNj' |
| 176 'A2OTBlYTAyMjVjNWNjYTM3ZTNjYTlmYWExOGVmYjVlM2UM') | 165 'A2OTBlYTAyMjVjNWNjYTM3ZTNjYTlmYWExOGVmYjVlM2UM') |
| 177 | 166 |
| 178 if 'suspected_cls' in processed_analysis_result: | 167 if 'suspected_cls' in processed_analysis_result: |
| 179 for cl in processed_analysis_result['suspected_cls']: | 168 for cl in processed_analysis_result['suspected_cls']: |
| 180 cl['confidence'] = round(cl['confidence'], 2) | 169 cl['confidence'] = round(cl['confidence'], 2) |
| 181 cl.pop('reason', None) | 170 cl.pop('reason', None) |
| 182 | 171 |
| 183 expected_messages_data = [json.dumps({ | 172 expected_messages_data = [json.dumps({ |
| 184 'crash_identifiers': crash_identifiers, | 173 'crash_identifiers': crash_data['crash_identifiers'], |
| 185 'client_id': 'fracas', | 174 'client_id': 'fracas', |
| 186 'result': processed_analysis_result, | 175 'result': processed_analysis_result, |
| 187 }, sort_keys=True)] | 176 }, sort_keys=True)] |
| 188 self.assertEqual(expected_messages_data, pubsub_publish_requests[0][0]) | 177 self.assertEqual(expected_messages_data, pubsub_publish_requests[0][0]) |
| 189 | 178 |
| 190 self.assertEqual(1, len(analyzed_crashes)) | 179 self.assertEqual(1, len(analyzed_crashes)) |
| 191 self.assertEqual( | 180 self.assertEqual( |
| 192 (signature, platform, stack_trace, chrome_version, None), | 181 (crash_data['signature'], crash_data['platform'], |
| 182 crash_data['stack_trace'], crash_data['chrome_version'], None), |
| 193 analyzed_crashes[0]) | 183 analyzed_crashes[0]) |
| 194 | 184 |
| 195 analysis = FracasCrashAnalysis.Get(crash_identifiers) | 185 analysis = FracasCrashAnalysis.Get(crash_data['crash_identifiers']) |
| 196 self.assertEqual(analysis_result, analysis.result) | 186 self.assertEqual(analysis_result, analysis.result) |
| 197 return analysis | 187 return analysis |
| 198 | 188 |
| 199 | |
| 200 def testRunningAnalysis(self): | 189 def testRunningAnalysis(self): |
| 201 analysis_result = { | 190 analysis_result = { |
| 202 'found': True, | 191 'found': True, |
| 203 'suspected_cls': [], | 192 'suspected_cls': [], |
| 204 'other_data': 'data', | 193 'other_data': 'data', |
| 205 } | 194 } |
| 206 analysis_tags = { | 195 analysis_tags = { |
| 207 'found_suspects': True, | 196 'found_suspects': True, |
| 208 'has_regression_range': True, | 197 'has_regression_range': True, |
| 209 'solution': 'core', | 198 'solution': 'core', |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 'unsupported_tag': '', | 239 'unsupported_tag': '', |
| 251 } | 240 } |
| 252 | 241 |
| 253 analysis = self._TestRunningAnalysisForResult( | 242 analysis = self._TestRunningAnalysisForResult( |
| 254 analysis_result, analysis_tags) | 243 analysis_result, analysis_tags) |
| 255 self.assertTrue(analysis.has_regression_range) | 244 self.assertTrue(analysis.has_regression_range) |
| 256 self.assertTrue(analysis.found_suspects) | 245 self.assertTrue(analysis.found_suspects) |
| 257 self.assertEqual('core', analysis.solution) | 246 self.assertEqual('core', analysis.solution) |
| 258 | 247 |
| 259 def testAnalysisAborted(self): | 248 def testAnalysisAborted(self): |
| 260 chrome_version = '1' | 249 crash_data = DummyCrashData() |
| 261 signature = 'signature' | 250 crash_identifiers = crash_data['crash_identifiers'] |
| 262 platform = 'win' | |
| 263 crash_identifiers = { | |
| 264 'chrome_version': chrome_version, | |
| 265 'signature': signature, | |
| 266 'channel': 'canary', | |
| 267 'platform': platform, | |
| 268 'process_type': 'browser', | |
| 269 } | |
| 270 analysis = FracasCrashAnalysis.Create(crash_identifiers) | 251 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 271 analysis.status = analysis_status.RUNNING | 252 analysis.status = analysis_status.RUNNING |
| 272 analysis.put() | 253 analysis.put() |
| 273 | 254 |
| 274 pipeline = crash_pipeline.CrashAnalysisPipeline(crash_identifiers, 'fracas') | 255 pipeline = crash_pipeline.CrashAnalysisPipeline(FinditForFracas(), |
| 275 pipeline._SetErrorIfAborted(True) | 256 crash_identifiers) |
| 257 pipeline._PutAbortedError() |
| 276 analysis = FracasCrashAnalysis.Get(crash_identifiers) | 258 analysis = FracasCrashAnalysis.Get(crash_identifiers) |
| 277 self.assertEqual(analysis_status.ERROR, analysis.status) | 259 self.assertEqual(analysis_status.ERROR, analysis.status) |
| OLD | NEW |