| 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_chromecrash |
| 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 self.assertTrue(findit_for_client.ResetAnalysis( |
| 96 analysis, crash_identifiers, chrome_version, |
| 97 signature, CrashClient.FRACAS, platform, |
| 98 stack_trace, customized_data)) |
| 99 analysis = FracasCrashAnalysis.Get(crash_identifiers) |
| 100 self.assertEqual(analysis.crashed_version, chrome_version) |
| 101 self.assertEqual(analysis.signature, signature) |
| 102 self.assertEqual(analysis.platform, platform) |
| 103 self.assertEqual(analysis.stack_trace, stack_trace) |
| 104 self.assertEqual(analysis.channel, customized_data['channel']) |
| 105 |
| 106 def testResetAnalysisForFracasNoneAnalysis(self): |
| 107 chrome_version = '1' |
| 108 signature = 'signature' |
| 109 platform = 'linux' |
| 110 stack_trace = 'stack_trace' |
| 111 crash_identifiers = { |
| 112 'chrome_version': chrome_version, |
| 113 'signature': signature, |
| 114 'channel': 'canary', |
| 115 'platform': platform, |
| 116 'process_type': 'browser', |
| 117 } |
| 118 customized_data = {'channel': 'canary'} |
| 119 self.assertTrue(findit_for_client.ResetAnalysis( |
| 120 None, crash_identifiers, chrome_version, |
| 121 signature, CrashClient.FRACAS, platform, |
| 122 stack_trace, customized_data)) |
| 123 analysis = FracasCrashAnalysis.Get(crash_identifiers) |
| 124 self.assertEqual(analysis.crashed_version, chrome_version) |
| 125 self.assertEqual(analysis.signature, signature) |
| 126 self.assertEqual(analysis.platform, platform) |
| 127 self.assertEqual(analysis.stack_trace, stack_trace) |
| 128 self.assertEqual(analysis.channel, customized_data['channel']) |
| 129 |
| 130 def testResetAnalysisForUnsupportedClientId(self): |
| 131 chrome_version = '1' |
| 132 signature = 'signature' |
| 133 platform = 'linux' |
| 134 stack_trace = 'stack_trace' |
| 135 crash_identifiers = { |
| 136 'chrome_version': chrome_version, |
| 137 'signature': signature, |
| 138 'channel': 'canary', |
| 139 'platform': platform, |
| 140 'process_type': 'browser', |
| 141 } |
| 142 customized_data = {'channel': 'canary'} |
| 143 |
| 144 self.assertFalse(findit_for_client.ResetAnalysis( |
| 145 None, crash_identifiers, chrome_version, |
| 146 signature, 'unsupported', platform, |
| 147 stack_trace, customized_data)) |
| 148 |
| 149 def testGetPublishResultFromAnalysisFoundTrue(self): |
| 150 mock_host = 'https://host.com' |
| 151 self.mock(app_identity, 'get_default_version_hostname', lambda: mock_host) |
| 152 |
| 153 analysis_result = { |
| 154 'found': True, |
| 155 'suspected_cls': [ |
| 156 {'confidence': 0.21434, |
| 157 'reason': ['reason1', 'reason2'], |
| 158 'other': 'data'} |
| 159 ], |
| 160 'other_data': 'data', |
| 161 } |
| 162 |
| 163 processed_analysis_result = copy.deepcopy(analysis_result) |
| 164 processed_analysis_result['feedback_url'] = ( |
| 165 mock_host + '/crash/fracas-result-feedback?' |
| 166 'key=agx0ZXN0YmVkLXRlc3RyQQsSE0ZyYWNhc0NyYXNoQW5hbHlzaXMiKDMzNTY5MDU3' |
| 167 'M2ZlYTFlZGZhMjViOTVjZmI4OGZhODFlNDk0YTEyODkM') |
| 168 |
| 169 for cl in processed_analysis_result['suspected_cls']: |
| 170 cl['confidence'] = round(cl['confidence'], 2) |
| 171 cl.pop('reason', None) |
| 172 |
| 173 crash_identifiers = {'signature': 'sig'} |
| 174 expected_messages_data = { |
| 175 'crash_identifiers': crash_identifiers, |
| 176 'client_id': CrashClient.FRACAS, |
| 177 'result': processed_analysis_result, |
| 178 } |
| 179 |
| 180 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 181 analysis.client_id = CrashClient.FRACAS |
| 182 analysis.result = analysis_result |
| 183 |
| 184 self.assertEqual(findit_for_client.GetPublishResultFromAnalysis( |
| 185 analysis, crash_identifiers, |
| 186 CrashClient.FRACAS), expected_messages_data) |
| 187 |
| 188 def testGetPublishResultFromAnalysisFoundFalse(self): |
| 189 mock_host = 'https://host.com' |
| 190 self.mock(app_identity, 'get_default_version_hostname', lambda: mock_host) |
| 191 |
| 192 analysis_result = { |
| 193 'found': False, |
| 194 } |
| 195 |
| 196 processed_analysis_result = copy.deepcopy(analysis_result) |
| 197 processed_analysis_result['feedback_url'] = ( |
| 198 mock_host + '/crash/fracas-result-feedback?' |
| 199 'key=agx0ZXN0YmVkLXRlc3RyQQsSE0ZyYWNhc0NyYXNoQW5hbHlzaXMiKDMzNTY5MDU3' |
| 200 'M2ZlYTFlZGZhMjViOTVjZmI4OGZhODFlNDk0YTEyODkM') |
| 201 |
| 202 crash_identifiers = {'signature': 'sig'} |
| 203 expected_messages_data = { |
| 204 'crash_identifiers': crash_identifiers, |
| 205 'client_id': CrashClient.FRACAS, |
| 206 'result': processed_analysis_result, |
| 207 } |
| 208 |
| 209 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 210 analysis.client_id = CrashClient.FRACAS |
| 211 analysis.result = analysis_result |
| 212 |
| 213 self.assertEqual(findit_for_client.GetPublishResultFromAnalysis( |
| 214 analysis, crash_identifiers, |
| 215 CrashClient.FRACAS), expected_messages_data) |
| 216 |
| 217 def testFindCulprit(self): |
| 218 expected_result = {'found': False} |
| 219 expected_tags = {'found_suspects': False, |
| 220 'has_regression_range': False} |
| 221 |
| 222 def _MockFindCulpritForChromeCrash(*_): |
| 223 return expected_result, expected_tags |
| 224 |
| 225 self.mock(findit_for_chromecrash, 'FindCulpritForChromeCrash', |
| 226 _MockFindCulpritForChromeCrash) |
| 227 |
| 228 analysis = FracasCrashAnalysis.Create({'signature': 'sig'}) |
| 229 analysis.client_id = CrashClient.FRACAS |
| 230 |
| 231 result, tags = findit_for_client.FindCulprit(analysis) |
| 232 self.assertEqual(result, expected_result) |
| 233 self.assertEqual(tags, expected_tags) |
| OLD | NEW |