Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 2 | # Copyright (c) 2014 Google, Inc |
| 3 | # |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 4 | |
| 5 | import os |
Simon Glass | ada78d4 | 2023-07-19 17:48:16 -0600 | [diff] [blame] | 6 | from pathlib import Path |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 7 | import shutil |
| 8 | import sys |
| 9 | import tempfile |
Simon Glass | ada78d4 | 2023-07-19 17:48:16 -0600 | [diff] [blame] | 10 | import time |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 11 | import unittest |
| 12 | |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 13 | from buildman import board |
Simon Glass | 20751d6 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 14 | from buildman import boards |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 15 | from buildman import bsettings |
| 16 | from buildman import cmdline |
| 17 | from buildman import control |
| 18 | from buildman import toolchain |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 19 | from patman import gitutil |
Simon Glass | 131444f | 2023-02-23 18:18:04 -0700 | [diff] [blame] | 20 | from u_boot_pylib import command |
| 21 | from u_boot_pylib import terminal |
| 22 | from u_boot_pylib import test_util |
| 23 | from u_boot_pylib import tools |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 24 | |
Simon Glass | 5e0441d | 2014-09-05 19:00:15 -0600 | [diff] [blame] | 25 | settings_data = ''' |
| 26 | # Buildman settings file |
Tom Rini | 93ebd46 | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 27 | [global] |
Simon Glass | 5e0441d | 2014-09-05 19:00:15 -0600 | [diff] [blame] | 28 | |
| 29 | [toolchain] |
| 30 | |
| 31 | [toolchain-alias] |
| 32 | |
| 33 | [make-flags] |
| 34 | src=/home/sjg/c/src |
| 35 | chroot=/home/sjg/c/chroot |
Masahiro Yamada | 72e545a | 2018-08-06 20:47:38 +0900 | [diff] [blame] | 36 | vboot=VBOOT_DEBUG=1 MAKEFLAGS_VBOOT=DEBUG=1 CFLAGS_EXTRA_VBOOT=-DUNROLL_LOOPS VBOOT_SOURCE=${src}/platform/vboot_reference |
Simon Glass | 5e0441d | 2014-09-05 19:00:15 -0600 | [diff] [blame] | 37 | chromeos_coreboot=VBOOT=${chroot}/build/link/usr ${vboot} |
| 38 | chromeos_daisy=VBOOT=${chroot}/build/daisy/usr ${vboot} |
| 39 | chromeos_peach=VBOOT=${chroot}/build/peach_pit/usr ${vboot} |
| 40 | ''' |
| 41 | |
Simon Glass | d4c6c8a | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 42 | BOARDS = [ |
Simon Glass | 560bd4a | 2023-07-19 17:48:12 -0600 | [diff] [blame] | 43 | ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 0', 'board0', ''], |
| 44 | ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board1', ''], |
Simon Glass | cbd3658 | 2014-09-05 19:00:16 -0600 | [diff] [blame] | 45 | ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''], |
Simon Glass | cbd3658 | 2014-09-05 19:00:16 -0600 | [diff] [blame] | 46 | ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''], |
| 47 | ] |
| 48 | |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 49 | commit_shortlog = """4aca821 patman: Avoid changing the order of tags |
| 50 | 39403bb patman: Use --no-pager' to stop git from forking a pager |
| 51 | db6e6f2 patman: Remove the -a option |
| 52 | f2ccf03 patman: Correct unit tests to run correctly |
| 53 | 1d097f9 patman: Fix indentation in terminal.py |
| 54 | d073747 patman: Support the 'reverse' option for 'git log |
| 55 | """ |
| 56 | |
| 57 | commit_log = ["""commit 7f6b8315d18f683c5181d0c3694818c1b2a20dcd |
| 58 | Author: Masahiro Yamada <yamada.m@jp.panasonic.com> |
| 59 | Date: 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 |
| 74 | Author: Simon Glass <sjg@chromium.org> |
| 75 | Date: 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 Glass | 359b55a6 | 2014-09-05 19:00:23 -0600 | [diff] [blame] | 85 | Series-version: 8 |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 86 | |
| 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 |
| 93 | Author: Simon Glass <sjg@chromium.org> |
| 94 | Date: 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 |
| 109 | Author: Simon Glass <sjg@chromium.org> |
| 110 | Date: 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 |
| 127 | Author: Simon Glass <sjg@chromium.org> |
| 128 | Date: 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 |
| 144 | Author: Simon Glass <sjg@chromium.org> |
| 145 | Date: 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 |
| 151 | Author: Simon Glass <sjg@chromium.org> |
| 152 | Date: 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 Glass | 359b55a6 | 2014-09-05 19:00:23 -0600 | [diff] [blame] | 163 | Series-version: 9 |
| 164 | |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 165 | Suggested-by: Masahiro Yamada <yamada.m@jp.panasonic.com> |
| 166 | Change-Id: Ib1518588c1a189ad5c3198aae76f8654aed8d0db |
| 167 | """] |
| 168 | |
| 169 | TEST_BRANCH = '__testbranch' |
| 170 | |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 171 | class 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 Rini | e95eddc | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 184 | self._output_dir = tempfile.mkdtemp() |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 185 | self._git_dir = os.path.join(self._base_dir, 'src') |
| 186 | self._buildman_pathname = sys.argv[0] |
Simon Glass | 5d4a787 | 2016-07-27 20:33:00 -0600 | [diff] [blame] | 187 | self._buildman_dir = os.path.dirname(os.path.realpath(sys.argv[0])) |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 188 | command.test_result = self._HandleCommand |
Simon Glass | 06b83a5 | 2023-07-19 17:49:05 -0600 | [diff] [blame] | 189 | bsettings.setup(None) |
| 190 | bsettings.add_file(settings_data) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 191 | self.setupToolchains() |
| 192 | self._toolchains.Add('arm-gcc', test=False) |
| 193 | self._toolchains.Add('powerpc-gcc', test=False) |
Simon Glass | 20751d6 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 194 | self._boards = boards.Boards() |
Simon Glass | d4c6c8a | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 195 | for brd in BOARDS: |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 196 | self._boards.add_board(board.Board(*brd)) |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 197 | |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 198 | # Directories where the source been cloned |
| 199 | self._clone_dirs = [] |
| 200 | self._commits = len(commit_shortlog.splitlines()) + 1 |
Simon Glass | d4c6c8a | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 201 | self._total_builds = self._commits * len(BOARDS) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 202 | |
| 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 Glass | 4aeceb9 | 2014-09-05 19:00:22 -0600 | [diff] [blame] | 209 | self._test_branch = TEST_BRANCH |
| 210 | |
Tom Rini | 93ebd46 | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 211 | # Set to True to report missing blobs |
| 212 | self._missing = False |
| 213 | |
Simon Glass | cef26b8 | 2023-07-19 17:48:15 -0600 | [diff] [blame] | 214 | 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 Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 220 | # Avoid sending any output and clear all terminal output |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 221 | terminal.set_print_test_mode() |
| 222 | terminal.get_print_test_lines() |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 223 | |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 224 | def tearDown(self): |
| 225 | shutil.rmtree(self._base_dir) |
Simon Glass | 211c74b | 2022-11-09 19:14:52 -0700 | [diff] [blame] | 226 | shutil.rmtree(self._output_dir) |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 227 | |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 228 | def setupToolchains(self): |
| 229 | self._toolchains = toolchain.Toolchains() |
| 230 | self._toolchains.Add('gcc', test=False) |
| 231 | |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 232 | def _RunBuildman(self, *args): |
Simon Glass | 840be73 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 233 | return command.run_pipe([[self._buildman_pathname] + list(args)], |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 234 | capture=True, capture_stderr=True) |
| 235 | |
Simon Glass | 09afcb7 | 2023-07-19 17:48:28 -0600 | [diff] [blame] | 236 | def _RunControl(self, *args, brds=False, clean_dir=False, |
| 237 | test_thread_exceptions=False, get_builder=True): |
Simon Glass | a29b3ea | 2021-04-11 16:27:25 +1200 | [diff] [blame] | 238 | """Run buildman |
| 239 | |
| 240 | Args: |
| 241 | args: List of arguments to pass |
Simon Glass | 09afcb7 | 2023-07-19 17:48:28 -0600 | [diff] [blame] | 242 | brds: Boards object, or False to pass self._boards, or None to pass |
| 243 | None |
Simon Glass | a29b3ea | 2021-04-11 16:27:25 +1200 | [diff] [blame] | 244 | clean_dir: Used for tests only, indicates that the existing output_dir |
| 245 | should be removed before starting the build |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 246 | 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 Glass | 09afcb7 | 2023-07-19 17:48:28 -0600 | [diff] [blame] | 249 | get_builder (bool): Set self._builder to the resulting builder |
Simon Glass | a29b3ea | 2021-04-11 16:27:25 +1200 | [diff] [blame] | 250 | |
| 251 | Returns: |
| 252 | result code from buildman |
| 253 | """ |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 254 | sys.argv = [sys.argv[0]] + list(args) |
Simon Glass | a56ac99 | 2023-07-19 17:49:04 -0600 | [diff] [blame] | 255 | args = cmdline.parse_args() |
Simon Glass | 09afcb7 | 2023-07-19 17:48:28 -0600 | [diff] [blame] | 256 | if brds == False: |
| 257 | brds = self._boards |
Simon Glass | c1e1e1d | 2023-07-19 17:48:30 -0600 | [diff] [blame] | 258 | result = control.do_buildman( |
Simon Glass | a56ac99 | 2023-07-19 17:49:04 -0600 | [diff] [blame] | 259 | args, toolchains=self._toolchains, make_func=self._HandleMake, |
| 260 | brds=brds, clean_dir=clean_dir, |
Simon Glass | c1e1e1d | 2023-07-19 17:48:30 -0600 | [diff] [blame] | 261 | test_thread_exceptions=test_thread_exceptions) |
Simon Glass | 09afcb7 | 2023-07-19 17:48:28 -0600 | [diff] [blame] | 262 | if get_builder: |
Simon Glass | af0e29f | 2023-07-19 17:48:31 -0600 | [diff] [blame] | 263 | self._builder = control.TEST_BUILDER |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 264 | return result |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 265 | |
| 266 | def testFullHelp(self): |
| 267 | command.test_result = None |
| 268 | result = self._RunBuildman('-H') |
Simon Glass | 79cc9be | 2022-11-09 19:14:43 -0700 | [diff] [blame] | 269 | help_file = os.path.join(self._buildman_dir, 'README.rst') |
Tom Rini | c3c0b6d | 2018-01-16 15:29:50 -0500 | [diff] [blame] | 270 | # 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 Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 274 | 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 Glass | 79cc9be | 2022-11-09 19:14:43 -0700 | [diff] [blame] | 280 | help_file = os.path.join(self._buildman_dir, 'README.rst') |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 281 | 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 Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 288 | gitutil.setup() |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 289 | self.assertEqual(gitutil.use_no_decorate, False) |
| 290 | |
| 291 | command.test_result = command.CommandResult(return_code=0) |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 292 | gitutil.setup() |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 293 | self.assertEqual(gitutil.use_no_decorate, True) |
| 294 | |
| 295 | def _HandleCommandGitLog(self, args): |
Simon Glass | 642e9a6 | 2016-03-12 18:50:31 -0700 | [diff] [blame] | 296 | if args[-1] == '--': |
| 297 | args = args[:-1] |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 298 | if '-n0' in args: |
| 299 | return command.CommandResult(return_code=0) |
Simon Glass | 4aeceb9 | 2014-09-05 19:00:22 -0600 | [diff] [blame] | 300 | elif args[-1] == 'upstream/master..%s' % self._test_branch: |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 301 | return command.CommandResult(return_code=0, stdout=commit_shortlog) |
| 302 | elif args[:3] == ['--no-color', '--no-decorate', '--reverse']: |
Simon Glass | 4aeceb9 | 2014-09-05 19:00:22 -0600 | [diff] [blame] | 303 | if args[-1] == self._test_branch: |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 304 | count = int(args[3][2:]) |
| 305 | return command.CommandResult(return_code=0, |
| 306 | stdout=''.join(commit_log[:count])) |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 307 | |
| 308 | # Not handled, so abort |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 309 | print('git log', args) |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 310 | sys.exit(1) |
| 311 | |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 312 | 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 Glass | 4aeceb9 | 2014-09-05 19:00:22 -0600 | [diff] [blame] | 318 | elif config == 'branch.%s.remote' % self._test_branch: |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 319 | return command.CommandResult(return_code=0, stdout='upstream\n') |
Simon Glass | 4aeceb9 | 2014-09-05 19:00:22 -0600 | [diff] [blame] | 320 | elif config == 'branch.%s.merge' % self._test_branch: |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 321 | return command.CommandResult(return_code=0, |
| 322 | stdout='refs/heads/master\n') |
| 323 | |
| 324 | # Not handled, so abort |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 325 | print('git config', args) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 326 | sys.exit(1) |
| 327 | |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 328 | 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 Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 345 | if git_args and git_args[-1] in ['--git-dir', '--work-tree']: |
| 346 | git_args.append(arg) |
| 347 | else: |
| 348 | sub_cmd = arg |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 349 | if sub_cmd == 'config': |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 350 | return self._HandleCommandGitConfig(args) |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 351 | elif sub_cmd == 'log': |
| 352 | return self._HandleCommandGitLog(args) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 353 | 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 Yasak | fede44a | 2020-09-03 15:51:03 +0300 | [diff] [blame] | 357 | elif sub_cmd == 'worktree': |
| 358 | return command.CommandResult(return_code=0) |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 359 | |
| 360 | # Not handled, so abort |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 361 | print('git', git_args, sub_cmd, args) |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 362 | 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 Kiernan | f07ed23 | 2018-05-31 04:48:33 +0000 | [diff] [blame] | 370 | def _HandleCommandObjcopy(self, args): |
| 371 | return command.CommandResult(return_code=0) |
| 372 | |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 373 | 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 Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 387 | wc = False |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 388 | if len(pipe_list) != 1: |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 389 | if pipe_list[1] == ['wc', '-l']: |
| 390 | wc = True |
| 391 | else: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 392 | print('invalid pipe', kwargs) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 393 | sys.exit(1) |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 394 | cmd = pipe_list[0][0] |
| 395 | args = pipe_list[0][1:] |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 396 | result = None |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 397 | if cmd == 'git': |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 398 | result = self._HandleCommandGit(args) |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 399 | elif cmd == './scripts/show-gnu-make': |
| 400 | return command.CommandResult(return_code=0, stdout='make') |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 401 | elif cmd.endswith('nm'): |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 402 | return self._HandleCommandNm(args) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 403 | elif cmd.endswith('objdump'): |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 404 | return self._HandleCommandObjdump(args) |
Alex Kiernan | f07ed23 | 2018-05-31 04:48:33 +0000 | [diff] [blame] | 405 | elif cmd.endswith('objcopy'): |
| 406 | return self._HandleCommandObjcopy(args) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 407 | elif cmd.endswith( 'size'): |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 408 | return self._HandleCommandSize(args) |
| 409 | |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 410 | if not result: |
| 411 | # Not handled, so abort |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 412 | print('unknown command', kwargs) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 413 | sys.exit(1) |
| 414 | |
| 415 | if wc: |
| 416 | result.stdout = len(result.stdout.splitlines()) |
| 417 | return result |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 418 | |
| 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 Glass | 840be73 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 428 | kwargs: Arguments to pass to command.run_pipe() |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 429 | """ |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 430 | self._make_calls += 1 |
Simon Glass | 828d70d | 2023-02-21 12:40:29 -0700 | [diff] [blame] | 431 | out_dir = '' |
| 432 | for arg in args: |
| 433 | if arg.startswith('O='): |
| 434 | out_dir = arg[2:] |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 435 | if stage == 'mrproper': |
| 436 | return command.CommandResult(return_code=0) |
| 437 | elif stage == 'config': |
Simon Glass | 828d70d | 2023-02-21 12:40:29 -0700 | [diff] [blame] | 438 | fname = os.path.join(cwd or '', out_dir, '.config') |
| 439 | tools.write_file(fname, b'CONFIG_SOMETHING=1') |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 440 | return command.CommandResult(return_code=0, |
| 441 | combined='Test configuration complete') |
| 442 | elif stage == 'build': |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 443 | stderr = '' |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 444 | fname = os.path.join(cwd or '', out_dir, 'u-boot') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 445 | tools.write_file(fname, b'U-Boot') |
Tom Rini | 93ebd46 | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 446 | |
| 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 |
| 451 | Image 'main-section' has faked external blobs and is non-functional: descriptor.bin fsp_m.bin fsp_s.bin vbt.bin |
| 452 | |
| 453 | Some images are invalid''' |
| 454 | else: |
| 455 | stderr = "binman: Filename 'fsp.bin' not found in input path" |
| 456 | elif type(commit) is not str: |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 457 | stderr = self._error.get((brd.target, commit.sequence)) |
Tom Rini | 93ebd46 | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 458 | |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 459 | if stderr: |
Tom Rini | 93ebd46 | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 460 | return command.CommandResult(return_code=2, stderr=stderr) |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 461 | return command.CommandResult(return_code=0) |
| 462 | |
| 463 | # Not handled, so abort |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 464 | print('make', stage) |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 465 | sys.exit(1) |
| 466 | |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 467 | # Example function to print output lines |
| 468 | def print_lines(self, lines): |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 469 | print(len(lines)) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 470 | for line in lines: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 471 | print(line) |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 472 | #self.print_lines(terminal.get_print_test_lines()) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 473 | |
Simon Glass | cbd3658 | 2014-09-05 19:00:16 -0600 | [diff] [blame] | 474 | def testNoBoards(self): |
| 475 | """Test that buildman aborts when there are no boards""" |
Simon Glass | 20751d6 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 476 | self._boards = boards.Boards() |
Simon Glass | cbd3658 | 2014-09-05 19:00:16 -0600 | [diff] [blame] | 477 | with self.assertRaises(SystemExit): |
| 478 | self._RunControl() |
| 479 | |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 480 | def testCurrentSource(self): |
| 481 | """Very simple test to invoke buildman on the current source""" |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 482 | self.setupToolchains(); |
Tom Rini | e95eddc | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 483 | self._RunControl('-o', self._output_dir) |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 484 | lines = terminal.get_print_test_lines() |
Simon Glass | d4c6c8a | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 485 | self.assertIn('Building current source for %d boards' % len(BOARDS), |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 486 | 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 Rini | e95eddc | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 496 | ret_code = self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir) |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 497 | lines = terminal.get_print_test_lines() |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 498 | |
| 499 | # Buildman always builds the upstream commit as well |
| 500 | self.assertIn('Building %d commits for %d boards' % |
Simon Glass | d4c6c8a | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 501 | (self._commits, len(BOARDS)), lines[0].text) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 502 | 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 Glass | e4cd506 | 2020-04-09 10:49:45 -0600 | [diff] [blame] | 507 | self.assertEqual(ret_code, 100) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 508 | |
| 509 | for commit in range(self._commits): |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 510 | for brd in self._boards.get_list(): |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 511 | if brd.arch != 'sandbox': |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 512 | errfile = self._builder.get_err_file(commit, brd.target) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 513 | fd = open(errfile) |
Simon Glass | bf353b8 | 2023-07-19 17:49:25 -0600 | [diff] [blame] | 514 | self.assertEqual( |
| 515 | fd.readlines(), |
| 516 | [f'Tool chain error for {brd.arch}: ' |
| 517 | f"No tool chain found for arch '{brd.arch}'"]) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 518 | fd.close() |
| 519 | |
| 520 | def testBranch(self): |
| 521 | """Test building a branch with all toolchains present""" |
Tom Rini | e95eddc | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 522 | self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 523 | self.assertEqual(self._builder.count, self._total_builds) |
| 524 | self.assertEqual(self._builder.fail, 0) |
| 525 | |
| 526 | def testCount(self): |
| 527 | """Test building a specific number of commitst""" |
Tom Rini | e95eddc | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 528 | self._RunControl('-b', TEST_BRANCH, '-c2', '-o', self._output_dir) |
Simon Glass | d4c6c8a | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 529 | self.assertEqual(self._builder.count, 2 * len(BOARDS)) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 530 | self.assertEqual(self._builder.fail, 0) |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 531 | # Each board has a config, and then one make per commit |
Simon Glass | d4c6c8a | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 532 | self.assertEqual(self._make_calls, len(BOARDS) * (1 + 2)) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 533 | |
| 534 | def testIncremental(self): |
| 535 | """Test building a branch twice - the second time should do nothing""" |
Tom Rini | e95eddc | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 536 | self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 537 | |
| 538 | # Each board has a mrproper, config, and then one make per commit |
Simon Glass | d4c6c8a | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 539 | self.assertEqual(self._make_calls, len(BOARDS) * (self._commits + 1)) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 540 | self._make_calls = 0 |
Tom Rini | e95eddc | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 541 | self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir, clean_dir=False) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 542 | self.assertEqual(self._make_calls, 0) |
| 543 | self.assertEqual(self._builder.count, self._total_builds) |
| 544 | self.assertEqual(self._builder.fail, 0) |
| 545 | |
| 546 | def testForceBuild(self): |
| 547 | """The -f flag should force a rebuild""" |
Tom Rini | e95eddc | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 548 | self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 549 | self._make_calls = 0 |
Tom Rini | e95eddc | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 550 | self._RunControl('-b', TEST_BRANCH, '-f', '-o', self._output_dir, clean_dir=False) |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 551 | # Each board has a config and one make per commit |
Simon Glass | d4c6c8a | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 552 | self.assertEqual(self._make_calls, len(BOARDS) * (self._commits + 1)) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 553 | |
| 554 | def testForceReconfigure(self): |
| 555 | """The -f flag should force a rebuild""" |
Tom Rini | e95eddc | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 556 | self._RunControl('-b', TEST_BRANCH, '-C', '-o', self._output_dir) |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 557 | # Each commit has a config and make |
Simon Glass | d4c6c8a | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 558 | self.assertEqual(self._make_calls, len(BOARDS) * self._commits * 2) |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 559 | |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 560 | def testMrproper(self): |
| 561 | """The -f flag should force a rebuild""" |
| 562 | self._RunControl('-b', TEST_BRANCH, '-m', '-o', self._output_dir) |
| 563 | # Each board has a mkproper, config and then one make per commit |
Simon Glass | d4c6c8a | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 564 | self.assertEqual(self._make_calls, len(BOARDS) * (self._commits + 2)) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 565 | |
| 566 | def testErrors(self): |
| 567 | """Test handling of build errors""" |
| 568 | self._error['board2', 1] = 'fred\n' |
Tom Rini | e95eddc | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 569 | self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 570 | self.assertEqual(self._builder.count, self._total_builds) |
| 571 | self.assertEqual(self._builder.fail, 1) |
| 572 | |
| 573 | # Remove the error. This should have no effect since the commit will |
| 574 | # not be rebuilt |
| 575 | del self._error['board2', 1] |
| 576 | self._make_calls = 0 |
Tom Rini | e95eddc | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 577 | self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir, clean_dir=False) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 578 | self.assertEqual(self._builder.count, self._total_builds) |
| 579 | self.assertEqual(self._make_calls, 0) |
| 580 | self.assertEqual(self._builder.fail, 1) |
| 581 | |
| 582 | # Now use the -F flag to force rebuild of the bad commit |
Tom Rini | e95eddc | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 583 | self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir, '-F', clean_dir=False) |
Simon Glass | 8e95956 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 584 | self.assertEqual(self._builder.count, self._total_builds) |
| 585 | self.assertEqual(self._builder.fail, 0) |
Simon Glass | 6029af1 | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 586 | self.assertEqual(self._make_calls, 2) |
Simon Glass | 4aeceb9 | 2014-09-05 19:00:22 -0600 | [diff] [blame] | 587 | |
| 588 | def testBranchWithSlash(self): |
| 589 | """Test building a branch with a '/' in the name""" |
| 590 | self._test_branch = '/__dev/__testbranch' |
Simon Glass | be9b52c | 2023-07-25 08:13:22 -0600 | [diff] [blame] | 591 | self._RunControl('-b', self._test_branch, '-o', self._output_dir, |
| 592 | clean_dir=False) |
Simon Glass | 4aeceb9 | 2014-09-05 19:00:22 -0600 | [diff] [blame] | 593 | self.assertEqual(self._builder.count, self._total_builds) |
| 594 | self.assertEqual(self._builder.fail, 0) |
Lothar Waßmann | ce6df92 | 2018-04-08 05:14:11 -0600 | [diff] [blame] | 595 | |
Simon Glass | ff48a21 | 2020-04-17 17:51:33 -0600 | [diff] [blame] | 596 | def testEnvironment(self): |
| 597 | """Test that the done and environment files are written to out-env""" |
| 598 | self._RunControl('-o', self._output_dir) |
| 599 | board0_dir = os.path.join(self._output_dir, 'current', 'board0') |
| 600 | self.assertTrue(os.path.exists(os.path.join(board0_dir, 'done'))) |
| 601 | self.assertTrue(os.path.exists(os.path.join(board0_dir, 'out-env'))) |
| 602 | |
Simon Glass | 93008e2 | 2021-04-11 16:27:28 +1200 | [diff] [blame] | 603 | def testEnvironmentUnicode(self): |
| 604 | """Test there are no unicode errors when the env has non-ASCII chars""" |
| 605 | try: |
| 606 | varname = b'buildman_test_var' |
| 607 | os.environb[varname] = b'strange\x80chars' |
| 608 | self.assertEqual(0, self._RunControl('-o', self._output_dir)) |
| 609 | board0_dir = os.path.join(self._output_dir, 'current', 'board0') |
| 610 | self.assertTrue(os.path.exists(os.path.join(board0_dir, 'done'))) |
| 611 | self.assertTrue(os.path.exists(os.path.join(board0_dir, 'out-env'))) |
| 612 | finally: |
| 613 | del os.environb[varname] |
| 614 | |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 615 | def testWorkInOutput(self): |
| 616 | """Test the -w option which should write directly to the output dir""" |
Simon Glass | 20751d6 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 617 | board_list = boards.Boards() |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 618 | board_list.add_board(board.Board(*BOARDS[0])) |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 619 | self._RunControl('-o', self._output_dir, '-w', clean_dir=False, |
Simon Glass | d4c6c8a | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 620 | brds=board_list) |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 621 | self.assertTrue( |
| 622 | os.path.exists(os.path.join(self._output_dir, 'u-boot'))) |
Simon Glass | e3c85ab | 2020-04-17 17:51:34 -0600 | [diff] [blame] | 623 | self.assertTrue( |
| 624 | os.path.exists(os.path.join(self._output_dir, 'done'))) |
| 625 | self.assertTrue( |
| 626 | os.path.exists(os.path.join(self._output_dir, 'out-env'))) |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 627 | |
| 628 | def testWorkInOutputFail(self): |
| 629 | """Test the -w option failures""" |
| 630 | with self.assertRaises(SystemExit) as e: |
| 631 | self._RunControl('-o', self._output_dir, '-w', clean_dir=False) |
| 632 | self.assertIn("single board", str(e.exception)) |
| 633 | self.assertFalse( |
| 634 | os.path.exists(os.path.join(self._output_dir, 'u-boot'))) |
| 635 | |
Simon Glass | 20751d6 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 636 | board_list = boards.Boards() |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 637 | board_list.add_board(board.Board(*BOARDS[0])) |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 638 | with self.assertRaises(SystemExit) as e: |
| 639 | self._RunControl('-b', self._test_branch, '-o', self._output_dir, |
Simon Glass | d4c6c8a | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 640 | '-w', clean_dir=False, brds=board_list) |
Simon Glass | b6eb8cf | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 641 | self.assertIn("single commit", str(e.exception)) |
Simon Glass | d9c9863 | 2020-04-17 17:51:32 -0600 | [diff] [blame] | 642 | |
Simon Glass | 20751d6 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 643 | board_list = boards.Boards() |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 644 | board_list.add_board(board.Board(*BOARDS[0])) |
Simon Glass | d9c9863 | 2020-04-17 17:51:32 -0600 | [diff] [blame] | 645 | with self.assertRaises(SystemExit) as e: |
| 646 | self._RunControl('-w', clean_dir=False) |
| 647 | self.assertIn("specify -o", str(e.exception)) |
Simon Glass | 9bf9a72 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 648 | |
| 649 | def testThreadExceptions(self): |
| 650 | """Test that exceptions in threads are reported""" |
| 651 | with test_util.capture_sys_output() as (stdout, stderr): |
| 652 | self.assertEqual(102, self._RunControl('-o', self._output_dir, |
| 653 | test_thread_exceptions=True)) |
Simon Glass | 9bac167 | 2022-01-22 05:07:32 -0700 | [diff] [blame] | 654 | self.assertIn( |
| 655 | 'Thread exception (use -T0 to run without threads): test exception', |
| 656 | stdout.getvalue()) |
Tom Rini | 93ebd46 | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 657 | |
| 658 | def testBlobs(self): |
| 659 | """Test handling of missing blobs""" |
| 660 | self._missing = True |
| 661 | |
| 662 | board0_dir = os.path.join(self._output_dir, 'current', 'board0') |
| 663 | errfile = os.path.join(board0_dir, 'err') |
| 664 | logfile = os.path.join(board0_dir, 'log') |
| 665 | |
| 666 | # We expect failure when there are missing blobs |
| 667 | result = self._RunControl('board0', '-o', self._output_dir) |
| 668 | self.assertEqual(100, result) |
| 669 | self.assertTrue(os.path.exists(os.path.join(board0_dir, 'done'))) |
| 670 | self.assertTrue(os.path.exists(errfile)) |
| 671 | self.assertIn(b"Filename 'fsp.bin' not found in input path", |
| 672 | tools.read_file(errfile)) |
| 673 | |
| 674 | def testBlobsAllowMissing(self): |
| 675 | """Allow missing blobs - still failure but a different exit code""" |
| 676 | self._missing = True |
| 677 | result = self._RunControl('board0', '-o', self._output_dir, '-M', |
| 678 | clean_dir=True) |
| 679 | self.assertEqual(101, result) |
| 680 | board0_dir = os.path.join(self._output_dir, 'current', 'board0') |
| 681 | errfile = os.path.join(board0_dir, 'err') |
| 682 | self.assertTrue(os.path.exists(errfile)) |
| 683 | self.assertIn(b'Some images are invalid', tools.read_file(errfile)) |
| 684 | |
| 685 | def testBlobsWarning(self): |
| 686 | """Allow missing blobs and ignore warnings""" |
| 687 | self._missing = True |
| 688 | result = self._RunControl('board0', '-o', self._output_dir, '-MW') |
| 689 | self.assertEqual(0, result) |
| 690 | board0_dir = os.path.join(self._output_dir, 'current', 'board0') |
| 691 | errfile = os.path.join(board0_dir, 'err') |
| 692 | self.assertIn(b'Some images are invalid', tools.read_file(errfile)) |
| 693 | |
| 694 | def testBlobSettings(self): |
| 695 | """Test with no settings""" |
| 696 | self.assertEqual(False, |
| 697 | control.get_allow_missing(False, False, 1, False)) |
| 698 | self.assertEqual(True, |
| 699 | control.get_allow_missing(True, False, 1, False)) |
| 700 | self.assertEqual(False, |
| 701 | control.get_allow_missing(True, True, 1, False)) |
| 702 | |
| 703 | def testBlobSettingsAlways(self): |
| 704 | """Test the 'always' policy""" |
Simon Glass | 06b83a5 | 2023-07-19 17:49:05 -0600 | [diff] [blame] | 705 | bsettings.set_item('global', 'allow-missing', 'always') |
Tom Rini | 93ebd46 | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 706 | self.assertEqual(True, |
| 707 | control.get_allow_missing(False, False, 1, False)) |
| 708 | self.assertEqual(False, |
| 709 | control.get_allow_missing(False, True, 1, False)) |
| 710 | |
| 711 | def testBlobSettingsBranch(self): |
| 712 | """Test the 'branch' policy""" |
Simon Glass | 06b83a5 | 2023-07-19 17:49:05 -0600 | [diff] [blame] | 713 | bsettings.set_item('global', 'allow-missing', 'branch') |
Tom Rini | 93ebd46 | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 714 | self.assertEqual(False, |
| 715 | control.get_allow_missing(False, False, 1, False)) |
| 716 | self.assertEqual(True, |
| 717 | control.get_allow_missing(False, False, 1, True)) |
| 718 | self.assertEqual(False, |
| 719 | control.get_allow_missing(False, True, 1, True)) |
| 720 | |
| 721 | def testBlobSettingsMultiple(self): |
| 722 | """Test the 'multiple' policy""" |
Simon Glass | 06b83a5 | 2023-07-19 17:49:05 -0600 | [diff] [blame] | 723 | bsettings.set_item('global', 'allow-missing', 'multiple') |
Tom Rini | 93ebd46 | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 724 | self.assertEqual(False, |
| 725 | control.get_allow_missing(False, False, 1, False)) |
| 726 | self.assertEqual(True, |
| 727 | control.get_allow_missing(False, False, 2, False)) |
| 728 | self.assertEqual(False, |
| 729 | control.get_allow_missing(False, True, 2, False)) |
| 730 | |
| 731 | def testBlobSettingsBranchMultiple(self): |
| 732 | """Test the 'branch multiple' policy""" |
Simon Glass | 06b83a5 | 2023-07-19 17:49:05 -0600 | [diff] [blame] | 733 | bsettings.set_item('global', 'allow-missing', 'branch multiple') |
Tom Rini | 93ebd46 | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 734 | self.assertEqual(False, |
| 735 | control.get_allow_missing(False, False, 1, False)) |
| 736 | self.assertEqual(True, |
| 737 | control.get_allow_missing(False, False, 1, True)) |
| 738 | self.assertEqual(True, |
| 739 | control.get_allow_missing(False, False, 2, False)) |
| 740 | self.assertEqual(True, |
| 741 | control.get_allow_missing(False, False, 2, True)) |
| 742 | self.assertEqual(False, |
| 743 | control.get_allow_missing(False, True, 2, True)) |
Simon Glass | 1382b1d | 2023-02-21 12:40:27 -0700 | [diff] [blame] | 744 | |
Simon Glass | f6bfcca | 2023-02-21 12:40:28 -0700 | [diff] [blame] | 745 | def check_command(self, *extra_args): |
| 746 | """Run a command with the extra arguments and return the commands used |
| 747 | |
| 748 | Args: |
| 749 | extra_args (list of str): List of extra arguments |
| 750 | |
| 751 | Returns: |
| 752 | list of str: Lines returned in the out-cmd file |
| 753 | """ |
| 754 | self._RunControl('-o', self._output_dir, *extra_args) |
Simon Glass | 1382b1d | 2023-02-21 12:40:27 -0700 | [diff] [blame] | 755 | board0_dir = os.path.join(self._output_dir, 'current', 'board0') |
| 756 | self.assertTrue(os.path.exists(os.path.join(board0_dir, 'done'))) |
| 757 | cmd_fname = os.path.join(board0_dir, 'out-cmd') |
| 758 | self.assertTrue(os.path.exists(cmd_fname)) |
| 759 | data = tools.read_file(cmd_fname) |
Simon Glass | 828d70d | 2023-02-21 12:40:29 -0700 | [diff] [blame] | 760 | |
| 761 | config_fname = os.path.join(board0_dir, '.config') |
| 762 | self.assertTrue(os.path.exists(config_fname)) |
| 763 | cfg_data = tools.read_file(config_fname) |
| 764 | |
| 765 | return data.splitlines(), cfg_data |
Simon Glass | f6bfcca | 2023-02-21 12:40:28 -0700 | [diff] [blame] | 766 | |
| 767 | def testCmdFile(self): |
| 768 | """Test that the -cmd-out file is produced""" |
Simon Glass | 828d70d | 2023-02-21 12:40:29 -0700 | [diff] [blame] | 769 | lines = self.check_command()[0] |
Simon Glass | 1382b1d | 2023-02-21 12:40:27 -0700 | [diff] [blame] | 770 | self.assertEqual(2, len(lines)) |
| 771 | self.assertRegex(lines[0], b'make O=/.*board0_defconfig') |
| 772 | self.assertRegex(lines[0], b'make O=/.*-s.*') |
Simon Glass | f6bfcca | 2023-02-21 12:40:28 -0700 | [diff] [blame] | 773 | |
| 774 | def testNoLto(self): |
| 775 | """Test that the --no-lto flag works""" |
Simon Glass | 828d70d | 2023-02-21 12:40:29 -0700 | [diff] [blame] | 776 | lines = self.check_command('-L')[0] |
Simon Glass | f6bfcca | 2023-02-21 12:40:28 -0700 | [diff] [blame] | 777 | self.assertIn(b'NO_LTO=1', lines[0]) |
| 778 | |
Simon Glass | 828d70d | 2023-02-21 12:40:29 -0700 | [diff] [blame] | 779 | def testReproducible(self): |
| 780 | """Test that the -r flag works""" |
| 781 | lines, cfg_data = self.check_command('-r') |
| 782 | self.assertIn(b'SOURCE_DATE_EPOCH=0', lines[0]) |
| 783 | |
| 784 | # We should see CONFIG_LOCALVERSION_AUTO unset |
| 785 | self.assertEqual(b'''CONFIG_SOMETHING=1 |
| 786 | # CONFIG_LOCALVERSION_AUTO is not set |
| 787 | ''', cfg_data) |
| 788 | |
| 789 | with test_util.capture_sys_output() as (stdout, stderr): |
| 790 | lines, cfg_data = self.check_command('-r', '-a', 'LOCALVERSION') |
| 791 | self.assertIn(b'SOURCE_DATE_EPOCH=0', lines[0]) |
| 792 | |
| 793 | # We should see CONFIG_LOCALVERSION_AUTO unset |
| 794 | self.assertEqual(b'''CONFIG_SOMETHING=1 |
| 795 | CONFIG_LOCALVERSION=y |
| 796 | ''', cfg_data) |
| 797 | self.assertIn('Not dropping LOCALVERSION_AUTO', stdout.getvalue()) |
Simon Glass | cef26b8 | 2023-07-19 17:48:15 -0600 | [diff] [blame] | 798 | |
| 799 | def test_scan_defconfigs(self): |
| 800 | """Test scanning the defconfigs to obtain all the boards""" |
| 801 | src = self._git_dir |
| 802 | |
| 803 | # Scan the test directory which contains a Kconfig and some *_defconfig |
| 804 | # files |
Simon Glass | 07a95d8 | 2023-07-19 17:48:21 -0600 | [diff] [blame] | 805 | params, warnings = self._boards.scan_defconfigs(src, src) |
Simon Glass | cef26b8 | 2023-07-19 17:48:15 -0600 | [diff] [blame] | 806 | |
| 807 | # We should get two boards |
| 808 | self.assertEquals(2, len(params)) |
Simon Glass | 07a95d8 | 2023-07-19 17:48:21 -0600 | [diff] [blame] | 809 | self.assertFalse(warnings) |
Simon Glass | cef26b8 | 2023-07-19 17:48:15 -0600 | [diff] [blame] | 810 | first = 0 if params[0]['target'] == 'board0' else 1 |
| 811 | board0 = params[first] |
| 812 | board2 = params[1 - first] |
| 813 | |
| 814 | self.assertEquals('arm', board0['arch']) |
| 815 | self.assertEquals('armv7', board0['cpu']) |
| 816 | self.assertEquals('-', board0['soc']) |
| 817 | self.assertEquals('Tester', board0['vendor']) |
| 818 | self.assertEquals('ARM Board 0', board0['board']) |
| 819 | self.assertEquals('config0', board0['config']) |
| 820 | self.assertEquals('board0', board0['target']) |
| 821 | |
| 822 | self.assertEquals('powerpc', board2['arch']) |
| 823 | self.assertEquals('ppc', board2['cpu']) |
| 824 | self.assertEquals('mpc85xx', board2['soc']) |
| 825 | self.assertEquals('Tester', board2['vendor']) |
| 826 | self.assertEquals('PowerPC board 1', board2['board']) |
| 827 | self.assertEquals('config2', board2['config']) |
| 828 | self.assertEquals('board2', board2['target']) |
| 829 | |
Simon Glass | ada78d4 | 2023-07-19 17:48:16 -0600 | [diff] [blame] | 830 | def test_output_is_new(self): |
| 831 | """Test detecting new changes to Kconfig""" |
| 832 | base = self._base_dir |
| 833 | src = self._git_dir |
| 834 | config_dir = os.path.join(src, 'configs') |
| 835 | delay = 0.02 |
| 836 | |
| 837 | # Create a boards.cfg file |
| 838 | boards_cfg = os.path.join(base, 'boards.cfg') |
| 839 | content = b'''# |
| 840 | # List of boards |
| 841 | # Automatically generated by buildman/boards.py: don't edit |
| 842 | # |
| 843 | # Status, Arch, CPU, SoC, Vendor, Board, Target, Config, Maintainers |
| 844 | |
| 845 | Active aarch64 armv8 - armltd corstone1000 board0 |
| 846 | Active aarch64 armv8 - armltd total_compute board2 |
| 847 | ''' |
| 848 | # Check missing file |
| 849 | self.assertFalse(boards.output_is_new(boards_cfg, config_dir, src)) |
| 850 | |
| 851 | # Check that the board.cfg file is newer |
| 852 | time.sleep(delay) |
| 853 | tools.write_file(boards_cfg, content) |
| 854 | self.assertTrue(boards.output_is_new(boards_cfg, config_dir, src)) |
| 855 | |
| 856 | # Touch the Kconfig files after a show delay to avoid a race |
| 857 | time.sleep(delay) |
| 858 | Path(os.path.join(src, 'Kconfig')).touch() |
| 859 | self.assertFalse(boards.output_is_new(boards_cfg, config_dir, src)) |
| 860 | Path(boards_cfg).touch() |
| 861 | self.assertTrue(boards.output_is_new(boards_cfg, config_dir, src)) |
| 862 | |
| 863 | # Touch a different Kconfig file |
| 864 | time.sleep(delay) |
| 865 | Path(os.path.join(src, 'Kconfig.something')).touch() |
| 866 | self.assertFalse(boards.output_is_new(boards_cfg, config_dir, src)) |
| 867 | Path(boards_cfg).touch() |
| 868 | self.assertTrue(boards.output_is_new(boards_cfg, config_dir, src)) |
| 869 | |
| 870 | # Touch a MAINTAINERS file |
| 871 | time.sleep(delay) |
| 872 | Path(os.path.join(src, 'MAINTAINERS')).touch() |
| 873 | self.assertFalse(boards.output_is_new(boards_cfg, config_dir, src)) |
| 874 | |
| 875 | Path(boards_cfg).touch() |
| 876 | self.assertTrue(boards.output_is_new(boards_cfg, config_dir, src)) |
| 877 | |
| 878 | # Touch a defconfig file |
| 879 | time.sleep(delay) |
| 880 | Path(os.path.join(config_dir, 'board0_defconfig')).touch() |
| 881 | self.assertFalse(boards.output_is_new(boards_cfg, config_dir, src)) |
| 882 | Path(boards_cfg).touch() |
| 883 | self.assertTrue(boards.output_is_new(boards_cfg, config_dir, src)) |
| 884 | |
| 885 | # Remove a board and check that the board.cfg file is now older |
| 886 | Path(os.path.join(config_dir, 'board0_defconfig')).unlink() |
| 887 | self.assertFalse(boards.output_is_new(boards_cfg, config_dir, src)) |
| 888 | |
Simon Glass | c0b6fcc | 2023-07-19 17:48:17 -0600 | [diff] [blame] | 889 | def test_maintainers(self): |
| 890 | """Test detecting boards without a MAINTAINERS entry""" |
| 891 | src = self._git_dir |
| 892 | main = os.path.join(src, 'boards', 'board0', 'MAINTAINERS') |
| 893 | other = os.path.join(src, 'boards', 'board2', 'MAINTAINERS') |
Simon Glass | 07a95d8 | 2023-07-19 17:48:21 -0600 | [diff] [blame] | 894 | kc_file = os.path.join(src, 'Kconfig') |
Simon Glass | c0b6fcc | 2023-07-19 17:48:17 -0600 | [diff] [blame] | 895 | config_dir = os.path.join(src, 'configs') |
| 896 | params_list, warnings = self._boards.build_board_list(config_dir, src) |
| 897 | |
| 898 | # There should be two boards no warnings |
| 899 | self.assertEquals(2, len(params_list)) |
| 900 | self.assertFalse(warnings) |
| 901 | |
| 902 | # Set an invalid status line in the file |
| 903 | orig_data = tools.read_file(main, binary=False) |
| 904 | lines = ['S: Other\n' if line.startswith('S:') else line |
| 905 | for line in orig_data.splitlines(keepends=True)] |
| 906 | tools.write_file(main, ''.join(lines), binary=False) |
| 907 | params_list, warnings = self._boards.build_board_list(config_dir, src) |
| 908 | self.assertEquals(2, len(params_list)) |
| 909 | params = params_list[0] |
| 910 | if params['target'] == 'board2': |
| 911 | params = params_list[1] |
| 912 | self.assertEquals('-', params['status']) |
| 913 | self.assertEquals(["WARNING: Other: unknown status for 'board0'"], |
| 914 | warnings) |
| 915 | |
| 916 | # Remove the status line (S:) from a file |
| 917 | lines = [line for line in orig_data.splitlines(keepends=True) |
| 918 | if not line.startswith('S:')] |
| 919 | tools.write_file(main, ''.join(lines), binary=False) |
| 920 | params_list, warnings = self._boards.build_board_list(config_dir, src) |
| 921 | self.assertEquals(2, len(params_list)) |
| 922 | self.assertEquals(["WARNING: -: unknown status for 'board0'"], warnings) |
| 923 | |
| 924 | # Remove the configs/ line (F:) from a file - this is the last line |
| 925 | data = ''.join(orig_data.splitlines(keepends=True)[:-1]) |
| 926 | tools.write_file(main, data, binary=False) |
| 927 | params_list, warnings = self._boards.build_board_list(config_dir, src) |
| 928 | self.assertEquals(2, len(params_list)) |
| 929 | self.assertEquals( |
Simon Glass | 263b598 | 2023-07-19 17:48:25 -0600 | [diff] [blame] | 930 | ["WARNING: no maintainers for 'board0'", |
| 931 | 'WARNING: orphaned defconfig in boards/board0/MAINTAINERS ending at line 4', |
| 932 | ], warnings) |
Simon Glass | c0b6fcc | 2023-07-19 17:48:17 -0600 | [diff] [blame] | 933 | |
Simon Glass | e6acab5 | 2023-07-19 17:48:26 -0600 | [diff] [blame] | 934 | # Mark a board as orphaned - this should give a warning |
| 935 | lines = ['S: Orphaned' if line.startswith('S') else line |
| 936 | for line in orig_data.splitlines(keepends=True)] |
| 937 | tools.write_file(main, ''.join(lines), binary=False) |
| 938 | params_list, warnings = self._boards.build_board_list(config_dir, src) |
| 939 | self.assertEquals(2, len(params_list)) |
| 940 | self.assertEquals(["WARNING: no maintainers for 'board0'"], warnings) |
| 941 | |
| 942 | # Change the maintainer to '-' - this should give a warning |
| 943 | lines = ['M: -' if line.startswith('M') else line |
| 944 | for line in orig_data.splitlines(keepends=True)] |
| 945 | tools.write_file(main, ''.join(lines), binary=False) |
| 946 | params_list, warnings = self._boards.build_board_list(config_dir, src) |
| 947 | self.assertEquals(2, len(params_list)) |
| 948 | self.assertEquals(["WARNING: -: unknown status for 'board0'"], warnings) |
| 949 | |
| 950 | # Remove the maintainer line (M:) from a file |
Simon Glass | c0b6fcc | 2023-07-19 17:48:17 -0600 | [diff] [blame] | 951 | lines = [line for line in orig_data.splitlines(keepends=True) |
| 952 | if not line.startswith('M:')] |
| 953 | tools.write_file(main, ''.join(lines), binary=False) |
| 954 | params_list, warnings = self._boards.build_board_list(config_dir, src) |
| 955 | self.assertEquals(2, len(params_list)) |
Simon Glass | e6acab5 | 2023-07-19 17:48:26 -0600 | [diff] [blame] | 956 | self.assertEquals(["WARNING: no maintainers for 'board0'"], warnings) |
Simon Glass | c0b6fcc | 2023-07-19 17:48:17 -0600 | [diff] [blame] | 957 | |
| 958 | # Move the contents of the second file into this one, removing the |
| 959 | # second file, to check multiple records in a single file. |
Simon Glass | 060ee97 | 2023-07-19 17:48:23 -0600 | [diff] [blame] | 960 | both_data = orig_data + tools.read_file(other, binary=False) |
| 961 | tools.write_file(main, both_data, binary=False) |
Simon Glass | c0b6fcc | 2023-07-19 17:48:17 -0600 | [diff] [blame] | 962 | os.remove(other) |
| 963 | params_list, warnings = self._boards.build_board_list(config_dir, src) |
| 964 | self.assertEquals(2, len(params_list)) |
| 965 | self.assertFalse(warnings) |
| 966 | |
Simon Glass | 9b828ec | 2023-07-19 17:48:19 -0600 | [diff] [blame] | 967 | # Add another record, this should be ignored with a warning |
Simon Glass | c0b6fcc | 2023-07-19 17:48:17 -0600 | [diff] [blame] | 968 | extra = '\n\nAnother\nM: Fred\nF: configs/board9_defconfig\nS: other\n' |
Simon Glass | 060ee97 | 2023-07-19 17:48:23 -0600 | [diff] [blame] | 969 | tools.write_file(main, both_data + extra, binary=False) |
Simon Glass | c0b6fcc | 2023-07-19 17:48:17 -0600 | [diff] [blame] | 970 | params_list, warnings = self._boards.build_board_list(config_dir, src) |
| 971 | self.assertEquals(2, len(params_list)) |
Simon Glass | 9b828ec | 2023-07-19 17:48:19 -0600 | [diff] [blame] | 972 | self.assertEquals( |
| 973 | ['WARNING: orphaned defconfig in boards/board0/MAINTAINERS ending at line 16'], |
| 974 | warnings) |
Simon Glass | 07a95d8 | 2023-07-19 17:48:21 -0600 | [diff] [blame] | 975 | |
| 976 | # Add another TARGET to the Kconfig |
Simon Glass | 060ee97 | 2023-07-19 17:48:23 -0600 | [diff] [blame] | 977 | tools.write_file(main, both_data, binary=False) |
Simon Glass | 061499b | 2023-07-19 17:48:22 -0600 | [diff] [blame] | 978 | orig_kc_data = tools.read_file(kc_file) |
Simon Glass | 07a95d8 | 2023-07-19 17:48:21 -0600 | [diff] [blame] | 979 | extra = (b''' |
| 980 | if TARGET_BOARD2 |
| 981 | config TARGET_OTHER |
| 982 | \tbool "other" |
| 983 | \tdefault y |
| 984 | endif |
| 985 | ''') |
Simon Glass | 061499b | 2023-07-19 17:48:22 -0600 | [diff] [blame] | 986 | tools.write_file(kc_file, orig_kc_data + extra) |
Simon Glass | 5e728d4 | 2023-07-19 17:48:27 -0600 | [diff] [blame] | 987 | params_list, warnings = self._boards.build_board_list(config_dir, src, |
| 988 | warn_targets=True) |
Simon Glass | 07a95d8 | 2023-07-19 17:48:21 -0600 | [diff] [blame] | 989 | self.assertEquals(2, len(params_list)) |
| 990 | self.assertEquals( |
| 991 | ['WARNING: board2_defconfig: Duplicate TARGET_xxx: board2 and other'], |
| 992 | warnings) |
Simon Glass | 061499b | 2023-07-19 17:48:22 -0600 | [diff] [blame] | 993 | |
| 994 | # Remove the TARGET_BOARD0 Kconfig option |
| 995 | lines = [b'' if line == b'config TARGET_BOARD2\n' else line |
| 996 | for line in orig_kc_data.splitlines(keepends=True)] |
| 997 | tools.write_file(kc_file, b''.join(lines)) |
Simon Glass | 5e728d4 | 2023-07-19 17:48:27 -0600 | [diff] [blame] | 998 | params_list, warnings = self._boards.build_board_list(config_dir, src, |
| 999 | warn_targets=True) |
Simon Glass | 061499b | 2023-07-19 17:48:22 -0600 | [diff] [blame] | 1000 | self.assertEquals(2, len(params_list)) |
| 1001 | self.assertEquals( |
| 1002 | ['WARNING: board2_defconfig: No TARGET_BOARD2 enabled'], |
| 1003 | warnings) |
Simon Glass | 060ee97 | 2023-07-19 17:48:23 -0600 | [diff] [blame] | 1004 | tools.write_file(kc_file, orig_kc_data) |
| 1005 | |
| 1006 | # Replace the last F: line of board 2 with an N: line |
| 1007 | data = ''.join(both_data.splitlines(keepends=True)[:-1]) |
| 1008 | tools.write_file(main, data + 'N: oa.*2\n', binary=False) |
| 1009 | params_list, warnings = self._boards.build_board_list(config_dir, src) |
| 1010 | self.assertEquals(2, len(params_list)) |
| 1011 | self.assertFalse(warnings) |
| 1012 | |
Simon Glass | 09afcb7 | 2023-07-19 17:48:28 -0600 | [diff] [blame] | 1013 | def testRegenBoards(self): |
| 1014 | """Test that we can regenerate the boards.cfg file""" |
| 1015 | outfile = os.path.join(self._output_dir, 'test-boards.cfg') |
| 1016 | if os.path.exists(outfile): |
| 1017 | os.remove(outfile) |
| 1018 | with test_util.capture_sys_output() as (stdout, stderr): |
| 1019 | result = self._RunControl('-R', outfile, brds=None, |
| 1020 | get_builder=False) |
| 1021 | self.assertTrue(os.path.exists(outfile)) |
Simon Glass | 8f317b9 | 2023-07-19 17:48:35 -0600 | [diff] [blame] | 1022 | |
| 1023 | def test_print_prefix(self): |
| 1024 | """Test that we can print the toolchain prefix""" |
| 1025 | with test_util.capture_sys_output() as (stdout, stderr): |
| 1026 | result = self._RunControl('-A', 'board0') |
| 1027 | self.assertEqual('arm-\n', stdout.getvalue()) |
| 1028 | self.assertEqual('', stderr.getvalue()) |
Simon Glass | 2097874 | 2023-07-19 17:48:38 -0600 | [diff] [blame] | 1029 | |
| 1030 | def test_exclude_one(self): |
| 1031 | """Test excluding a single board from an arch""" |
Simon Glass | be9b52c | 2023-07-25 08:13:22 -0600 | [diff] [blame] | 1032 | self._RunControl('arm', '-x', 'board1', '-o', self._output_dir) |
Simon Glass | 2097874 | 2023-07-19 17:48:38 -0600 | [diff] [blame] | 1033 | self.assertEqual(['board0'], |
| 1034 | [b.target for b in self._boards.get_selected()]) |
| 1035 | |
| 1036 | def test_exclude_arch(self): |
| 1037 | """Test excluding an arch""" |
Simon Glass | be9b52c | 2023-07-25 08:13:22 -0600 | [diff] [blame] | 1038 | self._RunControl('-x', 'arm', '-o', self._output_dir) |
Simon Glass | 2097874 | 2023-07-19 17:48:38 -0600 | [diff] [blame] | 1039 | self.assertEqual(['board2', 'board4'], |
| 1040 | [b.target for b in self._boards.get_selected()]) |
| 1041 | |
| 1042 | def test_exclude_comma(self): |
| 1043 | """Test excluding a comma-separated list of things""" |
Simon Glass | be9b52c | 2023-07-25 08:13:22 -0600 | [diff] [blame] | 1044 | self._RunControl('-x', 'arm,powerpc', '-o', self._output_dir) |
Simon Glass | 2097874 | 2023-07-19 17:48:38 -0600 | [diff] [blame] | 1045 | self.assertEqual(['board4'], |
| 1046 | [b.target for b in self._boards.get_selected()]) |
| 1047 | |
| 1048 | def test_exclude_list(self): |
| 1049 | """Test excluding a list of things""" |
Simon Glass | be9b52c | 2023-07-25 08:13:22 -0600 | [diff] [blame] | 1050 | self._RunControl('-x', 'board2', '-x' 'board4', '-o', self._output_dir) |
Simon Glass | 2097874 | 2023-07-19 17:48:38 -0600 | [diff] [blame] | 1051 | self.assertEqual(['board0', 'board1'], |
| 1052 | [b.target for b in self._boards.get_selected()]) |
Simon Glass | f56cc29 | 2023-07-19 17:49:03 -0600 | [diff] [blame] | 1053 | |
| 1054 | def test_single_boards(self): |
| 1055 | """Test building single boards""" |
Simon Glass | be9b52c | 2023-07-25 08:13:22 -0600 | [diff] [blame] | 1056 | self._RunControl('--boards', 'board1', '-o', self._output_dir) |
Simon Glass | f56cc29 | 2023-07-19 17:49:03 -0600 | [diff] [blame] | 1057 | self.assertEqual(1, self._builder.count) |
| 1058 | |
Simon Glass | be9b52c | 2023-07-25 08:13:22 -0600 | [diff] [blame] | 1059 | self._RunControl('--boards', 'board1', '--boards', 'board2', |
| 1060 | '-o', self._output_dir) |
Simon Glass | f56cc29 | 2023-07-19 17:49:03 -0600 | [diff] [blame] | 1061 | self.assertEqual(2, self._builder.count) |
| 1062 | |
Simon Glass | be9b52c | 2023-07-25 08:13:22 -0600 | [diff] [blame] | 1063 | self._RunControl('--boards', 'board1,board2', '--boards', 'board4', |
| 1064 | '-o', self._output_dir) |
Simon Glass | f56cc29 | 2023-07-19 17:49:03 -0600 | [diff] [blame] | 1065 | self.assertEqual(3, self._builder.count) |
Simon Glass | a8a0ce7 | 2023-07-19 17:49:28 -0600 | [diff] [blame] | 1066 | |
| 1067 | def test_print_arch(self): |
| 1068 | """Test that we can print the board architecture""" |
| 1069 | with test_util.capture_sys_output() as (stdout, stderr): |
| 1070 | result = self._RunControl('--print-arch', 'board0') |
| 1071 | self.assertEqual('arm\n', stdout.getvalue()) |
| 1072 | self.assertEqual('', stderr.getvalue()) |