Chromium Code Reviews| 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 """This module is interfacas between clients-specific code and core. | |
| 6 | |
| 7 Note, fracas and cracas are almost identical and fracas is an intermidiate | |
| 8 state while transfering to cracas, so they can be handled in the same code path | |
| 9 and can be referred to as chromecrash.""" | |
| 10 | |
| 11 import copy | |
| 12 import json | |
| 13 import logging | |
| 14 | |
| 15 from google.appengine.ext import ndb | |
| 16 | |
| 17 from common import appengine_util | |
| 18 from common import time_util | |
| 19 from crash import findit_for_chromecrash | |
| 20 from crash.type_enums import CrashClient | |
| 21 from model import analysis_status | |
| 22 from model.crash.crash_config import CrashConfig | |
| 23 from model.crash.fracas_crash_analysis import FracasCrashAnalysis | |
| 24 | |
| 25 _FINDIT_FRACAS_FEEDBACK_URL_TEMPLATE = '%s/crash/fracas-result-feedback?key=%s' | |
| 26 | |
| 27 | |
| 28 def CheckPolicyForClient(crash_identifiers, chrome_version, signature, | |
| 29 client_id, platform, stack_trace, customized_data): | |
| 30 """Checks if args pass client policy and updates parameters.""" | |
| 31 crash_config = CrashConfig.Get() | |
| 32 | |
| 33 # Cracas and Fracas share the sampe policy. | |
| 34 if client_id == CrashClient.FRACAS or client_id == CrashClient.CRACAS: | |
| 35 channel = customized_data.get('channel') | |
| 36 # TODO(katesonia): Remove the default value after adding validity check to | |
| 37 # config. | |
| 38 if platform not in crash_config.fracas.get( | |
| 39 'supported_platform_list_by_channel', {}).get(channel, []): | |
| 40 # Bail out if either the channel or platform is not supported yet. | |
| 41 logging.info('Ananlysis of channel %s, platform %s is not supported. ' | |
| 42 'No analysis is scheduled for %s', | |
| 43 channel, platform, repr(crash_identifiers)) | |
| 44 return False, None | |
| 45 | |
| 46 # TODO(katesonia): Remove the default value after adding validity check to | |
| 47 # config. | |
| 48 for blacklist_marker in crash_config.fracas.get( | |
| 49 'signature_blacklist_markers', []): | |
| 50 if blacklist_marker in signature: | |
| 51 logging.info('%s signature is not supported. ' | |
| 52 'No analysis is scheduled for %s', blacklist_marker, | |
| 53 repr(crash_identifiers)) | |
| 54 return False, None | |
| 55 | |
| 56 # TODO(katesonia): Remove the default value after adding validity check to | |
| 57 # config. | |
| 58 platform_rename = crash_config.fracas.get('platform_rename', {}) | |
| 59 platform = platform_rename.get(platform, platform) | |
| 60 | |
| 61 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. | |
| 62 # TODO(katesonia): Add clusterfuzz policy check. | |
| 63 pass | |
| 64 | |
| 65 return True, (crash_identifiers, chrome_version, signature, client_id, | |
| 66 platform, stack_trace, customized_data) | |
| 67 | |
| 68 | |
| 69 def GetAnalysisForClient(crash_identifiers, client_id): | |
| 70 if client_id == CrashClient.FRACAS: | |
| 71 return FracasCrashAnalysis.Get(crash_identifiers) | |
| 72 elif client_id == CrashClient.CRACAS: # pragma: no cover. | |
| 73 # TODO(katesonia): Add CracasCrashAnalysis model. | |
| 74 return None | |
| 75 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. | |
| 76 # TODO(katesonia): Add ClusterfuzzCrashAnalysis model. | |
| 77 return None | |
| 78 | |
| 79 return None | |
| 80 | |
| 81 | |
| 82 def CreateAnalysisForClient(crash_identifiers, client_id): | |
|
Martin Barbella
2016/09/19 21:42:37
Nit: missing docstring on this one.
Sharu Jiang
2016/09/19 23:30:38
Done.
| |
| 83 # A new analysis is needed if there is no analysis. | |
| 84 if client_id == CrashClient.FRACAS: | |
| 85 return FracasCrashAnalysis.Create(crash_identifiers) | |
| 86 elif client_id == CrashClient.CRACAS: # pragma: no cover. | |
| 87 # TODO(katesonia): define CracasCrashAnalysis. | |
| 88 return None | |
| 89 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. | |
| 90 # TODO(katesonia): define ClusterfuzzCrashAnalysis. | |
| 91 return None | |
| 92 | |
| 93 return None | |
| 94 | |
| 95 | |
| 96 def SetAnalysis(analysis, chrome_version, signature, | |
| 97 client_id, platform, stack_trace, customized_data): | |
| 98 """Sets necessary info in the analysis for findit to run analysis.""" | |
| 99 analysis.Reset() | |
| 100 | |
| 101 # Set common properties. | |
| 102 analysis.crashed_version = chrome_version | |
| 103 analysis.stack_trace = stack_trace | |
| 104 analysis.signature = signature | |
| 105 analysis.platform = platform | |
| 106 analysis.client_id = client_id | |
| 107 | |
| 108 if client_id == CrashClient.FRACAS or client_id == CrashClient.CRACAS: | |
| 109 # Set customized properties. | |
| 110 analysis.historical_metadata = customized_data.get('historical_metadata') | |
| 111 analysis.channel = customized_data.get('channel') | |
| 112 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. | |
| 113 # TODO(katesonia): Set up clusterfuzz customized data. | |
| 114 pass | |
| 115 | |
| 116 # Set analysis progress properties. | |
| 117 analysis.status = analysis_status.PENDING | |
| 118 analysis.requested_time = time_util.GetUTCNow() | |
| 119 | |
| 120 analysis.put() | |
| 121 | |
| 122 | |
| 123 def GetPublishResultFromAnalysis(analysis, crash_identifiers, client_id): | |
| 124 """Gets result to be published to client from datastore analysis.""" | |
| 125 analysis_result = copy.deepcopy(analysis.result) | |
| 126 | |
| 127 if (analysis.client_id == CrashClient.FRACAS or | |
| 128 analysis.client_id == CrashClient.CRACAS): | |
| 129 analysis_result['feedback_url'] = _FINDIT_FRACAS_FEEDBACK_URL_TEMPLATE % ( | |
| 130 appengine_util.GetDefaultVersionHostname(), analysis.key.urlsafe()) | |
| 131 if analysis_result['found']: | |
| 132 for cl in analysis_result['suspected_cls']: | |
| 133 cl['confidence'] = round(cl['confidence'], 2) | |
| 134 cl.pop('reason', None) | |
| 135 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. | |
| 136 # TODO(katesonia): Post process clusterfuzz analysis result if needed. | |
| 137 pass | |
| 138 | |
| 139 return { | |
| 140 'crash_identifiers': crash_identifiers, | |
| 141 'client_id': analysis.client_id, | |
| 142 'result': analysis_result, | |
| 143 } | |
| 144 | |
| 145 | |
| 146 def FindCulprit(analysis): | |
| 147 result = {'found': False} | |
| 148 tags = {'found_suspects': False, | |
| 149 'has_regression_range': False} | |
| 150 | |
| 151 if (analysis.client_id == CrashClient.FRACAS or | |
| 152 analysis.client_id == CrashClient.CRACAS): | |
| 153 result, tags = findit_for_chromecrash.FindCulpritForChromeCrash( | |
| 154 analysis.signature, analysis.platform, analysis.stack_trace, | |
| 155 analysis.crashed_version, analysis.historical_metadata) | |
| 156 elif analysis.client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. | |
| 157 # TODO(katesonia): Implement findit_for_clusterfuzz. | |
| 158 pass | |
| 159 | |
| 160 return result, tags | |
| OLD | NEW |