1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2012 The Chromium OS Authors.
12 # Bring in the patman libraries
13 our_path = os.path.dirname(os.path.realpath(__file__))
14 sys.path.append(os.path.join(our_path, '../patman'))
29 # Buildman settings file
39 '''main.c: In function 'main_loop':
40 main.c:260:6: warning: unused variable 'joe' [-Wunused-variable]
42 '''main.c: In function 'main_loop2':
43 main.c:295:2: error: 'fred' undeclared (first use in this function)
44 main.c:295:2: note: each undeclared identifier is reported only once for each function it appears in
45 make[1]: *** [main.o] Error 1
46 make: *** [common/libcommon.o] Error 2
49 '''arch/arm/dts/socfpga_arria10_socdk_sdmmc.dtb: Warning \
50 (avoid_unnecessary_addr_size): /clocks: unnecessary #address-cells/#size-cells \
51 without "ranges" or child "reg" property
53 '''powerpc-linux-ld: warning: dot moved backwards before `.bss'
54 powerpc-linux-ld: warning: dot moved backwards before `.bss'
55 powerpc-linux-ld: u-boot: section .text lma 0xfffc0000 overlaps previous sections
56 powerpc-linux-ld: u-boot: section .rodata lma 0xfffef3ec overlaps previous sections
57 powerpc-linux-ld: u-boot: section .reloc lma 0xffffa400 overlaps previous sections
58 powerpc-linux-ld: u-boot: section .data lma 0xffffcd38 overlaps previous sections
59 powerpc-linux-ld: u-boot: section .u_boot_cmd lma 0xffffeb40 overlaps previous sections
60 powerpc-linux-ld: u-boot: section .bootpg lma 0xfffff198 overlaps previous sections
62 '''In file included from %(basedir)sarch/sandbox/cpu/cpu.c:9:0:
63 %(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default]
64 %(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition
65 %(basedir)sarch/sandbox/cpu/cpu.c: In function 'do_reset':
66 %(basedir)sarch/sandbox/cpu/cpu.c:27:1: error: unknown type name 'blah'
67 %(basedir)sarch/sandbox/cpu/cpu.c:28:12: error: expected declaration specifiers or '...' before numeric constant
68 make[2]: *** [arch/sandbox/cpu/cpu.o] Error 1
69 make[1]: *** [arch/sandbox/cpu] Error 2
70 make[1]: *** Waiting for unfinished jobs....
71 In file included from %(basedir)scommon/board_f.c:55:0:
72 %(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default]
73 %(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition
74 make: *** [sub-make] Error 2
79 # hash, subject, return code, list of errors/warnings
81 ['1234', 'upstream/master, ok', 0, []],
82 ['5678', 'Second commit, a warning', 0, errors[0:1]],
83 ['9012', 'Third commit, error', 1, errors[0:2]],
84 ['3456', 'Fourth commit, warning', 0, [errors[0], errors[2]]],
85 ['7890', 'Fifth commit, link errors', 1, [errors[0], errors[3]]],
86 ['abcd', 'Sixth commit, fixes all errors', 0, []],
87 ['ef01', 'Seventh commit, check directory suppression', 1, [errors[4]]],
91 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board0', ''],
92 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 2', 'board1', ''],
93 ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''],
94 ['Active', 'powerpc', 'mpc83xx', '', 'Tester', 'PowerPC board 2', 'board3', ''],
95 ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''],
101 """Class that holds build options"""
104 class TestBuild(unittest.TestCase):
107 TODO: Write tests for the rest of the functionality
110 # Set up commits to build
113 for commit_info in commits:
114 comm = commit.Commit(commit_info[0])
115 comm.subject = commit_info[1]
116 comm.return_code = commit_info[2]
117 comm.error_list = commit_info[3]
118 comm.sequence = sequence
120 self.commits.append(comm)
122 # Set up boards to build
123 self.boards = board.Boards()
125 self.boards.AddBoard(board.Board(*brd))
126 self.boards.SelectBoards([])
128 # Add some test settings
129 bsettings.Setup(None)
130 bsettings.AddFile(settings_data)
132 # Set up the toolchains
133 self.toolchains = toolchain.Toolchains()
134 self.toolchains.Add('arm-linux-gcc', test=False)
135 self.toolchains.Add('sparc-linux-gcc', test=False)
136 self.toolchains.Add('powerpc-linux-gcc', test=False)
137 self.toolchains.Add('gcc', test=False)
139 # Avoid sending any output
140 terminal.SetPrintTestMode()
141 self._col = terminal.Color()
143 def Make(self, commit, brd, stage, *args, **kwargs):
146 result = command.CommandResult()
147 boardnum = int(brd.target[-1])
148 result.return_code = 0
150 result.stdout = ('This is the test output for board %s, commit %s' %
151 (brd.target, commit.hash))
152 if ((boardnum >= 1 and boardnum >= commit.sequence) or
153 boardnum == 4 and commit.sequence == 6):
154 result.return_code = commit.return_code
155 result.stderr = (''.join(commit.error_list)
156 % {'basedir' : base_dir + '/.bm-work/00/'})
160 if arg.startswith('O='):
163 if not os.path.isdir(target_dir):
166 result.combined = result.stdout + result.stderr
169 def assertSummary(self, text, arch, plus, boards, ok=False):
171 expected_colour = col.GREEN if ok else col.RED
172 expect = '%10s: ' % arch
173 # TODO(sjg@chromium.org): If plus is '', we shouldn't need this
174 expect += ' ' + col.Color(expected_colour, plus)
177 expect += col.Color(expected_colour, ' %s' % board)
178 self.assertEqual(text, expect)
180 def testOutput(self):
181 """Test basic builder operation and output
183 This does a line-by-line verification of the summary output.
187 base_dir = tempfile.mkdtemp()
188 if not os.path.isdir(base_dir):
190 build = builder.Builder(self.toolchains, base_dir, None, 1, 2,
191 checkout=False, show_unknown=False)
192 build.do_make = self.Make
193 board_selected = self.boards.GetSelectedDict()
195 build.BuildBoards(self.commits, board_selected, keep_outputs=False,
197 lines = terminal.GetPrintTestLines()
200 if line.text.strip():
203 # We should get two starting messages, then an update for every commit
205 self.assertEqual(count, len(commits) * len(boards) + 2)
206 build.SetDisplayOptions(show_errors=True);
207 build.ShowSummary(self.commits, board_selected)
208 #terminal.EchoPrintTestLines()
209 lines = terminal.GetPrintTestLines()
210 self.assertEqual(lines[0].text, '01: %s' % commits[0][1])
211 self.assertEqual(lines[1].text, '02: %s' % commits[1][1])
213 # We expect all archs to fail
214 col = terminal.Color()
215 self.assertSummary(lines[2].text, 'sandbox', '+', ['board4'])
216 self.assertSummary(lines[3].text, 'arm', '+', ['board1'])
217 self.assertSummary(lines[4].text, 'powerpc', '+', ['board2', 'board3'])
219 # Now we should have the compiler warning
220 self.assertEqual(lines[5].text, 'w+%s' %
221 errors[0].rstrip().replace('\n', '\nw+'))
222 self.assertEqual(lines[5].colour, col.MAGENTA)
224 self.assertEqual(lines[6].text, '03: %s' % commits[2][1])
225 self.assertSummary(lines[7].text, 'sandbox', '+', ['board4'])
226 self.assertSummary(lines[8].text, 'arm', '', ['board1'], ok=True)
227 self.assertSummary(lines[9].text, 'powerpc', '+', ['board2', 'board3'])
230 self.assertEqual(lines[10].text, '+%s' %
231 errors[1].rstrip().replace('\n', '\n+'))
233 self.assertEqual(lines[11].text, '04: %s' % commits[3][1])
234 self.assertSummary(lines[12].text, 'sandbox', '', ['board4'], ok=True)
235 self.assertSummary(lines[13].text, 'powerpc', '', ['board2', 'board3'],
238 # Compile error fixed
239 self.assertEqual(lines[14].text, '-%s' %
240 errors[1].rstrip().replace('\n', '\n-'))
241 self.assertEqual(lines[14].colour, col.GREEN)
243 self.assertEqual(lines[15].text, 'w+%s' %
244 errors[2].rstrip().replace('\n', '\nw+'))
245 self.assertEqual(lines[15].colour, col.MAGENTA)
247 self.assertEqual(lines[16].text, '05: %s' % commits[4][1])
248 self.assertSummary(lines[17].text, 'sandbox', '+', ['board4'])
249 self.assertSummary(lines[18].text, 'powerpc', '', ['board3'], ok=True)
251 # The second line of errors[3] is a duplicate, so buildman will drop it
252 expect = errors[3].rstrip().split('\n')
253 expect = [expect[0]] + expect[2:]
254 self.assertEqual(lines[19].text, '+%s' %
255 '\n'.join(expect).replace('\n', '\n+'))
257 self.assertEqual(lines[20].text, 'w-%s' %
258 errors[2].rstrip().replace('\n', '\nw-'))
260 self.assertEqual(lines[21].text, '06: %s' % commits[5][1])
261 self.assertSummary(lines[22].text, 'sandbox', '', ['board4'], ok=True)
263 # The second line of errors[3] is a duplicate, so buildman will drop it
264 expect = errors[3].rstrip().split('\n')
265 expect = [expect[0]] + expect[2:]
266 self.assertEqual(lines[23].text, '-%s' %
267 '\n'.join(expect).replace('\n', '\n-'))
269 self.assertEqual(lines[24].text, 'w-%s' %
270 errors[0].rstrip().replace('\n', '\nw-'))
272 self.assertEqual(lines[25].text, '07: %s' % commits[6][1])
273 self.assertSummary(lines[26].text, 'sandbox', '+', ['board4'])
275 # Pick out the correct error lines
276 expect_str = errors[4].rstrip().replace('%(basedir)s', '').split('\n')
277 expect = expect_str[3:8] + [expect_str[-1]]
278 self.assertEqual(lines[27].text, '+%s' %
279 '\n'.join(expect).replace('\n', '\n+'))
281 # Now the warnings lines
282 expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]]
283 self.assertEqual(lines[28].text, 'w+%s' %
284 '\n'.join(expect).replace('\n', '\nw+'))
286 self.assertEqual(len(lines), 29)
287 shutil.rmtree(base_dir)
290 """Test basic builder operation by building a branch"""
291 base_dir = tempfile.mkdtemp()
292 if not os.path.isdir(base_dir):
295 options.git = os.getcwd()
296 options.summary = False
298 options.dry_run = False
299 #options.git = os.path.join(base_dir, 'repo')
300 options.branch = 'test-buildman'
301 options.force_build = False
302 options.list_tool_chains = False
304 options.git_dir = None
305 options.threads = None
306 options.show_unknown = False
307 options.quick = False
308 options.show_errors = False
309 options.keep_outputs = False
311 control.DoBuildman(options, args)
312 shutil.rmtree(base_dir)
314 def testBoardSingle(self):
315 """Test single board selection"""
316 self.assertEqual(self.boards.SelectBoards(['sandbox']),
317 ({'all': ['board4'], 'sandbox': ['board4']}, []))
319 def testBoardArch(self):
320 """Test single board selection"""
321 self.assertEqual(self.boards.SelectBoards(['arm']),
322 ({'all': ['board0', 'board1'],
323 'arm': ['board0', 'board1']}, []))
325 def testBoardArchSingle(self):
326 """Test single board selection"""
327 self.assertEqual(self.boards.SelectBoards(['arm sandbox']),
328 ({'sandbox': ['board4'],
329 'all': ['board0', 'board1', 'board4'],
330 'arm': ['board0', 'board1']}, []))
333 def testBoardArchSingleMultiWord(self):
334 """Test single board selection"""
335 self.assertEqual(self.boards.SelectBoards(['arm', 'sandbox']),
336 ({'sandbox': ['board4'],
337 'all': ['board0', 'board1', 'board4'],
338 'arm': ['board0', 'board1']}, []))
340 def testBoardSingleAnd(self):
341 """Test single board selection"""
342 self.assertEqual(self.boards.SelectBoards(['Tester & arm']),
343 ({'Tester&arm': ['board0', 'board1'],
344 'all': ['board0', 'board1']}, []))
346 def testBoardTwoAnd(self):
347 """Test single board selection"""
348 self.assertEqual(self.boards.SelectBoards(['Tester', '&', 'arm',
349 'Tester' '&', 'powerpc',
351 ({'sandbox': ['board4'],
352 'all': ['board0', 'board1', 'board2', 'board3',
354 'Tester&powerpc': ['board2', 'board3'],
355 'Tester&arm': ['board0', 'board1']}, []))
357 def testBoardAll(self):
358 """Test single board selection"""
359 self.assertEqual(self.boards.SelectBoards([]),
360 ({'all': ['board0', 'board1', 'board2', 'board3',
363 def testBoardRegularExpression(self):
364 """Test single board selection"""
365 self.assertEqual(self.boards.SelectBoards(['T.*r&^Po']),
366 ({'all': ['board2', 'board3'],
367 'T.*r&^Po': ['board2', 'board3']}, []))
369 def testBoardDuplicate(self):
370 """Test single board selection"""
371 self.assertEqual(self.boards.SelectBoards(['sandbox sandbox',
373 ({'all': ['board4'], 'sandbox': ['board4']}, []))
374 def CheckDirs(self, build, dirname):
375 self.assertEqual('base%s' % dirname, build._GetOutputDir(1))
376 self.assertEqual('base%s/fred' % dirname,
377 build.GetBuildDir(1, 'fred'))
378 self.assertEqual('base%s/fred/done' % dirname,
379 build.GetDoneFile(1, 'fred'))
380 self.assertEqual('base%s/fred/u-boot.sizes' % dirname,
381 build.GetFuncSizesFile(1, 'fred', 'u-boot'))
382 self.assertEqual('base%s/fred/u-boot.objdump' % dirname,
383 build.GetObjdumpFile(1, 'fred', 'u-boot'))
384 self.assertEqual('base%s/fred/err' % dirname,
385 build.GetErrFile(1, 'fred'))
387 def testOutputDir(self):
388 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
389 checkout=False, show_unknown=False)
390 build.commits = self.commits
391 build.commit_count = len(self.commits)
392 subject = self.commits[1].subject.translate(builder.trans_valid_chars)
393 dirname ='/%02d_of_%02d_g%s_%s' % (2, build.commit_count, commits[1][0],
395 self.CheckDirs(build, dirname)
397 def testOutputDirCurrent(self):
398 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
399 checkout=False, show_unknown=False)
401 build.commit_count = 0
402 self.CheckDirs(build, '/current')
404 def testOutputDirNoSubdirs(self):
405 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
406 checkout=False, show_unknown=False,
409 build.commit_count = 0
410 self.CheckDirs(build, '')
412 def testToolchainAliases(self):
413 self.assertTrue(self.toolchains.Select('arm') != None)
414 with self.assertRaises(ValueError):
415 self.toolchains.Select('no-arch')
416 with self.assertRaises(ValueError):
417 self.toolchains.Select('x86')
419 self.toolchains = toolchain.Toolchains()
420 self.toolchains.Add('x86_64-linux-gcc', test=False)
421 self.assertTrue(self.toolchains.Select('x86') != None)
423 self.toolchains = toolchain.Toolchains()
424 self.toolchains.Add('i386-linux-gcc', test=False)
425 self.assertTrue(self.toolchains.Select('x86') != None)
427 def testToolchainDownload(self):
428 """Test that we can download toolchains"""
430 with test_util.capture_sys_output() as (stdout, stderr):
431 url = self.toolchains.LocateArchUrl('arm')
432 self.assertRegexpMatches(url, 'https://www.kernel.org/pub/tools/'
433 'crosstool/files/bin/x86_64/.*/'
434 'x86_64-gcc-.*-nolibc_arm-.*linux-gnueabi.tar.xz')
437 if __name__ == "__main__":