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

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

Issue 1861373003: [Findit] Initial code of findit for crash. Add scorers to apply heuristic rules. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Fix nits and rebase Created 4 years, 8 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
« no previous file with comments | « appengine/findit/crash/test/findit_for_crash_test.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 from common.blame import Region, Blame
6 from common.change_log import ChangeLog
7 from crash.callstack import StackFrame
8 from crash.results import Result, MatchResult, MatchResults
9 from crash.test.crash_test_suite import CrashTestSuite
10
11 DUMMY_CHANGELOG1 = ChangeLog.FromDict({
12 'author_name': 'r@chromium.org',
13 'message': 'dummy',
14 'committer_email': 'r@chromium.org',
15 'commit_position': 175900,
16 'author_email': 'r@chromium.org',
17 'touched_files': [
18 {
19 'change_type': 'modify',
20 'new_path': 'a.cc',
21 'old_path': 'a.cc',
22 },
23 {
24 'change_type': 'modify',
25 'new_path': 'b.cc',
26 'old_path': 'b.cc',
27 },
28 ],
29 'author_time': 'Thu Mar 31 21:24:43 2016',
30 'committer_time': 'Thu Mar 31 21:28:39 2016',
31 'commit_url':
32 'https://repo.test/+/1',
33 'code_review_url': 'https://codereview.chromium.org/3281',
34 'committer_name': 'r',
35 'revision': '1',
36 'reverted_revision': None
37 })
38
39 DUMMY_CHANGELOG2 = ChangeLog.FromDict({
40 'author_name': 'e@chromium.org',
41 'message': 'dummy',
42 'committer_email': 'e@chromium.org',
43 'commit_position': 175911,
44 'author_email': 'e@chromium.org',
45 'touched_files': [
46 {
47 'change_type': 'modify',
48 'new_path': 'a.cc',
49 'old_path': 'a.cc',
50 },
51 ],
52 'author_time': 'Thu Mar 31 21:24:43 2016',
53 'committer_time': 'Thu Mar 31 21:28:39 2016',
54 'commit_url':
55 'https://repo.test/+/2',
56 'code_review_url': 'https://codereview.chromium.org/3290',
57 'committer_name': 'e',
58 'revision': '2',
59 'reverted_revision': None
60 })
61
62 DUMMY_BLAME = Blame('4', 'a.cc')
63 DUMMY_BLAME.AddRegion(
64 Region(1, 5, '2', 'r', 'r@chromium.org', 'Thu Mar 25 21:24:43 2016'))
65 DUMMY_BLAME.AddRegion(
66 Region(6, 3, '1', 'e', 'e@chromium.org', 'Thu Mar 31 21:24:43 2016'))
67 DUMMY_BLAME.AddRegion(
68 Region(9, 2, '3', 'k', 'k@chromium.org', 'Thu Apr 1 21:24:43 2016'))
69
70 DUMMY_BLAME2 = Blame('4', 'b.cc')
71 DUMMY_BLAME.AddRegion(
72 Region(1, 5, '2', 'r', 'r@chromium.org', 'Thu Mar 25 21:24:43 2016'))
73 DUMMY_BLAME.AddRegion(
74 Region(6, 3, '1', 'e', 'e@chromium.org', 'Thu Mar 31 21:24:43 2016'))
75
76
77 class ResultsTest(CrashTestSuite):
78
79 def testResultToDict(self):
80
81 result = Result(DUMMY_CHANGELOG1, 'src/', '',
82 confidence=1, reason='some reason')
83
84 expected_result_json = {
85 'url': DUMMY_CHANGELOG1.commit_url,
86 'revision': DUMMY_CHANGELOG1.revision,
87 'dep_path': 'src/',
88 'component': '',
89 'author': DUMMY_CHANGELOG1.author_email,
90 'time': str(DUMMY_CHANGELOG1.author_time),
91 'reason': 'some reason',
92 'confidence': 1,
93 }
94
95 self.assertEqual(result.ToDict(), expected_result_json)
96
97 def testResultToString(self):
98
99 result = Result(DUMMY_CHANGELOG1, 'src/', '',
100 confidence=1, reason='some reason')
101
102 expected_result_str = ''
103 self.assertEqual(result.ToString(), expected_result_str)
104
105 result.file_to_stack_infos = {
106 'a.cc': [(StackFrame(0, 'src/', '', 'func', 'a.cc', []), 0)]
107 }
108 expected_result_str = 'Changed file a.cc which crashed in func (#0)'
109
110 self.assertEqual(str(result), expected_result_str)
111
112 def testMatchResultUpdate(self):
113 # Touched lines have intersection with crashed lines.
114 result = MatchResult(DUMMY_CHANGELOG1, 'src/', '',
115 confidence=1, reason='some reason')
116 stack_infos = [(StackFrame(0, 'src/', '', 'func', 'a.cc', [7]), 0)]
117
118 result.Update('a.cc', stack_infos, DUMMY_BLAME)
119 self.assertEqual(result.min_distance, 0)
120
121 # Touched lines are before crashed lines.
122 result = MatchResult(DUMMY_CHANGELOG1, 'src/', '',
123 confidence=1, reason='some reason')
124
125 stack_infos = [(StackFrame(0, 'src/', '', 'func', 'a.cc', [3]), 0)]
126
127 result.Update('a.cc', stack_infos, DUMMY_BLAME)
128 self.assertEqual(result.min_distance, 3)
129
130 # Touched lines are after crashed lines.
131 result = MatchResult(DUMMY_CHANGELOG1, 'src/', '',
132 confidence=1, reason='some reason')
133
134 stack_infos = [(StackFrame(0, 'src/', '', 'func', 'a.cc', [10]), 0)]
135
136 result.Update('a.cc', stack_infos, DUMMY_BLAME)
137 self.assertEqual(result.min_distance, 2)
138
139 def testMatchResultsGenerateMatchResults(self):
140 match_results = MatchResults(ignore_cls=set(['2']))
141 stack_infos1 = [(StackFrame(0, 'src/', '', 'func', 'a.cc', [7]), 0)]
142 stack_infos2 = [(StackFrame(1, 'src/', '', 'func', 'b.cc', [11]), 0)]
143 match_results.GenerateMatchResults('a.cc', 'src/', stack_infos1,
144 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2],
145 DUMMY_BLAME)
146
147 match_results.GenerateMatchResults('b.cc', 'src/', stack_infos2,
148 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2],
149 DUMMY_BLAME2)
150
151 expected_match_result = MatchResult(DUMMY_CHANGELOG1, 'src/', '')
152 expected_match_result.file_to_stack_infos = {
153 'a.cc': stack_infos1,
154 'b.cc': stack_infos2
155 }
156 expected_match_result.min_distance = 0
157
158 expected_match_results = MatchResults(ignore_cls=set(['2']))
159 expected_match_results['1'] = expected_match_result
160
161 self._VerifyTwoMatchResultsEqual(match_results, expected_match_results)
OLDNEW
« no previous file with comments | « appengine/findit/crash/test/findit_for_crash_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698