| 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 json |
| 7 |
| 8 from google.appengine.api import app_identity |
| 9 |
| 10 from crash import findit_for_client |
| 11 from crash import findit_for_fracas |
| 12 from crash.test.crash_testcase import CrashTestCase |
| 13 from crash.type_enums import CrashClient |
| 14 from model.crash.fracas_crash_analysis import FracasCrashAnalysis |
| 15 |
| 16 |
| 17 class FinditForClientTest(CrashTestCase): |
| 18 |
| 19 def testCheckPolicyUnsupportedPlatform(self): |
| 20 chrome_version = '1' |
| 21 signature = 'signature' |
| 22 platform = 'unsupported_platform' |
| 23 crash_identifiers = { |
| 24 'chrome_version': chrome_version, |
| 25 'signature': signature, |
| 26 'channel': 'canary', |
| 27 'platform': platform, |
| 28 'process_type': 'browser', |
| 29 } |
| 30 |
| 31 pass_check, _ = findit_for_client.CheckPolicyForClient( |
| 32 crash_identifiers, chrome_version, signature, |
| 33 CrashClient.FRACAS, platform, 'stack_trace', {'channel': 'canary'}) |
| 34 self.assertFalse(pass_check) |
| 35 |
| 36 def testCheckPolicyBlacklistedSignature(self): |
| 37 chrome_version = '1' |
| 38 signature = 'Blacklist marker signature' |
| 39 platform = 'win' |
| 40 crash_identifiers = { |
| 41 'chrome_version': chrome_version, |
| 42 'signature': signature, |
| 43 'channel': 'canary', |
| 44 'platform': platform, |
| 45 'process_type': 'browser', |
| 46 } |
| 47 |
| 48 pass_check, _ = findit_for_client.CheckPolicyForClient( |
| 49 crash_identifiers, chrome_version, signature, |
| 50 CrashClient.FRACAS, platform, 'stack_trace', {'channel': 'canary'}) |
| 51 self.assertFalse(pass_check) |
| 52 |
| 53 def testCheckPolicyPlatformRename(self): |
| 54 chrome_version = '1' |
| 55 signature = 'signature' |
| 56 platform = 'linux' |
| 57 crash_identifiers = { |
| 58 'chrome_version': chrome_version, |
| 59 'signature': signature, |
| 60 'channel': 'canary', |
| 61 'platform': platform, |
| 62 'process_type': 'browser', |
| 63 } |
| 64 |
| 65 pass_check, args = findit_for_client.CheckPolicyForClient( |
| 66 crash_identifiers, chrome_version, signature, |
| 67 CrashClient.FRACAS, platform, 'stack_trace', {'channel': 'canary'}) |
| 68 self.assertTrue(pass_check) |
| 69 self.assertEqual(args[4], 'unix') |
| 70 |
| 71 def testGetAnalysisForClient(self): |
| 72 crash_identifiers = {'signature': 'sig'} |
| 73 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 74 analysis.put() |
| 75 |
| 76 self.assertEqual(findit_for_client.GetAnalysisForClient( |
| 77 crash_identifiers, CrashClient.FRACAS), analysis) |
| 78 |
| 79 def testResetAnalysisForFracas(self): |
| 80 chrome_version = '1' |
| 81 signature = 'signature' |
| 82 platform = 'linux' |
| 83 stack_trace = 'stack_trace' |
| 84 crash_identifiers = { |
| 85 'chrome_version': chrome_version, |
| 86 'signature': signature, |
| 87 'channel': 'canary', |
| 88 'platform': platform, |
| 89 'process_type': 'browser', |
| 90 } |
| 91 customized_data = {'channel': 'canary'} |
| 92 |
| 93 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 94 |
| 95 findit_for_client.ResetAnalysis(analysis, crash_identifiers, chrome_version, |
| 96 signature, CrashClient.FRACAS, platform, |
| 97 stack_trace, customized_data) |
| 98 analysis = FracasCrashAnalysis.Get(crash_identifiers) |
| 99 self.assertEqual(analysis.crashed_version, chrome_version) |
| 100 self.assertEqual(analysis.signature, signature) |
| 101 self.assertEqual(analysis.platform, platform) |
| 102 self.assertEqual(analysis.stack_trace, stack_trace) |
| 103 self.assertEqual(analysis.channel, customized_data['channel']) |
| 104 |
| 105 def testResetAnalysisForFracasNoneAnalysis(self): |
| 106 chrome_version = '1' |
| 107 signature = 'signature' |
| 108 platform = 'linux' |
| 109 stack_trace = 'stack_trace' |
| 110 crash_identifiers = { |
| 111 'chrome_version': chrome_version, |
| 112 'signature': signature, |
| 113 'channel': 'canary', |
| 114 'platform': platform, |
| 115 'process_type': 'browser', |
| 116 } |
| 117 customized_data = {'channel': 'canary'} |
| 118 findit_for_client.ResetAnalysis(None, crash_identifiers, chrome_version, |
| 119 signature, CrashClient.FRACAS, platform, |
| 120 stack_trace, customized_data) |
| 121 analysis = FracasCrashAnalysis.Get(crash_identifiers) |
| 122 self.assertEqual(analysis.crashed_version, chrome_version) |
| 123 self.assertEqual(analysis.signature, signature) |
| 124 self.assertEqual(analysis.platform, platform) |
| 125 self.assertEqual(analysis.stack_trace, stack_trace) |
| 126 self.assertEqual(analysis.channel, customized_data['channel']) |
| 127 |
| 128 def testGetPublishResultFromAnalysisFoundTrue(self): |
| 129 mock_host = 'https://host.com' |
| 130 self.mock(app_identity, 'get_default_version_hostname', lambda: mock_host) |
| 131 |
| 132 analysis_result = { |
| 133 'found': True, |
| 134 'suspected_cls': [ |
| 135 {'confidence': 0.21434, |
| 136 'reason': ['reason1', 'reason2'], |
| 137 'other': 'data'} |
| 138 ], |
| 139 'other_data': 'data', |
| 140 } |
| 141 |
| 142 processed_analysis_result = copy.deepcopy(analysis_result) |
| 143 processed_analysis_result['feedback_url'] = ( |
| 144 mock_host + '/crash/fracas-result-feedback?' |
| 145 'key=agx0ZXN0YmVkLXRlc3RyQQsSE0ZyYWNhc0NyYXNoQW5hbHlzaXMiKDMzNTY5MDU3' |
| 146 'M2ZlYTFlZGZhMjViOTVjZmI4OGZhODFlNDk0YTEyODkM') |
| 147 |
| 148 for cl in processed_analysis_result['suspected_cls']: |
| 149 cl['confidence'] = round(cl['confidence'], 2) |
| 150 cl.pop('reason', None) |
| 151 |
| 152 crash_identifiers = {'signature': 'sig'} |
| 153 expected_messages_data = { |
| 154 'crash_identifiers': crash_identifiers, |
| 155 'client_id': CrashClient.FRACAS, |
| 156 'result': processed_analysis_result, |
| 157 } |
| 158 |
| 159 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 160 analysis.client_id = CrashClient.FRACAS |
| 161 analysis.result = analysis_result |
| 162 |
| 163 self.assertEqual(findit_for_client.GetPublishResultFromAnalysis( |
| 164 analysis, crash_identifiers, |
| 165 CrashClient.FRACAS), expected_messages_data) |
| 166 |
| 167 def testGetPublishResultFromAnalysisFoundFalse(self): |
| 168 mock_host = 'https://host.com' |
| 169 self.mock(app_identity, 'get_default_version_hostname', lambda: mock_host) |
| 170 |
| 171 analysis_result = { |
| 172 'found': False, |
| 173 } |
| 174 |
| 175 processed_analysis_result = copy.deepcopy(analysis_result) |
| 176 processed_analysis_result['feedback_url'] = ( |
| 177 mock_host + '/crash/fracas-result-feedback?' |
| 178 'key=agx0ZXN0YmVkLXRlc3RyQQsSE0ZyYWNhc0NyYXNoQW5hbHlzaXMiKDMzNTY5MDU3' |
| 179 'M2ZlYTFlZGZhMjViOTVjZmI4OGZhODFlNDk0YTEyODkM') |
| 180 |
| 181 crash_identifiers = {'signature': 'sig'} |
| 182 expected_messages_data = { |
| 183 'crash_identifiers': crash_identifiers, |
| 184 'client_id': CrashClient.FRACAS, |
| 185 'result': processed_analysis_result, |
| 186 } |
| 187 |
| 188 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 189 analysis.client_id = CrashClient.FRACAS |
| 190 analysis.result = analysis_result |
| 191 |
| 192 self.assertEqual(findit_for_client.GetPublishResultFromAnalysis( |
| 193 analysis, crash_identifiers, |
| 194 CrashClient.FRACAS), expected_messages_data) |
| 195 |
| 196 def testFindCulprit(self): |
| 197 expected_result = {'found': False} |
| 198 expected_tags = {'found_suspects': False, |
| 199 'has_regression_range': False} |
| 200 |
| 201 def _MockFindCulpritForChromeCrash(*_): |
| 202 return expected_result, expected_tags |
| 203 |
| 204 self.mock(findit_for_fracas, 'FindCulpritForChromeCrash', |
| 205 _MockFindCulpritForChromeCrash) |
| 206 |
| 207 analysis = FracasCrashAnalysis.Create({'signature': 'sig'}) |
| 208 analysis.client_id = CrashClient.FRACAS |
| 209 |
| 210 result, tags = findit_for_client.FindCulprit(analysis) |
| 211 self.assertEqual(result, expected_result) |
| 212 self.assertEqual(tags, expected_tags) |
| OLD | NEW |