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

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

Issue 2157433002: [Findit] Pass changed files info to Fracas, 2 face design. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Fix nits. Created 4 years, 5 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/parse_util_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
1 # Copyright 2016 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from common.blame import Region, Blame 5 from common.blame import Region, Blame
6 from common.change_log import ChangeLog 6 from common.change_log import ChangeLog
7 from crash.callstack import StackFrame 7 from crash.callstack import StackFrame
8 from crash.results import Result, MatchResult, MatchResults 8 from crash.results import Result, MatchResult, MatchResults
9 from crash.test.crash_test_suite import CrashTestSuite 9 from crash.test.crash_test_suite import CrashTestSuite
10 10
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 DUMMY_BLAME = Blame('4', 'a.cc') 62 DUMMY_BLAME = Blame('4', 'a.cc')
63 DUMMY_BLAME.AddRegion( 63 DUMMY_BLAME.AddRegion(
64 Region(1, 5, '2', 'r', 'r@chromium.org', 'Thu Mar 25 21:24:43 2016')) 64 Region(1, 5, '2', 'r', 'r@chromium.org', 'Thu Mar 25 21:24:43 2016'))
65 DUMMY_BLAME.AddRegion( 65 DUMMY_BLAME.AddRegion(
66 Region(6, 3, '1', 'e', 'e@chromium.org', 'Thu Mar 31 21:24:43 2016')) 66 Region(6, 3, '1', 'e', 'e@chromium.org', 'Thu Mar 31 21:24:43 2016'))
67 DUMMY_BLAME.AddRegion( 67 DUMMY_BLAME.AddRegion(
68 Region(9, 2, '3', 'k', 'k@chromium.org', 'Thu Apr 1 21:24:43 2016')) 68 Region(9, 2, '3', 'k', 'k@chromium.org', 'Thu Apr 1 21:24:43 2016'))
69 69
70 DUMMY_BLAME2 = Blame('4', 'b.cc') 70 DUMMY_BLAME2 = Blame('4', 'b.cc')
71 DUMMY_BLAME.AddRegion( 71 DUMMY_BLAME2.AddRegion(
72 Region(1, 5, '2', 'r', 'r@chromium.org', 'Thu Mar 25 21:24:43 2016')) 72 Region(1, 5, '2', 'r', 'r@chromium.org', 'Thu Mar 25 21:24:43 2016'))
73 DUMMY_BLAME.AddRegion( 73 DUMMY_BLAME2.AddRegion(
74 Region(6, 3, '1', 'e', 'e@chromium.org', 'Thu Mar 31 21:24:43 2016')) 74 Region(6, 3, '1', 'e', 'e@chromium.org', 'Thu Mar 31 21:24:43 2016'))
75 75
76 76
77 class ResultsTest(CrashTestSuite): 77 class ResultsTest(CrashTestSuite):
78 78
79 def testResultToDict(self): 79 def testResultToDict(self):
80 80
81 result = Result(DUMMY_CHANGELOG1, 'src/', 81 result = Result(DUMMY_CHANGELOG1, 'src/',
82 confidence=1, reason='some reason') 82 confidence=1, reasons=['MinDistance', 0.5, 'some reason'],
83 changed_files={'file': 'f', 'blame_url': 'http://b',
84 'info': 'min distance (LOC) 5'})
83 85
84 expected_result_json = { 86 expected_result_json = {
85 'url': DUMMY_CHANGELOG1.commit_url, 87 'url': DUMMY_CHANGELOG1.commit_url,
86 'review_url': DUMMY_CHANGELOG1.code_review_url, 88 'review_url': DUMMY_CHANGELOG1.code_review_url,
87 'revision': DUMMY_CHANGELOG1.revision, 89 'revision': DUMMY_CHANGELOG1.revision,
88 'project_path': 'src/', 90 'project_path': 'src/',
89 'author': DUMMY_CHANGELOG1.author_email, 91 'author': DUMMY_CHANGELOG1.author_email,
90 'time': str(DUMMY_CHANGELOG1.author_time), 92 'time': str(DUMMY_CHANGELOG1.author_time),
91 'reason': 'some reason', 93 'reasons': ['MinDistance', 0.5, 'some reason'],
94 'changed_files': {'file': 'f', 'blame_url': 'http://b',
95 'info': 'min distance (LOC) 5'},
92 'confidence': 1, 96 'confidence': 1,
93 } 97 }
94 98
95 self.assertEqual(result.ToDict(), expected_result_json) 99 self.assertEqual(result.ToDict(), expected_result_json)
96 100
97 def testResultToString(self): 101 def testResultToString(self):
98 102
99 result = Result(DUMMY_CHANGELOG1, 'src/', 103 result = Result(DUMMY_CHANGELOG1, 'src/', confidence=1)
100 confidence=1, reason='some reason')
101 104
102 expected_result_str = '' 105 expected_result_str = ''
103 self.assertEqual(result.ToString(), expected_result_str) 106 self.assertEqual(result.ToString(), expected_result_str)
104 107
105 result.file_to_stack_infos = { 108 result.file_to_stack_infos = {
106 'a.cc': [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', []), 0)] 109 'a.cc': [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', []), 0)]
107 } 110 }
108 expected_result_str = 'Changed file a.cc crashed in frame #0' 111 expected_result_str = 'Changed file a.cc crashed in frame #0'
109 112
110 self.assertEqual(str(result), expected_result_str) 113 self.assertEqual(str(result), expected_result_str)
111 114
112 def testMatchResultUpdate(self): 115 def testMatchResultUpdate(self):
113 # Touched lines have intersection with crashed lines. 116 # Touched lines have intersection with crashed lines.
114 result = MatchResult(DUMMY_CHANGELOG1, 'src/', 117 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1)
115 confidence=1, reason='some reason')
116 stack_infos = [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]), 0)] 118 stack_infos = [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]), 0)]
117 119
118 result.Update('a.cc', stack_infos, DUMMY_BLAME) 120 result.Update('a.cc', stack_infos, DUMMY_BLAME)
119 self.assertEqual(result.min_distance, 0) 121 self.assertEqual(result.file_to_analysis_info['a.cc']['min_distance'], 0)
120 122
121 # Touched lines are before crashed lines. 123 # Touched lines are before crashed lines.
122 result = MatchResult(DUMMY_CHANGELOG1, 'src/', 124 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1)
123 confidence=1, reason='some reason')
124 125
125 stack_infos = [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [3]), 0)] 126 stack_infos = [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [3]), 0)]
126 127
127 result.Update('a.cc', stack_infos, DUMMY_BLAME) 128 result.Update('a.cc', stack_infos, DUMMY_BLAME)
128 self.assertEqual(result.min_distance, 3) 129 self.assertEqual(result.file_to_analysis_info['a.cc']['min_distance'], 3)
129 130
130 # Touched lines are after crashed lines. 131 # Touched lines are after crashed lines.
131 result = MatchResult(DUMMY_CHANGELOG1, 'src/', 132 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1)
132 confidence=1, reason='some reason')
133 133
134 stack_infos = [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [10]), 0)] 134 stack_infos = [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [10]), 0)]
135 135
136 result.Update('a.cc', stack_infos, DUMMY_BLAME) 136 result.Update('a.cc', stack_infos, DUMMY_BLAME)
137 self.assertEqual(result.min_distance, 2) 137 self.assertEqual(result.file_to_analysis_info['a.cc']['min_distance'], 2)
138
139 def testMatchResultUpdateWithEmptyBlame(self):
140 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1)
141 stack_infos = [(StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]), 0)]
142
143 result.Update('a.cc', stack_infos, None)
144 self.assertEqual(result.file_to_stack_infos['a.cc'], stack_infos)
145 self.assertEqual(result.file_to_analysis_info, {})
146
147 def testMatchResultUpdateMinimumDistance(self):
148 result = MatchResult(DUMMY_CHANGELOG1, 'src/', confidence=1)
149 frame1 = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7])
150 frame2 = StackFrame(2, 'src/', 'func', 'a.cc', 'src/a.cc', [20])
151 stack_infos = [(frame1, 0), (frame2, 0)]
152
153 result.Update('a.cc', stack_infos, DUMMY_BLAME)
154 self.assertEqual(result.file_to_stack_infos['a.cc'], stack_infos)
155 self.assertEqual(result.file_to_analysis_info, {'a.cc': {
156 'min_distance': 0, 'min_distance_frame': frame1}})
138 157
139 def testMatchResultsGenerateMatchResults(self): 158 def testMatchResultsGenerateMatchResults(self):
140 match_results = MatchResults(ignore_cls=set(['2'])) 159 match_results = MatchResults(ignore_cls=set(['2']))
141 stack_infos1 = [(StackFrame( 160 frame1 = StackFrame(0, 'src/', 'func', 'a.cc', 'src/a.cc', [7])
142 0, 'src/', 'func', 'a.cc', 'src/a.cc', [7]), 0)] 161 frame2 = StackFrame(1, 'src/', 'func', 'b.cc', 'src/b.cc', [11])
143 stack_infos2 = [(StackFrame( 162 stack_infos1 = [(frame1, 0)]
144 1, 'src/', 'func', 'b.cc', 'src/b.cc', [11]), 0)] 163 stack_infos2 = [(frame2, 0)]
145 match_results.GenerateMatchResults('a.cc', 'src/', stack_infos1, 164 match_results.GenerateMatchResults('a.cc', 'src/', stack_infos1,
146 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2], 165 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2],
147 DUMMY_BLAME) 166 DUMMY_BLAME)
148 167
149 match_results.GenerateMatchResults('b.cc', 'src/', stack_infos2, 168 match_results.GenerateMatchResults('b.cc', 'src/', stack_infos2,
150 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2], 169 [DUMMY_CHANGELOG1, DUMMY_CHANGELOG2],
151 DUMMY_BLAME2) 170 DUMMY_BLAME2)
152 171
153 expected_match_result = MatchResult(DUMMY_CHANGELOG1, 'src/') 172 expected_match_result = MatchResult(DUMMY_CHANGELOG1, 'src/')
154 expected_match_result.file_to_stack_infos = { 173 expected_match_result.file_to_stack_infos = {
155 'a.cc': stack_infos1, 174 'a.cc': stack_infos1,
156 'b.cc': stack_infos2 175 'b.cc': stack_infos2,
157 } 176 }
158 expected_match_result.min_distance = 0 177 expected_match_result.file_to_analysis_info = {
178 'a.cc': {'min_distance': 0, 'min_distance_frame': frame1},
179 'b.cc': {'min_distance': 3, 'min_distance_frame': frame2},
180 }
159 181
160 expected_match_results = MatchResults(ignore_cls=set(['2'])) 182 expected_match_results = MatchResults(ignore_cls=set(['2']))
161 expected_match_results['1'] = expected_match_result 183 expected_match_results['1'] = expected_match_result
162 184
163 self._VerifyTwoMatchResultsEqual(match_results, expected_match_results) 185 self._VerifyTwoMatchResultsEqual(match_results, expected_match_results)
OLDNEW
« no previous file with comments | « appengine/findit/crash/test/parse_util_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698