| Index: appengine/findit/crash/test/findit_test.py
|
| diff --git a/appengine/findit/crash/test/findit_test.py b/appengine/findit/crash/test/findit_test.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..5d09f99fe7ed8fc390b192a7d300bd2343f308c4
|
| --- /dev/null
|
| +++ b/appengine/findit/crash/test/findit_test.py
|
| @@ -0,0 +1,136 @@
|
| +# Copyright 2016 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +import copy
|
| +import logging
|
| +
|
| +from google.appengine.api import app_identity
|
| +
|
| +from crash import crash_pipeline
|
| +from crash import findit
|
| +from crash import findit_for_chromecrash
|
| +from crash.culprit import NullCulprit
|
| +from crash.stacktrace import Stacktrace
|
| +from crash.crash_report import CrashReport
|
| +from crash.findit_for_chromecrash import FinditForChromeCrash
|
| +from crash.findit_for_chromecrash import FinditForFracas
|
| +from crash.test.crash_testcase import CrashTestCase
|
| +from crash.type_enums import CrashClient
|
| +from model.crash.fracas_crash_analysis import FracasCrashAnalysis
|
| +from crash.test.crash_pipeline_test import DummyCrashData
|
| +
|
| +class UnsupportedClient(findit.Findit):
|
| + @property
|
| + def client_id(self):
|
| + return self._client_id
|
| +
|
| + def __init__(self, client_id=None):
|
| + super(UnsupportedClient, self).__init__()
|
| + if client_id is None:
|
| + client_id = 'unsupported_client'
|
| + self._client_id = client_id
|
| +
|
| +
|
| +# TODO(wrengr): Our use of this highly suggests that |crash_identifiers|
|
| +# don't actually need to be passed around everywhere. The only parts that
|
| +# matter are the |channel| and the |process_type|, which can be passed
|
| +# separately.
|
| +def CrashIdentifiers(report):
|
| + return {
|
| + 'chrome_version': report.crashed_version,
|
| + 'signature': report.signature,
|
| + 'channel': 'canary',
|
| + 'platform': report.platform,
|
| + 'process_type': 'browser'
|
| + }
|
| +
|
| +DUMMY_REPORT1 = CrashReport(
|
| + crashed_version = '1',
|
| + signature = 'signature',
|
| + platform = 'win',
|
| + stacktrace = Stacktrace(),
|
| + regression_range = None)
|
| +
|
| +class FindTest(CrashTestCase):
|
| +
|
| + def testCheckPolicyUnsupportedClient(self):
|
| + self.assertIsNone(UnsupportedClient().CheckPolicy(DummyCrashData(
|
| + platform = 'canary',
|
| + signature = 'sig',
|
| + )))
|
| +
|
| + def testCheckPolicyUnsupportedPlatform(self):
|
| + self.assertIsNone(FinditForFracas().CheckPolicy(DummyCrashData(
|
| + platform = 'unsupported_platform')))
|
| +
|
| + def testCheckPolicyBlacklistedSignature(self):
|
| + self.assertIsNone(FinditForFracas().CheckPolicy(DummyCrashData(
|
| + signature = 'Blacklist marker signature')))
|
| +
|
| + def testCheckPolicyPlatformRename(self):
|
| + new_crash_data = FinditForFracas().CheckPolicy(DummyCrashData(
|
| + platform = 'linux'))
|
| + self.assertIsNotNone(new_crash_data,
|
| + 'FinditForFracas.CheckPolicy unexpectedly returned None')
|
| + self.assertEqual(new_crash_data['platform'], 'unix')
|
| +
|
| + def testGetAnalysisForFracas(self):
|
| + crash_identifiers = {'signature': 'sig'}
|
| + analysis = FracasCrashAnalysis.Create(crash_identifiers)
|
| + analysis.put()
|
| + self.assertEqual(FinditForFracas().GetAnalysis(crash_identifiers), analysis)
|
| +
|
| + def testGetAnalysisForUnsuportedClient(self):
|
| + crash_identifiers = {'signature': 'sig'}
|
| + analysis = FracasCrashAnalysis.Create(crash_identifiers)
|
| + analysis.put()
|
| + self.assertIsNone(
|
| + UnsupportedClient('Unsupported_client').GetAnalysis(crash_identifiers),
|
| + analysis)
|
| +
|
| + def testInitializeAnalysisForFracas(self):
|
| + crash_data = DummyCrashData(platform = 'linux')
|
| + crash_identifiers = crash_data['crash_identifiers']
|
| +
|
| + findit_client = FinditForFracas()
|
| + analysis = findit_client.CreateAnalysis(crash_identifiers)
|
| + findit_client._InitializeAnalysis(analysis, crash_data)
|
| + # We must put the (re)initialized analysis, or GetAnalysis will return None.
|
| + analysis.put()
|
| + analysis = findit_client.GetAnalysis(crash_identifiers)
|
| + self.assertIsNotNone(analysis,
|
| + 'FinditForFracas.GetAnalysis unexpectedly returned None')
|
| +
|
| + self.assertEqual(analysis.crashed_version, crash_data['crashed_version'])
|
| + self.assertEqual(analysis.signature, crash_data['signature'])
|
| + self.assertEqual(analysis.platform, crash_data['platform'])
|
| + self.assertEqual(analysis.stack_trace, crash_data['stack_trace'])
|
| + channel = crash_data['customized_data'].get('channel', None)
|
| + self.assertIsNotNone(channel,
|
| + 'channel is unexpectedly not defined in crash_data')
|
| + self.assertEqual(analysis.channel, channel)
|
| +
|
| + def testCreateAnalysisForFracas(self):
|
| + crash_identifiers = {'signature': 'sig'}
|
| + self.assertIsNotNone(FinditForFracas().CreateAnalysis(crash_identifiers))
|
| +
|
| + def testCreateAnalysisForUnsupportedClientId(self):
|
| + crash_identifiers = {'signature': 'sig'}
|
| + self.assertIsNone(UnsupportedClient('unsupported_id').CreateAnalysis(
|
| + crash_identifiers))
|
| +
|
| + # TODO(wrengr): what was the purpose of this test? It's just testing
|
| + # that mocking works.
|
| + def testFindCulprit(self):
|
| + self.mock(findit_for_chromecrash.FinditForChromeCrash, 'FindCulprit',
|
| + lambda self, *_: NullCulprit())
|
| +
|
| + # TODO(wrengr): clean this up.
|
| + analysis = FracasCrashAnalysis.Create({'signature': 'sig'})
|
| + analysis.client_id = CrashClient.FRACAS
|
| + result, tags = FinditForChromeCrash().FindCulprit(analysis).ToDicts()
|
| + expected_result, expected_tags = NullCulprit().ToDicts()
|
| + self.assertDictEqual(result, expected_result)
|
| + self.assertDictEqual(tags, expected_tags)
|
| +
|
|
|