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