| 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 """Gets analysis entity based on client id.""" |
| 71 if client_id == CrashClient.FRACAS: |
| 72 return FracasCrashAnalysis.Get(crash_identifiers) |
| 73 elif client_id == CrashClient.CRACAS: # pragma: no cover. |
| 74 # TODO(katesonia): Add CracasCrashAnalysis model. |
| 75 return None |
| 76 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. |
| 77 # TODO(katesonia): Add ClusterfuzzCrashAnalysis model. |
| 78 return None |
| 79 |
| 80 return None |
| 81 |
| 82 |
| 83 def CreateAnalysisForClient(crash_identifiers, client_id): |
| 84 """Creates analysis entity based on client id.""" |
| 85 if client_id == CrashClient.FRACAS: |
| 86 return FracasCrashAnalysis.Create(crash_identifiers) |
| 87 elif client_id == CrashClient.CRACAS: # pragma: no cover. |
| 88 # TODO(katesonia): define CracasCrashAnalysis. |
| 89 return None |
| 90 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. |
| 91 # TODO(katesonia): define ClusterfuzzCrashAnalysis. |
| 92 return None |
| 93 |
| 94 return None |
| 95 |
| 96 |
| 97 def SetAnalysis(analysis, chrome_version, signature, |
| 98 client_id, platform, stack_trace, customized_data): |
| 99 """Sets necessary info in the analysis for findit to run analysis.""" |
| 100 analysis.Reset() |
| 101 |
| 102 # Set common properties. |
| 103 analysis.crashed_version = chrome_version |
| 104 analysis.stack_trace = stack_trace |
| 105 analysis.signature = signature |
| 106 analysis.platform = platform |
| 107 analysis.client_id = client_id |
| 108 |
| 109 if client_id == CrashClient.FRACAS or client_id == CrashClient.CRACAS: |
| 110 # Set customized properties. |
| 111 analysis.historical_metadata = customized_data.get('historical_metadata') |
| 112 analysis.channel = customized_data.get('channel') |
| 113 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. |
| 114 # TODO(katesonia): Set up clusterfuzz customized data. |
| 115 pass |
| 116 |
| 117 # Set analysis progress properties. |
| 118 analysis.status = analysis_status.PENDING |
| 119 analysis.requested_time = time_util.GetUTCNow() |
| 120 |
| 121 analysis.put() |
| 122 |
| 123 |
| 124 def GetPublishResultFromAnalysis(analysis, crash_identifiers, client_id): |
| 125 """Gets result to be published to client from datastore analysis.""" |
| 126 analysis_result = copy.deepcopy(analysis.result) |
| 127 |
| 128 if (analysis.client_id == CrashClient.FRACAS or |
| 129 analysis.client_id == CrashClient.CRACAS): |
| 130 analysis_result['feedback_url'] = _FINDIT_FRACAS_FEEDBACK_URL_TEMPLATE % ( |
| 131 appengine_util.GetDefaultVersionHostname(), analysis.key.urlsafe()) |
| 132 if analysis_result['found']: |
| 133 for cl in analysis_result['suspected_cls']: |
| 134 cl['confidence'] = round(cl['confidence'], 2) |
| 135 cl.pop('reason', None) |
| 136 elif client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. |
| 137 # TODO(katesonia): Post process clusterfuzz analysis result if needed. |
| 138 pass |
| 139 |
| 140 return { |
| 141 'crash_identifiers': crash_identifiers, |
| 142 'client_id': analysis.client_id, |
| 143 'result': analysis_result, |
| 144 } |
| 145 |
| 146 |
| 147 def FindCulprit(analysis): |
| 148 result = {'found': False} |
| 149 tags = {'found_suspects': False, |
| 150 'has_regression_range': False} |
| 151 |
| 152 if (analysis.client_id == CrashClient.FRACAS or |
| 153 analysis.client_id == CrashClient.CRACAS): |
| 154 result, tags = findit_for_chromecrash.FindCulpritForChromeCrash( |
| 155 analysis.signature, analysis.platform, analysis.stack_trace, |
| 156 analysis.crashed_version, analysis.historical_metadata) |
| 157 elif analysis.client_id == CrashClient.CLUSTERFUZZ: # pragma: no cover. |
| 158 # TODO(katesonia): Implement findit_for_clusterfuzz. |
| 159 pass |
| 160 |
| 161 return result, tags |
| OLD | NEW |