blob: 3eaba07559b80388fae06148c23a99a96cfa870d [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Simon Glassfc3fe1c2013-04-03 11:07:16 +00002# Copyright (c) 2012 The Chromium OS Authors.
3#
Simon Glassfc3fe1c2013-04-03 11:07:16 +00004
5import os
6import shutil
7import sys
8import tempfile
9import time
10import unittest
11
12# Bring in the patman libraries
13our_path = os.path.dirname(os.path.realpath(__file__))
Simon Glassfc3fe1c2013-04-03 11:07:16 +000014
Simon Glass0ede00f2020-04-17 18:09:02 -060015from buildman import board
16from buildman import bsettings
17from buildman import builder
18from buildman import control
19from buildman import toolchain
Simon Glassbf776672020-04-17 18:09:04 -060020from patman import commit
21from patman import command
22from patman import terminal
23from patman import test_util
24from patman import tools
Simon Glassfc3fe1c2013-04-03 11:07:16 +000025
Simon Glasscb39a102017-11-12 21:52:14 -070026use_network = True
27
Simon Glasscc935292014-12-01 17:34:04 -070028settings_data = '''
29# Buildman settings file
30
31[toolchain]
32main: /usr/sbin
33
34[toolchain-alias]
35x86: i386 x86_64
36'''
37
Simon Glass113a8a52020-04-09 15:08:53 -060038migration = '''===================== WARNING ======================
39This board does not use CONFIG_DM. CONFIG_DM will be
40compulsory starting with the v2020.01 release.
41Failure to update may result in board removal.
42See doc/driver-model/migration.rst for more info.
43====================================================
44'''
45
Simon Glassfc3fe1c2013-04-03 11:07:16 +000046errors = [
47 '''main.c: In function 'main_loop':
48main.c:260:6: warning: unused variable 'joe' [-Wunused-variable]
49''',
Simon Glass6208fce2014-09-05 19:00:08 -060050 '''main.c: In function 'main_loop2':
Simon Glassfc3fe1c2013-04-03 11:07:16 +000051main.c:295:2: error: 'fred' undeclared (first use in this function)
52main.c:295:2: note: each undeclared identifier is reported only once for each function it appears in
53make[1]: *** [main.o] Error 1
54make: *** [common/libcommon.o] Error 2
55Make failed
56''',
Simon Glass2d483332018-11-06 16:02:11 -070057 '''arch/arm/dts/socfpga_arria10_socdk_sdmmc.dtb: Warning \
58(avoid_unnecessary_addr_size): /clocks: unnecessary #address-cells/#size-cells \
59without "ranges" or child "reg" property
Simon Glassfc3fe1c2013-04-03 11:07:16 +000060''',
61 '''powerpc-linux-ld: warning: dot moved backwards before `.bss'
62powerpc-linux-ld: warning: dot moved backwards before `.bss'
63powerpc-linux-ld: u-boot: section .text lma 0xfffc0000 overlaps previous sections
64powerpc-linux-ld: u-boot: section .rodata lma 0xfffef3ec overlaps previous sections
65powerpc-linux-ld: u-boot: section .reloc lma 0xffffa400 overlaps previous sections
66powerpc-linux-ld: u-boot: section .data lma 0xffffcd38 overlaps previous sections
67powerpc-linux-ld: u-boot: section .u_boot_cmd lma 0xffffeb40 overlaps previous sections
68powerpc-linux-ld: u-boot: section .bootpg lma 0xfffff198 overlaps previous sections
Simon Glass930c8d42014-09-05 19:00:21 -060069''',
70 '''In file included from %(basedir)sarch/sandbox/cpu/cpu.c:9:0:
71%(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default]
72%(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition
73%(basedir)sarch/sandbox/cpu/cpu.c: In function 'do_reset':
74%(basedir)sarch/sandbox/cpu/cpu.c:27:1: error: unknown type name 'blah'
75%(basedir)sarch/sandbox/cpu/cpu.c:28:12: error: expected declaration specifiers or '...' before numeric constant
76make[2]: *** [arch/sandbox/cpu/cpu.o] Error 1
77make[1]: *** [arch/sandbox/cpu] Error 2
78make[1]: *** Waiting for unfinished jobs....
79In file included from %(basedir)scommon/board_f.c:55:0:
80%(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default]
81%(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition
82make: *** [sub-make] Error 2
Simon Glassfc3fe1c2013-04-03 11:07:16 +000083'''
84]
85
86
87# hash, subject, return code, list of errors/warnings
88commits = [
Simon Glass113a8a52020-04-09 15:08:53 -060089 ['1234', 'upstream/master, migration warning', 0, []],
Simon Glassfc3fe1c2013-04-03 11:07:16 +000090 ['5678', 'Second commit, a warning', 0, errors[0:1]],
91 ['9012', 'Third commit, error', 1, errors[0:2]],
92 ['3456', 'Fourth commit, warning', 0, [errors[0], errors[2]]],
93 ['7890', 'Fifth commit, link errors', 1, [errors[0], errors[3]]],
Simon Glass930c8d42014-09-05 19:00:21 -060094 ['abcd', 'Sixth commit, fixes all errors', 0, []],
Simon Glass113a8a52020-04-09 15:08:53 -060095 ['ef01', 'Seventh commit, fix migration, check directory suppression', 1,
96 [errors[4]]],
Simon Glassfc3fe1c2013-04-03 11:07:16 +000097]
98
99boards = [
Simon Glasse19d5782013-09-23 17:35:16 -0600100 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board0', ''],
101 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 2', 'board1', ''],
102 ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''],
Simon Glass251f5862017-11-12 21:52:15 -0700103 ['Active', 'powerpc', 'mpc83xx', '', 'Tester', 'PowerPC board 2', 'board3', ''],
Simon Glasse19d5782013-09-23 17:35:16 -0600104 ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''],
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000105]
106
Simon Glass4466c1f2014-12-01 17:33:51 -0700107BASE_DIR = 'base'
108
Simon Glass6af71012018-11-06 16:02:13 -0700109OUTCOME_OK, OUTCOME_WARN, OUTCOME_ERR = range(3)
110
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000111class Options:
112 """Class that holds build options"""
113 pass
114
115class TestBuild(unittest.TestCase):
116 """Test buildman
117
118 TODO: Write tests for the rest of the functionality
119 """
120 def setUp(self):
121 # Set up commits to build
122 self.commits = []
123 sequence = 0
124 for commit_info in commits:
125 comm = commit.Commit(commit_info[0])
126 comm.subject = commit_info[1]
127 comm.return_code = commit_info[2]
128 comm.error_list = commit_info[3]
Simon Glass113a8a52020-04-09 15:08:53 -0600129 if sequence < 6:
130 comm.error_list += [migration]
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000131 comm.sequence = sequence
132 sequence += 1
133 self.commits.append(comm)
134
135 # Set up boards to build
136 self.boards = board.Boards()
137 for brd in boards:
138 self.boards.AddBoard(board.Board(*brd))
139 self.boards.SelectBoards([])
140
Simon Glasscc935292014-12-01 17:34:04 -0700141 # Add some test settings
142 bsettings.Setup(None)
143 bsettings.AddFile(settings_data)
144
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000145 # Set up the toolchains
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000146 self.toolchains = toolchain.Toolchains()
147 self.toolchains.Add('arm-linux-gcc', test=False)
148 self.toolchains.Add('sparc-linux-gcc', test=False)
149 self.toolchains.Add('powerpc-linux-gcc', test=False)
150 self.toolchains.Add('gcc', test=False)
151
Simon Glass6208fce2014-09-05 19:00:08 -0600152 # Avoid sending any output
153 terminal.SetPrintTestMode()
154 self._col = terminal.Color()
155
Simon Glassaf430652020-04-09 15:08:31 -0600156 self.base_dir = tempfile.mkdtemp()
157 if not os.path.isdir(self.base_dir):
158 os.mkdir(self.base_dir)
Simon Glass930c8d42014-09-05 19:00:21 -0600159
Simon Glassaf430652020-04-09 15:08:31 -0600160 def tearDown(self):
161 shutil.rmtree(self.base_dir)
162
163 def Make(self, commit, brd, stage, *args, **kwargs):
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000164 result = command.CommandResult()
165 boardnum = int(brd.target[-1])
166 result.return_code = 0
167 result.stderr = ''
168 result.stdout = ('This is the test output for board %s, commit %s' %
169 (brd.target, commit.hash))
Simon Glass930c8d42014-09-05 19:00:21 -0600170 if ((boardnum >= 1 and boardnum >= commit.sequence) or
171 boardnum == 4 and commit.sequence == 6):
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000172 result.return_code = commit.return_code
Simon Glass930c8d42014-09-05 19:00:21 -0600173 result.stderr = (''.join(commit.error_list)
Simon Glassaf430652020-04-09 15:08:31 -0600174 % {'basedir' : self.base_dir + '/.bm-work/00/'})
Simon Glass113a8a52020-04-09 15:08:53 -0600175 elif commit.sequence < 6:
176 result.stderr = migration
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000177
178 result.combined = result.stdout + result.stderr
179 return result
180
Simon Glass6af71012018-11-06 16:02:13 -0700181 def assertSummary(self, text, arch, plus, boards, outcome=OUTCOME_ERR):
Simon Glass6208fce2014-09-05 19:00:08 -0600182 col = self._col
Simon Glass6af71012018-11-06 16:02:13 -0700183 expected_colour = (col.GREEN if outcome == OUTCOME_OK else
184 col.YELLOW if outcome == OUTCOME_WARN else col.RED)
Simon Glass6208fce2014-09-05 19:00:08 -0600185 expect = '%10s: ' % arch
186 # TODO(sjg@chromium.org): If plus is '', we shouldn't need this
Simon Glass63c619e2015-02-05 22:06:11 -0700187 expect += ' ' + col.Color(expected_colour, plus)
Simon Glass6208fce2014-09-05 19:00:08 -0600188 expect += ' '
189 for board in boards:
190 expect += col.Color(expected_colour, ' %s' % board)
191 self.assertEqual(text, expect)
192
Simon Glassce558db2020-04-09 15:08:32 -0600193 def _SetupTest(self, echo_lines=False, **kwdisplay_args):
194 """Set up the test by running a build and summary
Simon Glass6208fce2014-09-05 19:00:08 -0600195
Simon Glassce558db2020-04-09 15:08:32 -0600196 Args:
197 echo_lines: True to echo lines to the terminal to aid test
198 development
199 kwdisplay_args: Dict of arguemnts to pass to
200 Builder.SetDisplayOptions()
201
202 Returns:
203 Iterator containing the output lines, each a PrintLine() object
Simon Glass6208fce2014-09-05 19:00:08 -0600204 """
Simon Glassaf430652020-04-09 15:08:31 -0600205 build = builder.Builder(self.toolchains, self.base_dir, None, 1, 2,
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000206 checkout=False, show_unknown=False)
207 build.do_make = self.Make
208 board_selected = self.boards.GetSelectedDict()
209
Simon Glass6af71012018-11-06 16:02:13 -0700210 # Build the boards for the pre-defined commits and warnings/errors
211 # associated with each. This calls our Make() to inject the fake output.
Simon Glasse5a0e5d2014-08-09 15:33:03 -0600212 build.BuildBoards(self.commits, board_selected, keep_outputs=False,
213 verbose=False)
Simon Glass6208fce2014-09-05 19:00:08 -0600214 lines = terminal.GetPrintTestLines()
215 count = 0
216 for line in lines:
217 if line.text.strip():
218 count += 1
219
Simon Glass7b33f212020-04-09 15:08:47 -0600220 # We should get two starting messages, an update for every commit built
221 # and a summary message
222 self.assertEqual(count, len(commits) * len(boards) + 3)
Simon Glassce558db2020-04-09 15:08:32 -0600223 build.SetDisplayOptions(**kwdisplay_args);
Simon Glassb2ea7ab2014-08-09 15:33:02 -0600224 build.ShowSummary(self.commits, board_selected)
Simon Glassce558db2020-04-09 15:08:32 -0600225 if echo_lines:
226 terminal.EchoPrintTestLines()
227 return iter(terminal.GetPrintTestLines())
Simon Glass6af71012018-11-06 16:02:13 -0700228
Simon Glass113a8a52020-04-09 15:08:53 -0600229 def _CheckOutput(self, lines, list_error_boards=False,
230 filter_dtb_warnings=False,
231 filter_migration_warnings=False):
Simon Glassce558db2020-04-09 15:08:32 -0600232 """Check for expected output from the build summary
233
234 Args:
235 lines: Iterator containing the lines returned from the summary
Simon Glasse631a2b2020-04-09 15:08:34 -0600236 list_error_boards: Adjust the check for output produced with the
237 --list-error-boards flag
Simon Glass174592b2020-04-09 15:08:52 -0600238 filter_dtb_warnings: Adjust the check for output produced with the
239 --filter-dtb-warnings flag
Simon Glassce558db2020-04-09 15:08:32 -0600240 """
Simon Glass8c9a2672020-04-09 15:08:37 -0600241 def add_line_prefix(prefix, boards, error_str, colour):
Simon Glassc9dd80b2020-04-09 15:08:33 -0600242 """Add a prefix to each line of a string
243
244 The training \n in error_str is removed before processing
245
246 Args:
247 prefix: String prefix to add
248 error_str: Error string containing the lines
Simon Glass8c9a2672020-04-09 15:08:37 -0600249 colour: Expected colour for the line. Note that the board list,
250 if present, always appears in magenta
Simon Glassc9dd80b2020-04-09 15:08:33 -0600251
252 Returns:
253 New string where each line has the prefix added
254 """
255 lines = error_str.strip().splitlines()
Simon Glass8c9a2672020-04-09 15:08:37 -0600256 new_lines = []
257 for line in lines:
258 if boards:
259 expect = self._col.Color(colour, prefix + '(')
260 expect += self._col.Color(self._col.MAGENTA, boards,
261 bright=False)
262 expect += self._col.Color(colour, ') %s' % line)
263 else:
264 expect = self._col.Color(colour, prefix + line)
265 new_lines.append(expect)
Simon Glassc9dd80b2020-04-09 15:08:33 -0600266 return '\n'.join(new_lines)
267
Simon Glass113a8a52020-04-09 15:08:53 -0600268 col = terminal.Color()
269 boards01234 = ('board0 board1 board2 board3 board4'
270 if list_error_boards else '')
Simon Glass9ef0ceb2020-04-09 15:08:38 -0600271 boards1234 = 'board1 board2 board3 board4' if list_error_boards else ''
272 boards234 = 'board2 board3 board4' if list_error_boards else ''
273 boards34 = 'board3 board4' if list_error_boards else ''
Simon Glasse631a2b2020-04-09 15:08:34 -0600274 boards4 = 'board4' if list_error_boards else ''
275
Simon Glass113a8a52020-04-09 15:08:53 -0600276 # Upstream commit: migration warnings only
Simon Glassc3bc4f12020-04-09 15:08:30 -0600277 self.assertEqual(next(lines).text, '01: %s' % commits[0][1])
Simon Glass6af71012018-11-06 16:02:13 -0700278
Simon Glass113a8a52020-04-09 15:08:53 -0600279 if not filter_migration_warnings:
280 self.assertSummary(next(lines).text, 'arm', 'w+',
281 ['board0', 'board1'], outcome=OUTCOME_WARN)
282 self.assertSummary(next(lines).text, 'powerpc', 'w+',
283 ['board2', 'board3'], outcome=OUTCOME_WARN)
284 self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
285 outcome=OUTCOME_WARN)
286
287 self.assertEqual(next(lines).text,
288 add_line_prefix('+', boards01234, migration, col.RED))
289
Simon Glass6af71012018-11-06 16:02:13 -0700290 # Second commit: all archs should fail with warnings
Simon Glassc3bc4f12020-04-09 15:08:30 -0600291 self.assertEqual(next(lines).text, '02: %s' % commits[1][1])
Simon Glass6208fce2014-09-05 19:00:08 -0600292
Simon Glass113a8a52020-04-09 15:08:53 -0600293 if filter_migration_warnings:
294 self.assertSummary(next(lines).text, 'arm', 'w+',
295 ['board1'], outcome=OUTCOME_WARN)
296 self.assertSummary(next(lines).text, 'powerpc', 'w+',
297 ['board2', 'board3'], outcome=OUTCOME_WARN)
298 self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
299 outcome=OUTCOME_WARN)
Simon Glass6208fce2014-09-05 19:00:08 -0600300
Simon Glass6af71012018-11-06 16:02:13 -0700301 # Second commit: The warnings should be listed
Simon Glass8c9a2672020-04-09 15:08:37 -0600302 self.assertEqual(next(lines).text,
303 add_line_prefix('w+', boards1234, errors[0], col.YELLOW))
Simon Glass6208fce2014-09-05 19:00:08 -0600304
Simon Glass6af71012018-11-06 16:02:13 -0700305 # Third commit: Still fails
Simon Glassc3bc4f12020-04-09 15:08:30 -0600306 self.assertEqual(next(lines).text, '03: %s' % commits[2][1])
Simon Glass113a8a52020-04-09 15:08:53 -0600307 if filter_migration_warnings:
308 self.assertSummary(next(lines).text, 'arm', '',
309 ['board1'], outcome=OUTCOME_OK)
Simon Glassc3bc4f12020-04-09 15:08:30 -0600310 self.assertSummary(next(lines).text, 'powerpc', '+',
311 ['board2', 'board3'])
312 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
Simon Glass6208fce2014-09-05 19:00:08 -0600313
Simon Glass6af71012018-11-06 16:02:13 -0700314 # Expect a compiler error
Simon Glass8c9a2672020-04-09 15:08:37 -0600315 self.assertEqual(next(lines).text,
316 add_line_prefix('+', boards234, errors[1], col.RED))
Simon Glass6208fce2014-09-05 19:00:08 -0600317
Simon Glass6af71012018-11-06 16:02:13 -0700318 # Fourth commit: Compile errors are fixed, just have warning for board3
Simon Glassc3bc4f12020-04-09 15:08:30 -0600319 self.assertEqual(next(lines).text, '04: %s' % commits[3][1])
Simon Glass113a8a52020-04-09 15:08:53 -0600320 if filter_migration_warnings:
321 expect = '%10s: ' % 'powerpc'
322 expect += ' ' + col.Color(col.GREEN, '')
323 expect += ' '
324 expect += col.Color(col.GREEN, ' %s' % 'board2')
325 expect += ' ' + col.Color(col.YELLOW, 'w+')
326 expect += ' '
327 expect += col.Color(col.YELLOW, ' %s' % 'board3')
328 self.assertEqual(next(lines).text, expect)
329 else:
330 self.assertSummary(next(lines).text, 'powerpc', 'w+',
331 ['board2', 'board3'], outcome=OUTCOME_WARN)
Simon Glassc3bc4f12020-04-09 15:08:30 -0600332 self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
Simon Glass113a8a52020-04-09 15:08:53 -0600333 outcome=OUTCOME_WARN)
Simon Glass6208fce2014-09-05 19:00:08 -0600334
335 # Compile error fixed
Simon Glass8c9a2672020-04-09 15:08:37 -0600336 self.assertEqual(next(lines).text,
337 add_line_prefix('-', boards234, errors[1], col.GREEN))
Simon Glass6208fce2014-09-05 19:00:08 -0600338
Simon Glass174592b2020-04-09 15:08:52 -0600339 if not filter_dtb_warnings:
340 self.assertEqual(
341 next(lines).text,
342 add_line_prefix('w+', boards34, errors[2], col.YELLOW))
Simon Glass6208fce2014-09-05 19:00:08 -0600343
Simon Glass6af71012018-11-06 16:02:13 -0700344 # Fifth commit
Simon Glassc3bc4f12020-04-09 15:08:30 -0600345 self.assertEqual(next(lines).text, '05: %s' % commits[4][1])
Simon Glass113a8a52020-04-09 15:08:53 -0600346 if filter_migration_warnings:
347 self.assertSummary(next(lines).text, 'powerpc', '', ['board3'],
348 outcome=OUTCOME_OK)
Simon Glassc3bc4f12020-04-09 15:08:30 -0600349 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
Simon Glass6208fce2014-09-05 19:00:08 -0600350
351 # The second line of errors[3] is a duplicate, so buildman will drop it
352 expect = errors[3].rstrip().split('\n')
353 expect = [expect[0]] + expect[2:]
Simon Glassc9dd80b2020-04-09 15:08:33 -0600354 expect = '\n'.join(expect)
Simon Glass8c9a2672020-04-09 15:08:37 -0600355 self.assertEqual(next(lines).text,
356 add_line_prefix('+', boards4, expect, col.RED))
Simon Glass6208fce2014-09-05 19:00:08 -0600357
Simon Glass174592b2020-04-09 15:08:52 -0600358 if not filter_dtb_warnings:
359 self.assertEqual(
360 next(lines).text,
361 add_line_prefix('w-', boards34, errors[2], col.CYAN))
Simon Glass6208fce2014-09-05 19:00:08 -0600362
Simon Glass6af71012018-11-06 16:02:13 -0700363 # Sixth commit
Simon Glassc3bc4f12020-04-09 15:08:30 -0600364 self.assertEqual(next(lines).text, '06: %s' % commits[5][1])
Simon Glass113a8a52020-04-09 15:08:53 -0600365 if filter_migration_warnings:
366 self.assertSummary(next(lines).text, 'sandbox', '', ['board4'],
367 outcome=OUTCOME_OK)
368 else:
369 self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
370 outcome=OUTCOME_WARN)
Simon Glass6208fce2014-09-05 19:00:08 -0600371
372 # The second line of errors[3] is a duplicate, so buildman will drop it
373 expect = errors[3].rstrip().split('\n')
374 expect = [expect[0]] + expect[2:]
Simon Glassc9dd80b2020-04-09 15:08:33 -0600375 expect = '\n'.join(expect)
Simon Glass8c9a2672020-04-09 15:08:37 -0600376 self.assertEqual(next(lines).text,
377 add_line_prefix('-', boards4, expect, col.GREEN))
378 self.assertEqual(next(lines).text,
379 add_line_prefix('w-', boards4, errors[0], col.CYAN))
Simon Glass6208fce2014-09-05 19:00:08 -0600380
Simon Glass6af71012018-11-06 16:02:13 -0700381 # Seventh commit
Simon Glassc3bc4f12020-04-09 15:08:30 -0600382 self.assertEqual(next(lines).text, '07: %s' % commits[6][1])
Simon Glass113a8a52020-04-09 15:08:53 -0600383 if filter_migration_warnings:
384 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
385 else:
386 self.assertSummary(next(lines).text, 'arm', '', ['board0', 'board1'],
387 outcome=OUTCOME_OK)
388 self.assertSummary(next(lines).text, 'powerpc', '',
389 ['board2', 'board3'], outcome=OUTCOME_OK)
390 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
Simon Glass930c8d42014-09-05 19:00:21 -0600391
392 # Pick out the correct error lines
393 expect_str = errors[4].rstrip().replace('%(basedir)s', '').split('\n')
394 expect = expect_str[3:8] + [expect_str[-1]]
Simon Glassc9dd80b2020-04-09 15:08:33 -0600395 expect = '\n'.join(expect)
Simon Glass113a8a52020-04-09 15:08:53 -0600396 if not filter_migration_warnings:
397 self.assertEqual(
398 next(lines).text,
399 add_line_prefix('-', boards01234, migration, col.GREEN))
400
Simon Glass8c9a2672020-04-09 15:08:37 -0600401 self.assertEqual(next(lines).text,
402 add_line_prefix('+', boards4, expect, col.RED))
Simon Glass930c8d42014-09-05 19:00:21 -0600403
404 # Now the warnings lines
405 expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]]
Simon Glassc9dd80b2020-04-09 15:08:33 -0600406 expect = '\n'.join(expect)
Simon Glass8c9a2672020-04-09 15:08:37 -0600407 self.assertEqual(next(lines).text,
408 add_line_prefix('w+', boards4, expect, col.YELLOW))
Simon Glass930c8d42014-09-05 19:00:21 -0600409
Simon Glassce558db2020-04-09 15:08:32 -0600410 def testOutput(self):
411 """Test basic builder operation and output
412
413 This does a line-by-line verification of the summary output.
414 """
415 lines = self._SetupTest(show_errors=True)
Simon Glass174592b2020-04-09 15:08:52 -0600416 self._CheckOutput(lines, list_error_boards=False,
417 filter_dtb_warnings=False)
Simon Glasse631a2b2020-04-09 15:08:34 -0600418
419 def testErrorBoards(self):
420 """Test output with --list-error-boards
421
422 This does a line-by-line verification of the summary output.
423 """
424 lines = self._SetupTest(show_errors=True, list_error_boards=True)
Simon Glass113a8a52020-04-09 15:08:53 -0600425 self._CheckOutput(lines, list_error_boards=True)
Simon Glass174592b2020-04-09 15:08:52 -0600426
427 def testFilterDtb(self):
428 """Test output with --filter-dtb-warnings
429
430 This does a line-by-line verification of the summary output.
431 """
432 lines = self._SetupTest(show_errors=True, filter_dtb_warnings=True)
Simon Glass113a8a52020-04-09 15:08:53 -0600433 self._CheckOutput(lines, filter_dtb_warnings=True)
434
435 def testFilterMigration(self):
436 """Test output with --filter-migration-warnings
437
438 This does a line-by-line verification of the summary output.
439 """
440 lines = self._SetupTest(show_errors=True,
441 filter_migration_warnings=True)
442 self._CheckOutput(lines, filter_migration_warnings=True)
Simon Glassce558db2020-04-09 15:08:32 -0600443
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000444 def _testGit(self):
445 """Test basic builder operation by building a branch"""
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000446 options = Options()
447 options.git = os.getcwd()
448 options.summary = False
449 options.jobs = None
450 options.dry_run = False
Simon Glassaf430652020-04-09 15:08:31 -0600451 #options.git = os.path.join(self.base_dir, 'repo')
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000452 options.branch = 'test-buildman'
453 options.force_build = False
454 options.list_tool_chains = False
455 options.count = -1
456 options.git_dir = None
457 options.threads = None
458 options.show_unknown = False
459 options.quick = False
460 options.show_errors = False
461 options.keep_outputs = False
462 args = ['tegra20']
463 control.DoBuildman(options, args)
464
Simon Glass6131bea2014-08-09 15:33:08 -0600465 def testBoardSingle(self):
466 """Test single board selection"""
467 self.assertEqual(self.boards.SelectBoards(['sandbox']),
Simon Glass06890362018-06-11 23:26:46 -0600468 ({'all': ['board4'], 'sandbox': ['board4']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600469
470 def testBoardArch(self):
471 """Test single board selection"""
472 self.assertEqual(self.boards.SelectBoards(['arm']),
Simon Glass06890362018-06-11 23:26:46 -0600473 ({'all': ['board0', 'board1'],
474 'arm': ['board0', 'board1']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600475
476 def testBoardArchSingle(self):
477 """Test single board selection"""
478 self.assertEqual(self.boards.SelectBoards(['arm sandbox']),
Simon Glass06890362018-06-11 23:26:46 -0600479 ({'sandbox': ['board4'],
Simon Glass251f5862017-11-12 21:52:15 -0700480 'all': ['board0', 'board1', 'board4'],
Simon Glass06890362018-06-11 23:26:46 -0600481 'arm': ['board0', 'board1']}, []))
Simon Glass251f5862017-11-12 21:52:15 -0700482
Simon Glass6131bea2014-08-09 15:33:08 -0600483
484 def testBoardArchSingleMultiWord(self):
485 """Test single board selection"""
486 self.assertEqual(self.boards.SelectBoards(['arm', 'sandbox']),
Simon Glass06890362018-06-11 23:26:46 -0600487 ({'sandbox': ['board4'],
488 'all': ['board0', 'board1', 'board4'],
489 'arm': ['board0', 'board1']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600490
491 def testBoardSingleAnd(self):
492 """Test single board selection"""
493 self.assertEqual(self.boards.SelectBoards(['Tester & arm']),
Simon Glass06890362018-06-11 23:26:46 -0600494 ({'Tester&arm': ['board0', 'board1'],
495 'all': ['board0', 'board1']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600496
497 def testBoardTwoAnd(self):
498 """Test single board selection"""
499 self.assertEqual(self.boards.SelectBoards(['Tester', '&', 'arm',
500 'Tester' '&', 'powerpc',
501 'sandbox']),
Simon Glass06890362018-06-11 23:26:46 -0600502 ({'sandbox': ['board4'],
Simon Glass251f5862017-11-12 21:52:15 -0700503 'all': ['board0', 'board1', 'board2', 'board3',
504 'board4'],
505 'Tester&powerpc': ['board2', 'board3'],
Simon Glass06890362018-06-11 23:26:46 -0600506 'Tester&arm': ['board0', 'board1']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600507
508 def testBoardAll(self):
509 """Test single board selection"""
Simon Glass251f5862017-11-12 21:52:15 -0700510 self.assertEqual(self.boards.SelectBoards([]),
Simon Glass06890362018-06-11 23:26:46 -0600511 ({'all': ['board0', 'board1', 'board2', 'board3',
512 'board4']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600513
514 def testBoardRegularExpression(self):
515 """Test single board selection"""
516 self.assertEqual(self.boards.SelectBoards(['T.*r&^Po']),
Simon Glass06890362018-06-11 23:26:46 -0600517 ({'all': ['board2', 'board3'],
518 'T.*r&^Po': ['board2', 'board3']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600519
520 def testBoardDuplicate(self):
521 """Test single board selection"""
522 self.assertEqual(self.boards.SelectBoards(['sandbox sandbox',
523 'sandbox']),
Simon Glass06890362018-06-11 23:26:46 -0600524 ({'all': ['board4'], 'sandbox': ['board4']}, []))
Simon Glass4466c1f2014-12-01 17:33:51 -0700525 def CheckDirs(self, build, dirname):
526 self.assertEqual('base%s' % dirname, build._GetOutputDir(1))
527 self.assertEqual('base%s/fred' % dirname,
528 build.GetBuildDir(1, 'fred'))
529 self.assertEqual('base%s/fred/done' % dirname,
530 build.GetDoneFile(1, 'fred'))
531 self.assertEqual('base%s/fred/u-boot.sizes' % dirname,
532 build.GetFuncSizesFile(1, 'fred', 'u-boot'))
533 self.assertEqual('base%s/fred/u-boot.objdump' % dirname,
534 build.GetObjdumpFile(1, 'fred', 'u-boot'))
535 self.assertEqual('base%s/fred/err' % dirname,
536 build.GetErrFile(1, 'fred'))
537
538 def testOutputDir(self):
539 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
540 checkout=False, show_unknown=False)
541 build.commits = self.commits
542 build.commit_count = len(self.commits)
543 subject = self.commits[1].subject.translate(builder.trans_valid_chars)
Simon Glass3918dfa2020-07-19 12:28:11 -0600544 dirname ='/%02d_g%s_%s' % (2, commits[1][0], subject[:20])
Simon Glass4466c1f2014-12-01 17:33:51 -0700545 self.CheckDirs(build, dirname)
546
547 def testOutputDirCurrent(self):
548 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
549 checkout=False, show_unknown=False)
550 build.commits = None
551 build.commit_count = 0
552 self.CheckDirs(build, '/current')
Simon Glass6131bea2014-08-09 15:33:08 -0600553
Simon Glass5971ab52014-12-01 17:33:55 -0700554 def testOutputDirNoSubdirs(self):
555 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
556 checkout=False, show_unknown=False,
557 no_subdirs=True)
558 build.commits = None
559 build.commit_count = 0
560 self.CheckDirs(build, '')
561
Simon Glass9b83bfd2014-12-01 17:34:05 -0700562 def testToolchainAliases(self):
563 self.assertTrue(self.toolchains.Select('arm') != None)
564 with self.assertRaises(ValueError):
565 self.toolchains.Select('no-arch')
566 with self.assertRaises(ValueError):
567 self.toolchains.Select('x86')
568
569 self.toolchains = toolchain.Toolchains()
570 self.toolchains.Add('x86_64-linux-gcc', test=False)
571 self.assertTrue(self.toolchains.Select('x86') != None)
572
573 self.toolchains = toolchain.Toolchains()
574 self.toolchains.Add('i386-linux-gcc', test=False)
575 self.assertTrue(self.toolchains.Select('x86') != None)
576
Simon Glass827e37b2014-12-01 17:34:06 -0700577 def testToolchainDownload(self):
578 """Test that we can download toolchains"""
Simon Glasscb39a102017-11-12 21:52:14 -0700579 if use_network:
Simon Glass4b4bc062018-10-01 21:12:43 -0600580 with test_util.capture_sys_output() as (stdout, stderr):
581 url = self.toolchains.LocateArchUrl('arm')
Simon Glassda753e32018-10-01 21:12:35 -0600582 self.assertRegexpMatches(url, 'https://www.kernel.org/pub/tools/'
583 'crosstool/files/bin/x86_64/.*/'
Simon Glass55a98d92020-04-17 17:51:30 -0600584 'x86_64-gcc-.*-nolibc[-_]arm-.*linux-gnueabi.tar.xz')
Simon Glass827e37b2014-12-01 17:34:06 -0700585
Simon Glass57cb9d52019-12-05 15:59:14 -0700586 def testGetEnvArgs(self):
587 """Test the GetEnvArgs() function"""
588 tc = self.toolchains.Select('arm')
589 self.assertEqual('arm-linux-',
590 tc.GetEnvArgs(toolchain.VAR_CROSS_COMPILE))
591 self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_PATH))
592 self.assertEqual('arm',
593 tc.GetEnvArgs(toolchain.VAR_ARCH))
594 self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS))
595
596 self.toolchains.Add('/path/to/x86_64-linux-gcc', test=False)
597 tc = self.toolchains.Select('x86')
598 self.assertEqual('/path/to',
599 tc.GetEnvArgs(toolchain.VAR_PATH))
600 tc.override_toolchain = 'clang'
601 self.assertEqual('HOSTCC=clang CC=clang',
602 tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS))
603
Simon Glass925f6ad2020-03-18 09:42:45 -0600604 def testPrepareOutputSpace(self):
605 def _Touch(fname):
606 tools.WriteFile(os.path.join(base_dir, fname), b'')
607
608 base_dir = tempfile.mkdtemp()
609
610 # Add various files that we want removed and left alone
Ovidiu Panait7664b032020-05-15 09:30:12 +0300611 to_remove = ['01_g0982734987_title', '102_g92bf_title',
612 '01_g2938abd8_title']
613 to_leave = ['something_else', '01-something.patch', '01_another']
Simon Glass925f6ad2020-03-18 09:42:45 -0600614 for name in to_remove + to_leave:
615 _Touch(name)
616
617 build = builder.Builder(self.toolchains, base_dir, None, 1, 2)
618 build.commits = self.commits
619 build.commit_count = len(commits)
620 result = set(build._GetOutputSpaceRemovals())
621 expected = set([os.path.join(base_dir, f) for f in to_remove])
622 self.assertEqual(expected, result)
Simon Glass827e37b2014-12-01 17:34:06 -0700623
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000624if __name__ == "__main__":
625 unittest.main()