blob: f92add7a7c5ed93391ec956631693fad116d085a [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
Simon Glass20751d62022-07-11 19:04:03 -060013from buildman import boards
Simon Glassf0d9c102020-04-17 18:09:02 -060014from buildman import bsettings
15from buildman import builder
Simon Glass22901f92022-01-22 05:07:31 -070016from buildman import cfgutil
Simon Glassf0d9c102020-04-17 18:09:02 -060017from buildman import control
18from buildman import toolchain
Simon Glassa997ea52020-04-17 18:09:04 -060019from patman import commit
Simon Glass131444f2023-02-23 18:18:04 -070020from u_boot_pylib import command
21from u_boot_pylib import terminal
22from u_boot_pylib import test_util
23from u_boot_pylib import tools
Simon Glassc05694f2013-04-03 11:07:16 +000024
Simon Glass2bfc6972017-11-12 21:52:14 -070025use_network = True
26
Simon Glass4bea81e2014-12-01 17:34:04 -070027settings_data = '''
28# Buildman settings file
29
30[toolchain]
31main: /usr/sbin
32
33[toolchain-alias]
34x86: i386 x86_64
35'''
36
Simon Glassf4ebfba2020-04-09 15:08:53 -060037migration = '''===================== WARNING ======================
38This board does not use CONFIG_DM. CONFIG_DM will be
39compulsory starting with the v2020.01 release.
40Failure to update may result in board removal.
Johannes Krottmayerce53c8b2022-03-01 04:49:51 +010041See doc/develop/driver-model/migration.rst for more info.
Simon Glassf4ebfba2020-04-09 15:08:53 -060042====================================================
43'''
44
Simon Glassc05694f2013-04-03 11:07:16 +000045errors = [
46 '''main.c: In function 'main_loop':
47main.c:260:6: warning: unused variable 'joe' [-Wunused-variable]
48''',
Simon Glass7fb8aa22014-09-05 19:00:08 -060049 '''main.c: In function 'main_loop2':
Simon Glassc05694f2013-04-03 11:07:16 +000050main.c:295:2: error: 'fred' undeclared (first use in this function)
51main.c:295:2: note: each undeclared identifier is reported only once for each function it appears in
52make[1]: *** [main.o] Error 1
53make: *** [common/libcommon.o] Error 2
54Make failed
55''',
Simon Glass0db94432018-11-06 16:02:11 -070056 '''arch/arm/dts/socfpga_arria10_socdk_sdmmc.dtb: Warning \
57(avoid_unnecessary_addr_size): /clocks: unnecessary #address-cells/#size-cells \
58without "ranges" or child "reg" property
Simon Glassc05694f2013-04-03 11:07:16 +000059''',
60 '''powerpc-linux-ld: warning: dot moved backwards before `.bss'
61powerpc-linux-ld: warning: dot moved backwards before `.bss'
62powerpc-linux-ld: u-boot: section .text lma 0xfffc0000 overlaps previous sections
63powerpc-linux-ld: u-boot: section .rodata lma 0xfffef3ec overlaps previous sections
64powerpc-linux-ld: u-boot: section .reloc lma 0xffffa400 overlaps previous sections
65powerpc-linux-ld: u-boot: section .data lma 0xffffcd38 overlaps previous sections
66powerpc-linux-ld: u-boot: section .u_boot_cmd lma 0xffffeb40 overlaps previous sections
67powerpc-linux-ld: u-boot: section .bootpg lma 0xfffff198 overlaps previous sections
Simon Glassa8b7b1b2014-09-05 19:00:21 -060068''',
69 '''In file included from %(basedir)sarch/sandbox/cpu/cpu.c:9: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%(basedir)sarch/sandbox/cpu/cpu.c: In function 'do_reset':
73%(basedir)sarch/sandbox/cpu/cpu.c:27:1: error: unknown type name 'blah'
74%(basedir)sarch/sandbox/cpu/cpu.c:28:12: error: expected declaration specifiers or '...' before numeric constant
75make[2]: *** [arch/sandbox/cpu/cpu.o] Error 1
76make[1]: *** [arch/sandbox/cpu] Error 2
77make[1]: *** Waiting for unfinished jobs....
78In file included from %(basedir)scommon/board_f.c:55:0:
79%(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default]
80%(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition
81make: *** [sub-make] Error 2
Simon Glassc05694f2013-04-03 11:07:16 +000082'''
83]
84
85
86# hash, subject, return code, list of errors/warnings
87commits = [
Simon Glassf4ebfba2020-04-09 15:08:53 -060088 ['1234', 'upstream/master, migration warning', 0, []],
Simon Glassc05694f2013-04-03 11:07:16 +000089 ['5678', 'Second commit, a warning', 0, errors[0:1]],
90 ['9012', 'Third commit, error', 1, errors[0:2]],
91 ['3456', 'Fourth commit, warning', 0, [errors[0], errors[2]]],
92 ['7890', 'Fifth commit, link errors', 1, [errors[0], errors[3]]],
Simon Glassa8b7b1b2014-09-05 19:00:21 -060093 ['abcd', 'Sixth commit, fixes all errors', 0, []],
Simon Glassf4ebfba2020-04-09 15:08:53 -060094 ['ef01', 'Seventh commit, fix migration, check directory suppression', 1,
95 [errors[4]]],
Simon Glassc05694f2013-04-03 11:07:16 +000096]
97
Simon Glassb0786df2022-07-11 19:03:59 -060098BOARDS = [
Simon Glass584cf862013-09-23 17:35:16 -060099 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board0', ''],
100 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 2', 'board1', ''],
101 ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''],
Simon Glass5e0f06d2017-11-12 21:52:15 -0700102 ['Active', 'powerpc', 'mpc83xx', '', 'Tester', 'PowerPC board 2', 'board3', ''],
Simon Glass584cf862013-09-23 17:35:16 -0600103 ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''],
Simon Glassc05694f2013-04-03 11:07:16 +0000104]
105
Simon Glass2e1646c2014-12-01 17:33:51 -0700106BASE_DIR = 'base'
107
Simon Glass071a1782018-11-06 16:02:13 -0700108OUTCOME_OK, OUTCOME_WARN, OUTCOME_ERR = range(3)
109
Simon Glassc05694f2013-04-03 11:07:16 +0000110class Options:
111 """Class that holds build options"""
112 pass
113
114class TestBuild(unittest.TestCase):
115 """Test buildman
116
117 TODO: Write tests for the rest of the functionality
118 """
119 def setUp(self):
120 # Set up commits to build
121 self.commits = []
122 sequence = 0
123 for commit_info in commits:
124 comm = commit.Commit(commit_info[0])
125 comm.subject = commit_info[1]
126 comm.return_code = commit_info[2]
127 comm.error_list = commit_info[3]
Simon Glassf4ebfba2020-04-09 15:08:53 -0600128 if sequence < 6:
129 comm.error_list += [migration]
Simon Glassc05694f2013-04-03 11:07:16 +0000130 comm.sequence = sequence
131 sequence += 1
132 self.commits.append(comm)
133
134 # Set up boards to build
Simon Glass20751d62022-07-11 19:04:03 -0600135 self.brds = boards.Boards()
Simon Glassb0786df2022-07-11 19:03:59 -0600136 for brd in BOARDS:
Simon Glass127a2392022-07-11 19:04:02 -0600137 self.brds.add_board(board.Board(*brd))
138 self.brds.select_boards([])
Simon Glassc05694f2013-04-03 11:07:16 +0000139
Simon Glass4bea81e2014-12-01 17:34:04 -0700140 # Add some test settings
Simon Glass06b83a52023-07-19 17:49:05 -0600141 bsettings.setup(None)
142 bsettings.add_file(settings_data)
Simon Glass4bea81e2014-12-01 17:34:04 -0700143
Simon Glassc05694f2013-04-03 11:07:16 +0000144 # Set up the toolchains
Simon Glassc05694f2013-04-03 11:07:16 +0000145 self.toolchains = toolchain.Toolchains()
146 self.toolchains.Add('arm-linux-gcc', test=False)
147 self.toolchains.Add('sparc-linux-gcc', test=False)
148 self.toolchains.Add('powerpc-linux-gcc', test=False)
149 self.toolchains.Add('gcc', test=False)
150
Simon Glass7fb8aa22014-09-05 19:00:08 -0600151 # Avoid sending any output
Simon Glass02811582022-01-29 14:14:18 -0700152 terminal.set_print_test_mode()
Simon Glass7fb8aa22014-09-05 19:00:08 -0600153 self._col = terminal.Color()
154
Simon Glass09bbfcd2020-04-09 15:08:31 -0600155 self.base_dir = tempfile.mkdtemp()
156 if not os.path.isdir(self.base_dir):
157 os.mkdir(self.base_dir)
Simon Glassa8b7b1b2014-09-05 19:00:21 -0600158
Simon Glass09bbfcd2020-04-09 15:08:31 -0600159 def tearDown(self):
160 shutil.rmtree(self.base_dir)
161
162 def Make(self, commit, brd, stage, *args, **kwargs):
Simon Glassc05694f2013-04-03 11:07:16 +0000163 result = command.CommandResult()
164 boardnum = int(brd.target[-1])
165 result.return_code = 0
166 result.stderr = ''
167 result.stdout = ('This is the test output for board %s, commit %s' %
168 (brd.target, commit.hash))
Simon Glassa8b7b1b2014-09-05 19:00:21 -0600169 if ((boardnum >= 1 and boardnum >= commit.sequence) or
170 boardnum == 4 and commit.sequence == 6):
Simon Glassc05694f2013-04-03 11:07:16 +0000171 result.return_code = commit.return_code
Simon Glassa8b7b1b2014-09-05 19:00:21 -0600172 result.stderr = (''.join(commit.error_list)
Simon Glass09bbfcd2020-04-09 15:08:31 -0600173 % {'basedir' : self.base_dir + '/.bm-work/00/'})
Simon Glassf4ebfba2020-04-09 15:08:53 -0600174 elif commit.sequence < 6:
175 result.stderr = migration
Simon Glassc05694f2013-04-03 11:07:16 +0000176
177 result.combined = result.stdout + result.stderr
178 return result
179
Simon Glassb0786df2022-07-11 19:03:59 -0600180 def assertSummary(self, text, arch, plus, brds, outcome=OUTCOME_ERR):
Simon Glass7fb8aa22014-09-05 19:00:08 -0600181 col = self._col
Simon Glass071a1782018-11-06 16:02:13 -0700182 expected_colour = (col.GREEN if outcome == OUTCOME_OK else
183 col.YELLOW if outcome == OUTCOME_WARN else col.RED)
Simon Glass7fb8aa22014-09-05 19:00:08 -0600184 expect = '%10s: ' % arch
185 # TODO(sjg@chromium.org): If plus is '', we shouldn't need this
Simon Glassf45d3742022-01-29 14:14:17 -0700186 expect += ' ' + col.build(expected_colour, plus)
Simon Glass7fb8aa22014-09-05 19:00:08 -0600187 expect += ' '
Simon Glassb0786df2022-07-11 19:03:59 -0600188 for brd in brds:
Simon Glass8132f982022-07-11 19:03:57 -0600189 expect += col.build(expected_colour, ' %s' % brd)
Simon Glass7fb8aa22014-09-05 19:00:08 -0600190 self.assertEqual(text, expect)
191
Simon Glassc635d892021-01-30 22:17:46 -0700192 def _SetupTest(self, echo_lines=False, threads=1, **kwdisplay_args):
Simon Glass724c1752020-04-09 15:08:32 -0600193 """Set up the test by running a build and summary
Simon Glass7fb8aa22014-09-05 19:00:08 -0600194
Simon Glass724c1752020-04-09 15:08:32 -0600195 Args:
196 echo_lines: True to echo lines to the terminal to aid test
197 development
Heinrich Schuchardt37153112024-04-19 13:37:46 +0200198 kwdisplay_args: Dict of arguments to pass to
Simon Glass724c1752020-04-09 15:08:32 -0600199 Builder.SetDisplayOptions()
200
201 Returns:
202 Iterator containing the output lines, each a PrintLine() object
Simon Glass7fb8aa22014-09-05 19:00:08 -0600203 """
Simon Glassc635d892021-01-30 22:17:46 -0700204 build = builder.Builder(self.toolchains, self.base_dir, None, threads,
205 2, checkout=False, show_unknown=False)
Simon Glassc05694f2013-04-03 11:07:16 +0000206 build.do_make = self.Make
Simon Glass127a2392022-07-11 19:04:02 -0600207 board_selected = self.brds.get_selected_dict()
Simon Glassc05694f2013-04-03 11:07:16 +0000208
Simon Glass071a1782018-11-06 16:02:13 -0700209 # Build the boards for the pre-defined commits and warnings/errors
210 # associated with each. This calls our Make() to inject the fake output.
Simon Glassbc74d942023-07-19 17:49:06 -0600211 build.build_boards(self.commits, board_selected, keep_outputs=False,
212 verbose=False)
Simon Glass02811582022-01-29 14:14:18 -0700213 lines = terminal.get_print_test_lines()
Simon Glass7fb8aa22014-09-05 19:00:08 -0600214 count = 0
215 for line in lines:
216 if line.text.strip():
217 count += 1
218
Simon Glass726ae812020-04-09 15:08:47 -0600219 # We should get two starting messages, an update for every commit built
220 # and a summary message
Simon Glassb0786df2022-07-11 19:03:59 -0600221 self.assertEqual(count, len(commits) * len(BOARDS) + 3)
Simon Glassbc74d942023-07-19 17:49:06 -0600222 build.set_display_options(**kwdisplay_args);
223 build.show_summary(self.commits, board_selected)
Simon Glass724c1752020-04-09 15:08:32 -0600224 if echo_lines:
Simon Glass02811582022-01-29 14:14:18 -0700225 terminal.echo_print_test_lines()
226 return iter(terminal.get_print_test_lines())
Simon Glass071a1782018-11-06 16:02:13 -0700227
Simon Glassf4ebfba2020-04-09 15:08:53 -0600228 def _CheckOutput(self, lines, list_error_boards=False,
229 filter_dtb_warnings=False,
230 filter_migration_warnings=False):
Simon Glass724c1752020-04-09 15:08:32 -0600231 """Check for expected output from the build summary
232
233 Args:
234 lines: Iterator containing the lines returned from the summary
Simon Glassdacbe1e2020-04-09 15:08:34 -0600235 list_error_boards: Adjust the check for output produced with the
236 --list-error-boards flag
Simon Glass9ea93812020-04-09 15:08:52 -0600237 filter_dtb_warnings: Adjust the check for output produced with the
238 --filter-dtb-warnings flag
Simon Glass724c1752020-04-09 15:08:32 -0600239 """
Simon Glassb0786df2022-07-11 19:03:59 -0600240 def add_line_prefix(prefix, brds, error_str, colour):
Simon Glass6643eb42020-04-09 15:08:33 -0600241 """Add a prefix to each line of a string
242
243 The training \n in error_str is removed before processing
244
245 Args:
246 prefix: String prefix to add
247 error_str: Error string containing the lines
Simon Glassea49f9b2020-04-09 15:08:37 -0600248 colour: Expected colour for the line. Note that the board list,
249 if present, always appears in magenta
Simon Glass6643eb42020-04-09 15:08:33 -0600250
251 Returns:
252 New string where each line has the prefix added
253 """
254 lines = error_str.strip().splitlines()
Simon Glassea49f9b2020-04-09 15:08:37 -0600255 new_lines = []
256 for line in lines:
Simon Glassb0786df2022-07-11 19:03:59 -0600257 if brds:
Simon Glassf45d3742022-01-29 14:14:17 -0700258 expect = self._col.build(colour, prefix + '(')
Simon Glassb0786df2022-07-11 19:03:59 -0600259 expect += self._col.build(self._col.MAGENTA, brds,
Simon Glassea49f9b2020-04-09 15:08:37 -0600260 bright=False)
Simon Glassf45d3742022-01-29 14:14:17 -0700261 expect += self._col.build(colour, ') %s' % line)
Simon Glassea49f9b2020-04-09 15:08:37 -0600262 else:
Simon Glassf45d3742022-01-29 14:14:17 -0700263 expect = self._col.build(colour, prefix + line)
Simon Glassea49f9b2020-04-09 15:08:37 -0600264 new_lines.append(expect)
Simon Glass6643eb42020-04-09 15:08:33 -0600265 return '\n'.join(new_lines)
266
Simon Glassf4ebfba2020-04-09 15:08:53 -0600267 col = terminal.Color()
268 boards01234 = ('board0 board1 board2 board3 board4'
269 if list_error_boards else '')
Simon Glass070589b2020-04-09 15:08:38 -0600270 boards1234 = 'board1 board2 board3 board4' if list_error_boards else ''
271 boards234 = 'board2 board3 board4' if list_error_boards else ''
272 boards34 = 'board3 board4' if list_error_boards else ''
Simon Glassdacbe1e2020-04-09 15:08:34 -0600273 boards4 = 'board4' if list_error_boards else ''
274
Simon Glassf4ebfba2020-04-09 15:08:53 -0600275 # Upstream commit: migration warnings only
Simon Glass575ce512020-04-09 15:08:30 -0600276 self.assertEqual(next(lines).text, '01: %s' % commits[0][1])
Simon Glass071a1782018-11-06 16:02:13 -0700277
Simon Glassf4ebfba2020-04-09 15:08:53 -0600278 if not filter_migration_warnings:
279 self.assertSummary(next(lines).text, 'arm', 'w+',
280 ['board0', 'board1'], outcome=OUTCOME_WARN)
281 self.assertSummary(next(lines).text, 'powerpc', 'w+',
282 ['board2', 'board3'], outcome=OUTCOME_WARN)
283 self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
284 outcome=OUTCOME_WARN)
285
286 self.assertEqual(next(lines).text,
287 add_line_prefix('+', boards01234, migration, col.RED))
288
Simon Glass071a1782018-11-06 16:02:13 -0700289 # Second commit: all archs should fail with warnings
Simon Glass575ce512020-04-09 15:08:30 -0600290 self.assertEqual(next(lines).text, '02: %s' % commits[1][1])
Simon Glass7fb8aa22014-09-05 19:00:08 -0600291
Simon Glassf4ebfba2020-04-09 15:08:53 -0600292 if filter_migration_warnings:
293 self.assertSummary(next(lines).text, 'arm', 'w+',
294 ['board1'], outcome=OUTCOME_WARN)
295 self.assertSummary(next(lines).text, 'powerpc', 'w+',
296 ['board2', 'board3'], outcome=OUTCOME_WARN)
297 self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
298 outcome=OUTCOME_WARN)
Simon Glass7fb8aa22014-09-05 19:00:08 -0600299
Simon Glass071a1782018-11-06 16:02:13 -0700300 # Second commit: The warnings should be listed
Simon Glassea49f9b2020-04-09 15:08:37 -0600301 self.assertEqual(next(lines).text,
302 add_line_prefix('w+', boards1234, errors[0], col.YELLOW))
Simon Glass7fb8aa22014-09-05 19:00:08 -0600303
Simon Glass071a1782018-11-06 16:02:13 -0700304 # Third commit: Still fails
Simon Glass575ce512020-04-09 15:08:30 -0600305 self.assertEqual(next(lines).text, '03: %s' % commits[2][1])
Simon Glassf4ebfba2020-04-09 15:08:53 -0600306 if filter_migration_warnings:
307 self.assertSummary(next(lines).text, 'arm', '',
308 ['board1'], outcome=OUTCOME_OK)
Simon Glass575ce512020-04-09 15:08:30 -0600309 self.assertSummary(next(lines).text, 'powerpc', '+',
310 ['board2', 'board3'])
311 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
Simon Glass7fb8aa22014-09-05 19:00:08 -0600312
Simon Glass071a1782018-11-06 16:02:13 -0700313 # Expect a compiler error
Simon Glassea49f9b2020-04-09 15:08:37 -0600314 self.assertEqual(next(lines).text,
315 add_line_prefix('+', boards234, errors[1], col.RED))
Simon Glass7fb8aa22014-09-05 19:00:08 -0600316
Simon Glass071a1782018-11-06 16:02:13 -0700317 # Fourth commit: Compile errors are fixed, just have warning for board3
Simon Glass575ce512020-04-09 15:08:30 -0600318 self.assertEqual(next(lines).text, '04: %s' % commits[3][1])
Simon Glassf4ebfba2020-04-09 15:08:53 -0600319 if filter_migration_warnings:
320 expect = '%10s: ' % 'powerpc'
Simon Glassf45d3742022-01-29 14:14:17 -0700321 expect += ' ' + col.build(col.GREEN, '')
Simon Glassf4ebfba2020-04-09 15:08:53 -0600322 expect += ' '
Simon Glassf45d3742022-01-29 14:14:17 -0700323 expect += col.build(col.GREEN, ' %s' % 'board2')
324 expect += ' ' + col.build(col.YELLOW, 'w+')
Simon Glassf4ebfba2020-04-09 15:08:53 -0600325 expect += ' '
Simon Glassf45d3742022-01-29 14:14:17 -0700326 expect += col.build(col.YELLOW, ' %s' % 'board3')
Simon Glassf4ebfba2020-04-09 15:08:53 -0600327 self.assertEqual(next(lines).text, expect)
328 else:
329 self.assertSummary(next(lines).text, 'powerpc', 'w+',
330 ['board2', 'board3'], outcome=OUTCOME_WARN)
Simon Glass575ce512020-04-09 15:08:30 -0600331 self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
Simon Glassf4ebfba2020-04-09 15:08:53 -0600332 outcome=OUTCOME_WARN)
Simon Glass7fb8aa22014-09-05 19:00:08 -0600333
334 # Compile error fixed
Simon Glassea49f9b2020-04-09 15:08:37 -0600335 self.assertEqual(next(lines).text,
336 add_line_prefix('-', boards234, errors[1], col.GREEN))
Simon Glass7fb8aa22014-09-05 19:00:08 -0600337
Simon Glass9ea93812020-04-09 15:08:52 -0600338 if not filter_dtb_warnings:
339 self.assertEqual(
340 next(lines).text,
341 add_line_prefix('w+', boards34, errors[2], col.YELLOW))
Simon Glass7fb8aa22014-09-05 19:00:08 -0600342
Simon Glass071a1782018-11-06 16:02:13 -0700343 # Fifth commit
Simon Glass575ce512020-04-09 15:08:30 -0600344 self.assertEqual(next(lines).text, '05: %s' % commits[4][1])
Simon Glassf4ebfba2020-04-09 15:08:53 -0600345 if filter_migration_warnings:
346 self.assertSummary(next(lines).text, 'powerpc', '', ['board3'],
347 outcome=OUTCOME_OK)
Simon Glass575ce512020-04-09 15:08:30 -0600348 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
Simon Glass7fb8aa22014-09-05 19:00:08 -0600349
350 # The second line of errors[3] is a duplicate, so buildman will drop it
351 expect = errors[3].rstrip().split('\n')
352 expect = [expect[0]] + expect[2:]
Simon Glass6643eb42020-04-09 15:08:33 -0600353 expect = '\n'.join(expect)
Simon Glassea49f9b2020-04-09 15:08:37 -0600354 self.assertEqual(next(lines).text,
355 add_line_prefix('+', boards4, expect, col.RED))
Simon Glass7fb8aa22014-09-05 19:00:08 -0600356
Simon Glass9ea93812020-04-09 15:08:52 -0600357 if not filter_dtb_warnings:
358 self.assertEqual(
359 next(lines).text,
360 add_line_prefix('w-', boards34, errors[2], col.CYAN))
Simon Glass7fb8aa22014-09-05 19:00:08 -0600361
Simon Glass071a1782018-11-06 16:02:13 -0700362 # Sixth commit
Simon Glass575ce512020-04-09 15:08:30 -0600363 self.assertEqual(next(lines).text, '06: %s' % commits[5][1])
Simon Glassf4ebfba2020-04-09 15:08:53 -0600364 if filter_migration_warnings:
365 self.assertSummary(next(lines).text, 'sandbox', '', ['board4'],
366 outcome=OUTCOME_OK)
367 else:
368 self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
369 outcome=OUTCOME_WARN)
Simon Glass7fb8aa22014-09-05 19:00:08 -0600370
371 # The second line of errors[3] is a duplicate, so buildman will drop it
372 expect = errors[3].rstrip().split('\n')
373 expect = [expect[0]] + expect[2:]
Simon Glass6643eb42020-04-09 15:08:33 -0600374 expect = '\n'.join(expect)
Simon Glassea49f9b2020-04-09 15:08:37 -0600375 self.assertEqual(next(lines).text,
376 add_line_prefix('-', boards4, expect, col.GREEN))
377 self.assertEqual(next(lines).text,
378 add_line_prefix('w-', boards4, errors[0], col.CYAN))
Simon Glass7fb8aa22014-09-05 19:00:08 -0600379
Simon Glass071a1782018-11-06 16:02:13 -0700380 # Seventh commit
Simon Glass575ce512020-04-09 15:08:30 -0600381 self.assertEqual(next(lines).text, '07: %s' % commits[6][1])
Simon Glassf4ebfba2020-04-09 15:08:53 -0600382 if filter_migration_warnings:
383 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
384 else:
385 self.assertSummary(next(lines).text, 'arm', '', ['board0', 'board1'],
386 outcome=OUTCOME_OK)
387 self.assertSummary(next(lines).text, 'powerpc', '',
388 ['board2', 'board3'], outcome=OUTCOME_OK)
389 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
Simon Glassa8b7b1b2014-09-05 19:00:21 -0600390
391 # Pick out the correct error lines
392 expect_str = errors[4].rstrip().replace('%(basedir)s', '').split('\n')
393 expect = expect_str[3:8] + [expect_str[-1]]
Simon Glass6643eb42020-04-09 15:08:33 -0600394 expect = '\n'.join(expect)
Simon Glassf4ebfba2020-04-09 15:08:53 -0600395 if not filter_migration_warnings:
396 self.assertEqual(
397 next(lines).text,
398 add_line_prefix('-', boards01234, migration, col.GREEN))
399
Simon Glassea49f9b2020-04-09 15:08:37 -0600400 self.assertEqual(next(lines).text,
401 add_line_prefix('+', boards4, expect, col.RED))
Simon Glassa8b7b1b2014-09-05 19:00:21 -0600402
403 # Now the warnings lines
404 expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]]
Simon Glass6643eb42020-04-09 15:08:33 -0600405 expect = '\n'.join(expect)
Simon Glassea49f9b2020-04-09 15:08:37 -0600406 self.assertEqual(next(lines).text,
407 add_line_prefix('w+', boards4, expect, col.YELLOW))
Simon Glassa8b7b1b2014-09-05 19:00:21 -0600408
Simon Glass724c1752020-04-09 15:08:32 -0600409 def testOutput(self):
410 """Test basic builder operation and output
411
412 This does a line-by-line verification of the summary output.
413 """
414 lines = self._SetupTest(show_errors=True)
Simon Glass9ea93812020-04-09 15:08:52 -0600415 self._CheckOutput(lines, list_error_boards=False,
416 filter_dtb_warnings=False)
Simon Glassdacbe1e2020-04-09 15:08:34 -0600417
418 def testErrorBoards(self):
419 """Test output with --list-error-boards
420
421 This does a line-by-line verification of the summary output.
422 """
423 lines = self._SetupTest(show_errors=True, list_error_boards=True)
Simon Glassf4ebfba2020-04-09 15:08:53 -0600424 self._CheckOutput(lines, list_error_boards=True)
Simon Glass9ea93812020-04-09 15:08:52 -0600425
426 def testFilterDtb(self):
427 """Test output with --filter-dtb-warnings
428
429 This does a line-by-line verification of the summary output.
430 """
431 lines = self._SetupTest(show_errors=True, filter_dtb_warnings=True)
Simon Glassf4ebfba2020-04-09 15:08:53 -0600432 self._CheckOutput(lines, filter_dtb_warnings=True)
433
434 def testFilterMigration(self):
435 """Test output with --filter-migration-warnings
436
437 This does a line-by-line verification of the summary output.
438 """
439 lines = self._SetupTest(show_errors=True,
440 filter_migration_warnings=True)
441 self._CheckOutput(lines, filter_migration_warnings=True)
Simon Glass724c1752020-04-09 15:08:32 -0600442
Simon Glassc635d892021-01-30 22:17:46 -0700443 def testSingleThread(self):
444 """Test operation without threading"""
445 lines = self._SetupTest(show_errors=True, threads=0)
446 self._CheckOutput(lines, list_error_boards=False,
447 filter_dtb_warnings=False)
448
Simon Glassc05694f2013-04-03 11:07:16 +0000449 def _testGit(self):
450 """Test basic builder operation by building a branch"""
Simon Glassc05694f2013-04-03 11:07:16 +0000451 options = Options()
452 options.git = os.getcwd()
453 options.summary = False
454 options.jobs = None
455 options.dry_run = False
Simon Glass09bbfcd2020-04-09 15:08:31 -0600456 #options.git = os.path.join(self.base_dir, 'repo')
Simon Glassc05694f2013-04-03 11:07:16 +0000457 options.branch = 'test-buildman'
458 options.force_build = False
459 options.list_tool_chains = False
460 options.count = -1
461 options.git_dir = None
462 options.threads = None
463 options.show_unknown = False
464 options.quick = False
465 options.show_errors = False
466 options.keep_outputs = False
467 args = ['tegra20']
Simon Glassc1e1e1d2023-07-19 17:48:30 -0600468 control.do_buildman(options, args)
Simon Glassc05694f2013-04-03 11:07:16 +0000469
Simon Glassaa40f9a2014-08-09 15:33:08 -0600470 def testBoardSingle(self):
471 """Test single board selection"""
Simon Glass127a2392022-07-11 19:04:02 -0600472 self.assertEqual(self.brds.select_boards(['sandbox']),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600473 ({'all': ['board4'], 'sandbox': ['board4']}, []))
Simon Glassaa40f9a2014-08-09 15:33:08 -0600474
475 def testBoardArch(self):
476 """Test single board selection"""
Simon Glass127a2392022-07-11 19:04:02 -0600477 self.assertEqual(self.brds.select_boards(['arm']),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600478 ({'all': ['board0', 'board1'],
479 'arm': ['board0', 'board1']}, []))
Simon Glassaa40f9a2014-08-09 15:33:08 -0600480
481 def testBoardArchSingle(self):
482 """Test single board selection"""
Simon Glass127a2392022-07-11 19:04:02 -0600483 self.assertEqual(self.brds.select_boards(['arm sandbox']),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600484 ({'sandbox': ['board4'],
Simon Glass5e0f06d2017-11-12 21:52:15 -0700485 'all': ['board0', 'board1', 'board4'],
Simon Glassd9eb9f02018-06-11 23:26:46 -0600486 'arm': ['board0', 'board1']}, []))
Simon Glass5e0f06d2017-11-12 21:52:15 -0700487
Simon Glassaa40f9a2014-08-09 15:33:08 -0600488
489 def testBoardArchSingleMultiWord(self):
490 """Test single board selection"""
Simon Glass127a2392022-07-11 19:04:02 -0600491 self.assertEqual(self.brds.select_boards(['arm', 'sandbox']),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600492 ({'sandbox': ['board4'],
493 'all': ['board0', 'board1', 'board4'],
494 'arm': ['board0', 'board1']}, []))
Simon Glassaa40f9a2014-08-09 15:33:08 -0600495
496 def testBoardSingleAnd(self):
497 """Test single board selection"""
Simon Glass127a2392022-07-11 19:04:02 -0600498 self.assertEqual(self.brds.select_boards(['Tester & arm']),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600499 ({'Tester&arm': ['board0', 'board1'],
500 'all': ['board0', 'board1']}, []))
Simon Glassaa40f9a2014-08-09 15:33:08 -0600501
502 def testBoardTwoAnd(self):
503 """Test single board selection"""
Simon Glass127a2392022-07-11 19:04:02 -0600504 self.assertEqual(self.brds.select_boards(['Tester', '&', 'arm',
Simon Glassaa40f9a2014-08-09 15:33:08 -0600505 'Tester' '&', 'powerpc',
506 'sandbox']),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600507 ({'sandbox': ['board4'],
Simon Glass5e0f06d2017-11-12 21:52:15 -0700508 'all': ['board0', 'board1', 'board2', 'board3',
509 'board4'],
510 'Tester&powerpc': ['board2', 'board3'],
Simon Glassd9eb9f02018-06-11 23:26:46 -0600511 'Tester&arm': ['board0', 'board1']}, []))
Simon Glassaa40f9a2014-08-09 15:33:08 -0600512
513 def testBoardAll(self):
514 """Test single board selection"""
Simon Glass127a2392022-07-11 19:04:02 -0600515 self.assertEqual(self.brds.select_boards([]),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600516 ({'all': ['board0', 'board1', 'board2', 'board3',
517 'board4']}, []))
Simon Glassaa40f9a2014-08-09 15:33:08 -0600518
519 def testBoardRegularExpression(self):
520 """Test single board selection"""
Simon Glass127a2392022-07-11 19:04:02 -0600521 self.assertEqual(self.brds.select_boards(['T.*r&^Po']),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600522 ({'all': ['board2', 'board3'],
523 'T.*r&^Po': ['board2', 'board3']}, []))
Simon Glassaa40f9a2014-08-09 15:33:08 -0600524
525 def testBoardDuplicate(self):
526 """Test single board selection"""
Simon Glass127a2392022-07-11 19:04:02 -0600527 self.assertEqual(self.brds.select_boards(['sandbox sandbox',
Simon Glassaa40f9a2014-08-09 15:33:08 -0600528 'sandbox']),
Simon Glassd9eb9f02018-06-11 23:26:46 -0600529 ({'all': ['board4'], 'sandbox': ['board4']}, []))
Simon Glass2e1646c2014-12-01 17:33:51 -0700530 def CheckDirs(self, build, dirname):
Simon Glass4cb54682023-07-19 17:49:10 -0600531 self.assertEqual('base%s' % dirname, build.get_output_dir(1))
Simon Glass2e1646c2014-12-01 17:33:51 -0700532 self.assertEqual('base%s/fred' % dirname,
Simon Glassbc74d942023-07-19 17:49:06 -0600533 build.get_build_dir(1, 'fred'))
Simon Glass2e1646c2014-12-01 17:33:51 -0700534 self.assertEqual('base%s/fred/done' % dirname,
Simon Glassbc74d942023-07-19 17:49:06 -0600535 build.get_done_file(1, 'fred'))
Simon Glass2e1646c2014-12-01 17:33:51 -0700536 self.assertEqual('base%s/fred/u-boot.sizes' % dirname,
Simon Glassbc74d942023-07-19 17:49:06 -0600537 build.get_func_sizes_file(1, 'fred', 'u-boot'))
Simon Glass2e1646c2014-12-01 17:33:51 -0700538 self.assertEqual('base%s/fred/u-boot.objdump' % dirname,
Simon Glassbc74d942023-07-19 17:49:06 -0600539 build.get_objdump_file(1, 'fred', 'u-boot'))
Simon Glass2e1646c2014-12-01 17:33:51 -0700540 self.assertEqual('base%s/fred/err' % dirname,
Simon Glassbc74d942023-07-19 17:49:06 -0600541 build.get_err_file(1, 'fred'))
Simon Glass2e1646c2014-12-01 17:33:51 -0700542
543 def testOutputDir(self):
544 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
545 checkout=False, show_unknown=False)
546 build.commits = self.commits
547 build.commit_count = len(self.commits)
548 subject = self.commits[1].subject.translate(builder.trans_valid_chars)
Simon Glass36971712020-07-19 12:28:11 -0600549 dirname ='/%02d_g%s_%s' % (2, commits[1][0], subject[:20])
Simon Glass2e1646c2014-12-01 17:33:51 -0700550 self.CheckDirs(build, dirname)
551
552 def testOutputDirCurrent(self):
553 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
554 checkout=False, show_unknown=False)
555 build.commits = None
556 build.commit_count = 0
557 self.CheckDirs(build, '/current')
Simon Glassaa40f9a2014-08-09 15:33:08 -0600558
Simon Glasse87bde12014-12-01 17:33:55 -0700559 def testOutputDirNoSubdirs(self):
560 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
561 checkout=False, show_unknown=False,
562 no_subdirs=True)
563 build.commits = None
564 build.commit_count = 0
565 self.CheckDirs(build, '')
566
Simon Glassc1528c12014-12-01 17:34:05 -0700567 def testToolchainAliases(self):
568 self.assertTrue(self.toolchains.Select('arm') != None)
569 with self.assertRaises(ValueError):
570 self.toolchains.Select('no-arch')
571 with self.assertRaises(ValueError):
572 self.toolchains.Select('x86')
573
574 self.toolchains = toolchain.Toolchains()
575 self.toolchains.Add('x86_64-linux-gcc', test=False)
576 self.assertTrue(self.toolchains.Select('x86') != None)
577
578 self.toolchains = toolchain.Toolchains()
579 self.toolchains.Add('i386-linux-gcc', test=False)
580 self.assertTrue(self.toolchains.Select('x86') != None)
581
Simon Glass7e803e12014-12-01 17:34:06 -0700582 def testToolchainDownload(self):
583 """Test that we can download toolchains"""
Simon Glass2bfc6972017-11-12 21:52:14 -0700584 if use_network:
Simon Glass04150022018-10-01 21:12:43 -0600585 with test_util.capture_sys_output() as (stdout, stderr):
586 url = self.toolchains.LocateArchUrl('arm')
Simon Glass72e358c2018-10-01 21:12:35 -0600587 self.assertRegexpMatches(url, 'https://www.kernel.org/pub/tools/'
588 'crosstool/files/bin/x86_64/.*/'
Simon Glassdd65c5f2020-04-17 17:51:30 -0600589 'x86_64-gcc-.*-nolibc[-_]arm-.*linux-gnueabi.tar.xz')
Simon Glass7e803e12014-12-01 17:34:06 -0700590
Simon Glass48ac42e2019-12-05 15:59:14 -0700591 def testGetEnvArgs(self):
592 """Test the GetEnvArgs() function"""
593 tc = self.toolchains.Select('arm')
594 self.assertEqual('arm-linux-',
595 tc.GetEnvArgs(toolchain.VAR_CROSS_COMPILE))
596 self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_PATH))
597 self.assertEqual('arm',
598 tc.GetEnvArgs(toolchain.VAR_ARCH))
599 self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS))
600
601 self.toolchains.Add('/path/to/x86_64-linux-gcc', test=False)
602 tc = self.toolchains.Select('x86')
603 self.assertEqual('/path/to',
604 tc.GetEnvArgs(toolchain.VAR_PATH))
605 tc.override_toolchain = 'clang'
606 self.assertEqual('HOSTCC=clang CC=clang',
607 tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS))
608
Simon Glass5dc1ca72020-03-18 09:42:45 -0600609 def testPrepareOutputSpace(self):
610 def _Touch(fname):
Simon Glass80025522022-01-29 14:14:04 -0700611 tools.write_file(os.path.join(base_dir, fname), b'')
Simon Glass5dc1ca72020-03-18 09:42:45 -0600612
613 base_dir = tempfile.mkdtemp()
614
615 # Add various files that we want removed and left alone
Ovidiu Panaitee8e9cb2020-05-15 09:30:12 +0300616 to_remove = ['01_g0982734987_title', '102_g92bf_title',
617 '01_g2938abd8_title']
618 to_leave = ['something_else', '01-something.patch', '01_another']
Simon Glass5dc1ca72020-03-18 09:42:45 -0600619 for name in to_remove + to_leave:
620 _Touch(name)
621
622 build = builder.Builder(self.toolchains, base_dir, None, 1, 2)
623 build.commits = self.commits
624 build.commit_count = len(commits)
Simon Glassbc74d942023-07-19 17:49:06 -0600625 result = set(build._get_output_space_removals())
Simon Glass5dc1ca72020-03-18 09:42:45 -0600626 expected = set([os.path.join(base_dir, f) for f in to_remove])
627 self.assertEqual(expected, result)
Simon Glass7e803e12014-12-01 17:34:06 -0700628
Simon Glass22901f92022-01-22 05:07:31 -0700629 def test_adjust_cfg_nop(self):
630 """check various adjustments of config that are nops"""
631 # enable an enabled CONFIG
632 self.assertEqual(
633 'CONFIG_FRED=y',
634 cfgutil.adjust_cfg_line('CONFIG_FRED=y', {'FRED':'FRED'})[0])
635
636 # disable a disabled CONFIG
637 self.assertEqual(
638 '# CONFIG_FRED is not set',
639 cfgutil.adjust_cfg_line(
640 '# CONFIG_FRED is not set', {'FRED':'~FRED'})[0])
641
642 # use the adjust_cfg_lines() function
643 self.assertEqual(
644 ['CONFIG_FRED=y'],
645 cfgutil.adjust_cfg_lines(['CONFIG_FRED=y'], {'FRED':'FRED'}))
646 self.assertEqual(
647 ['# CONFIG_FRED is not set'],
648 cfgutil.adjust_cfg_lines(['CONFIG_FRED=y'], {'FRED':'~FRED'}))
649
650 # handling an empty line
651 self.assertEqual('#', cfgutil.adjust_cfg_line('#', {'FRED':'~FRED'})[0])
652
653 def test_adjust_cfg(self):
654 """check various adjustments of config"""
655 # disable a CONFIG
656 self.assertEqual(
657 '# CONFIG_FRED is not set',
658 cfgutil.adjust_cfg_line('CONFIG_FRED=1' , {'FRED':'~FRED'})[0])
659
660 # enable a disabled CONFIG
661 self.assertEqual(
662 'CONFIG_FRED=y',
663 cfgutil.adjust_cfg_line(
664 '# CONFIG_FRED is not set', {'FRED':'FRED'})[0])
665
666 # enable a CONFIG that doesn't exist
667 self.assertEqual(
668 ['CONFIG_FRED=y'],
669 cfgutil.adjust_cfg_lines([], {'FRED':'FRED'}))
670
671 # disable a CONFIG that doesn't exist
672 self.assertEqual(
673 ['# CONFIG_FRED is not set'],
674 cfgutil.adjust_cfg_lines([], {'FRED':'~FRED'}))
675
676 # disable a value CONFIG
677 self.assertEqual(
678 '# CONFIG_FRED is not set',
679 cfgutil.adjust_cfg_line('CONFIG_FRED="fred"' , {'FRED':'~FRED'})[0])
680
681 # setting a value CONFIG
682 self.assertEqual(
683 'CONFIG_FRED="fred"',
684 cfgutil.adjust_cfg_line('# CONFIG_FRED is not set' ,
685 {'FRED':'FRED="fred"'})[0])
686
687 # changing a value CONFIG
688 self.assertEqual(
689 'CONFIG_FRED="fred"',
690 cfgutil.adjust_cfg_line('CONFIG_FRED="ernie"' ,
691 {'FRED':'FRED="fred"'})[0])
692
693 # setting a value for a CONFIG that doesn't exist
694 self.assertEqual(
695 ['CONFIG_FRED="fred"'],
696 cfgutil.adjust_cfg_lines([], {'FRED':'FRED="fred"'}))
697
698 def test_convert_adjust_cfg_list(self):
699 """Check conversion of the list of changes into a dict"""
700 self.assertEqual({}, cfgutil.convert_list_to_dict(None))
701
702 expect = {
703 'FRED':'FRED',
704 'MARY':'~MARY',
705 'JOHN':'JOHN=0x123',
706 'ALICE':'ALICE="alice"',
707 'AMY':'AMY',
708 'ABE':'~ABE',
709 'MARK':'MARK=0x456',
710 'ANNA':'ANNA="anna"',
711 }
712 actual = cfgutil.convert_list_to_dict(
713 ['FRED', '~MARY', 'JOHN=0x123', 'ALICE="alice"',
714 'CONFIG_AMY', '~CONFIG_ABE', 'CONFIG_MARK=0x456',
715 'CONFIG_ANNA="anna"'])
716 self.assertEqual(expect, actual)
717
718 def test_check_cfg_file(self):
719 """Test check_cfg_file detects conflicts as expected"""
720 # Check failure to disable CONFIG
721 result = cfgutil.check_cfg_lines(['CONFIG_FRED=1'], {'FRED':'~FRED'})
722 self.assertEqual([['~FRED', 'CONFIG_FRED=1']], result)
723
724 result = cfgutil.check_cfg_lines(
725 ['CONFIG_FRED=1', 'CONFIG_MARY="mary"'], {'FRED':'~FRED'})
726 self.assertEqual([['~FRED', 'CONFIG_FRED=1']], result)
727
728 result = cfgutil.check_cfg_lines(
729 ['CONFIG_FRED=1', 'CONFIG_MARY="mary"'], {'MARY':'~MARY'})
730 self.assertEqual([['~MARY', 'CONFIG_MARY="mary"']], result)
731
732 # Check failure to enable CONFIG
733 result = cfgutil.check_cfg_lines(
734 ['# CONFIG_FRED is not set'], {'FRED':'FRED'})
735 self.assertEqual([['FRED', '# CONFIG_FRED is not set']], result)
736
737 # Check failure to set CONFIG value
738 result = cfgutil.check_cfg_lines(
739 ['# CONFIG_FRED is not set', 'CONFIG_MARY="not"'],
740 {'MARY':'MARY="mary"', 'FRED':'FRED'})
741 self.assertEqual([
742 ['FRED', '# CONFIG_FRED is not set'],
743 ['MARY="mary"', 'CONFIG_MARY="not"']], result)
744
745 # Check failure to add CONFIG value
746 result = cfgutil.check_cfg_lines([], {'MARY':'MARY="mary"'})
747 self.assertEqual([
748 ['MARY="mary"', 'Missing expected line: CONFIG_MARY="mary"']], result)
749
750
Simon Glassc05694f2013-04-03 11:07:16 +0000751if __name__ == "__main__":
752 unittest.main()