2 # Copyright (c) 2012 The Chromium OS Authors.
4 # SPDX-License-Identifier: GPL-2.0+
14 # Bring in the patman libraries
15 our_path = os.path.dirname(os.path.realpath(__file__))
16 sys.path.append(os.path.join(our_path, '../patman'))
28 '''main.c: In function 'main_loop':
29 main.c:260:6: warning: unused variable 'joe' [-Wunused-variable]
31 '''main.c: In function 'main_loop2':
32 main.c:295:2: error: 'fred' undeclared (first use in this function)
33 main.c:295:2: note: each undeclared identifier is reported only once for each function it appears in
34 make[1]: *** [main.o] Error 1
35 make: *** [common/libcommon.o] Error 2
38 '''main.c: In function 'main_loop3':
39 main.c:280:6: warning: unused variable 'mary' [-Wunused-variable]
41 '''powerpc-linux-ld: warning: dot moved backwards before `.bss'
42 powerpc-linux-ld: warning: dot moved backwards before `.bss'
43 powerpc-linux-ld: u-boot: section .text lma 0xfffc0000 overlaps previous sections
44 powerpc-linux-ld: u-boot: section .rodata lma 0xfffef3ec overlaps previous sections
45 powerpc-linux-ld: u-boot: section .reloc lma 0xffffa400 overlaps previous sections
46 powerpc-linux-ld: u-boot: section .data lma 0xffffcd38 overlaps previous sections
47 powerpc-linux-ld: u-boot: section .u_boot_cmd lma 0xffffeb40 overlaps previous sections
48 powerpc-linux-ld: u-boot: section .bootpg lma 0xfffff198 overlaps previous sections
53 # hash, subject, return code, list of errors/warnings
55 ['1234', 'upstream/master, ok', 0, []],
56 ['5678', 'Second commit, a warning', 0, errors[0:1]],
57 ['9012', 'Third commit, error', 1, errors[0:2]],
58 ['3456', 'Fourth commit, warning', 0, [errors[0], errors[2]]],
59 ['7890', 'Fifth commit, link errors', 1, [errors[0], errors[3]]],
60 ['abcd', 'Sixth commit, fixes all errors', 0, []]
64 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board0', ''],
65 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 2', 'board1', ''],
66 ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''],
67 ['Active', 'powerpc', 'mpc5xx', '', 'Tester', 'PowerPC board 2', 'board3', ''],
68 ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''],
72 """Class that holds build options"""
75 class TestBuild(unittest.TestCase):
78 TODO: Write tests for the rest of the functionality
81 # Set up commits to build
84 for commit_info in commits:
85 comm = commit.Commit(commit_info[0])
86 comm.subject = commit_info[1]
87 comm.return_code = commit_info[2]
88 comm.error_list = commit_info[3]
89 comm.sequence = sequence
91 self.commits.append(comm)
93 # Set up boards to build
94 self.boards = board.Boards()
96 self.boards.AddBoard(board.Board(*brd))
97 self.boards.SelectBoards([])
99 # Set up the toolchains
101 self.toolchains = toolchain.Toolchains()
102 self.toolchains.Add('arm-linux-gcc', test=False)
103 self.toolchains.Add('sparc-linux-gcc', test=False)
104 self.toolchains.Add('powerpc-linux-gcc', test=False)
105 self.toolchains.Add('gcc', test=False)
107 # Avoid sending any output
108 terminal.SetPrintTestMode()
109 self._col = terminal.Color()
111 def Make(self, commit, brd, stage, *args, **kwargs):
112 result = command.CommandResult()
113 boardnum = int(brd.target[-1])
114 result.return_code = 0
116 result.stdout = ('This is the test output for board %s, commit %s' %
117 (brd.target, commit.hash))
118 if boardnum >= 1 and boardnum >= commit.sequence:
119 result.return_code = commit.return_code
120 result.stderr = ''.join(commit.error_list)
124 if arg.startswith('O='):
127 if not os.path.isdir(target_dir):
130 result.combined = result.stdout + result.stderr
133 def assertSummary(self, text, arch, plus, boards, ok=False):
135 expected_colour = col.GREEN if ok else col.RED
136 expect = '%10s: ' % arch
137 # TODO(sjg@chromium.org): If plus is '', we shouldn't need this
138 expect += col.Color(expected_colour, plus)
141 expect += col.Color(expected_colour, ' %s' % board)
142 self.assertEqual(text, expect)
144 def testOutput(self):
145 """Test basic builder operation and output
147 This does a line-by-line verification of the summary output.
149 output_dir = tempfile.mkdtemp()
150 if not os.path.isdir(output_dir):
152 build = builder.Builder(self.toolchains, output_dir, None, 1, 2,
153 checkout=False, show_unknown=False)
154 build.do_make = self.Make
155 board_selected = self.boards.GetSelectedDict()
157 build.BuildBoards(self.commits, board_selected, keep_outputs=False,
159 lines = terminal.GetPrintTestLines()
162 if line.text.strip():
165 # We should get one starting message, then an update for every commit
167 self.assertEqual(count, len(commits) * len(boards) + 1)
168 build.SetDisplayOptions(show_errors=True);
169 build.ShowSummary(self.commits, board_selected)
170 lines = terminal.GetPrintTestLines()
171 self.assertEqual(lines[0].text, '01: %s' % commits[0][1])
172 self.assertEqual(lines[1].text, '02: %s' % commits[1][1])
174 # We expect all archs to fail
175 col = terminal.Color()
176 self.assertSummary(lines[2].text, 'sandbox', '+', ['board4'])
177 self.assertSummary(lines[3].text, 'arm', '+', ['board1'])
178 self.assertSummary(lines[4].text, 'powerpc', '+', ['board2', 'board3'])
180 # Now we should have the compiler warning
181 self.assertEqual(lines[5].text, 'w+%s' %
182 errors[0].rstrip().replace('\n', '\nw+'))
183 self.assertEqual(lines[5].colour, col.MAGENTA)
185 self.assertEqual(lines[6].text, '03: %s' % commits[2][1])
186 self.assertSummary(lines[7].text, 'sandbox', '+', ['board4'])
187 self.assertSummary(lines[8].text, 'arm', '', ['board1'], ok=True)
188 self.assertSummary(lines[9].text, 'powerpc', '+', ['board2', 'board3'])
191 self.assertEqual(lines[10].text, '+%s' %
192 errors[1].rstrip().replace('\n', '\n+'))
194 self.assertEqual(lines[11].text, '04: %s' % commits[3][1])
195 self.assertSummary(lines[12].text, 'sandbox', '', ['board4'], ok=True)
196 self.assertSummary(lines[13].text, 'powerpc', '', ['board2', 'board3'],
199 # Compile error fixed
200 self.assertEqual(lines[14].text, '-%s' %
201 errors[1].rstrip().replace('\n', '\n-'))
202 self.assertEqual(lines[14].colour, col.GREEN)
204 self.assertEqual(lines[15].text, 'w+%s' %
205 errors[2].rstrip().replace('\n', '\nw+'))
206 self.assertEqual(lines[15].colour, col.MAGENTA)
208 self.assertEqual(lines[16].text, '05: %s' % commits[4][1])
209 self.assertSummary(lines[17].text, 'sandbox', '+', ['board4'])
210 self.assertSummary(lines[18].text, 'powerpc', '', ['board3'], ok=True)
212 # The second line of errors[3] is a duplicate, so buildman will drop it
213 expect = errors[3].rstrip().split('\n')
214 expect = [expect[0]] + expect[2:]
215 self.assertEqual(lines[19].text, '+%s' %
216 '\n'.join(expect).replace('\n', '\n+'))
218 self.assertEqual(lines[20].text, 'w-%s' %
219 errors[2].rstrip().replace('\n', '\nw-'))
221 self.assertEqual(lines[21].text, '06: %s' % commits[5][1])
222 self.assertSummary(lines[22].text, 'sandbox', '', ['board4'], ok=True)
224 # The second line of errors[3] is a duplicate, so buildman will drop it
225 expect = errors[3].rstrip().split('\n')
226 expect = [expect[0]] + expect[2:]
227 self.assertEqual(lines[23].text, '-%s' %
228 '\n'.join(expect).replace('\n', '\n-'))
230 self.assertEqual(lines[24].text, 'w-%s' %
231 errors[0].rstrip().replace('\n', '\nw-'))
233 self.assertEqual(len(lines), 25)
236 """Test basic builder operation by building a branch"""
237 base_dir = tempfile.mkdtemp()
238 if not os.path.isdir(base_dir):
241 options.git = os.getcwd()
242 options.summary = False
244 options.dry_run = False
245 #options.git = os.path.join(base_dir, 'repo')
246 options.branch = 'test-buildman'
247 options.force_build = False
248 options.list_tool_chains = False
250 options.git_dir = None
251 options.threads = None
252 options.show_unknown = False
253 options.quick = False
254 options.show_errors = False
255 options.keep_outputs = False
257 control.DoBuildman(options, args)
259 def testBoardSingle(self):
260 """Test single board selection"""
261 self.assertEqual(self.boards.SelectBoards(['sandbox']),
262 {'all': 1, 'sandbox': 1})
264 def testBoardArch(self):
265 """Test single board selection"""
266 self.assertEqual(self.boards.SelectBoards(['arm']),
267 {'all': 2, 'arm': 2})
269 def testBoardArchSingle(self):
270 """Test single board selection"""
271 self.assertEqual(self.boards.SelectBoards(['arm sandbox']),
272 {'all': 3, 'arm': 2, 'sandbox' : 1})
274 def testBoardArchSingleMultiWord(self):
275 """Test single board selection"""
276 self.assertEqual(self.boards.SelectBoards(['arm', 'sandbox']),
277 {'all': 3, 'arm': 2, 'sandbox' : 1})
279 def testBoardSingleAnd(self):
280 """Test single board selection"""
281 self.assertEqual(self.boards.SelectBoards(['Tester & arm']),
282 {'all': 2, 'Tester&arm': 2})
284 def testBoardTwoAnd(self):
285 """Test single board selection"""
286 self.assertEqual(self.boards.SelectBoards(['Tester', '&', 'arm',
287 'Tester' '&', 'powerpc',
289 {'all': 5, 'Tester&powerpc': 2, 'Tester&arm': 2,
292 def testBoardAll(self):
293 """Test single board selection"""
294 self.assertEqual(self.boards.SelectBoards([]), {'all': 5})
296 def testBoardRegularExpression(self):
297 """Test single board selection"""
298 self.assertEqual(self.boards.SelectBoards(['T.*r&^Po']),
299 {'T.*r&^Po': 2, 'all': 2})
301 def testBoardDuplicate(self):
302 """Test single board selection"""
303 self.assertEqual(self.boards.SelectBoards(['sandbox sandbox',
305 {'all': 1, 'sandbox': 1})
307 if __name__ == "__main__":