]>
git.ipfire.org Git - people/ms/u-boot.git/blob - tools/buildman/test.py
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'))
30 # Buildman settings file
40 '''main.c: In function 'main_loop':
41 main.c:260:6: warning: unused variable 'joe' [-Wunused-variable]
43 '''main.c: In function 'main_loop2':
44 main.c:295:2: error: 'fred' undeclared (first use in this function)
45 main.c:295:2: note: each undeclared identifier is reported only once for each function it appears in
46 make[1]: *** [main.o] Error 1
47 make: *** [common/libcommon.o] Error 2
50 '''main.c: In function 'main_loop3':
51 main.c:280:6: warning: unused variable 'mary' [-Wunused-variable]
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'], 'all': ['board0', 'board1', 'board4'], 'arm': ['board0', 'board1']})
338 def testBoardSingleAnd(self
):
339 """Test single board selection"""
340 self
.assertEqual(self
.boards
.SelectBoards(['Tester & arm']),
341 {'Tester&arm': ['board0', 'board1'], 'all': ['board0', 'board1']})
343 def testBoardTwoAnd(self
):
344 """Test single board selection"""
345 self
.assertEqual(self
.boards
.SelectBoards(['Tester', '&', 'arm',
346 'Tester' '&', 'powerpc',
348 {'sandbox': ['board4'],
349 'all': ['board0', 'board1', 'board2', 'board3',
351 'Tester&powerpc': ['board2', 'board3'],
352 'Tester&arm': ['board0', 'board1']})
354 def testBoardAll(self
):
355 """Test single board selection"""
356 self
.assertEqual(self
.boards
.SelectBoards([]),
357 {'all': ['board0', 'board1', 'board2', 'board3',
360 def testBoardRegularExpression(self
):
361 """Test single board selection"""
362 self
.assertEqual(self
.boards
.SelectBoards(['T.*r&^Po']),
363 {'all': ['board2', 'board3'],
364 'T.*r&^Po': ['board2', 'board3']})
366 def testBoardDuplicate(self
):
367 """Test single board selection"""
368 self
.assertEqual(self
.boards
.SelectBoards(['sandbox sandbox',
370 {'all': ['board4'], 'sandbox': ['board4']})
371 def CheckDirs(self
, build
, dirname
):
372 self
.assertEqual('base%s' % dirname
, build
._GetOutputDir
(1))
373 self
.assertEqual('base%s/fred' % dirname
,
374 build
.GetBuildDir(1, 'fred'))
375 self
.assertEqual('base%s/fred/done' % dirname
,
376 build
.GetDoneFile(1, 'fred'))
377 self
.assertEqual('base%s/fred/u-boot.sizes' % dirname
,
378 build
.GetFuncSizesFile(1, 'fred', 'u-boot'))
379 self
.assertEqual('base%s/fred/u-boot.objdump' % dirname
,
380 build
.GetObjdumpFile(1, 'fred', 'u-boot'))
381 self
.assertEqual('base%s/fred/err' % dirname
,
382 build
.GetErrFile(1, 'fred'))
384 def testOutputDir(self
):
385 build
= builder
.Builder(self
.toolchains
, BASE_DIR
, None, 1, 2,
386 checkout
=False, show_unknown
=False)
387 build
.commits
= self
.commits
388 build
.commit_count
= len(self
.commits
)
389 subject
= self
.commits
[1].subject
.translate(builder
.trans_valid_chars
)
390 dirname
='/%02d_of_%02d_g%s_%s' % (2, build
.commit_count
, commits
[1][0],
392 self
.CheckDirs(build
, dirname
)
394 def testOutputDirCurrent(self
):
395 build
= builder
.Builder(self
.toolchains
, BASE_DIR
, None, 1, 2,
396 checkout
=False, show_unknown
=False)
398 build
.commit_count
= 0
399 self
.CheckDirs(build
, '/current')
401 def testOutputDirNoSubdirs(self
):
402 build
= builder
.Builder(self
.toolchains
, BASE_DIR
, None, 1, 2,
403 checkout
=False, show_unknown
=False,
406 build
.commit_count
= 0
407 self
.CheckDirs(build
, '')
409 def testToolchainAliases(self
):
410 self
.assertTrue(self
.toolchains
.Select('arm') != None)
411 with self
.assertRaises(ValueError):
412 self
.toolchains
.Select('no-arch')
413 with self
.assertRaises(ValueError):
414 self
.toolchains
.Select('x86')
416 self
.toolchains
= toolchain
.Toolchains()
417 self
.toolchains
.Add('x86_64-linux-gcc', test
=False)
418 self
.assertTrue(self
.toolchains
.Select('x86') != None)
420 self
.toolchains
= toolchain
.Toolchains()
421 self
.toolchains
.Add('i386-linux-gcc', test
=False)
422 self
.assertTrue(self
.toolchains
.Select('x86') != None)
424 def testToolchainDownload(self
):
425 """Test that we can download toolchains"""
427 self
.assertEqual('https://www.kernel.org/pub/tools/crosstool/files/bin/x86_64/4.9.0/x86_64-gcc-4.9.0-nolibc_arm-unknown-linux-gnueabi.tar.xz',
428 self
.toolchains
.LocateArchUrl('arm'))
431 if __name__
== "__main__":