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