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 # Buildman settings file
38 '''main.c: In function 'main_loop':
39 main.c:260:6: warning: unused variable 'joe' [-Wunused-variable]
41 '''main.c: In function 'main_loop2':
42 main.c:295:2: error: 'fred' undeclared (first use in this function)
43 main.c:295:2: note: each undeclared identifier is reported only once for each function it appears in
44 make[1]: *** [main.o] Error 1
45 make: *** [common/libcommon.o] Error 2
48 '''main.c: In function 'main_loop3':
49 main.c:280:6: warning: unused variable 'mary' [-Wunused-variable]
51 '''powerpc-linux-ld: warning: dot moved backwards before `.bss'
52 powerpc-linux-ld: warning: dot moved backwards before `.bss'
53 powerpc-linux-ld: u-boot: section .text lma 0xfffc0000 overlaps previous sections
54 powerpc-linux-ld: u-boot: section .rodata lma 0xfffef3ec overlaps previous sections
55 powerpc-linux-ld: u-boot: section .reloc lma 0xffffa400 overlaps previous sections
56 powerpc-linux-ld: u-boot: section .data lma 0xffffcd38 overlaps previous sections
57 powerpc-linux-ld: u-boot: section .u_boot_cmd lma 0xffffeb40 overlaps previous sections
58 powerpc-linux-ld: u-boot: section .bootpg lma 0xfffff198 overlaps previous sections
60 '''In file included from %(basedir)sarch/sandbox/cpu/cpu.c:9:0:
61 %(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default]
62 %(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition
63 %(basedir)sarch/sandbox/cpu/cpu.c: In function 'do_reset':
64 %(basedir)sarch/sandbox/cpu/cpu.c:27:1: error: unknown type name 'blah'
65 %(basedir)sarch/sandbox/cpu/cpu.c:28:12: error: expected declaration specifiers or '...' before numeric constant
66 make[2]: *** [arch/sandbox/cpu/cpu.o] Error 1
67 make[1]: *** [arch/sandbox/cpu] Error 2
68 make[1]: *** Waiting for unfinished jobs....
69 In file included from %(basedir)scommon/board_f.c:55:0:
70 %(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default]
71 %(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition
72 make: *** [sub-make] Error 2
77 # hash, subject, return code, list of errors/warnings
79 ['1234', 'upstream/master, ok', 0, []],
80 ['5678', 'Second commit, a warning', 0, errors[0:1]],
81 ['9012', 'Third commit, error', 1, errors[0:2]],
82 ['3456', 'Fourth commit, warning', 0, [errors[0], errors[2]]],
83 ['7890', 'Fifth commit, link errors', 1, [errors[0], errors[3]]],
84 ['abcd', 'Sixth commit, fixes all errors', 0, []],
85 ['ef01', 'Seventh commit, check directory suppression', 1, [errors[4]]],
89 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board0', ''],
90 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 2', 'board1', ''],
91 ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''],
92 ['Active', 'powerpc', 'mpc5xx', '', 'Tester', 'PowerPC board 2', 'board3', ''],
93 ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''],
99 """Class that holds build options"""
102 class TestBuild(unittest.TestCase):
105 TODO: Write tests for the rest of the functionality
108 # Set up commits to build
111 for commit_info in commits:
112 comm = commit.Commit(commit_info[0])
113 comm.subject = commit_info[1]
114 comm.return_code = commit_info[2]
115 comm.error_list = commit_info[3]
116 comm.sequence = sequence
118 self.commits.append(comm)
120 # Set up boards to build
121 self.boards = board.Boards()
123 self.boards.AddBoard(board.Board(*brd))
124 self.boards.SelectBoards([])
126 # Add some test settings
127 bsettings.Setup(None)
128 bsettings.AddFile(settings_data)
130 # Set up the toolchains
131 self.toolchains = toolchain.Toolchains()
132 self.toolchains.Add('arm-linux-gcc', test=False)
133 self.toolchains.Add('sparc-linux-gcc', test=False)
134 self.toolchains.Add('powerpc-linux-gcc', test=False)
135 self.toolchains.Add('gcc', test=False)
137 # Avoid sending any output
138 terminal.SetPrintTestMode()
139 self._col = terminal.Color()
141 def Make(self, commit, brd, stage, *args, **kwargs):
144 result = command.CommandResult()
145 boardnum = int(brd.target[-1])
146 result.return_code = 0
148 result.stdout = ('This is the test output for board %s, commit %s' %
149 (brd.target, commit.hash))
150 if ((boardnum >= 1 and boardnum >= commit.sequence) or
151 boardnum == 4 and commit.sequence == 6):
152 result.return_code = commit.return_code
153 result.stderr = (''.join(commit.error_list)
154 % {'basedir' : base_dir + '/.bm-work/00/'})
158 if arg.startswith('O='):
161 if not os.path.isdir(target_dir):
164 result.combined = result.stdout + result.stderr
167 def assertSummary(self, text, arch, plus, boards, ok=False):
169 expected_colour = col.GREEN if ok else col.RED
170 expect = '%10s: ' % arch
171 # TODO(sjg@chromium.org): If plus is '', we shouldn't need this
172 expect += col.Color(expected_colour, plus)
175 expect += col.Color(expected_colour, ' %s' % board)
176 self.assertEqual(text, expect)
178 def testOutput(self):
179 """Test basic builder operation and output
181 This does a line-by-line verification of the summary output.
185 base_dir = tempfile.mkdtemp()
186 if not os.path.isdir(base_dir):
188 build = builder.Builder(self.toolchains, base_dir, None, 1, 2,
189 checkout=False, show_unknown=False)
190 build.do_make = self.Make
191 board_selected = self.boards.GetSelectedDict()
193 build.BuildBoards(self.commits, board_selected, keep_outputs=False,
195 lines = terminal.GetPrintTestLines()
198 if line.text.strip():
201 # We should get one starting message, then an update for every commit
203 self.assertEqual(count, len(commits) * len(boards) + 1)
204 build.SetDisplayOptions(show_errors=True);
205 build.ShowSummary(self.commits, board_selected)
206 #terminal.EchoPrintTestLines()
207 lines = terminal.GetPrintTestLines()
208 self.assertEqual(lines[0].text, '01: %s' % commits[0][1])
209 self.assertEqual(lines[1].text, '02: %s' % commits[1][1])
211 # We expect all archs to fail
212 col = terminal.Color()
213 self.assertSummary(lines[2].text, 'sandbox', '+', ['board4'])
214 self.assertSummary(lines[3].text, 'arm', '+', ['board1'])
215 self.assertSummary(lines[4].text, 'powerpc', '+', ['board2', 'board3'])
217 # Now we should have the compiler warning
218 self.assertEqual(lines[5].text, 'w+%s' %
219 errors[0].rstrip().replace('\n', '\nw+'))
220 self.assertEqual(lines[5].colour, col.MAGENTA)
222 self.assertEqual(lines[6].text, '03: %s' % commits[2][1])
223 self.assertSummary(lines[7].text, 'sandbox', '+', ['board4'])
224 self.assertSummary(lines[8].text, 'arm', '', ['board1'], ok=True)
225 self.assertSummary(lines[9].text, 'powerpc', '+', ['board2', 'board3'])
228 self.assertEqual(lines[10].text, '+%s' %
229 errors[1].rstrip().replace('\n', '\n+'))
231 self.assertEqual(lines[11].text, '04: %s' % commits[3][1])
232 self.assertSummary(lines[12].text, 'sandbox', '', ['board4'], ok=True)
233 self.assertSummary(lines[13].text, 'powerpc', '', ['board2', 'board3'],
236 # Compile error fixed
237 self.assertEqual(lines[14].text, '-%s' %
238 errors[1].rstrip().replace('\n', '\n-'))
239 self.assertEqual(lines[14].colour, col.GREEN)
241 self.assertEqual(lines[15].text, 'w+%s' %
242 errors[2].rstrip().replace('\n', '\nw+'))
243 self.assertEqual(lines[15].colour, col.MAGENTA)
245 self.assertEqual(lines[16].text, '05: %s' % commits[4][1])
246 self.assertSummary(lines[17].text, 'sandbox', '+', ['board4'])
247 self.assertSummary(lines[18].text, 'powerpc', '', ['board3'], ok=True)
249 # The second line of errors[3] is a duplicate, so buildman will drop it
250 expect = errors[3].rstrip().split('\n')
251 expect = [expect[0]] + expect[2:]
252 self.assertEqual(lines[19].text, '+%s' %
253 '\n'.join(expect).replace('\n', '\n+'))
255 self.assertEqual(lines[20].text, 'w-%s' %
256 errors[2].rstrip().replace('\n', '\nw-'))
258 self.assertEqual(lines[21].text, '06: %s' % commits[5][1])
259 self.assertSummary(lines[22].text, 'sandbox', '', ['board4'], ok=True)
261 # The second line of errors[3] is a duplicate, so buildman will drop it
262 expect = errors[3].rstrip().split('\n')
263 expect = [expect[0]] + expect[2:]
264 self.assertEqual(lines[23].text, '-%s' %
265 '\n'.join(expect).replace('\n', '\n-'))
267 self.assertEqual(lines[24].text, 'w-%s' %
268 errors[0].rstrip().replace('\n', '\nw-'))
270 self.assertEqual(lines[25].text, '07: %s' % commits[6][1])
271 self.assertSummary(lines[26].text, 'sandbox', '+', ['board4'])
273 # Pick out the correct error lines
274 expect_str = errors[4].rstrip().replace('%(basedir)s', '').split('\n')
275 expect = expect_str[3:8] + [expect_str[-1]]
276 self.assertEqual(lines[27].text, '+%s' %
277 '\n'.join(expect).replace('\n', '\n+'))
279 # Now the warnings lines
280 expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]]
281 self.assertEqual(lines[28].text, 'w+%s' %
282 '\n'.join(expect).replace('\n', '\nw+'))
284 self.assertEqual(len(lines), 29)
285 shutil.rmtree(base_dir)
288 """Test basic builder operation by building a branch"""
289 base_dir = tempfile.mkdtemp()
290 if not os.path.isdir(base_dir):
293 options.git = os.getcwd()
294 options.summary = False
296 options.dry_run = False
297 #options.git = os.path.join(base_dir, 'repo')
298 options.branch = 'test-buildman'
299 options.force_build = False
300 options.list_tool_chains = False
302 options.git_dir = None
303 options.threads = None
304 options.show_unknown = False
305 options.quick = False
306 options.show_errors = False
307 options.keep_outputs = False
309 control.DoBuildman(options, args)
310 shutil.rmtree(base_dir)
312 def testBoardSingle(self):
313 """Test single board selection"""
314 self.assertEqual(self.boards.SelectBoards(['sandbox']),
315 {'all': 1, 'sandbox': 1})
317 def testBoardArch(self):
318 """Test single board selection"""
319 self.assertEqual(self.boards.SelectBoards(['arm']),
320 {'all': 2, 'arm': 2})
322 def testBoardArchSingle(self):
323 """Test single board selection"""
324 self.assertEqual(self.boards.SelectBoards(['arm sandbox']),
325 {'all': 3, 'arm': 2, 'sandbox' : 1})
327 def testBoardArchSingleMultiWord(self):
328 """Test single board selection"""
329 self.assertEqual(self.boards.SelectBoards(['arm', 'sandbox']),
330 {'all': 3, 'arm': 2, 'sandbox' : 1})
332 def testBoardSingleAnd(self):
333 """Test single board selection"""
334 self.assertEqual(self.boards.SelectBoards(['Tester & arm']),
335 {'all': 2, 'Tester&arm': 2})
337 def testBoardTwoAnd(self):
338 """Test single board selection"""
339 self.assertEqual(self.boards.SelectBoards(['Tester', '&', 'arm',
340 'Tester' '&', 'powerpc',
342 {'all': 5, 'Tester&powerpc': 2, 'Tester&arm': 2,
345 def testBoardAll(self):
346 """Test single board selection"""
347 self.assertEqual(self.boards.SelectBoards([]), {'all': 5})
349 def testBoardRegularExpression(self):
350 """Test single board selection"""
351 self.assertEqual(self.boards.SelectBoards(['T.*r&^Po']),
352 {'T.*r&^Po': 2, 'all': 2})
354 def testBoardDuplicate(self):
355 """Test single board selection"""
356 self.assertEqual(self.boards.SelectBoards(['sandbox sandbox',
358 {'all': 1, 'sandbox': 1})
359 def CheckDirs(self, build, dirname):
360 self.assertEqual('base%s' % dirname, build._GetOutputDir(1))
361 self.assertEqual('base%s/fred' % dirname,
362 build.GetBuildDir(1, 'fred'))
363 self.assertEqual('base%s/fred/done' % dirname,
364 build.GetDoneFile(1, 'fred'))
365 self.assertEqual('base%s/fred/u-boot.sizes' % dirname,
366 build.GetFuncSizesFile(1, 'fred', 'u-boot'))
367 self.assertEqual('base%s/fred/u-boot.objdump' % dirname,
368 build.GetObjdumpFile(1, 'fred', 'u-boot'))
369 self.assertEqual('base%s/fred/err' % dirname,
370 build.GetErrFile(1, 'fred'))
372 def testOutputDir(self):
373 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
374 checkout=False, show_unknown=False)
375 build.commits = self.commits
376 build.commit_count = len(self.commits)
377 subject = self.commits[1].subject.translate(builder.trans_valid_chars)
378 dirname ='/%02d_of_%02d_g%s_%s' % (2, build.commit_count, commits[1][0],
380 self.CheckDirs(build, dirname)
382 def testOutputDirCurrent(self):
383 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
384 checkout=False, show_unknown=False)
386 build.commit_count = 0
387 self.CheckDirs(build, '/current')
389 def testOutputDirNoSubdirs(self):
390 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
391 checkout=False, show_unknown=False,
394 build.commit_count = 0
395 self.CheckDirs(build, '')
397 def testToolchainAliases(self):
398 self.assertTrue(self.toolchains.Select('arm') != None)
399 with self.assertRaises(ValueError):
400 self.toolchains.Select('no-arch')
401 with self.assertRaises(ValueError):
402 self.toolchains.Select('x86')
404 self.toolchains = toolchain.Toolchains()
405 self.toolchains.Add('x86_64-linux-gcc', test=False)
406 self.assertTrue(self.toolchains.Select('x86') != None)
408 self.toolchains = toolchain.Toolchains()
409 self.toolchains.Add('i386-linux-gcc', test=False)
410 self.assertTrue(self.toolchains.Select('x86') != None)
412 if __name__ == "__main__":