]>
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'))
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
50 '''In file included from %(basedir)sarch/sandbox/cpu/cpu.c:9:0:
51 %(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default]
52 %(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition
53 %(basedir)sarch/sandbox/cpu/cpu.c: In function 'do_reset':
54 %(basedir)sarch/sandbox/cpu/cpu.c:27:1: error: unknown type name 'blah'
55 %(basedir)sarch/sandbox/cpu/cpu.c:28:12: error: expected declaration specifiers or '...' before numeric constant
56 make[2]: *** [arch/sandbox/cpu/cpu.o] Error 1
57 make[1]: *** [arch/sandbox/cpu] Error 2
58 make[1]: *** Waiting for unfinished jobs....
59 In file included from %(basedir)scommon/board_f.c:55:0:
60 %(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default]
61 %(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition
62 make: *** [sub-make] Error 2
67 # hash, subject, return code, list of errors/warnings
69 ['1234', 'upstream/master, ok', 0, []],
70 ['5678', 'Second commit, a warning', 0, errors
[0:1]],
71 ['9012', 'Third commit, error', 1, errors
[0:2]],
72 ['3456', 'Fourth commit, warning', 0, [errors
[0], errors
[2]]],
73 ['7890', 'Fifth commit, link errors', 1, [errors
[0], errors
[3]]],
74 ['abcd', 'Sixth commit, fixes all errors', 0, []],
75 ['ef01', 'Seventh commit, check directory suppression', 1, [errors
[4]]],
79 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board0', ''],
80 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 2', 'board1', ''],
81 ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''],
82 ['Active', 'powerpc', 'mpc5xx', '', 'Tester', 'PowerPC board 2', 'board3', ''],
83 ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''],
87 """Class that holds build options"""
90 class TestBuild(unittest
.TestCase
):
93 TODO: Write tests for the rest of the functionality
96 # Set up commits to build
99 for commit_info
in commits
:
100 comm
= commit
.Commit(commit_info
[0])
101 comm
.subject
= commit_info
[1]
102 comm
.return_code
= commit_info
[2]
103 comm
.error_list
= commit_info
[3]
104 comm
.sequence
= sequence
106 self
.commits
.append(comm
)
108 # Set up boards to build
109 self
.boards
= board
.Boards()
111 self
.boards
.AddBoard(board
.Board(*brd
))
112 self
.boards
.SelectBoards([])
114 # Set up the toolchains
116 self
.toolchains
= toolchain
.Toolchains()
117 self
.toolchains
.Add('arm-linux-gcc', test
=False)
118 self
.toolchains
.Add('sparc-linux-gcc', test
=False)
119 self
.toolchains
.Add('powerpc-linux-gcc', test
=False)
120 self
.toolchains
.Add('gcc', test
=False)
122 # Avoid sending any output
123 terminal
.SetPrintTestMode()
124 self
._col
= terminal
.Color()
126 def Make(self
, commit
, brd
, stage
, *args
, **kwargs
):
129 result
= command
.CommandResult()
130 boardnum
= int(brd
.target
[-1])
131 result
.return_code
= 0
133 result
.stdout
= ('This is the test output for board %s, commit %s' %
134 (brd
.target
, commit
.hash))
135 if ((boardnum
>= 1 and boardnum
>= commit
.sequence
) or
136 boardnum
== 4 and commit
.sequence
== 6):
137 result
.return_code
= commit
.return_code
138 result
.stderr
= (''.join(commit
.error_list
)
139 % {'basedir' : base_dir
+ '/.bm-work/00/'})
143 if arg
.startswith('O='):
146 if not os
.path
.isdir(target_dir
):
149 result
.combined
= result
.stdout
+ result
.stderr
152 def assertSummary(self
, text
, arch
, plus
, boards
, ok
=False):
154 expected_colour
= col
.GREEN
if ok
else col
.RED
155 expect
= '%10s: ' % arch
156 # TODO(sjg@chromium.org): If plus is '', we shouldn't need this
157 expect
+= col
.Color(expected_colour
, plus
)
160 expect
+= col
.Color(expected_colour
, ' %s' % board
)
161 self
.assertEqual(text
, expect
)
163 def testOutput(self
):
164 """Test basic builder operation and output
166 This does a line-by-line verification of the summary output.
170 base_dir
= tempfile
.mkdtemp()
171 if not os
.path
.isdir(base_dir
):
173 build
= builder
.Builder(self
.toolchains
, base_dir
, None, 1, 2,
174 checkout
=False, show_unknown
=False)
175 build
.do_make
= self
.Make
176 board_selected
= self
.boards
.GetSelectedDict()
178 build
.BuildBoards(self
.commits
, board_selected
, keep_outputs
=False,
180 lines
= terminal
.GetPrintTestLines()
183 if line
.text
.strip():
186 # We should get one starting message, then an update for every commit
188 self
.assertEqual(count
, len(commits
) * len(boards
) + 1)
189 build
.SetDisplayOptions(show_errors
=True);
190 build
.ShowSummary(self
.commits
, board_selected
)
191 #terminal.EchoPrintTestLines()
192 lines
= terminal
.GetPrintTestLines()
193 self
.assertEqual(lines
[0].text
, '01: %s' % commits
[0][1])
194 self
.assertEqual(lines
[1].text
, '02: %s' % commits
[1][1])
196 # We expect all archs to fail
197 col
= terminal
.Color()
198 self
.assertSummary(lines
[2].text
, 'sandbox', '+', ['board4'])
199 self
.assertSummary(lines
[3].text
, 'arm', '+', ['board1'])
200 self
.assertSummary(lines
[4].text
, 'powerpc', '+', ['board2', 'board3'])
202 # Now we should have the compiler warning
203 self
.assertEqual(lines
[5].text
, 'w+%s' %
204 errors
[0].rstrip().replace('\n', '\nw+'))
205 self
.assertEqual(lines
[5].colour
, col
.MAGENTA
)
207 self
.assertEqual(lines
[6].text
, '03: %s' % commits
[2][1])
208 self
.assertSummary(lines
[7].text
, 'sandbox', '+', ['board4'])
209 self
.assertSummary(lines
[8].text
, 'arm', '', ['board1'], ok
=True)
210 self
.assertSummary(lines
[9].text
, 'powerpc', '+', ['board2', 'board3'])
213 self
.assertEqual(lines
[10].text
, '+%s' %
214 errors
[1].rstrip().replace('\n', '\n+'))
216 self
.assertEqual(lines
[11].text
, '04: %s' % commits
[3][1])
217 self
.assertSummary(lines
[12].text
, 'sandbox', '', ['board4'], ok
=True)
218 self
.assertSummary(lines
[13].text
, 'powerpc', '', ['board2', 'board3'],
221 # Compile error fixed
222 self
.assertEqual(lines
[14].text
, '-%s' %
223 errors
[1].rstrip().replace('\n', '\n-'))
224 self
.assertEqual(lines
[14].colour
, col
.GREEN
)
226 self
.assertEqual(lines
[15].text
, 'w+%s' %
227 errors
[2].rstrip().replace('\n', '\nw+'))
228 self
.assertEqual(lines
[15].colour
, col
.MAGENTA
)
230 self
.assertEqual(lines
[16].text
, '05: %s' % commits
[4][1])
231 self
.assertSummary(lines
[17].text
, 'sandbox', '+', ['board4'])
232 self
.assertSummary(lines
[18].text
, 'powerpc', '', ['board3'], ok
=True)
234 # The second line of errors[3] is a duplicate, so buildman will drop it
235 expect
= errors
[3].rstrip().split('\n')
236 expect
= [expect
[0]] + expect
[2:]
237 self
.assertEqual(lines
[19].text
, '+%s' %
238 '\n'.join(expect
).replace('\n', '\n+'))
240 self
.assertEqual(lines
[20].text
, 'w-%s' %
241 errors
[2].rstrip().replace('\n', '\nw-'))
243 self
.assertEqual(lines
[21].text
, '06: %s' % commits
[5][1])
244 self
.assertSummary(lines
[22].text
, 'sandbox', '', ['board4'], ok
=True)
246 # The second line of errors[3] is a duplicate, so buildman will drop it
247 expect
= errors
[3].rstrip().split('\n')
248 expect
= [expect
[0]] + expect
[2:]
249 self
.assertEqual(lines
[23].text
, '-%s' %
250 '\n'.join(expect
).replace('\n', '\n-'))
252 self
.assertEqual(lines
[24].text
, 'w-%s' %
253 errors
[0].rstrip().replace('\n', '\nw-'))
255 self
.assertEqual(lines
[25].text
, '07: %s' % commits
[6][1])
256 self
.assertSummary(lines
[26].text
, 'sandbox', '+', ['board4'])
258 # Pick out the correct error lines
259 expect_str
= errors
[4].rstrip().replace('%(basedir)s', '').split('\n')
260 expect
= expect_str
[3:8] + [expect_str
[-1]]
261 self
.assertEqual(lines
[27].text
, '+%s' %
262 '\n'.join(expect
).replace('\n', '\n+'))
264 # Now the warnings lines
265 expect
= [expect_str
[0]] + expect_str
[10:12] + [expect_str
[9]]
266 self
.assertEqual(lines
[28].text
, 'w+%s' %
267 '\n'.join(expect
).replace('\n', '\nw+'))
269 self
.assertEqual(len(lines
), 29)
270 shutil
.rmtree(base_dir
)
273 """Test basic builder operation by building a branch"""
274 base_dir
= tempfile
.mkdtemp()
275 if not os
.path
.isdir(base_dir
):
278 options
.git
= os
.getcwd()
279 options
.summary
= False
281 options
.dry_run
= False
282 #options.git = os.path.join(base_dir, 'repo')
283 options
.branch
= 'test-buildman'
284 options
.force_build
= False
285 options
.list_tool_chains
= False
287 options
.git_dir
= None
288 options
.threads
= None
289 options
.show_unknown
= False
290 options
.quick
= False
291 options
.show_errors
= False
292 options
.keep_outputs
= False
294 control
.DoBuildman(options
, args
)
295 shutil
.rmtree(base_dir
)
297 def testBoardSingle(self
):
298 """Test single board selection"""
299 self
.assertEqual(self
.boards
.SelectBoards(['sandbox']),
300 {'all': 1, 'sandbox': 1})
302 def testBoardArch(self
):
303 """Test single board selection"""
304 self
.assertEqual(self
.boards
.SelectBoards(['arm']),
305 {'all': 2, 'arm': 2})
307 def testBoardArchSingle(self
):
308 """Test single board selection"""
309 self
.assertEqual(self
.boards
.SelectBoards(['arm sandbox']),
310 {'all': 3, 'arm': 2, 'sandbox' : 1})
312 def testBoardArchSingleMultiWord(self
):
313 """Test single board selection"""
314 self
.assertEqual(self
.boards
.SelectBoards(['arm', 'sandbox']),
315 {'all': 3, 'arm': 2, 'sandbox' : 1})
317 def testBoardSingleAnd(self
):
318 """Test single board selection"""
319 self
.assertEqual(self
.boards
.SelectBoards(['Tester & arm']),
320 {'all': 2, 'Tester&arm': 2})
322 def testBoardTwoAnd(self
):
323 """Test single board selection"""
324 self
.assertEqual(self
.boards
.SelectBoards(['Tester', '&', 'arm',
325 'Tester' '&', 'powerpc',
327 {'all': 5, 'Tester&powerpc': 2, 'Tester&arm': 2,
330 def testBoardAll(self
):
331 """Test single board selection"""
332 self
.assertEqual(self
.boards
.SelectBoards([]), {'all': 5})
334 def testBoardRegularExpression(self
):
335 """Test single board selection"""
336 self
.assertEqual(self
.boards
.SelectBoards(['T.*r&^Po']),
337 {'T.*r&^Po': 2, 'all': 2})
339 def testBoardDuplicate(self
):
340 """Test single board selection"""
341 self
.assertEqual(self
.boards
.SelectBoards(['sandbox sandbox',
343 {'all': 1, 'sandbox': 1})
345 if __name__
== "__main__":