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

Side by Side Diff: appengine/findit/waterfall/test/build_failure_analysis_test.py

Issue 838003004: [Findit] Add three sub-pipelines to analyze build failure. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Address comments. Created 5 years, 11 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 2015 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 unittest
6
7 from common.diff import ChangeType
8 from waterfall import build_failure_analysis
9 from waterfall.failure_signal import FailureSignal
10
11
12 class BuildFailureAnalysisTest(unittest.TestCase):
13
14 def testIsSameFile(self):
15 self.assertTrue(build_failure_analysis._IsSameFile('a/b/x.cc', 'x.cc'))
16 self.assertFalse(build_failure_analysis._IsSameFile('a/pre_x.cc.', 'x.cc'))
17 self.assertFalse(build_failure_analysis._IsSameFile('a/x.cc.', 'a/y.cc'))
18
19 def testNormalizeObjectFile(self):
20 cases = {
21 'obj/a/T.x.o': 'a/x.o',
22 'obj/a/T.x.y.o': 'a/x.y.o',
23 'x.o': 'x.o'
24 }
25 for obj_file, expected_file in cases.iteritems():
26 self.assertEqual(
27 expected_file,
28 build_failure_analysis._NormalizeObjectFile(obj_file))
29
30 def testStripCommonPostfix(self):
31 cases = {
32 'a_file':
33 'a_file_%s.cc' % '_'.join(build_failure_analysis._COMMON_SUFFIXES),
34 'src/b_file': 'src/b_file_impl_mac.h',
35 'c_file': 'c_file_browsertest.cc'
36 }
37 for expected_file, file_path in cases.iteritems():
38 self.assertEqual(
39 expected_file,
40 build_failure_analysis._StripExtensionAndCommonPostfix(file_path))
41
42 def testIsCorrelated(self):
43 self.assertTrue(build_failure_analysis._IsCorrelated('a.py', 'a_test.py'))
44 self.assertTrue(
45 build_failure_analysis._IsCorrelated('a.h', 'a_impl_test.o'))
46 self.assertTrue(
47 build_failure_analysis._IsCorrelated('a/b/x.cc', 'a/b/y.cc'))
48
49 self.assertFalse(
50 build_failure_analysis._IsCorrelated('a/x.cc', 'a/b/y.cc'))
51
52 def testCheckFilesAgainstSuspectedCL(self):
53 failure_signal_json = {
54 'files': {
55 'src/a/b/f1.cc': [],
56 'b/c/f2.h': [10, 20],
57 'd/e/f3_test.cc': [],
58 'x/y/f4.py': [],
59 'f5_impl.cc': []
60 }
61 }
62 change_log_json = {
63 'touched_files': [
64 {
65 'change_type': ChangeType.ADD,
66 'old_path': '/dev/null',
67 'new_path': 'a/b/f1.cc'
68 },
69 {
70 'change_type': ChangeType.MODIFY,
71 'old_path': 'a/b/c/f2.h',
72 'new_path': 'a/b/c/f2.h'
73 },
74 {
75 'change_type': ChangeType.MODIFY,
76 'old_path': 'd/e/f3.h',
77 'new_path': 'd/e/f3.h'
78 },
79 {
80 'change_type': ChangeType.DELETE,
81 'old_path': 'x/y/f4.py',
82 'new_path': '/dev/null'
83 },
84 {
85 'change_type': ChangeType.DELETE,
86 'old_path': 'h/f5.h',
87 'new_path': '/dev/null'
88 },
89 {
90 'change_type': ChangeType.RENAME,
91 'old_path': 't/y/x.cc',
92 'new_path': 's/z/x.cc'
93 },
94 ]
95 }
96
97 justification = build_failure_analysis.CheckFiles(
98 FailureSignal.FromJson(failure_signal_json), change_log_json)
99 self.assertIsNotNone(justification)
100 self.assertEqual(2, justification['suspects'])
101 self.assertEqual(13, justification['scores'])
102
103 def testCheckFilesAgainstUnrelatedCL(self):
104 failure_signal_json = {
105 'files': {
106 'src/a/b/f.cc': [],
107 }
108 }
109 change_log_json = {
110 'touched_files': [
111 {
112 'change_type': ChangeType.ADD,
113 'old_path': '/dev/null',
114 'new_path': 'a/d/f1.cc'
115 },
116 ]
117 }
118
119 justification = build_failure_analysis.CheckFiles(
120 FailureSignal.FromJson(failure_signal_json), change_log_json)
121 self.assertIsNone(justification)
122
123 def testAnalyzeSuccesfulBuild(self):
124 failure_info = {
125 'failed': False,
126 }
127 result = build_failure_analysis.AnalyzeBuildFailure(
128 failure_info, None, None)
129 self.assertEqual(0, len(result))
130
131 def testAnalyzeBuildFailure(self):
132 failure_info = {
133 'failed': True,
134 'failed_steps': {
135 'a': {
136 'current_failure': 99,
137 'first_failure': 98,
138 },
139 'b': {
140 'current_failure': 99,
141 'first_failure': 98,
142 },
143 },
144 'builds': {
145 '99': {
146 'blame_list': ['r99_1', 'r99_2'],
147 },
148 '98': {
149 'blame_list': ['r98_1'],
150 },
151 }
152 }
153 change_logs = {
154 'r99_1': {
155 'touched_files': [
156 {
157 'change_type': ChangeType.ADD,
158 'old_path': '/dev/null',
159 'new_path': 'x/y/f99_1.cc'
160 },
161 ],
162 },
163 'r99_2': {
164 'touched_files': [
165 {
166 'change_type': ChangeType.MODIFY,
167 'old_path': 'a/b/f99_2.cc',
168 'new_path': 'a/b/f99_2.cc'
169 },
170 ],
171 },
172 'r98_1': {
173 'touched_files': [
174 {
175 'change_type': ChangeType.MODIFY,
176 'old_path': 'y/z/f98.cc',
177 'new_path': 'y/z/f98.cc'
178 },
179 ],
180 },
181 }
182 failure_signals_json = {
183 'a': {
184 'files': {
185 'src/a/b/f99_2.cc': [],
186 },
187 },
188 'b': {
189 'files': {
190 'f.cc': [],
191 },
192 },
193 }
194 expected_analysis_result = {
195 'a': {
196 'r99_2': {
197 'suspects': 0,
198 'scores': 1,
199 'hints': [
200 'modify a/b/f99_2.cc',
201 ]
202 },
203 },
204 }
205
206 analysis_result = build_failure_analysis.AnalyzeBuildFailure(
207 failure_info, change_logs, failure_signals_json)
208 self.assertEqual(expected_analysis_result, analysis_result)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698