Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: appengine/findit/crash/test/findit_test.py

Issue 2414523002: [Findit] Reorganizing findit_for_*.py (Closed)
Patch Set: more debugging Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 logging
7
8 from google.appengine.api import app_identity
9
10 from crash import crash_pipeline
11 from crash import findit
12 from crash import findit_for_chromecrash
13 from crash.culprit import NullCulprit
14 from crash.stacktrace import Stacktrace
15 from crash.crash_report import CrashReport
16 from crash.findit_for_chromecrash import FinditForChromeCrash
17 from crash.findit_for_chromecrash import FinditForFracas
18 from crash.test.crash_testcase import CrashTestCase
19 from crash.type_enums import CrashClient
20 from model.crash.fracas_crash_analysis import FracasCrashAnalysis
21 from crash.test.crash_pipeline_test import DummyCrashData
22
23 class UnsupportedClient(findit.Findit):
24 @property
25 def client_id(self):
26 return self._client_id
27
28 def __init__(self, client_id=None):
29 super(UnsupportedClient, self).__init__()
30 if client_id is None:
31 client_id = 'unsupported_client'
32 self._client_id = client_id
33
34
35 # TODO(wrengr): Our use of this highly suggests that |crash_identifiers|
36 # don't actually need to be passed around everywhere. The only parts that
37 # matter are the |channel| and the |process_type|, which can be passed
38 # separately.
39 def CrashIdentifiers(report):
40 return {
41 # TODO(wrengr): we keep waffling between whether this is
42 # called 'chrome_version' or 'crashed_version', which causes
43 # |testInitializeAnalysisForFracas| to be flaky.
44 'chrome_version': report.crashed_version,
45 'signature': report.signature,
46 'channel': 'canary',
47 'platform': report.platform,
48 'process_type': 'browser'
49 }
50
51 DUMMY_REPORT1 = CrashReport(
52 crashed_version = '1',
53 signature = 'signature',
54 platform = 'win',
55 stacktrace = Stacktrace(),
56 regression_range = None)
57
58 class FindTest(CrashTestCase):
59
60 def testCheckPolicyUnsupportedClient(self):
61 self.assertIsNone(UnsupportedClient().CheckPolicy(DummyCrashData(
62 platform = 'canary',
63 signature = 'sig',
64 )))
65
66 def testCheckPolicyUnsupportedPlatform(self):
67 self.assertIsNone(FinditForFracas().CheckPolicy(DummyCrashData(
68 platform = 'unsupported_platform')))
69
70 def testCheckPolicyBlacklistedSignature(self):
71 self.assertIsNone(FinditForFracas().CheckPolicy(DummyCrashData(
72 signature = 'Blacklist marker signature')))
73
74 def testCheckPolicyPlatformRename(self):
75 new_crash_data = FinditForFracas().CheckPolicy(DummyCrashData(
76 platform = 'linux'))
77 self.assertIsNotNone(new_crash_data,
78 'FinditForFracas.CheckPolicy unexpectedly returned None')
79 self.assertEqual(new_crash_data['platform'], 'unix')
80
81 def testGetAnalysisForFracas(self):
82 crash_identifiers = {'signature': 'sig'}
83 analysis = FracasCrashAnalysis.Create(crash_identifiers)
84 analysis.put()
85 self.assertEqual(FinditForFracas().GetAnalysis(crash_identifiers), analysis)
86
87 def testGetAnalysisForUnsuportedClient(self):
88 crash_identifiers = {'signature': 'sig'}
89 analysis = FracasCrashAnalysis.Create(crash_identifiers)
90 analysis.put()
91 self.assertIsNone(
92 UnsupportedClient('Unsupported_client').GetAnalysis(crash_identifiers),
93 analysis)
94
95 def testInitializeAnalysisForFracas(self):
96 crash_data = DummyCrashData(platform = 'linux')
97 crash_identifiers = crash_data['crash_identifiers']
98
99 findit_client = FinditForFracas()
100 analysis = findit_client.CreateAnalysis(crash_identifiers)
101 findit_client._InitializeAnalysis(analysis, crash_data)
102 # We must put the (re)initialized analysis, or GetAnalysis will return None.
103 analysis.put()
104 analysis = findit_client.GetAnalysis(crash_identifiers)
105 self.assertIsNotNone(analysis,
106 'FinditForFracas.GetAnalysis unexpectedly returned None')
107
108 self.assertEqual(analysis.crashed_version, crash_data['crashed_version'])
109 self.assertEqual(analysis.signature, crash_data['signature'])
110 self.assertEqual(analysis.platform, crash_data['platform'])
111 self.assertEqual(analysis.stack_trace, crash_data['stack_trace'])
112 channel = crash_data['customized_data'].get('channel', None)
113 self.assertIsNotNone(channel,
114 'channel is unexpectedly not defined in crash_data')
115 self.assertEqual(analysis.channel, channel)
116
117 def testCreateAnalysisForFracas(self):
118 crash_identifiers = {'signature': 'sig'}
119 self.assertIsNotNone(FinditForFracas().CreateAnalysis(crash_identifiers))
120
121 def testCreateAnalysisForUnsupportedClientId(self):
122 crash_identifiers = {'signature': 'sig'}
123 self.assertIsNone(UnsupportedClient('unsupported_id').CreateAnalysis(
124 crash_identifiers))
125
126 # TODO(wrengr): what was the purpose of this test? It's just testing
127 # that mocking works.
128 def testFindCulprit(self):
129 self.mock(findit_for_chromecrash.FinditForChromeCrash, 'FindCulprit',
130 lambda self, *_: NullCulprit())
131
132 # TODO(wrengr): clean this up.
133 analysis = FracasCrashAnalysis.Create({'signature': 'sig'})
134 analysis.client_id = CrashClient.FRACAS
135 result, tags = FinditForChromeCrash().FindCulprit(analysis).ToDicts()
136 expected_result, expected_tags = NullCulprit().ToDicts()
137 self.assertDictEqual(result, expected_result)
138 self.assertDictEqual(tags, expected_tags)
139
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698