| OLD | NEW |
| (Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import copy |
| 6 import logging |
| 7 |
| 8 from google.appengine.api import app_identity |
| 9 |
| 10 from crash import crash_pipeline |
| 11 from crash import findit |
| 12 from crash import findit_for_chromecrash |
| 13 from crash.culprit import NullCulprit |
| 14 from crash.stacktrace import Stacktrace |
| 15 from crash.crash_report import CrashReport |
| 16 from crash.findit_for_chromecrash import FinditForChromeCrash |
| 17 from crash.findit_for_chromecrash import FinditForFracas |
| 18 from crash.test.crash_testcase import CrashTestCase |
| 19 from crash.type_enums import CrashClient |
| 20 from model.crash.fracas_crash_analysis import FracasCrashAnalysis |
| 21 from crash.test.crash_pipeline_test import DummyCrashData |
| 22 |
| 23 class UnsupportedClient(findit.Findit): |
| 24 @property |
| 25 def client_id(self): |
| 26 return self._client_id |
| 27 |
| 28 def __init__(self, client_id=None): |
| 29 super(UnsupportedClient, self).__init__() |
| 30 if client_id is None: |
| 31 client_id = 'unsupported_client' |
| 32 self._client_id = client_id |
| 33 |
| 34 |
| 35 # TODO(wrengr): Our use of this highly suggests that |crash_identifiers| |
| 36 # don't actually need to be passed around everywhere. The only parts that |
| 37 # matter are the |channel| and the |process_type|, which can be passed |
| 38 # separately. |
| 39 def CrashIdentifiers(report): |
| 40 return { |
| 41 'chrome_version': report.crashed_version, |
| 42 'signature': report.signature, |
| 43 'channel': 'canary', |
| 44 'platform': report.platform, |
| 45 'process_type': 'browser' |
| 46 } |
| 47 |
| 48 DUMMY_REPORT1 = CrashReport( |
| 49 crashed_version = '1', |
| 50 signature = 'signature', |
| 51 platform = 'win', |
| 52 stacktrace = Stacktrace(), |
| 53 regression_range = None) |
| 54 |
| 55 class FindTest(CrashTestCase): |
| 56 |
| 57 def testCheckPolicyUnsupportedClient(self): |
| 58 self.assertIsNone(UnsupportedClient().CheckPolicy(DummyCrashData( |
| 59 platform = 'canary', |
| 60 signature = 'sig', |
| 61 ))) |
| 62 |
| 63 def testCheckPolicyUnsupportedPlatform(self): |
| 64 self.assertIsNone(FinditForFracas().CheckPolicy(DummyCrashData( |
| 65 platform = 'unsupported_platform'))) |
| 66 |
| 67 def testCheckPolicyBlacklistedSignature(self): |
| 68 self.assertIsNone(FinditForFracas().CheckPolicy(DummyCrashData( |
| 69 signature = 'Blacklist marker signature'))) |
| 70 |
| 71 def testCheckPolicyPlatformRename(self): |
| 72 new_crash_data = FinditForFracas().CheckPolicy(DummyCrashData( |
| 73 platform = 'linux')) |
| 74 self.assertIsNotNone(new_crash_data, |
| 75 'FinditForFracas.CheckPolicy unexpectedly returned None') |
| 76 self.assertEqual(new_crash_data['platform'], 'unix') |
| 77 |
| 78 def testGetAnalysisForFracas(self): |
| 79 crash_identifiers = {'signature': 'sig'} |
| 80 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 81 analysis.put() |
| 82 self.assertEqual(FinditForFracas().GetAnalysis(crash_identifiers), analysis) |
| 83 |
| 84 def testGetAnalysisForUnsuportedClient(self): |
| 85 crash_identifiers = {'signature': 'sig'} |
| 86 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 87 analysis.put() |
| 88 self.assertIsNone( |
| 89 UnsupportedClient('Unsupported_client').GetAnalysis(crash_identifiers), |
| 90 analysis) |
| 91 |
| 92 def testInitializeAnalysisForFracas(self): |
| 93 crash_data = DummyCrashData(platform = 'linux') |
| 94 crash_identifiers = crash_data['crash_identifiers'] |
| 95 |
| 96 findit_client = FinditForFracas() |
| 97 analysis = findit_client.CreateAnalysis(crash_identifiers) |
| 98 findit_client._InitializeAnalysis(analysis, crash_data) |
| 99 # We must put the (re)initialized analysis, or GetAnalysis will return None. |
| 100 analysis.put() |
| 101 analysis = findit_client.GetAnalysis(crash_identifiers) |
| 102 self.assertIsNotNone(analysis, |
| 103 'FinditForFracas.GetAnalysis unexpectedly returned None') |
| 104 |
| 105 self.assertEqual(analysis.crashed_version, crash_data['crashed_version']) |
| 106 self.assertEqual(analysis.signature, crash_data['signature']) |
| 107 self.assertEqual(analysis.platform, crash_data['platform']) |
| 108 self.assertEqual(analysis.stack_trace, crash_data['stack_trace']) |
| 109 channel = crash_data['customized_data'].get('channel', None) |
| 110 self.assertIsNotNone(channel, |
| 111 'channel is unexpectedly not defined in crash_data') |
| 112 self.assertEqual(analysis.channel, channel) |
| 113 |
| 114 def testCreateAnalysisForFracas(self): |
| 115 crash_identifiers = {'signature': 'sig'} |
| 116 self.assertIsNotNone(FinditForFracas().CreateAnalysis(crash_identifiers)) |
| 117 |
| 118 def testCreateAnalysisForUnsupportedClientId(self): |
| 119 crash_identifiers = {'signature': 'sig'} |
| 120 self.assertIsNone(UnsupportedClient('unsupported_id').CreateAnalysis( |
| 121 crash_identifiers)) |
| 122 |
| 123 # TODO(wrengr): what was the purpose of this test? It's just testing |
| 124 # that mocking works. |
| 125 def testFindCulprit(self): |
| 126 self.mock(findit_for_chromecrash.FinditForChromeCrash, 'FindCulprit', |
| 127 lambda self, *_: NullCulprit()) |
| 128 |
| 129 # TODO(wrengr): clean this up. |
| 130 analysis = FracasCrashAnalysis.Create({'signature': 'sig'}) |
| 131 analysis.client_id = CrashClient.FRACAS |
| 132 result, tags = FinditForChromeCrash().FindCulprit(analysis).ToDicts() |
| 133 expected_result, expected_tags = NullCulprit().ToDicts() |
| 134 self.assertDictEqual(result, expected_result) |
| 135 self.assertDictEqual(tags, expected_tags) |
| 136 |
| OLD | NEW |