blob: aaf4cde91eec911815a864c761d4cc4bcdc77885 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Simon Glassed098bb2014-09-05 19:00:13 -06002# Copyright (c) 2014 Google, Inc
3#
Simon Glassed098bb2014-09-05 19:00:13 -06004
5import os
Simon Glassada78d42023-07-19 17:48:16 -06006from pathlib import Path
Simon Glassed098bb2014-09-05 19:00:13 -06007import shutil
8import sys
9import tempfile
Simon Glassada78d42023-07-19 17:48:16 -060010import time
Simon Glassed098bb2014-09-05 19:00:13 -060011import unittest
12
Simon Glassf0d9c102020-04-17 18:09:02 -060013from buildman import board
Simon Glass20751d62022-07-11 19:04:03 -060014from buildman import boards
Simon Glassf0d9c102020-04-17 18:09:02 -060015from buildman import bsettings
16from buildman import cmdline
17from buildman import control
18from buildman import toolchain
Simon Glassa997ea52020-04-17 18:09:04 -060019from patman import gitutil
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 Glassed098bb2014-09-05 19:00:13 -060024
Simon Glass5e0441d2014-09-05 19:00:15 -060025settings_data = '''
26# Buildman settings file
Tom Rini93ebd462022-11-09 19:14:53 -070027[global]
Simon Glass5e0441d2014-09-05 19:00:15 -060028
29[toolchain]
30
31[toolchain-alias]
32
33[make-flags]
34src=/home/sjg/c/src
35chroot=/home/sjg/c/chroot
Masahiro Yamada72e545a2018-08-06 20:47:38 +090036vboot=VBOOT_DEBUG=1 MAKEFLAGS_VBOOT=DEBUG=1 CFLAGS_EXTRA_VBOOT=-DUNROLL_LOOPS VBOOT_SOURCE=${src}/platform/vboot_reference
Simon Glass5e0441d2014-09-05 19:00:15 -060037chromeos_coreboot=VBOOT=${chroot}/build/link/usr ${vboot}
38chromeos_daisy=VBOOT=${chroot}/build/daisy/usr ${vboot}
39chromeos_peach=VBOOT=${chroot}/build/peach_pit/usr ${vboot}
40'''
41
Simon Glassd4c6c8a2022-07-11 19:03:58 -060042BOARDS = [
Simon Glass560bd4a2023-07-19 17:48:12 -060043 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 0', 'board0', ''],
44 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board1', ''],
Simon Glasscbd36582014-09-05 19:00:16 -060045 ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''],
Simon Glasscbd36582014-09-05 19:00:16 -060046 ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''],
47]
48
Simon Glass8e959562014-09-05 19:00:20 -060049commit_shortlog = """4aca821 patman: Avoid changing the order of tags
5039403bb patman: Use --no-pager' to stop git from forking a pager
51db6e6f2 patman: Remove the -a option
52f2ccf03 patman: Correct unit tests to run correctly
531d097f9 patman: Fix indentation in terminal.py
54d073747 patman: Support the 'reverse' option for 'git log
55"""
56
57commit_log = ["""commit 7f6b8315d18f683c5181d0c3694818c1b2a20dcd
58Author: Masahiro Yamada <yamada.m@jp.panasonic.com>
59Date: Fri Aug 22 19:12:41 2014 +0900
60
61 buildman: refactor help message
62
63 "buildman [options]" is displayed by default.
64
65 Append the rest of help messages to parser.usage
66 instead of replacing it.
67
68 Besides, "-b <branch>" is not mandatory since commit fea5858e.
69 Drop it from the usage.
70
71 Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
72""",
73"""commit d0737479be6baf4db5e2cdbee123e96bc5ed0ba8
74Author: Simon Glass <sjg@chromium.org>
75Date: Thu Aug 14 16:48:25 2014 -0600
76
77 patman: Support the 'reverse' option for 'git log'
78
79 This option is currently not supported, but needs to be, for buildman to
80 operate as expected.
81
82 Series-changes: 7
83 - Add new patch to fix the 'reverse' bug
84
Simon Glass359b55a62014-09-05 19:00:23 -060085 Series-version: 8
Simon Glass8e959562014-09-05 19:00:20 -060086
87 Change-Id: I79078f792e8b390b8a1272a8023537821d45feda
88 Reported-by: York Sun <yorksun@freescale.com>
89 Signed-off-by: Simon Glass <sjg@chromium.org>
90
91""",
92"""commit 1d097f9ab487c5019152fd47bda126839f3bf9fc
93Author: Simon Glass <sjg@chromium.org>
94Date: Sat Aug 9 11:44:32 2014 -0600
95
96 patman: Fix indentation in terminal.py
97
98 This code came from a different project with 2-character indentation. Fix
99 it for U-Boot.
100
101 Series-changes: 6
102 - Add new patch to fix indentation in teminal.py
103
104 Change-Id: I5a74d2ebbb3cc12a665f5c725064009ac96e8a34
105 Signed-off-by: Simon Glass <sjg@chromium.org>
106
107""",
108"""commit f2ccf03869d1e152c836515a3ceb83cdfe04a105
109Author: Simon Glass <sjg@chromium.org>
110Date: Sat Aug 9 11:08:24 2014 -0600
111
112 patman: Correct unit tests to run correctly
113
114 It seems that doctest behaves differently now, and some of the unit tests
115 do not run. Adjust the tests to work correctly.
116
117 ./tools/patman/patman --test
118 <unittest.result.TestResult run=10 errors=0 failures=0>
119
120 Series-changes: 6
121 - Add new patch to fix patman unit tests
122
123 Change-Id: I3d2ca588f4933e1f9d6b1665a00e4ae58269ff3b
124
125""",
126"""commit db6e6f2f9331c5a37647d6668768d4a40b8b0d1c
127Author: Simon Glass <sjg@chromium.org>
128Date: Sat Aug 9 12:06:02 2014 -0600
129
130 patman: Remove the -a option
131
132 It seems that this is no longer needed, since checkpatch.pl will catch
133 whitespace problems in patches. Also the option is not widely used, so
134 it seems safe to just remove it.
135
136 Series-changes: 6
137 - Add new patch to remove patman's -a option
138
139 Suggested-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
140 Change-Id: I5821a1c75154e532c46513486ca40b808de7e2cc
141
142""",
143"""commit 39403bb4f838153028a6f21ca30bf100f3791133
144Author: Simon Glass <sjg@chromium.org>
145Date: Thu Aug 14 21:50:52 2014 -0600
146
147 patman: Use --no-pager' to stop git from forking a pager
148
149""",
150"""commit 4aca821e27e97925c039e69fd37375b09c6f129c
151Author: Simon Glass <sjg@chromium.org>
152Date: Fri Aug 22 15:57:39 2014 -0600
153
154 patman: Avoid changing the order of tags
155
156 patman collects tags that it sees in the commit and places them nicely
157 sorted at the end of the patch. However, this is not really necessary and
158 in fact is apparently not desirable.
159
160 Series-changes: 9
161 - Add new patch to avoid changing the order of tags
162
Simon Glass359b55a62014-09-05 19:00:23 -0600163 Series-version: 9
164
Simon Glass8e959562014-09-05 19:00:20 -0600165 Suggested-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
166 Change-Id: Ib1518588c1a189ad5c3198aae76f8654aed8d0db
167"""]
168
169TEST_BRANCH = '__testbranch'
170
Simon Glassed098bb2014-09-05 19:00:13 -0600171class TestFunctional(unittest.TestCase):
172 """Functional test for buildman.
173
174 This aims to test from just below the invocation of buildman (parsing
175 of arguments) to 'make' and 'git' invocation. It is not a true
176 emd-to-end test, as it mocks git, make and the tool chain. But this
177 makes it easier to detect when the builder is doing the wrong thing,
178 since in many cases this test code will fail. For example, only a
179 very limited subset of 'git' arguments is supported - anything
180 unexpected will fail.
181 """
182 def setUp(self):
183 self._base_dir = tempfile.mkdtemp()
Tom Rinie95eddc2019-10-07 17:17:36 -0400184 self._output_dir = tempfile.mkdtemp()
Simon Glassed098bb2014-09-05 19:00:13 -0600185 self._git_dir = os.path.join(self._base_dir, 'src')
186 self._buildman_pathname = sys.argv[0]
Simon Glass5d4a7872016-07-27 20:33:00 -0600187 self._buildman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
Simon Glassed098bb2014-09-05 19:00:13 -0600188 command.test_result = self._HandleCommand
Simon Glass22901f92022-01-22 05:07:31 -0700189 bsettings.Setup(None)
190 bsettings.AddFile(settings_data)
Simon Glass8e959562014-09-05 19:00:20 -0600191 self.setupToolchains()
192 self._toolchains.Add('arm-gcc', test=False)
193 self._toolchains.Add('powerpc-gcc', test=False)
Simon Glass20751d62022-07-11 19:04:03 -0600194 self._boards = boards.Boards()
Simon Glassd4c6c8a2022-07-11 19:03:58 -0600195 for brd in BOARDS:
Simon Glass127a2392022-07-11 19:04:02 -0600196 self._boards.add_board(board.Board(*brd))
Simon Glassed098bb2014-09-05 19:00:13 -0600197
Simon Glass8e959562014-09-05 19:00:20 -0600198 # Directories where the source been cloned
199 self._clone_dirs = []
200 self._commits = len(commit_shortlog.splitlines()) + 1
Simon Glassd4c6c8a2022-07-11 19:03:58 -0600201 self._total_builds = self._commits * len(BOARDS)
Simon Glass8e959562014-09-05 19:00:20 -0600202
203 # Number of calls to make
204 self._make_calls = 0
205
206 # Map of [board, commit] to error messages
207 self._error = {}
208
Simon Glass4aeceb92014-09-05 19:00:22 -0600209 self._test_branch = TEST_BRANCH
210
Tom Rini93ebd462022-11-09 19:14:53 -0700211 # Set to True to report missing blobs
212 self._missing = False
213
Simon Glasscef26b82023-07-19 17:48:15 -0600214 self._buildman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
215 self._test_dir = os.path.join(self._buildman_dir, 'test')
216
217 # Set up some fake source files
218 shutil.copytree(self._test_dir, self._git_dir)
219
Simon Glass8e959562014-09-05 19:00:20 -0600220 # Avoid sending any output and clear all terminal output
Simon Glass02811582022-01-29 14:14:18 -0700221 terminal.set_print_test_mode()
222 terminal.get_print_test_lines()
Simon Glass8e959562014-09-05 19:00:20 -0600223
Simon Glassed098bb2014-09-05 19:00:13 -0600224 def tearDown(self):
225 shutil.rmtree(self._base_dir)
Simon Glass211c74b2022-11-09 19:14:52 -0700226 shutil.rmtree(self._output_dir)
Simon Glassed098bb2014-09-05 19:00:13 -0600227
Simon Glass8e959562014-09-05 19:00:20 -0600228 def setupToolchains(self):
229 self._toolchains = toolchain.Toolchains()
230 self._toolchains.Add('gcc', test=False)
231
Simon Glassed098bb2014-09-05 19:00:13 -0600232 def _RunBuildman(self, *args):
Simon Glass840be732022-01-29 14:14:05 -0700233 return command.run_pipe([[self._buildman_pathname] + list(args)],
Simon Glassed098bb2014-09-05 19:00:13 -0600234 capture=True, capture_stderr=True)
235
Simon Glass09afcb72023-07-19 17:48:28 -0600236 def _RunControl(self, *args, brds=False, clean_dir=False,
237 test_thread_exceptions=False, get_builder=True):
Simon Glassa29b3ea2021-04-11 16:27:25 +1200238 """Run buildman
239
240 Args:
241 args: List of arguments to pass
Simon Glass09afcb72023-07-19 17:48:28 -0600242 brds: Boards object, or False to pass self._boards, or None to pass
243 None
Simon Glassa29b3ea2021-04-11 16:27:25 +1200244 clean_dir: Used for tests only, indicates that the existing output_dir
245 should be removed before starting the build
Simon Glass9bf9a722021-04-11 16:27:27 +1200246 test_thread_exceptions: Uses for tests only, True to make the threads
247 raise an exception instead of reporting their result. This simulates
248 a failure in the code somewhere
Simon Glass09afcb72023-07-19 17:48:28 -0600249 get_builder (bool): Set self._builder to the resulting builder
Simon Glassa29b3ea2021-04-11 16:27:25 +1200250
251 Returns:
252 result code from buildman
253 """
Simon Glassed098bb2014-09-05 19:00:13 -0600254 sys.argv = [sys.argv[0]] + list(args)
Simon Glasse145b2c2023-07-19 17:49:01 -0600255 options, args = cmdline.parse_args()
Simon Glass09afcb72023-07-19 17:48:28 -0600256 if brds == False:
257 brds = self._boards
Simon Glassc1e1e1d2023-07-19 17:48:30 -0600258 result = control.do_buildman(
259 options, args, toolchains=self._toolchains,
260 make_func=self._HandleMake, brds=brds, clean_dir=clean_dir,
261 test_thread_exceptions=test_thread_exceptions)
Simon Glass09afcb72023-07-19 17:48:28 -0600262 if get_builder:
Simon Glassaf0e29f2023-07-19 17:48:31 -0600263 self._builder = control.TEST_BUILDER
Simon Glass8e959562014-09-05 19:00:20 -0600264 return result
Simon Glassed098bb2014-09-05 19:00:13 -0600265
266 def testFullHelp(self):
267 command.test_result = None
268 result = self._RunBuildman('-H')
Simon Glass79cc9be2022-11-09 19:14:43 -0700269 help_file = os.path.join(self._buildman_dir, 'README.rst')
Tom Rinic3c0b6d2018-01-16 15:29:50 -0500270 # Remove possible extraneous strings
271 extra = '::::::::::::::\n' + help_file + '\n::::::::::::::\n'
272 gothelp = result.stdout.replace(extra, '')
273 self.assertEqual(len(gothelp), os.path.getsize(help_file))
Simon Glassed098bb2014-09-05 19:00:13 -0600274 self.assertEqual(0, len(result.stderr))
275 self.assertEqual(0, result.return_code)
276
277 def testHelp(self):
278 command.test_result = None
279 result = self._RunBuildman('-h')
Simon Glass79cc9be2022-11-09 19:14:43 -0700280 help_file = os.path.join(self._buildman_dir, 'README.rst')
Simon Glassed098bb2014-09-05 19:00:13 -0600281 self.assertTrue(len(result.stdout) > 1000)
282 self.assertEqual(0, len(result.stderr))
283 self.assertEqual(0, result.return_code)
284
285 def testGitSetup(self):
286 """Test gitutils.Setup(), from outside the module itself"""
287 command.test_result = command.CommandResult(return_code=1)
Simon Glass761648b2022-01-29 14:14:11 -0700288 gitutil.setup()
Simon Glassed098bb2014-09-05 19:00:13 -0600289 self.assertEqual(gitutil.use_no_decorate, False)
290
291 command.test_result = command.CommandResult(return_code=0)
Simon Glass761648b2022-01-29 14:14:11 -0700292 gitutil.setup()
Simon Glassed098bb2014-09-05 19:00:13 -0600293 self.assertEqual(gitutil.use_no_decorate, True)
294
295 def _HandleCommandGitLog(self, args):
Simon Glass642e9a62016-03-12 18:50:31 -0700296 if args[-1] == '--':
297 args = args[:-1]
Simon Glassed098bb2014-09-05 19:00:13 -0600298 if '-n0' in args:
299 return command.CommandResult(return_code=0)
Simon Glass4aeceb92014-09-05 19:00:22 -0600300 elif args[-1] == 'upstream/master..%s' % self._test_branch:
Simon Glass8e959562014-09-05 19:00:20 -0600301 return command.CommandResult(return_code=0, stdout=commit_shortlog)
302 elif args[:3] == ['--no-color', '--no-decorate', '--reverse']:
Simon Glass4aeceb92014-09-05 19:00:22 -0600303 if args[-1] == self._test_branch:
Simon Glass8e959562014-09-05 19:00:20 -0600304 count = int(args[3][2:])
305 return command.CommandResult(return_code=0,
306 stdout=''.join(commit_log[:count]))
Simon Glassed098bb2014-09-05 19:00:13 -0600307
308 # Not handled, so abort
Simon Glassc78ed662019-10-31 07:42:53 -0600309 print('git log', args)
Simon Glassed098bb2014-09-05 19:00:13 -0600310 sys.exit(1)
311
Simon Glass8e959562014-09-05 19:00:20 -0600312 def _HandleCommandGitConfig(self, args):
313 config = args[0]
314 if config == 'sendemail.aliasesfile':
315 return command.CommandResult(return_code=0)
316 elif config.startswith('branch.badbranch'):
317 return command.CommandResult(return_code=1)
Simon Glass4aeceb92014-09-05 19:00:22 -0600318 elif config == 'branch.%s.remote' % self._test_branch:
Simon Glass8e959562014-09-05 19:00:20 -0600319 return command.CommandResult(return_code=0, stdout='upstream\n')
Simon Glass4aeceb92014-09-05 19:00:22 -0600320 elif config == 'branch.%s.merge' % self._test_branch:
Simon Glass8e959562014-09-05 19:00:20 -0600321 return command.CommandResult(return_code=0,
322 stdout='refs/heads/master\n')
323
324 # Not handled, so abort
Simon Glassc78ed662019-10-31 07:42:53 -0600325 print('git config', args)
Simon Glass8e959562014-09-05 19:00:20 -0600326 sys.exit(1)
327
Simon Glassed098bb2014-09-05 19:00:13 -0600328 def _HandleCommandGit(self, in_args):
329 """Handle execution of a git command
330
331 This uses a hacked-up parser.
332
333 Args:
334 in_args: Arguments after 'git' from the command line
335 """
336 git_args = [] # Top-level arguments to git itself
337 sub_cmd = None # Git sub-command selected
338 args = [] # Arguments to the git sub-command
339 for arg in in_args:
340 if sub_cmd:
341 args.append(arg)
342 elif arg[0] == '-':
343 git_args.append(arg)
344 else:
Simon Glass8e959562014-09-05 19:00:20 -0600345 if git_args and git_args[-1] in ['--git-dir', '--work-tree']:
346 git_args.append(arg)
347 else:
348 sub_cmd = arg
Simon Glassed098bb2014-09-05 19:00:13 -0600349 if sub_cmd == 'config':
Simon Glass8e959562014-09-05 19:00:20 -0600350 return self._HandleCommandGitConfig(args)
Simon Glassed098bb2014-09-05 19:00:13 -0600351 elif sub_cmd == 'log':
352 return self._HandleCommandGitLog(args)
Simon Glass8e959562014-09-05 19:00:20 -0600353 elif sub_cmd == 'clone':
354 return command.CommandResult(return_code=0)
355 elif sub_cmd == 'checkout':
356 return command.CommandResult(return_code=0)
Alper Nebi Yasakfede44a2020-09-03 15:51:03 +0300357 elif sub_cmd == 'worktree':
358 return command.CommandResult(return_code=0)
Simon Glassed098bb2014-09-05 19:00:13 -0600359
360 # Not handled, so abort
Simon Glassc78ed662019-10-31 07:42:53 -0600361 print('git', git_args, sub_cmd, args)
Simon Glassed098bb2014-09-05 19:00:13 -0600362 sys.exit(1)
363
364 def _HandleCommandNm(self, args):
365 return command.CommandResult(return_code=0)
366
367 def _HandleCommandObjdump(self, args):
368 return command.CommandResult(return_code=0)
369
Alex Kiernanf07ed232018-05-31 04:48:33 +0000370 def _HandleCommandObjcopy(self, args):
371 return command.CommandResult(return_code=0)
372
Simon Glassed098bb2014-09-05 19:00:13 -0600373 def _HandleCommandSize(self, args):
374 return command.CommandResult(return_code=0)
375
376 def _HandleCommand(self, **kwargs):
377 """Handle a command execution.
378
379 The command is in kwargs['pipe-list'], as a list of pipes, each a
380 list of commands. The command should be emulated as required for
381 testing purposes.
382
383 Returns:
384 A CommandResult object
385 """
386 pipe_list = kwargs['pipe_list']
Simon Glass8e959562014-09-05 19:00:20 -0600387 wc = False
Simon Glassed098bb2014-09-05 19:00:13 -0600388 if len(pipe_list) != 1:
Simon Glass8e959562014-09-05 19:00:20 -0600389 if pipe_list[1] == ['wc', '-l']:
390 wc = True
391 else:
Simon Glassc78ed662019-10-31 07:42:53 -0600392 print('invalid pipe', kwargs)
Simon Glass8e959562014-09-05 19:00:20 -0600393 sys.exit(1)
Simon Glassed098bb2014-09-05 19:00:13 -0600394 cmd = pipe_list[0][0]
395 args = pipe_list[0][1:]
Simon Glass8e959562014-09-05 19:00:20 -0600396 result = None
Simon Glassed098bb2014-09-05 19:00:13 -0600397 if cmd == 'git':
Simon Glass8e959562014-09-05 19:00:20 -0600398 result = self._HandleCommandGit(args)
Simon Glassed098bb2014-09-05 19:00:13 -0600399 elif cmd == './scripts/show-gnu-make':
400 return command.CommandResult(return_code=0, stdout='make')
Simon Glass8e959562014-09-05 19:00:20 -0600401 elif cmd.endswith('nm'):
Simon Glassed098bb2014-09-05 19:00:13 -0600402 return self._HandleCommandNm(args)
Simon Glass8e959562014-09-05 19:00:20 -0600403 elif cmd.endswith('objdump'):
Simon Glassed098bb2014-09-05 19:00:13 -0600404 return self._HandleCommandObjdump(args)
Alex Kiernanf07ed232018-05-31 04:48:33 +0000405 elif cmd.endswith('objcopy'):
406 return self._HandleCommandObjcopy(args)
Simon Glass8e959562014-09-05 19:00:20 -0600407 elif cmd.endswith( 'size'):
Simon Glassed098bb2014-09-05 19:00:13 -0600408 return self._HandleCommandSize(args)
409
Simon Glass8e959562014-09-05 19:00:20 -0600410 if not result:
411 # Not handled, so abort
Simon Glassc78ed662019-10-31 07:42:53 -0600412 print('unknown command', kwargs)
Simon Glass8e959562014-09-05 19:00:20 -0600413 sys.exit(1)
414
415 if wc:
416 result.stdout = len(result.stdout.splitlines())
417 return result
Simon Glassed098bb2014-09-05 19:00:13 -0600418
419 def _HandleMake(self, commit, brd, stage, cwd, *args, **kwargs):
420 """Handle execution of 'make'
421
422 Args:
423 commit: Commit object that is being built
424 brd: Board object that is being built
425 stage: Stage that we are at (mrproper, config, build)
426 cwd: Directory where make should be run
427 args: Arguments to pass to make
Simon Glass840be732022-01-29 14:14:05 -0700428 kwargs: Arguments to pass to command.run_pipe()
Simon Glassed098bb2014-09-05 19:00:13 -0600429 """
Simon Glass8e959562014-09-05 19:00:20 -0600430 self._make_calls += 1
Simon Glass828d70d2023-02-21 12:40:29 -0700431 out_dir = ''
432 for arg in args:
433 if arg.startswith('O='):
434 out_dir = arg[2:]
Simon Glassed098bb2014-09-05 19:00:13 -0600435 if stage == 'mrproper':
436 return command.CommandResult(return_code=0)
437 elif stage == 'config':
Simon Glass828d70d2023-02-21 12:40:29 -0700438 fname = os.path.join(cwd or '', out_dir, '.config')
439 tools.write_file(fname, b'CONFIG_SOMETHING=1')
Simon Glassed098bb2014-09-05 19:00:13 -0600440 return command.CommandResult(return_code=0,
441 combined='Test configuration complete')
442 elif stage == 'build':
Simon Glass8e959562014-09-05 19:00:20 -0600443 stderr = ''
Simon Glassb6eb8cf2020-03-18 09:42:42 -0600444 fname = os.path.join(cwd or '', out_dir, 'u-boot')
Simon Glass80025522022-01-29 14:14:04 -0700445 tools.write_file(fname, b'U-Boot')
Tom Rini93ebd462022-11-09 19:14:53 -0700446
447 # Handle missing blobs
448 if self._missing:
449 if 'BINMAN_ALLOW_MISSING=1' in args:
450 stderr = '''+Image 'main-section' is missing external blobs and is non-functional: intel-descriptor intel-ifwi intel-fsp-m intel-fsp-s intel-vbt
451Image 'main-section' has faked external blobs and is non-functional: descriptor.bin fsp_m.bin fsp_s.bin vbt.bin
452
453Some images are invalid'''
454 else:
455 stderr = "binman: Filename 'fsp.bin' not found in input path"
456 elif type(commit) is not str:
Simon Glass8e959562014-09-05 19:00:20 -0600457 stderr = self._error.get((brd.target, commit.sequence))
Tom Rini93ebd462022-11-09 19:14:53 -0700458
Simon Glass8e959562014-09-05 19:00:20 -0600459 if stderr:
Tom Rini93ebd462022-11-09 19:14:53 -0700460 return command.CommandResult(return_code=2, stderr=stderr)
Simon Glassed098bb2014-09-05 19:00:13 -0600461 return command.CommandResult(return_code=0)
462
463 # Not handled, so abort
Simon Glassc78ed662019-10-31 07:42:53 -0600464 print('make', stage)
Simon Glassed098bb2014-09-05 19:00:13 -0600465 sys.exit(1)
466
Simon Glass8e959562014-09-05 19:00:20 -0600467 # Example function to print output lines
468 def print_lines(self, lines):
Simon Glassc78ed662019-10-31 07:42:53 -0600469 print(len(lines))
Simon Glass8e959562014-09-05 19:00:20 -0600470 for line in lines:
Simon Glassc78ed662019-10-31 07:42:53 -0600471 print(line)
Simon Glass02811582022-01-29 14:14:18 -0700472 #self.print_lines(terminal.get_print_test_lines())
Simon Glass8e959562014-09-05 19:00:20 -0600473
Simon Glasscbd36582014-09-05 19:00:16 -0600474 def testNoBoards(self):
475 """Test that buildman aborts when there are no boards"""
Simon Glass20751d62022-07-11 19:04:03 -0600476 self._boards = boards.Boards()
Simon Glasscbd36582014-09-05 19:00:16 -0600477 with self.assertRaises(SystemExit):
478 self._RunControl()
479
Simon Glassed098bb2014-09-05 19:00:13 -0600480 def testCurrentSource(self):
481 """Very simple test to invoke buildman on the current source"""
Simon Glass8e959562014-09-05 19:00:20 -0600482 self.setupToolchains();
Tom Rinie95eddc2019-10-07 17:17:36 -0400483 self._RunControl('-o', self._output_dir)
Simon Glass02811582022-01-29 14:14:18 -0700484 lines = terminal.get_print_test_lines()
Simon Glassd4c6c8a2022-07-11 19:03:58 -0600485 self.assertIn('Building current source for %d boards' % len(BOARDS),
Simon Glass8e959562014-09-05 19:00:20 -0600486 lines[0].text)
487
488 def testBadBranch(self):
489 """Test that we can detect an invalid branch"""
490 with self.assertRaises(ValueError):
491 self._RunControl('-b', 'badbranch')
492
493 def testBadToolchain(self):
494 """Test that missing toolchains are detected"""
495 self.setupToolchains();
Tom Rinie95eddc2019-10-07 17:17:36 -0400496 ret_code = self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir)
Simon Glass02811582022-01-29 14:14:18 -0700497 lines = terminal.get_print_test_lines()
Simon Glass8e959562014-09-05 19:00:20 -0600498
499 # Buildman always builds the upstream commit as well
500 self.assertIn('Building %d commits for %d boards' %
Simon Glassd4c6c8a2022-07-11 19:03:58 -0600501 (self._commits, len(BOARDS)), lines[0].text)
Simon Glass8e959562014-09-05 19:00:20 -0600502 self.assertEqual(self._builder.count, self._total_builds)
503
504 # Only sandbox should succeed, the others don't have toolchains
505 self.assertEqual(self._builder.fail,
506 self._total_builds - self._commits)
Simon Glasse4cd5062020-04-09 10:49:45 -0600507 self.assertEqual(ret_code, 100)
Simon Glass8e959562014-09-05 19:00:20 -0600508
509 for commit in range(self._commits):
Simon Glass127a2392022-07-11 19:04:02 -0600510 for brd in self._boards.get_list():
Simon Glass8132f982022-07-11 19:03:57 -0600511 if brd.arch != 'sandbox':
512 errfile = self._builder.GetErrFile(commit, brd.target)
Simon Glass8e959562014-09-05 19:00:20 -0600513 fd = open(errfile)
514 self.assertEqual(fd.readlines(),
Simon Glass8132f982022-07-11 19:03:57 -0600515 ['No tool chain for %s\n' % brd.arch])
Simon Glass8e959562014-09-05 19:00:20 -0600516 fd.close()
517
518 def testBranch(self):
519 """Test building a branch with all toolchains present"""
Tom Rinie95eddc2019-10-07 17:17:36 -0400520 self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir)
Simon Glass8e959562014-09-05 19:00:20 -0600521 self.assertEqual(self._builder.count, self._total_builds)
522 self.assertEqual(self._builder.fail, 0)
523
524 def testCount(self):
525 """Test building a specific number of commitst"""
Tom Rinie95eddc2019-10-07 17:17:36 -0400526 self._RunControl('-b', TEST_BRANCH, '-c2', '-o', self._output_dir)
Simon Glassd4c6c8a2022-07-11 19:03:58 -0600527 self.assertEqual(self._builder.count, 2 * len(BOARDS))
Simon Glass8e959562014-09-05 19:00:20 -0600528 self.assertEqual(self._builder.fail, 0)
Simon Glass6029af12020-04-09 15:08:51 -0600529 # Each board has a config, and then one make per commit
Simon Glassd4c6c8a2022-07-11 19:03:58 -0600530 self.assertEqual(self._make_calls, len(BOARDS) * (1 + 2))
Simon Glass8e959562014-09-05 19:00:20 -0600531
532 def testIncremental(self):
533 """Test building a branch twice - the second time should do nothing"""
Tom Rinie95eddc2019-10-07 17:17:36 -0400534 self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir)
Simon Glass8e959562014-09-05 19:00:20 -0600535
536 # Each board has a mrproper, config, and then one make per commit
Simon Glassd4c6c8a2022-07-11 19:03:58 -0600537 self.assertEqual(self._make_calls, len(BOARDS) * (self._commits + 1))
Simon Glass8e959562014-09-05 19:00:20 -0600538 self._make_calls = 0
Tom Rinie95eddc2019-10-07 17:17:36 -0400539 self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir, clean_dir=False)
Simon Glass8e959562014-09-05 19:00:20 -0600540 self.assertEqual(self._make_calls, 0)
541 self.assertEqual(self._builder.count, self._total_builds)
542 self.assertEqual(self._builder.fail, 0)
543
544 def testForceBuild(self):
545 """The -f flag should force a rebuild"""
Tom Rinie95eddc2019-10-07 17:17:36 -0400546 self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir)
Simon Glass8e959562014-09-05 19:00:20 -0600547 self._make_calls = 0
Tom Rinie95eddc2019-10-07 17:17:36 -0400548 self._RunControl('-b', TEST_BRANCH, '-f', '-o', self._output_dir, clean_dir=False)
Simon Glass6029af12020-04-09 15:08:51 -0600549 # Each board has a config and one make per commit
Simon Glassd4c6c8a2022-07-11 19:03:58 -0600550 self.assertEqual(self._make_calls, len(BOARDS) * (self._commits + 1))
Simon Glass8e959562014-09-05 19:00:20 -0600551
552 def testForceReconfigure(self):
553 """The -f flag should force a rebuild"""
Tom Rinie95eddc2019-10-07 17:17:36 -0400554 self._RunControl('-b', TEST_BRANCH, '-C', '-o', self._output_dir)
Simon Glass6029af12020-04-09 15:08:51 -0600555 # Each commit has a config and make
Simon Glassd4c6c8a2022-07-11 19:03:58 -0600556 self.assertEqual(self._make_calls, len(BOARDS) * self._commits * 2)
Simon Glass6029af12020-04-09 15:08:51 -0600557
Simon Glass6029af12020-04-09 15:08:51 -0600558 def testMrproper(self):
559 """The -f flag should force a rebuild"""
560 self._RunControl('-b', TEST_BRANCH, '-m', '-o', self._output_dir)
561 # Each board has a mkproper, config and then one make per commit
Simon Glassd4c6c8a2022-07-11 19:03:58 -0600562 self.assertEqual(self._make_calls, len(BOARDS) * (self._commits + 2))
Simon Glass8e959562014-09-05 19:00:20 -0600563
564 def testErrors(self):
565 """Test handling of build errors"""
566 self._error['board2', 1] = 'fred\n'
Tom Rinie95eddc2019-10-07 17:17:36 -0400567 self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir)
Simon Glass8e959562014-09-05 19:00:20 -0600568 self.assertEqual(self._builder.count, self._total_builds)
569 self.assertEqual(self._builder.fail, 1)
570
571 # Remove the error. This should have no effect since the commit will
572 # not be rebuilt
573 del self._error['board2', 1]
574 self._make_calls = 0
Tom Rinie95eddc2019-10-07 17:17:36 -0400575 self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir, clean_dir=False)
Simon Glass8e959562014-09-05 19:00:20 -0600576 self.assertEqual(self._builder.count, self._total_builds)
577 self.assertEqual(self._make_calls, 0)
578 self.assertEqual(self._builder.fail, 1)
579
580 # Now use the -F flag to force rebuild of the bad commit
Tom Rinie95eddc2019-10-07 17:17:36 -0400581 self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir, '-F', clean_dir=False)
Simon Glass8e959562014-09-05 19:00:20 -0600582 self.assertEqual(self._builder.count, self._total_builds)
583 self.assertEqual(self._builder.fail, 0)
Simon Glass6029af12020-04-09 15:08:51 -0600584 self.assertEqual(self._make_calls, 2)
Simon Glass4aeceb92014-09-05 19:00:22 -0600585
586 def testBranchWithSlash(self):
587 """Test building a branch with a '/' in the name"""
588 self._test_branch = '/__dev/__testbranch'
589 self._RunControl('-b', self._test_branch, clean_dir=False)
590 self.assertEqual(self._builder.count, self._total_builds)
591 self.assertEqual(self._builder.fail, 0)
Lothar Waßmannce6df922018-04-08 05:14:11 -0600592
Simon Glassff48a212020-04-17 17:51:33 -0600593 def testEnvironment(self):
594 """Test that the done and environment files are written to out-env"""
595 self._RunControl('-o', self._output_dir)
596 board0_dir = os.path.join(self._output_dir, 'current', 'board0')
597 self.assertTrue(os.path.exists(os.path.join(board0_dir, 'done')))
598 self.assertTrue(os.path.exists(os.path.join(board0_dir, 'out-env')))
599
Simon Glass93008e22021-04-11 16:27:28 +1200600 def testEnvironmentUnicode(self):
601 """Test there are no unicode errors when the env has non-ASCII chars"""
602 try:
603 varname = b'buildman_test_var'
604 os.environb[varname] = b'strange\x80chars'
605 self.assertEqual(0, self._RunControl('-o', self._output_dir))
606 board0_dir = os.path.join(self._output_dir, 'current', 'board0')
607 self.assertTrue(os.path.exists(os.path.join(board0_dir, 'done')))
608 self.assertTrue(os.path.exists(os.path.join(board0_dir, 'out-env')))
609 finally:
610 del os.environb[varname]
611
Simon Glassb6eb8cf2020-03-18 09:42:42 -0600612 def testWorkInOutput(self):
613 """Test the -w option which should write directly to the output dir"""
Simon Glass20751d62022-07-11 19:04:03 -0600614 board_list = boards.Boards()
Simon Glass127a2392022-07-11 19:04:02 -0600615 board_list.add_board(board.Board(*BOARDS[0]))
Simon Glassb6eb8cf2020-03-18 09:42:42 -0600616 self._RunControl('-o', self._output_dir, '-w', clean_dir=False,
Simon Glassd4c6c8a2022-07-11 19:03:58 -0600617 brds=board_list)
Simon Glassb6eb8cf2020-03-18 09:42:42 -0600618 self.assertTrue(
619 os.path.exists(os.path.join(self._output_dir, 'u-boot')))
Simon Glasse3c85ab2020-04-17 17:51:34 -0600620 self.assertTrue(
621 os.path.exists(os.path.join(self._output_dir, 'done')))
622 self.assertTrue(
623 os.path.exists(os.path.join(self._output_dir, 'out-env')))
Simon Glassb6eb8cf2020-03-18 09:42:42 -0600624
625 def testWorkInOutputFail(self):
626 """Test the -w option failures"""
627 with self.assertRaises(SystemExit) as e:
628 self._RunControl('-o', self._output_dir, '-w', clean_dir=False)
629 self.assertIn("single board", str(e.exception))
630 self.assertFalse(
631 os.path.exists(os.path.join(self._output_dir, 'u-boot')))
632
Simon Glass20751d62022-07-11 19:04:03 -0600633 board_list = boards.Boards()
Simon Glass127a2392022-07-11 19:04:02 -0600634 board_list.add_board(board.Board(*BOARDS[0]))
Simon Glassb6eb8cf2020-03-18 09:42:42 -0600635 with self.assertRaises(SystemExit) as e:
636 self._RunControl('-b', self._test_branch, '-o', self._output_dir,
Simon Glassd4c6c8a2022-07-11 19:03:58 -0600637 '-w', clean_dir=False, brds=board_list)
Simon Glassb6eb8cf2020-03-18 09:42:42 -0600638 self.assertIn("single commit", str(e.exception))
Simon Glassd9c98632020-04-17 17:51:32 -0600639
Simon Glass20751d62022-07-11 19:04:03 -0600640 board_list = boards.Boards()
Simon Glass127a2392022-07-11 19:04:02 -0600641 board_list.add_board(board.Board(*BOARDS[0]))
Simon Glassd9c98632020-04-17 17:51:32 -0600642 with self.assertRaises(SystemExit) as e:
643 self._RunControl('-w', clean_dir=False)
644 self.assertIn("specify -o", str(e.exception))
Simon Glass9bf9a722021-04-11 16:27:27 +1200645
646 def testThreadExceptions(self):
647 """Test that exceptions in threads are reported"""
648 with test_util.capture_sys_output() as (stdout, stderr):
649 self.assertEqual(102, self._RunControl('-o', self._output_dir,
650 test_thread_exceptions=True))
Simon Glass9bac1672022-01-22 05:07:32 -0700651 self.assertIn(
652 'Thread exception (use -T0 to run without threads): test exception',
653 stdout.getvalue())
Tom Rini93ebd462022-11-09 19:14:53 -0700654
655 def testBlobs(self):
656 """Test handling of missing blobs"""
657 self._missing = True
658
659 board0_dir = os.path.join(self._output_dir, 'current', 'board0')
660 errfile = os.path.join(board0_dir, 'err')
661 logfile = os.path.join(board0_dir, 'log')
662
663 # We expect failure when there are missing blobs
664 result = self._RunControl('board0', '-o', self._output_dir)
665 self.assertEqual(100, result)
666 self.assertTrue(os.path.exists(os.path.join(board0_dir, 'done')))
667 self.assertTrue(os.path.exists(errfile))
668 self.assertIn(b"Filename 'fsp.bin' not found in input path",
669 tools.read_file(errfile))
670
671 def testBlobsAllowMissing(self):
672 """Allow missing blobs - still failure but a different exit code"""
673 self._missing = True
674 result = self._RunControl('board0', '-o', self._output_dir, '-M',
675 clean_dir=True)
676 self.assertEqual(101, result)
677 board0_dir = os.path.join(self._output_dir, 'current', 'board0')
678 errfile = os.path.join(board0_dir, 'err')
679 self.assertTrue(os.path.exists(errfile))
680 self.assertIn(b'Some images are invalid', tools.read_file(errfile))
681
682 def testBlobsWarning(self):
683 """Allow missing blobs and ignore warnings"""
684 self._missing = True
685 result = self._RunControl('board0', '-o', self._output_dir, '-MW')
686 self.assertEqual(0, result)
687 board0_dir = os.path.join(self._output_dir, 'current', 'board0')
688 errfile = os.path.join(board0_dir, 'err')
689 self.assertIn(b'Some images are invalid', tools.read_file(errfile))
690
691 def testBlobSettings(self):
692 """Test with no settings"""
693 self.assertEqual(False,
694 control.get_allow_missing(False, False, 1, False))
695 self.assertEqual(True,
696 control.get_allow_missing(True, False, 1, False))
697 self.assertEqual(False,
698 control.get_allow_missing(True, True, 1, False))
699
700 def testBlobSettingsAlways(self):
701 """Test the 'always' policy"""
702 bsettings.SetItem('global', 'allow-missing', 'always')
703 self.assertEqual(True,
704 control.get_allow_missing(False, False, 1, False))
705 self.assertEqual(False,
706 control.get_allow_missing(False, True, 1, False))
707
708 def testBlobSettingsBranch(self):
709 """Test the 'branch' policy"""
710 bsettings.SetItem('global', 'allow-missing', 'branch')
711 self.assertEqual(False,
712 control.get_allow_missing(False, False, 1, False))
713 self.assertEqual(True,
714 control.get_allow_missing(False, False, 1, True))
715 self.assertEqual(False,
716 control.get_allow_missing(False, True, 1, True))
717
718 def testBlobSettingsMultiple(self):
719 """Test the 'multiple' policy"""
720 bsettings.SetItem('global', 'allow-missing', 'multiple')
721 self.assertEqual(False,
722 control.get_allow_missing(False, False, 1, False))
723 self.assertEqual(True,
724 control.get_allow_missing(False, False, 2, False))
725 self.assertEqual(False,
726 control.get_allow_missing(False, True, 2, False))
727
728 def testBlobSettingsBranchMultiple(self):
729 """Test the 'branch multiple' policy"""
730 bsettings.SetItem('global', 'allow-missing', 'branch multiple')
731 self.assertEqual(False,
732 control.get_allow_missing(False, False, 1, False))
733 self.assertEqual(True,
734 control.get_allow_missing(False, False, 1, True))
735 self.assertEqual(True,
736 control.get_allow_missing(False, False, 2, False))
737 self.assertEqual(True,
738 control.get_allow_missing(False, False, 2, True))
739 self.assertEqual(False,
740 control.get_allow_missing(False, True, 2, True))
Simon Glass1382b1d2023-02-21 12:40:27 -0700741
Simon Glassf6bfcca2023-02-21 12:40:28 -0700742 def check_command(self, *extra_args):
743 """Run a command with the extra arguments and return the commands used
744
745 Args:
746 extra_args (list of str): List of extra arguments
747
748 Returns:
749 list of str: Lines returned in the out-cmd file
750 """
751 self._RunControl('-o', self._output_dir, *extra_args)
Simon Glass1382b1d2023-02-21 12:40:27 -0700752 board0_dir = os.path.join(self._output_dir, 'current', 'board0')
753 self.assertTrue(os.path.exists(os.path.join(board0_dir, 'done')))
754 cmd_fname = os.path.join(board0_dir, 'out-cmd')
755 self.assertTrue(os.path.exists(cmd_fname))
756 data = tools.read_file(cmd_fname)
Simon Glass828d70d2023-02-21 12:40:29 -0700757
758 config_fname = os.path.join(board0_dir, '.config')
759 self.assertTrue(os.path.exists(config_fname))
760 cfg_data = tools.read_file(config_fname)
761
762 return data.splitlines(), cfg_data
Simon Glassf6bfcca2023-02-21 12:40:28 -0700763
764 def testCmdFile(self):
765 """Test that the -cmd-out file is produced"""
Simon Glass828d70d2023-02-21 12:40:29 -0700766 lines = self.check_command()[0]
Simon Glass1382b1d2023-02-21 12:40:27 -0700767 self.assertEqual(2, len(lines))
768 self.assertRegex(lines[0], b'make O=/.*board0_defconfig')
769 self.assertRegex(lines[0], b'make O=/.*-s.*')
Simon Glassf6bfcca2023-02-21 12:40:28 -0700770
771 def testNoLto(self):
772 """Test that the --no-lto flag works"""
Simon Glass828d70d2023-02-21 12:40:29 -0700773 lines = self.check_command('-L')[0]
Simon Glassf6bfcca2023-02-21 12:40:28 -0700774 self.assertIn(b'NO_LTO=1', lines[0])
775
Simon Glass828d70d2023-02-21 12:40:29 -0700776 def testReproducible(self):
777 """Test that the -r flag works"""
778 lines, cfg_data = self.check_command('-r')
779 self.assertIn(b'SOURCE_DATE_EPOCH=0', lines[0])
780
781 # We should see CONFIG_LOCALVERSION_AUTO unset
782 self.assertEqual(b'''CONFIG_SOMETHING=1
783# CONFIG_LOCALVERSION_AUTO is not set
784''', cfg_data)
785
786 with test_util.capture_sys_output() as (stdout, stderr):
787 lines, cfg_data = self.check_command('-r', '-a', 'LOCALVERSION')
788 self.assertIn(b'SOURCE_DATE_EPOCH=0', lines[0])
789
790 # We should see CONFIG_LOCALVERSION_AUTO unset
791 self.assertEqual(b'''CONFIG_SOMETHING=1
792CONFIG_LOCALVERSION=y
793''', cfg_data)
794 self.assertIn('Not dropping LOCALVERSION_AUTO', stdout.getvalue())
Simon Glasscef26b82023-07-19 17:48:15 -0600795
796 def test_scan_defconfigs(self):
797 """Test scanning the defconfigs to obtain all the boards"""
798 src = self._git_dir
799
800 # Scan the test directory which contains a Kconfig and some *_defconfig
801 # files
Simon Glass07a95d82023-07-19 17:48:21 -0600802 params, warnings = self._boards.scan_defconfigs(src, src)
Simon Glasscef26b82023-07-19 17:48:15 -0600803
804 # We should get two boards
805 self.assertEquals(2, len(params))
Simon Glass07a95d82023-07-19 17:48:21 -0600806 self.assertFalse(warnings)
Simon Glasscef26b82023-07-19 17:48:15 -0600807 first = 0 if params[0]['target'] == 'board0' else 1
808 board0 = params[first]
809 board2 = params[1 - first]
810
811 self.assertEquals('arm', board0['arch'])
812 self.assertEquals('armv7', board0['cpu'])
813 self.assertEquals('-', board0['soc'])
814 self.assertEquals('Tester', board0['vendor'])
815 self.assertEquals('ARM Board 0', board0['board'])
816 self.assertEquals('config0', board0['config'])
817 self.assertEquals('board0', board0['target'])
818
819 self.assertEquals('powerpc', board2['arch'])
820 self.assertEquals('ppc', board2['cpu'])
821 self.assertEquals('mpc85xx', board2['soc'])
822 self.assertEquals('Tester', board2['vendor'])
823 self.assertEquals('PowerPC board 1', board2['board'])
824 self.assertEquals('config2', board2['config'])
825 self.assertEquals('board2', board2['target'])
826
Simon Glassada78d42023-07-19 17:48:16 -0600827 def test_output_is_new(self):
828 """Test detecting new changes to Kconfig"""
829 base = self._base_dir
830 src = self._git_dir
831 config_dir = os.path.join(src, 'configs')
832 delay = 0.02
833
834 # Create a boards.cfg file
835 boards_cfg = os.path.join(base, 'boards.cfg')
836 content = b'''#
837# List of boards
838# Automatically generated by buildman/boards.py: don't edit
839#
840# Status, Arch, CPU, SoC, Vendor, Board, Target, Config, Maintainers
841
842Active aarch64 armv8 - armltd corstone1000 board0
843Active aarch64 armv8 - armltd total_compute board2
844'''
845 # Check missing file
846 self.assertFalse(boards.output_is_new(boards_cfg, config_dir, src))
847
848 # Check that the board.cfg file is newer
849 time.sleep(delay)
850 tools.write_file(boards_cfg, content)
851 self.assertTrue(boards.output_is_new(boards_cfg, config_dir, src))
852
853 # Touch the Kconfig files after a show delay to avoid a race
854 time.sleep(delay)
855 Path(os.path.join(src, 'Kconfig')).touch()
856 self.assertFalse(boards.output_is_new(boards_cfg, config_dir, src))
857 Path(boards_cfg).touch()
858 self.assertTrue(boards.output_is_new(boards_cfg, config_dir, src))
859
860 # Touch a different Kconfig file
861 time.sleep(delay)
862 Path(os.path.join(src, 'Kconfig.something')).touch()
863 self.assertFalse(boards.output_is_new(boards_cfg, config_dir, src))
864 Path(boards_cfg).touch()
865 self.assertTrue(boards.output_is_new(boards_cfg, config_dir, src))
866
867 # Touch a MAINTAINERS file
868 time.sleep(delay)
869 Path(os.path.join(src, 'MAINTAINERS')).touch()
870 self.assertFalse(boards.output_is_new(boards_cfg, config_dir, src))
871
872 Path(boards_cfg).touch()
873 self.assertTrue(boards.output_is_new(boards_cfg, config_dir, src))
874
875 # Touch a defconfig file
876 time.sleep(delay)
877 Path(os.path.join(config_dir, 'board0_defconfig')).touch()
878 self.assertFalse(boards.output_is_new(boards_cfg, config_dir, src))
879 Path(boards_cfg).touch()
880 self.assertTrue(boards.output_is_new(boards_cfg, config_dir, src))
881
882 # Remove a board and check that the board.cfg file is now older
883 Path(os.path.join(config_dir, 'board0_defconfig')).unlink()
884 self.assertFalse(boards.output_is_new(boards_cfg, config_dir, src))
885
Simon Glassc0b6fcc2023-07-19 17:48:17 -0600886 def test_maintainers(self):
887 """Test detecting boards without a MAINTAINERS entry"""
888 src = self._git_dir
889 main = os.path.join(src, 'boards', 'board0', 'MAINTAINERS')
890 other = os.path.join(src, 'boards', 'board2', 'MAINTAINERS')
Simon Glass07a95d82023-07-19 17:48:21 -0600891 kc_file = os.path.join(src, 'Kconfig')
Simon Glassc0b6fcc2023-07-19 17:48:17 -0600892 config_dir = os.path.join(src, 'configs')
893 params_list, warnings = self._boards.build_board_list(config_dir, src)
894
895 # There should be two boards no warnings
896 self.assertEquals(2, len(params_list))
897 self.assertFalse(warnings)
898
899 # Set an invalid status line in the file
900 orig_data = tools.read_file(main, binary=False)
901 lines = ['S: Other\n' if line.startswith('S:') else line
902 for line in orig_data.splitlines(keepends=True)]
903 tools.write_file(main, ''.join(lines), binary=False)
904 params_list, warnings = self._boards.build_board_list(config_dir, src)
905 self.assertEquals(2, len(params_list))
906 params = params_list[0]
907 if params['target'] == 'board2':
908 params = params_list[1]
909 self.assertEquals('-', params['status'])
910 self.assertEquals(["WARNING: Other: unknown status for 'board0'"],
911 warnings)
912
913 # Remove the status line (S:) from a file
914 lines = [line for line in orig_data.splitlines(keepends=True)
915 if not line.startswith('S:')]
916 tools.write_file(main, ''.join(lines), binary=False)
917 params_list, warnings = self._boards.build_board_list(config_dir, src)
918 self.assertEquals(2, len(params_list))
919 self.assertEquals(["WARNING: -: unknown status for 'board0'"], warnings)
920
921 # Remove the configs/ line (F:) from a file - this is the last line
922 data = ''.join(orig_data.splitlines(keepends=True)[:-1])
923 tools.write_file(main, data, binary=False)
924 params_list, warnings = self._boards.build_board_list(config_dir, src)
925 self.assertEquals(2, len(params_list))
926 self.assertEquals(
Simon Glass263b5982023-07-19 17:48:25 -0600927 ["WARNING: no maintainers for 'board0'",
928 'WARNING: orphaned defconfig in boards/board0/MAINTAINERS ending at line 4',
929 ], warnings)
Simon Glassc0b6fcc2023-07-19 17:48:17 -0600930
Simon Glasse6acab52023-07-19 17:48:26 -0600931 # Mark a board as orphaned - this should give a warning
932 lines = ['S: Orphaned' if line.startswith('S') else line
933 for line in orig_data.splitlines(keepends=True)]
934 tools.write_file(main, ''.join(lines), binary=False)
935 params_list, warnings = self._boards.build_board_list(config_dir, src)
936 self.assertEquals(2, len(params_list))
937 self.assertEquals(["WARNING: no maintainers for 'board0'"], warnings)
938
939 # Change the maintainer to '-' - this should give a warning
940 lines = ['M: -' if line.startswith('M') else line
941 for line in orig_data.splitlines(keepends=True)]
942 tools.write_file(main, ''.join(lines), binary=False)
943 params_list, warnings = self._boards.build_board_list(config_dir, src)
944 self.assertEquals(2, len(params_list))
945 self.assertEquals(["WARNING: -: unknown status for 'board0'"], warnings)
946
947 # Remove the maintainer line (M:) from a file
Simon Glassc0b6fcc2023-07-19 17:48:17 -0600948 lines = [line for line in orig_data.splitlines(keepends=True)
949 if not line.startswith('M:')]
950 tools.write_file(main, ''.join(lines), binary=False)
951 params_list, warnings = self._boards.build_board_list(config_dir, src)
952 self.assertEquals(2, len(params_list))
Simon Glasse6acab52023-07-19 17:48:26 -0600953 self.assertEquals(["WARNING: no maintainers for 'board0'"], warnings)
Simon Glassc0b6fcc2023-07-19 17:48:17 -0600954
955 # Move the contents of the second file into this one, removing the
956 # second file, to check multiple records in a single file.
Simon Glass060ee972023-07-19 17:48:23 -0600957 both_data = orig_data + tools.read_file(other, binary=False)
958 tools.write_file(main, both_data, binary=False)
Simon Glassc0b6fcc2023-07-19 17:48:17 -0600959 os.remove(other)
960 params_list, warnings = self._boards.build_board_list(config_dir, src)
961 self.assertEquals(2, len(params_list))
962 self.assertFalse(warnings)
963
Simon Glass9b828ec2023-07-19 17:48:19 -0600964 # Add another record, this should be ignored with a warning
Simon Glassc0b6fcc2023-07-19 17:48:17 -0600965 extra = '\n\nAnother\nM: Fred\nF: configs/board9_defconfig\nS: other\n'
Simon Glass060ee972023-07-19 17:48:23 -0600966 tools.write_file(main, both_data + extra, binary=False)
Simon Glassc0b6fcc2023-07-19 17:48:17 -0600967 params_list, warnings = self._boards.build_board_list(config_dir, src)
968 self.assertEquals(2, len(params_list))
Simon Glass9b828ec2023-07-19 17:48:19 -0600969 self.assertEquals(
970 ['WARNING: orphaned defconfig in boards/board0/MAINTAINERS ending at line 16'],
971 warnings)
Simon Glass07a95d82023-07-19 17:48:21 -0600972
973 # Add another TARGET to the Kconfig
Simon Glass060ee972023-07-19 17:48:23 -0600974 tools.write_file(main, both_data, binary=False)
Simon Glass061499b2023-07-19 17:48:22 -0600975 orig_kc_data = tools.read_file(kc_file)
Simon Glass07a95d82023-07-19 17:48:21 -0600976 extra = (b'''
977if TARGET_BOARD2
978config TARGET_OTHER
979\tbool "other"
980\tdefault y
981endif
982''')
Simon Glass061499b2023-07-19 17:48:22 -0600983 tools.write_file(kc_file, orig_kc_data + extra)
Simon Glass5e728d42023-07-19 17:48:27 -0600984 params_list, warnings = self._boards.build_board_list(config_dir, src,
985 warn_targets=True)
Simon Glass07a95d82023-07-19 17:48:21 -0600986 self.assertEquals(2, len(params_list))
987 self.assertEquals(
988 ['WARNING: board2_defconfig: Duplicate TARGET_xxx: board2 and other'],
989 warnings)
Simon Glass061499b2023-07-19 17:48:22 -0600990
991 # Remove the TARGET_BOARD0 Kconfig option
992 lines = [b'' if line == b'config TARGET_BOARD2\n' else line
993 for line in orig_kc_data.splitlines(keepends=True)]
994 tools.write_file(kc_file, b''.join(lines))
Simon Glass5e728d42023-07-19 17:48:27 -0600995 params_list, warnings = self._boards.build_board_list(config_dir, src,
996 warn_targets=True)
Simon Glass061499b2023-07-19 17:48:22 -0600997 self.assertEquals(2, len(params_list))
998 self.assertEquals(
999 ['WARNING: board2_defconfig: No TARGET_BOARD2 enabled'],
1000 warnings)
Simon Glass060ee972023-07-19 17:48:23 -06001001 tools.write_file(kc_file, orig_kc_data)
1002
1003 # Replace the last F: line of board 2 with an N: line
1004 data = ''.join(both_data.splitlines(keepends=True)[:-1])
1005 tools.write_file(main, data + 'N: oa.*2\n', binary=False)
1006 params_list, warnings = self._boards.build_board_list(config_dir, src)
1007 self.assertEquals(2, len(params_list))
1008 self.assertFalse(warnings)
1009
Simon Glass09afcb72023-07-19 17:48:28 -06001010 def testRegenBoards(self):
1011 """Test that we can regenerate the boards.cfg file"""
1012 outfile = os.path.join(self._output_dir, 'test-boards.cfg')
1013 if os.path.exists(outfile):
1014 os.remove(outfile)
1015 with test_util.capture_sys_output() as (stdout, stderr):
1016 result = self._RunControl('-R', outfile, brds=None,
1017 get_builder=False)
1018 self.assertTrue(os.path.exists(outfile))
Simon Glass8f317b92023-07-19 17:48:35 -06001019
1020 def test_print_prefix(self):
1021 """Test that we can print the toolchain prefix"""
1022 with test_util.capture_sys_output() as (stdout, stderr):
1023 result = self._RunControl('-A', 'board0')
1024 self.assertEqual('arm-\n', stdout.getvalue())
1025 self.assertEqual('', stderr.getvalue())
Simon Glass20978742023-07-19 17:48:38 -06001026
1027 def test_exclude_one(self):
1028 """Test excluding a single board from an arch"""
1029 self._RunControl('arm', '-x', 'board1')
1030 self.assertEqual(['board0'],
1031 [b.target for b in self._boards.get_selected()])
1032
1033 def test_exclude_arch(self):
1034 """Test excluding an arch"""
1035 self._RunControl('-x', 'arm')
1036 self.assertEqual(['board2', 'board4'],
1037 [b.target for b in self._boards.get_selected()])
1038
1039 def test_exclude_comma(self):
1040 """Test excluding a comma-separated list of things"""
1041 self._RunControl('-x', 'arm,powerpc')
1042 self.assertEqual(['board4'],
1043 [b.target for b in self._boards.get_selected()])
1044
1045 def test_exclude_list(self):
1046 """Test excluding a list of things"""
1047 self._RunControl('-x', 'board2', '-x' 'board4')
1048 self.assertEqual(['board0', 'board1'],
1049 [b.target for b in self._boards.get_selected()])
Simon Glassf56cc292023-07-19 17:49:03 -06001050
1051 def test_single_boards(self):
1052 """Test building single boards"""
1053 self._RunControl('--boards', 'board1')
1054 self.assertEqual(1, self._builder.count)
1055
1056 self._RunControl('--boards', 'board1', '--boards', 'board2')
1057 self.assertEqual(2, self._builder.count)
1058
1059 self._RunControl('--boards', 'board1,board2', '--boards', 'board4')
1060 self.assertEqual(3, self._builder.count)