| 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 # TODO(katesonia): Move this to fracas config. |
| 26 _FINDIT_FRACAS_FEEDBACK_URL_TEMPLATE = '%s/crash/fracas-result-feedback?key=%s' |
| 27 # TODO(katesonia): Move this to a common config in config page. |
| 28 _SUPPORTED_CLIENTS = [CrashClient.FRACAS] |
| 29 |
| 30 |
| 31 def CheckPolicyForClient(crash_identifiers, chrome_version, signature, |
| 32 client_id, platform, stack_trace, customized_data): |
| 33 """Checks if args pass client policy and updates parameters.""" |
| 34 if client_id not in _SUPPORTED_CLIENTS: |
| 35 return False, None |
| 36 |
| 37 crash_config = CrashConfig.Get() |
| 38 |
| 39 # Cracas and Fracas share the sampe policy. |
| 40 if client_id == CrashClient.FRACAS or client_id == CrashClient.CRACAS: |
| 41 channel = customized_data.get('channel') |
| 42 # TODO(katesonia): Remove the default value after adding validity check to |
| 43 # config. |
| 44 if platform not in crash_config.fracas.get( |
| 45 'supported_platform_list_by_channel', {}).get(channel, []): |
| 46 # Bail out if either the channel or platform is not supported yet. |
| 47 logging.info('Ananlysis of channel %s, platform %s is not supported. ' |
| 48 'No analysis is scheduled for %s', |
| 49 channel, platform, repr(crash_identifiers)) |
| 50 return False, None |
| 51 |
| 52 # TODO(katesonia): Remove the default value after adding validity check to |
| 53 # config. |
| 54 for blacklist_marker in crash_config.fracas.get( |
| 55 'signature_blacklist_markers', []): |
| 56 if blacklist_marker in signature: |
| 57 logging.info('%s signature is not supported. ' |
| 58 'No analysis is scheduled for %s', blacklist_marker, |
| 59 repr(crash_identifiers)) |
| 60 return False, None |
| 61 |
| 62 # TODO(katesonia): Remove the default value after adding validity check to |
| 63 # config. |
| 64 platform_rename = crash_config.fracas.get('platform_rename', {}) |
| 65 platform = platform_rename.get(platform, platform) |
| 66 |
| 67 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. |
| 68 # TODO(katesonia): Add clusterfuzz policy check. |
| 69 pass |
| 70 |
| 71 return True, (crash_identifiers, chrome_version, signature, client_id, |
| 72 platform, stack_trace, customized_data) |
| 73 |
| 74 |
| 75 def GetAnalysisForClient(crash_identifiers, client_id): |
| 76 """Gets analysis entity based on client id.""" |
| 77 if client_id == CrashClient.FRACAS: |
| 78 return FracasCrashAnalysis.Get(crash_identifiers) |
| 79 elif client_id == CrashClient.CRACAS: # pragma: no cover. |
| 80 # TODO(katesonia): Add CracasCrashAnalysis model. |
| 81 return None |
| 82 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. |
| 83 # TODO(katesonia): Add ClusterfuzzCrashAnalysis model. |
| 84 return None |
| 85 |
| 86 return None |
| 87 |
| 88 |
| 89 def CreateAnalysisForClient(crash_identifiers, client_id): |
| 90 """Creates analysis entity based on client id.""" |
| 91 if client_id == CrashClient.FRACAS: |
| 92 return FracasCrashAnalysis.Create(crash_identifiers) |
| 93 elif client_id == CrashClient.CRACAS: # pragma: no cover. |
| 94 # TODO(katesonia): define CracasCrashAnalysis. |
| 95 return None |
| 96 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. |
| 97 # TODO(katesonia): define ClusterfuzzCrashAnalysis. |
| 98 return None |
| 99 |
| 100 return None |
| 101 |
| 102 |
| 103 def ResetAnalysis(analysis, chrome_version, signature, |
| 104 client_id, platform, stack_trace, customized_data): |
| 105 """Sets necessary info in the analysis for findit to run analysis.""" |
| 106 analysis.Reset() |
| 107 |
| 108 # Set common properties. |
| 109 analysis.crashed_version = chrome_version |
| 110 analysis.stack_trace = stack_trace |
| 111 analysis.signature = signature |
| 112 analysis.platform = platform |
| 113 analysis.client_id = client_id |
| 114 |
| 115 if client_id == CrashClient.FRACAS or client_id == CrashClient.CRACAS: |
| 116 # Set customized properties. |
| 117 analysis.historical_metadata = customized_data.get('historical_metadata') |
| 118 analysis.channel = customized_data.get('channel') |
| 119 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. |
| 120 # TODO(katesonia): Set up clusterfuzz customized data. |
| 121 pass |
| 122 |
| 123 # Set analysis progress properties. |
| 124 analysis.status = analysis_status.PENDING |
| 125 analysis.requested_time = time_util.GetUTCNow() |
| 126 |
| 127 analysis.put() |
| 128 |
| 129 |
| 130 def GetPublishResultFromAnalysis(analysis, crash_identifiers, client_id): |
| 131 """Gets result to be published to client from datastore analysis.""" |
| 132 analysis_result = copy.deepcopy(analysis.result) |
| 133 |
| 134 if (analysis.client_id == CrashClient.FRACAS or |
| 135 analysis.client_id == CrashClient.CRACAS): |
| 136 analysis_result['feedback_url'] = _FINDIT_FRACAS_FEEDBACK_URL_TEMPLATE % ( |
| 137 appengine_util.GetDefaultVersionHostname(), analysis.key.urlsafe()) |
| 138 if analysis_result['found']: |
| 139 for cl in analysis_result['suspected_cls']: |
| 140 cl['confidence'] = round(cl['confidence'], 2) |
| 141 cl.pop('reason', None) |
| 142 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. |
| 143 # TODO(katesonia): Post process clusterfuzz analysis result if needed. |
| 144 pass |
| 145 |
| 146 return { |
| 147 'crash_identifiers': crash_identifiers, |
| 148 'client_id': analysis.client_id, |
| 149 'result': analysis_result, |
| 150 } |
| 151 |
| 152 |
| 153 def FindCulprit(analysis): |
| 154 result = {'found': False} |
| 155 tags = {'found_suspects': False, |
| 156 'has_regression_range': False} |
| 157 |
| 158 if (analysis.client_id == CrashClient.FRACAS or |
| 159 analysis.client_id == CrashClient.CRACAS): |
| 160 result, tags = findit_for_chromecrash.FindCulpritForChromeCrash( |
| 161 analysis.signature, analysis.platform, analysis.stack_trace, |
| 162 analysis.crashed_version, analysis.historical_metadata) |
| 163 elif analysis.client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. |
| 164 # TODO(katesonia): Implement findit_for_clusterfuzz. |
| 165 pass |
| 166 |
| 167 return result, tags |
| OLD | NEW |