blob: 27287438eeae7d6221876539fe9d21945118ed68 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Simon Glassc05694f2013-04-03 11:07:16 +00002# Copyright (c) 2012 The Chromium OS Authors.
3#
Simon Glassc05694f2013-04-03 11:07:16 +00004
5import os
6import shutil
7import sys
8import tempfile
9import time
10import unittest
11
Simon Glassf0d9c102020-04-17 18:09:02 -060012from buildman import board
13from buildman import bsettings
14from buildman import builder
Simon Glass22901f92022-01-22 05:07:31 -070015from buildman import cfgutil
Simon Glassf0d9c102020-04-17 18:09:02 -060016from buildman import control
17from buildman import toolchain
Simon Glassa997ea52020-04-17 18:09:04 -060018from patman import commit
19from patman import command
20from patman import terminal
21from patman import test_util
22from patman import tools
Simon Glassc05694f2013-04-03 11:07:16 +000023
Simon Glass2bfc6972017-11-12 21:52:14 -070024use_network = True
25
Simon Glass4bea81e2014-12-01 17:34:04 -070026settings_data = '''
27# Buildman settings file
28
29[toolchain]
30main: /usr/sbin
31
32[toolchain-alias]
33x86: i386 x86_64
34'''
35
Simon Glassf4ebfba2020-04-09 15:08:53 -060036migration = '''===================== WARNING ======================
37This board does not use CONFIG_DM. CONFIG_DM will be
38compulsory starting with the v2020.01 release.
39Failure to update may result in board removal.
Johannes Krottmayerce53c8b2022-03-01 04:49:51 +010040See doc/develop/driver-model/migration.rst for more info.
Simon Glassf4ebfba2020-04-09 15:08:53 -060041====================================================
42'''
43
Simon Glassc05694f2013-04-03 11:07:16 +000044errors = [
45 '''main.c: In function 'main_loop':
46main.c:260:6: warning: unused variable 'joe' [-Wunused-variable]
47''',
Simon Glass7fb8aa22014-09-05 19:00:08 -060048 '''main.c: In function 'main_loop2':
Simon Glassc05694f2013-04-03 11:07:16 +000049main.c:295:2: error: 'fred' undeclared (first use in this function)
50main.c:295:2: note: each undeclared identifier is reported only once for each function it appears in
51make[1]: *** [main.o] Error 1
52make: *** [common/libcommon.o] Error 2
53Make failed
54''',
Simon Glass0db94432018-11-06 16:02:11 -070055 '''arch/arm/dts/socfpga_arria10_socdk_sdmmc.dtb: Warning \
56(avoid_unnecessary_addr_size): /clocks: unnecessary #address-cells/#size-cells \
57without "ranges" or child "reg" property
Simon Glassc05694f2013-04-03 11:07:16 +000058''',
59 '''powerpc-linux-ld: warning: dot moved backwards before `.bss'
60powerpc-linux-ld: warning: dot moved backwards before `.bss'
61powerpc-linux-ld: u-boot: section .text lma 0xfffc0000 overlaps previous sections
62powerpc-linux-ld: u-boot: section .rodata lma 0xfffef3ec overlaps previous sections
63powerpc-linux-ld: u-boot: section .reloc lma 0xffffa400 overlaps previous sections
64powerpc-linux-ld: u-boot: section .data lma 0xffffcd38 overlaps previous sections
65powerpc-linux-ld: u-boot: section .u_boot_cmd lma 0xffffeb40 overlaps previous sections
66powerpc-linux-ld: u-boot: section .bootpg lma 0xfffff198 overlaps previous sections
Simon Glassa8b7b1b2014-09-05 19:00:21 -060067''',
68 '''In file included from %(basedir)sarch/sandbox/cpu/cpu.c:9:0:
69%(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default]
70%(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition
71%(basedir)sarch/sandbox/cpu/cpu.c: In function 'do_reset':
72%(basedir)sarch/sandbox/cpu/cpu.c:27:1: error: unknown type name 'blah'
73%(basedir)sarch/sandbox/cpu/cpu.c:28:12: error: expected declaration specifiers or '...' before numeric constant
74make[2]: *** [arch/sandbox/cpu/cpu.o] Error 1
75make[1]: *** [arch/sandbox/cpu] Error 2
76make[1]: *** Waiting for unfinished jobs....
77In file included from %(basedir)scommon/board_f.c:55:0:
78%(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default]
79%(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition
80make: *** [sub-make] Error 2
Simon Glassc05694f2013-04-03 11:07:16 +000081'''
82]
83
84
85# hash, subject, return code, list of errors/warnings
86commits = [
Simon Glassf4ebfba2020-04-09 15:08:53 -060087 ['1234', 'upstream/master, migration warning', 0, []],
Simon Glassc05694f2013-04-03 11:07:16 +000088 ['5678', 'Second commit, a warning', 0, errors[0:1]],
89 ['9012', 'Third commit, error', 1, errors[0:2]],
90 ['3456', 'Fourth commit, warning', 0, [errors[0], errors[2]]],
91 ['7890', 'Fifth commit, link errors', 1, [errors[0], errors[3]]],
Simon Glassa8b7b1b2014-09-05 19:00:21 -060092 ['abcd', 'Sixth commit, fixes all errors', 0, []],
Simon Glassf4ebfba2020-04-09 15:08:53 -060093 ['ef01', 'Seventh commit, fix migration, check directory suppression', 1,
94 [errors[4]]],
Simon Glassc05694f2013-04-03 11:07:16 +000095]
96
97boards = [
Simon Glass584cf862013-09-23 17:35:16 -060098 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board0', ''],
99 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 2', 'board1', ''],
100 ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''],
Simon Glass5e0f06d2017-11-12 21:52:15 -0700101 ['Active', 'powerpc', 'mpc83xx', '', 'Tester', 'PowerPC board 2', 'board3', ''],
Simon Glass584cf862013-09-23 17:35:16 -0600102 ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''],
Simon Glassc05694f2013-04-03 11:07:16 +0000103]
104
Simon Glass2e1646c2014-12-01 17:33:51 -0700105BASE_DIR = 'base'
106
Simon Glass071a1782018-11-06 16:02:13 -0700107OUTCOME_OK, OUTCOME_WARN, OUTCOME_ERR = range(3)
108
Simon Glassc05694f2013-04-03 11:07:16 +0000109class Options:
110 """Class that holds build options"""
111 pass
112
113class TestBuild(unittest.TestCase):
114 """Test buildman
115
116 TODO: Write tests for the rest of the functionality
117 """
118 def setUp(self):
119 # Set up commits to build
120 self.commits = []
121 sequence = 0
122 for commit_info in commits:
123 comm = commit.Commit(commit_info[0])
124 comm.subject = commit_info[1]
125 comm.return_code = commit_info[2]
126 comm.error_list = commit_info[3]
Simon Glassf4ebfba2020-04-09 15:08:53 -0600127 if sequence < 6:
128 comm.error_list += [migration]
Simon Glassc05694f2013-04-03 11:07:16 +0000129 comm.sequence = sequence
130 sequence += 1
131 self.commits.append(comm)
132
133 # Set up boards to build
134 self.boards = board.Boards()
135 for brd in boards:
136 self.boards.AddBoard(board.Board(*brd))
137 self.boards.SelectBoards([])
138
Simon Glass4bea81e2014-12-01 17:34:04 -0700139 # Add some test settings
140 bsettings.Setup(None)
141 bsettings.AddFile(settings_data)
142
Simon Glassc05694f2013-04-03 11:07:16 +0000143 # Set up the toolchains
Simon Glassc05694f2013-04-03 11:07:16 +0000144 self.toolchains = toolchain.Toolchains()
145 self.toolchains.Add('arm-linux-gcc', test=False)
146 self.toolchains.Add('sparc-linux-gcc', test=False)
147 self.toolchains.Add('powerpc-linux-gcc', test=False)
148 self.toolchains.Add('gcc', test=False)
149
Simon Glass7fb8aa22014-09-05 19:00:08 -0600150 # Avoid sending any output
Simon Glass02811582022-01-29 14:14:18 -0700151 terminal.set_print_test_mode()
Simon Glass7fb8aa22014-09-05 19:00:08 -0600152 self._col = terminal.Color()
153
Simon Glass09bbfcd2020-04-09 15:08:31 -0600154 self.base_dir = tempfile.mkdtemp()
155 if not os.path.isdir(self.base_dir):
156 os.mkdir(self.base_dir)
Simon Glassa8b7b1b2014-09-05 19:00:21 -0600157
Simon Glass09bbfcd2020-04-09 15:08:31 -0600158 def tearDown(self):
159 shutil.rmtree(self.base_dir)
160
161 def Make(self, commit, brd, stage, *args, **kwargs):
Simon Glassc05694f2013-04-03 11:07:16 +0000162 result = command.CommandResult()
163 boardnum = int(brd.target[-1])
164 result.return_code = 0
165 result.stderr = ''
166 result.stdout = ('This is the test output for board %s, commit %s' %
167 (brd.target, commit.hash))
Simon Glassa8b7b1b2014-09-05 19:00:21 -0600168 if ((boardnum >= 1 and boardnum >= commit.sequence) or
169 boardnum == 4 and commit.sequence == 6):
Simon Glassc05694f2013-04-03 11:07:16 +0000170 result.return_code = commit.return_code
Simon Glassa8b7b1b2014-09-05 19:00:21 -0600171 result.stderr = (''.join(commit.error_list)
Simon Glass09bbfcd2020-04-09 15:08:31 -0600172 % {'basedir' : self.base_dir + '/.bm-work/00/'})
Simon Glassf4ebfba2020-04-09 15:08:53 -0600173 elif commit.sequence < 6:
174 result.stderr = migration
Simon Glassc05694f2013-04-03 11:07:16 +0000175
176 result.combined = result.stdout + result.stderr
177 return result
178
Simon Glass071a1782018-11-06 16:02:13 -0700179 def assertSummary(self, text, arch, plus, boards, outcome=OUTCOME_ERR):
Simon Glass7fb8aa22014-09-05 19:00:08 -0600180 col = self._col
Simon Glass071a1782018-11-06 16:02:13 -0700181 expected_colour = (col.GREEN if outcome == OUTCOME_OK else
182 col.YELLOW if outcome == OUTCOME_WARN else col.RED)
Simon Glass7fb8aa22014-09-05 19:00:08 -0600183 expect = '%10s: ' % arch
184 # TODO(sjg@chromium.org): If plus is '', we shouldn't need this
Simon Glassf45d3742022-01-29 14:14:17 -0700185 expect += ' ' + col.build(expected_colour, plus)
Simon Glass7fb8aa22014-09-05 19:00:08 -0600186 expect += ' '
187 for board in boards:
Simon Glassf45d3742022-01-29 14:14:17 -0700188 expect += col.build(expected_colour, ' %s' % board)
Simon Glass7fb8aa22014-09-05 19:00:08 -0600189 self.assertEqual(text, expect)
190
Simon Glassc635d892021-01-30 22:17:46 -0700191 def _SetupTest(self, echo_lines=False, threads=1, **kwdisplay_args):
Simon Glass724c1752020-04-09 15:08:32 -0600192 """Set up the test by running a build and summary
Simon Glass7fb8aa22014-09-05 19:00:08 -0600193
Simon Glass724c1752020-04-09 15:08:32 -0600194 Args:
195 echo_lines: True to echo lines to the terminal to aid test
196 development
197 kwdisplay_args: Dict of arguemnts to pass to
198 Builder.SetDisplayOptions()
199
200 Returns:
201 Iterator containing the output lines, each a PrintLine() object
Simon Glass7fb8aa22014-09-05 19:00:08 -0600202 """
Simon Glassc635d892021-01-30 22:17:46 -0700203 build = builder.Builder(self.toolchains, self.base_dir, None, threads,
204 2, checkout=False, show_unknown=False)
Simon Glassc05694f2013-04-03 11:07:16 +0000205 build.do_make = self.Make
206 board_selected = self.boards.GetSelectedDict()
207
Simon Glass071a1782018-11-06 16:02:13 -0700208 # Build the boards for the pre-defined commits and warnings/errors
209 # associated with each. This calls our Make() to inject the fake output.
Simon Glass78e418e2014-08-09 15:33:03 -0600210 build.BuildBoards(self.commits, board_selected, keep_outputs=False,
211 verbose=False)
Simon Glass02811582022-01-29 14:14:18 -0700212 lines = terminal.get_print_test_lines()
Simon Glass7fb8aa22014-09-05 19:00:08 -0600213 count = 0
214 for line in lines:
215 if line.text.strip():
216 count += 1
217
Simon Glass726ae812020-04-09 15:08:47 -0600218 # We should get two starting messages, an update for every commit built
219 # and a summary message
220 self.assertEqual(count, len(commits) * len(boards) + 3)
Simon Glass724c1752020-04-09 15:08:32 -0600221 build.SetDisplayOptions(**kwdisplay_args);
Simon Glasseb48bbc2014-08-09 15:33:02 -0600222 build.ShowSummary(self.commits, board_selected)
Simon Glass724c1752020-04-09 15:08:32 -0600223 if echo_lines:
Simon Glass02811582022-01-29 14:14:18 -0700224 terminal.echo_print_test_lines()
225 return iter(terminal.get_print_test_lines())
Simon Glass071a1782018-11-06 16:02:13 -0700226
Simon Glassf4ebfba2020-04-09 15:08:53 -0600227 def _CheckOutput(self, lines, list_error_boards=False,
228 filter_dtb_warnings=False,
229 filter_migration_warnings=False):
Simon Glass724c1752020-04-09 15:08:32 -0600230 """Check for expected output from the build summary
231
232 Args:
233 lines: Iterator containing the lines returned from the summary
Simon Glassdacbe1e2020-04-09 15:08:34 -0600234 list_error_boards: Adjust the check for output produced with the
235 --list-error-boards flag
Simon Glass9ea93812020-04-09 15:08:52 -0600236 filter_dtb_warnings: Adjust the check for output produced with the
237 --filter-dtb-warnings flag
Simon Glass724c1752020-04-09 15:08:32 -0600238 """
Simon Glassea49f9b2020-04-09 15:08:37 -0600239 def add_line_prefix(prefix, boards, error_str, colour):
Simon Glass6643eb42020-04-09 15:08:33 -0600240 """Add a prefix to each line of a string
241
242 The training \n in error_str is removed before processing
243
244 Args:
245 prefix: String prefix to add
246 error_str: Error string containing the lines
Simon Glassea49f9b2020-04-09 15:08:37 -0600247 colour: Expected colour for the line. Note that the board list,
248 if present, always appears in magenta
Simon Glass6643eb42020-04-09 15:08:33 -0600249
250 Returns:
251 New string where each line has the prefix added
252 """
253 lines = error_str.strip().splitlines()
Simon Glassea49f9b2020-04-09 15:08:37 -0600254 new_lines = []
255 for line in lines:
256 if boards:
Simon Glassf45d3742022-01-29 14:14:17 -0700257 expect = self._col.build(colour, prefix + '(')
258 expect += self._col.build(self._col.MAGENTA, boards,
Simon Glassea49f9b2020-04-09 15:08:37 -0600259 bright=False)
Simon Glassf45d3742022-01-29 14:14:17 -0700260 expect += self._col.build(colour, ') %s' % line)
Simon Glassea49f9b2020-04-09 15:08:37 -0600261 else:
Simon Glassf45d3742022-01-29 14:14:17 -0700262 expect = self._col.build(colour, prefix + line)
Simon Glassea49f9b2020-04-09 15:08:37 -0600263 new_lines.append(expect)
Simon Glass6643eb42020-04-09 15:08:33 -0600264 return '\n'.join(new_lines)
265
Simon Glassf4ebfba2020-04-09 15:08:53 -0600266 col = terminal.Color()
267 boards01234 = ('board0 board1 board2 board3 board4'
268 if list_error_boards else '')
Simon Glass070589b2020-04-09 15:08:38 -0600269 boards1234 = 'board1 board2 board3 board4' if list_error_boards else ''
270 boards234 = 'board2 board3 board4' if list_error_boards else ''
271 boards34 = 'board3 board4' if list_error_boards else ''
Simon Glassdacbe1e2020-04-09 15:08:34 -0600272 boards4 = 'board4' if list_error_boards else ''
273
Simon Glassf4ebfba2020-04-09 15:08:53 -0600274 # Upstream commit: migration warnings only
Simon Glass575ce512020-04-09 15:08:30 -0600275 self.assertEqual(next(lines).text, '01: %s' % commits[0][1])
Simon Glass071a1782018-11-06 16:02:13 -0700276
Simon Glassf4ebfba2020-04-09 15:08:53 -0600277 if not filter_migration_warnings:
278 self.assertSummary(next(lines).text, 'arm', 'w+',
279 ['board0', 'board1'], outcome=OUTCOME_WARN)
280 self.assertSummary(next(lines).text, 'powerpc', 'w+',
281 ['board2', 'board3'], outcome=OUTCOME_WARN)
282 self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
283 outcome=OUTCOME_WARN)
284
285 self.assertEqual(next(lines).text,
286 add_line_prefix('+', boards01234, migration, col.RED))
287
Simon Glass071a1782018-11-06 16:02:13 -0700288 # Second commit: all archs should fail with warnings
Simon Glass575ce512020-04-09 15:08:30 -0600289 self.assertEqual(next(lines).text, '02: %s' % commits[1][1])
Simon Glass7fb8aa22014-09-05 19:00:08 -0600290
Simon Glassf4ebfba2020-04-09 15:08:53 -0600291 if filter_migration_warnings:
292 self.assertSummary(next(lines).text, 'arm', 'w+',
293 ['board1'], outcome=OUTCOME_WARN)
294 self.assertSummary(next(lines).text, 'powerpc', 'w+',
295 ['board2', 'board3'], outcome=OUTCOME_WARN)
296 self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
297 outcome=OUTCOME_WARN)
Simon Glass7fb8aa22014-09-05 19:00:08 -0600298
Simon Glass071a1782018-11-06 16:02:13 -0700299 # Second commit: The warnings should be listed
Simon Glassea49f9b2020-04-09 15:08:37 -0600300 self.assertEqual(next(lines).text,
301 add_line_prefix('w+', boards1234, errors[0], col.YELLOW))
Simon Glass7fb8aa22014-09-05 19:00:08 -0600302
Simon Glass071a1782018-11-06 16:02:13 -0700303 # Third commit: Still fails
Simon Glass575ce512020-04-09 15:08:30 -0600304 self.assertEqual(next(lines).text, '03: %s' % commits[2][1])
Simon Glassf4ebfba2020-04-09 15:08:53 -0600305 if filter_migration_warnings:
306 self.assertSummary(next(lines).text, 'arm', '',
307 ['board1'], outcome=OUTCOME_OK)
Simon Glass575ce512020-04-09 15:08:30 -0600308 self.assertSummary(next(lines).text, 'powerpc', '+',
309 ['board2', 'board3'])
310 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
Simon Glass7fb8aa22014-09-05 19:00:08 -0600311
Simon Glass071a1782018-11-06 16:02:13 -0700312 # Expect a compiler error
Simon Glassea49f9b2020-04-09 15:08:37 -0600313 self.assertEqual(next(lines).text,
314 add_line_prefix('+', boards234, errors[1], col.RED))
Simon Glass7fb8aa22014-09-05 19:00:08 -0600315
Simon Glass071a1782018-11-06 16:02:13 -0700316 # Fourth commit: Compile errors are fixed, just have warning for board3
Simon Glass575ce512020-04-09 15:08:30 -0600317 self.assertEqual(next(lines).text, '04: %s' % commits[3][1])
Simon Glassf4ebfba2020-04-09 15:08:53 -0600318 if filter_migration_warnings:
319 expect = '%10s: ' % 'powerpc'
Simon Glassf45d3742022-01-29 14:14:17 -0700320 expect += ' ' + col.build(col.GREEN, '')
Simon Glassf4ebfba2020-04-09 15:08:53 -0600321 expect += ' '
Simon Glassf45d3742022-01-29 14:14:17 -0700322 expect += col.build(col.GREEN, ' %s' % 'board2')
323 expect += ' ' + col.build(col.YELLOW, 'w+')
Simon Glassf4ebfba2020-04-09 15:08:53 -0600324 expect += ' '
Simon Glassf45d3742022-01-29 14:14:17 -0700325 expect += col.build(col.YELLOW, ' %s' % 'board3')
Simon Glassf4ebfba2020-04-09 15:08:53 -0600326 self.assertEqual(next(lines).text, expect)
327 else:
328 self.assertSummary(next(lines).text, 'powerpc', 'w+',
329 ['board2', 'board3'], outcome=OUTCOME_WARN)
Simon Glass575ce512020-04-09 15:08:30 -0600330 self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
Simon Glassf4ebfba2020-04-09 15:08:53 -0600331 outcome=OUTCOME_WARN)
Simon Glass7fb8aa22014-09-05 19:00:08 -0600332
333 # Compile error fixed
Simon Glassea49f9b2020-04-09 15:08:37 -0600334 self.assertEqual(next(lines).text,
335 add_line_prefix('-', boards234, errors[1], col.GREEN))
Simon Glass7fb8aa22014-09-05 19:00:08 -0600336
Simon Glass9ea93812020-04-09 15:08:52 -0600337 if not filter_dtb_warnings:
338 self.assertEqual(
339 next(lines).text,
340 add_line_prefix('w+', boards34, errors[2], col.YELLOW))
Simon Glass7fb8aa22014-09-05 19:00:08 -0600341
Simon Glass071a1782018-11-06 16:02:13 -0700342 # Fifth commit
Simon Glass575ce512020-04-09 15:08:30 -0600343 self.assertEqual(next(lines).text, '05: %s' % commits[4][1])
Simon Glassf4ebfba2020-04-09 15:08:53 -0600344 if filter_migration_warnings:
345 self.assertSummary(next(lines).text, 'powerpc', '', ['board3'],
346 outcome=OUTCOME_OK)
Simon Glass575ce512020-04-09 15:08:30 -0600347 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
Simon Glass7fb8aa22014-09-05 19:00:08 -0600348
349 # The second line of errors[3] is a duplicate, so buildman will drop it
350 expect = errors[3].rstrip().split('\n')
351 expect = [expect[0]] + expect[2:]
Simon Glass6643eb42020-04-09 15:08:33 -0600352 expect = '\n'.join(expect)
Simon Glassea49f9b2020-04-09 15:08:37 -0600353 self.assertEqual(next(lines).text,
354 add_line_prefix('+', boards4, expect, col.RED))
Simon Glass7fb8aa22014-09-05 19:00:08 -0600355
Simon Glass9ea93812020-04-09 15:08:52 -0600356 if not filter_dtb_warnings:
357 self.assertEqual(
358 next(lines).text,
359 add_line_prefix('w-', boards34, errors[2], col.CYAN))
Simon Glass7fb8aa22014-09-05 19:00:08 -0600360
Simon Glass071a1782018-11-06 16:02:13 -0700361 # Sixth commit
Simon Glass575ce512020-04-09 15:08:30 -0600362 self.assertEqual(next(lines).text, '06: %s' % commits[5][1])
Simon Glassf4ebfba2020-04-09 15:08:53 -0600363 if filter_migration_warnings:
364 self.assertSummary(next(lines).text, 'sandbox', '', ['board4'],
365 outcome=OUTCOME_OK)
366 else:
367 self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
368 outcome=OUTCOME_WARN)
Simon Glass7fb8aa22014-09-05 19:00:08 -0600369
370 # The second line of errors[3] is a duplicate, so buildman will drop it
371 expect = errors[3].rstrip().split('\n')
372 expect = [expect[0]] + expect[2:]
Simon Glass6643eb42020-04-09 15:08:33 -0600373 expect = '\n'.join(expect)
Simon Glassea49f9b2020-04-09 15:08:37 -0600374 self.assertEqual(next(lines).text,
375 add_line_prefix('-', boards4, expect, col.GREEN))
376 self.assertEqual(next(lines).text,
377 add_line_prefix('w-', boards4, errors[0], col.CYAN))
Simon Glass7fb8aa22014-09-05 19:00:08 -0600378
Simon Glass071a1782018-11-06 16:02:13 -0700379 # Seventh commit
Simon Glass575ce512020-04-09 15:08:30 -0600380 self.assertEqual(next(lines).text, '07: %s' % commits[6][1])
Simon Glassf4ebfba2020-04-09 15:08:53 -0600381 if filter_migration_warnings:
382 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
383 else:
384 self.assertSummary(next(lines).text, 'arm', '', ['board0', 'board1'],
385 outcome=OUTCOME_OK)
386 self.assertSummary(next(lines).text, 'powerpc', '',
387 ['board2', 'board3'], outcome=OUTCOME_OK)
388 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
Simon Glassa8b7b1b2014-09-05 19:00:21 -0600389
390 # Pick out the correct error lines
391 expect_str = errors[4].rstrip().replace('%(basedir)s', '').split('\n')
392 expect = expect_str[3:8] + [expect_str[-1]]
Simon Glass6643eb42020-04-09 15:08:33 -0600393 expect = '\n'.join(expect)
Simon Glassf4ebfba2020-04-09 15:08:53 -0600394 if not filter_migration_warnings:
395 self.assertEqual(
396 next(lines).text,
397 add_line_prefix('-', boards01234, migration, col.GREEN))
398
Simon Glassea49f9b2020-04-09 15:08:37 -0600399 self.assertEqual(next(lines).text,
400 add_line_prefix('+', boards4, expect, col.RED))
Simon Glassa8b7b1b2014-09-05 19:00:21 -0600401
402 # Now the warnings lines
403 expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]]
Simon Glass6643eb42020-04-09 15:08:33 -0600404 expect = '\n'.join(expect)
Simon Glassea49f9b2020-04-09 15:08:37 -0600405 self.assertEqual(next(lines).text,
406 add_line_prefix('w+', boards4, expect, col.YELLOW))
Simon Glassa8b7b1b2014-09-05 19:00:21 -0600407
Simon Glass724c1752020-04-09 15:08:32 -0600408 def testOutput(self):
409 """Test basic builder operation and output
410
411 This does a line-by-line verification of the summary output.
412 """
413 lines = self._SetupTest(show_errors=True)
Simon Glass9ea93812020-04-09 15:08:52 -0600414 self._CheckOutput(lines, list_error_boards=False,
415 filter_dtb_warnings=False)
Simon Glassdacbe1e2020-04-09 15:08:34 -0600416
417 def testErrorBoards(self):
418 """Test output with --list-error-boards
419
420 This does a line-by-line verification of the summary output.
421 """
422 lines = self._SetupTest(show_errors=True, list_error_boards=True)
Simon Glassf4ebfba2020-04-09 15:08:53 -0600423 self._CheckOutput(lines, list_error_boards=True)
Simon Glass9ea93812020-04-09 15:08:52 -0600424
425 def testFilterDtb(self):
426 """Test output with --filter-dtb-warnings
427
428 This does a line-by-line verification of the summary output.
429 """
430 lines = self._SetupTest(show_errors=True, filter_dtb_warnings=True)
Simon Glassf4ebfba2020-04-09 15:08:53 -0600431 self._CheckOutput(lines, filter_dtb_warnings=True)
432
433 def testFilterMigration(self):
434 """Test output with --filter-migration-warnings
435
436 This does a line-by-line verification of the summary output.
437 """
438 lines = self._SetupTest(show_errors=True,
439 filter_migration_warnings=True)
440 self._CheckOutput(lines, filter_migration_warnings=True)
Simon Glass724c1752020-04-09 15:08:32 -0600441
Simon Glassc635d892021-01-30 22:17:46 -0700442 def testSingleThread(self):
443 """Test operation without threading"""
444 lines = self._SetupTest(show_errors=True, threads=0)
445 self._CheckOutput(lines, list_error_boards=False,
446 filter_dtb_warnings=False)
447
Simon Glassc05694f2013-04-03 11:07:16 +0000448 def _testGit(self):
449 """Test basic builder operation by building a branch"""
Simon Glassc05694f2013-04-03 11:07:16 +0000450 options = Options()
451 options.git = os.getcwd()
452 options.summary = False
453 options.jobs = None
454 options.dry_run = False
Simon Glass09bbfcd2020-04-09 15:08:31 -0600455 #options.git = os.path.join(self.base_dir, 'repo')
Simon Glassc05694f2013-04-03 11:07:16 +0000456 options.branch = 'test-buildman'
457 options.force_build = False
458 options.list_tool_chains = False
459 options.count = -1
460 options.git_dir = None
461 options.threads = None
462 options.show_unknown = False
463 options.quick = False
464 options.show_errors = False
465 options.keep_outputs = False
466 args = ['tegra20']
467 control.DoBuildman(options, args)
468
Simon Glassaa40f9a2014-08-09 15:33:08 -0600469 def testBoardSingle(self):
470 """Test single board selection"""
471 self.assertEqual(self.boards.SelectBoards(['sandbox']),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600472 ({'all': ['board4'], 'sandbox': ['board4']}, []))
Simon Glassaa40f9a2014-08-09 15:33:08 -0600473
474 def testBoardArch(self):
475 """Test single board selection"""
476 self.assertEqual(self.boards.SelectBoards(['arm']),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600477 ({'all': ['board0', 'board1'],
478 'arm': ['board0', 'board1']}, []))
Simon Glassaa40f9a2014-08-09 15:33:08 -0600479
480 def testBoardArchSingle(self):
481 """Test single board selection"""
482 self.assertEqual(self.boards.SelectBoards(['arm sandbox']),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600483 ({'sandbox': ['board4'],
Simon Glass5e0f06d2017-11-12 21:52:15 -0700484 'all': ['board0', 'board1', 'board4'],
Simon Glassd9eb9f02018-06-11 23:26:46 -0600485 'arm': ['board0', 'board1']}, []))
Simon Glass5e0f06d2017-11-12 21:52:15 -0700486
Simon Glassaa40f9a2014-08-09 15:33:08 -0600487
488 def testBoardArchSingleMultiWord(self):
489 """Test single board selection"""
490 self.assertEqual(self.boards.SelectBoards(['arm', 'sandbox']),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600491 ({'sandbox': ['board4'],
492 'all': ['board0', 'board1', 'board4'],
493 'arm': ['board0', 'board1']}, []))
Simon Glassaa40f9a2014-08-09 15:33:08 -0600494
495 def testBoardSingleAnd(self):
496 """Test single board selection"""
497 self.assertEqual(self.boards.SelectBoards(['Tester & arm']),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600498 ({'Tester&arm': ['board0', 'board1'],
499 'all': ['board0', 'board1']}, []))
Simon Glassaa40f9a2014-08-09 15:33:08 -0600500
501 def testBoardTwoAnd(self):
502 """Test single board selection"""
503 self.assertEqual(self.boards.SelectBoards(['Tester', '&', 'arm',
504 'Tester' '&', 'powerpc',
505 'sandbox']),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600506 ({'sandbox': ['board4'],
Simon Glass5e0f06d2017-11-12 21:52:15 -0700507 'all': ['board0', 'board1', 'board2', 'board3',
508 'board4'],
509 'Tester&powerpc': ['board2', 'board3'],
Simon Glassd9eb9f02018-06-11 23:26:46 -0600510 'Tester&arm': ['board0', 'board1']}, []))
Simon Glassaa40f9a2014-08-09 15:33:08 -0600511
512 def testBoardAll(self):
513 """Test single board selection"""
Simon Glass5e0f06d2017-11-12 21:52:15 -0700514 self.assertEqual(self.boards.SelectBoards([]),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600515 ({'all': ['board0', 'board1', 'board2', 'board3',
516 'board4']}, []))
Simon Glassaa40f9a2014-08-09 15:33:08 -0600517
518 def testBoardRegularExpression(self):
519 """Test single board selection"""
520 self.assertEqual(self.boards.SelectBoards(['T.*r&^Po']),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600521 ({'all': ['board2', 'board3'],
522 'T.*r&^Po': ['board2', 'board3']}, []))
Simon Glassaa40f9a2014-08-09 15:33:08 -0600523
524 def testBoardDuplicate(self):
525 """Test single board selection"""
526 self.assertEqual(self.boards.SelectBoards(['sandbox sandbox',
527 'sandbox']),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600528 ({'all': ['board4'], 'sandbox': ['board4']}, []))
Simon Glass2e1646c2014-12-01 17:33:51 -0700529 def CheckDirs(self, build, dirname):
530 self.assertEqual('base%s' % dirname, build._GetOutputDir(1))
531 self.assertEqual('base%s/fred' % dirname,
532 build.GetBuildDir(1, 'fred'))
533 self.assertEqual('base%s/fred/done' % dirname,
534 build.GetDoneFile(1, 'fred'))
535 self.assertEqual('base%s/fred/u-boot.sizes' % dirname,
536 build.GetFuncSizesFile(1, 'fred', 'u-boot'))
537 self.assertEqual('base%s/fred/u-boot.objdump' % dirname,
538 build.GetObjdumpFile(1, 'fred', 'u-boot'))
539 self.assertEqual('base%s/fred/err' % dirname,
540 build.GetErrFile(1, 'fred'))
541
542 def testOutputDir(self):
543 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
544 checkout=False, show_unknown=False)
545 build.commits = self.commits
546 build.commit_count = len(self.commits)
547 subject = self.commits[1].subject.translate(builder.trans_valid_chars)
Simon Glass36971712020-07-19 12:28:11 -0600548 dirname ='/%02d_g%s_%s' % (2, commits[1][0], subject[:20])
Simon Glass2e1646c2014-12-01 17:33:51 -0700549 self.CheckDirs(build, dirname)
550
551 def testOutputDirCurrent(self):
552 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
553 checkout=False, show_unknown=False)
554 build.commits = None
555 build.commit_count = 0
556 self.CheckDirs(build, '/current')
Simon Glassaa40f9a2014-08-09 15:33:08 -0600557
Simon Glasse87bde12014-12-01 17:33:55 -0700558 def testOutputDirNoSubdirs(self):
559 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
560 checkout=False, show_unknown=False,
561 no_subdirs=True)
562 build.commits = None
563 build.commit_count = 0
564 self.CheckDirs(build, '')
565
Simon Glassc1528c12014-12-01 17:34:05 -0700566 def testToolchainAliases(self):
567 self.assertTrue(self.toolchains.Select('arm') != None)
568 with self.assertRaises(ValueError):
569 self.toolchains.Select('no-arch')
570 with self.assertRaises(ValueError):
571 self.toolchains.Select('x86')
572
573 self.toolchains = toolchain.Toolchains()
574 self.toolchains.Add('x86_64-linux-gcc', test=False)
575 self.assertTrue(self.toolchains.Select('x86') != None)
576
577 self.toolchains = toolchain.Toolchains()
578 self.toolchains.Add('i386-linux-gcc', test=False)
579 self.assertTrue(self.toolchains.Select('x86') != None)
580
Simon Glass7e803e12014-12-01 17:34:06 -0700581 def testToolchainDownload(self):
582 """Test that we can download toolchains"""
Simon Glass2bfc6972017-11-12 21:52:14 -0700583 if use_network:
Simon Glass04150022018-10-01 21:12:43 -0600584 with test_util.capture_sys_output() as (stdout, stderr):
585 url = self.toolchains.LocateArchUrl('arm')
Simon Glass72e358c2018-10-01 21:12:35 -0600586 self.assertRegexpMatches(url, 'https://www.kernel.org/pub/tools/'
587 'crosstool/files/bin/x86_64/.*/'
Simon Glassdd65c5f2020-04-17 17:51:30 -0600588 'x86_64-gcc-.*-nolibc[-_]arm-.*linux-gnueabi.tar.xz')
Simon Glass7e803e12014-12-01 17:34:06 -0700589
Simon Glass48ac42e2019-12-05 15:59:14 -0700590 def testGetEnvArgs(self):
591 """Test the GetEnvArgs() function"""
592 tc = self.toolchains.Select('arm')
593 self.assertEqual('arm-linux-',
594 tc.GetEnvArgs(toolchain.VAR_CROSS_COMPILE))
595 self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_PATH))
596 self.assertEqual('arm',
597 tc.GetEnvArgs(toolchain.VAR_ARCH))
598 self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS))
599
600 self.toolchains.Add('/path/to/x86_64-linux-gcc', test=False)
601 tc = self.toolchains.Select('x86')
602 self.assertEqual('/path/to',
603 tc.GetEnvArgs(toolchain.VAR_PATH))
604 tc.override_toolchain = 'clang'
605 self.assertEqual('HOSTCC=clang CC=clang',
606 tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS))
607
Simon Glass5dc1ca72020-03-18 09:42:45 -0600608 def testPrepareOutputSpace(self):
609 def _Touch(fname):
Simon Glass80025522022-01-29 14:14:04 -0700610 tools.write_file(os.path.join(base_dir, fname), b'')
Simon Glass5dc1ca72020-03-18 09:42:45 -0600611
612 base_dir = tempfile.mkdtemp()
613
614 # Add various files that we want removed and left alone
Ovidiu Panaitee8e9cb2020-05-15 09:30:12 +0300615 to_remove = ['01_g0982734987_title', '102_g92bf_title',
616 '01_g2938abd8_title']
617 to_leave = ['something_else', '01-something.patch', '01_another']
Simon Glass5dc1ca72020-03-18 09:42:45 -0600618 for name in to_remove + to_leave:
619 _Touch(name)
620
621 build = builder.Builder(self.toolchains, base_dir, None, 1, 2)
622 build.commits = self.commits
623 build.commit_count = len(commits)
624 result = set(build._GetOutputSpaceRemovals())
625 expected = set([os.path.join(base_dir, f) for f in to_remove])
626 self.assertEqual(expected, result)
Simon Glass7e803e12014-12-01 17:34:06 -0700627
Simon Glass22901f92022-01-22 05:07:31 -0700628 def test_adjust_cfg_nop(self):
629 """check various adjustments of config that are nops"""
630 # enable an enabled CONFIG
631 self.assertEqual(
632 'CONFIG_FRED=y',
633 cfgutil.adjust_cfg_line('CONFIG_FRED=y', {'FRED':'FRED'})[0])
634
635 # disable a disabled CONFIG
636 self.assertEqual(
637 '# CONFIG_FRED is not set',
638 cfgutil.adjust_cfg_line(
639 '# CONFIG_FRED is not set', {'FRED':'~FRED'})[0])
640
641 # use the adjust_cfg_lines() function
642 self.assertEqual(
643 ['CONFIG_FRED=y'],
644 cfgutil.adjust_cfg_lines(['CONFIG_FRED=y'], {'FRED':'FRED'}))
645 self.assertEqual(
646 ['# CONFIG_FRED is not set'],
647 cfgutil.adjust_cfg_lines(['CONFIG_FRED=y'], {'FRED':'~FRED'}))
648
649 # handling an empty line
650 self.assertEqual('#', cfgutil.adjust_cfg_line('#', {'FRED':'~FRED'})[0])
651
652 def test_adjust_cfg(self):
653 """check various adjustments of config"""
654 # disable a CONFIG
655 self.assertEqual(
656 '# CONFIG_FRED is not set',
657 cfgutil.adjust_cfg_line('CONFIG_FRED=1' , {'FRED':'~FRED'})[0])
658
659 # enable a disabled CONFIG
660 self.assertEqual(
661 'CONFIG_FRED=y',
662 cfgutil.adjust_cfg_line(
663 '# CONFIG_FRED is not set', {'FRED':'FRED'})[0])
664
665 # enable a CONFIG that doesn't exist
666 self.assertEqual(
667 ['CONFIG_FRED=y'],
668 cfgutil.adjust_cfg_lines([], {'FRED':'FRED'}))
669
670 # disable a CONFIG that doesn't exist
671 self.assertEqual(
672 ['# CONFIG_FRED is not set'],
673 cfgutil.adjust_cfg_lines([], {'FRED':'~FRED'}))
674
675 # disable a value CONFIG
676 self.assertEqual(
677 '# CONFIG_FRED is not set',
678 cfgutil.adjust_cfg_line('CONFIG_FRED="fred"' , {'FRED':'~FRED'})[0])
679
680 # setting a value CONFIG
681 self.assertEqual(
682 'CONFIG_FRED="fred"',
683 cfgutil.adjust_cfg_line('# CONFIG_FRED is not set' ,
684 {'FRED':'FRED="fred"'})[0])
685
686 # changing a value CONFIG
687 self.assertEqual(
688 'CONFIG_FRED="fred"',
689 cfgutil.adjust_cfg_line('CONFIG_FRED="ernie"' ,
690 {'FRED':'FRED="fred"'})[0])
691
692 # setting a value for a CONFIG that doesn't exist
693 self.assertEqual(
694 ['CONFIG_FRED="fred"'],
695 cfgutil.adjust_cfg_lines([], {'FRED':'FRED="fred"'}))
696
697 def test_convert_adjust_cfg_list(self):
698 """Check conversion of the list of changes into a dict"""
699 self.assertEqual({}, cfgutil.convert_list_to_dict(None))
700
701 expect = {
702 'FRED':'FRED',
703 'MARY':'~MARY',
704 'JOHN':'JOHN=0x123',
705 'ALICE':'ALICE="alice"',
706 'AMY':'AMY',
707 'ABE':'~ABE',
708 'MARK':'MARK=0x456',
709 'ANNA':'ANNA="anna"',
710 }
711 actual = cfgutil.convert_list_to_dict(
712 ['FRED', '~MARY', 'JOHN=0x123', 'ALICE="alice"',
713 'CONFIG_AMY', '~CONFIG_ABE', 'CONFIG_MARK=0x456',
714 'CONFIG_ANNA="anna"'])
715 self.assertEqual(expect, actual)
716
717 def test_check_cfg_file(self):
718 """Test check_cfg_file detects conflicts as expected"""
719 # Check failure to disable CONFIG
720 result = cfgutil.check_cfg_lines(['CONFIG_FRED=1'], {'FRED':'~FRED'})
721 self.assertEqual([['~FRED', 'CONFIG_FRED=1']], result)
722
723 result = cfgutil.check_cfg_lines(
724 ['CONFIG_FRED=1', 'CONFIG_MARY="mary"'], {'FRED':'~FRED'})
725 self.assertEqual([['~FRED', 'CONFIG_FRED=1']], result)
726
727 result = cfgutil.check_cfg_lines(
728 ['CONFIG_FRED=1', 'CONFIG_MARY="mary"'], {'MARY':'~MARY'})
729 self.assertEqual([['~MARY', 'CONFIG_MARY="mary"']], result)
730
731 # Check failure to enable CONFIG
732 result = cfgutil.check_cfg_lines(
733 ['# CONFIG_FRED is not set'], {'FRED':'FRED'})
734 self.assertEqual([['FRED', '# CONFIG_FRED is not set']], result)
735
736 # Check failure to set CONFIG value
737 result = cfgutil.check_cfg_lines(
738 ['# CONFIG_FRED is not set', 'CONFIG_MARY="not"'],
739 {'MARY':'MARY="mary"', 'FRED':'FRED'})
740 self.assertEqual([
741 ['FRED', '# CONFIG_FRED is not set'],
742 ['MARY="mary"', 'CONFIG_MARY="not"']], result)
743
744 # Check failure to add CONFIG value
745 result = cfgutil.check_cfg_lines([], {'MARY':'MARY="mary"'})
746 self.assertEqual([
747 ['MARY="mary"', 'Missing expected line: CONFIG_MARY="mary"']], result)
748
749
Simon Glassc05694f2013-04-03 11:07:16 +0000750if __name__ == "__main__":
751 unittest.main()