Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 2 | # Copyright (c) 2014 Google, Inc |
| 3 | # |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 4 | |
| 5 | import os |
| 6 | import shutil |
| 7 | import sys |
| 8 | import tempfile |
| 9 | import unittest |
| 10 | |
Simon Glass | 0ede00f | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 11 | from buildman import board |
Simon Glass | c52bd22 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 12 | from buildman import boards |
Simon Glass | 0ede00f | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 13 | from buildman import bsettings |
| 14 | from buildman import cmdline |
| 15 | from buildman import control |
| 16 | from buildman import toolchain |
Simon Glass | bf77667 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 17 | from patman import command |
| 18 | from patman import gitutil |
| 19 | from patman import terminal |
Simon Glass | 8116c78 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 20 | from patman import test_util |
Simon Glass | bf77667 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 21 | from patman import tools |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 22 | |
Simon Glass | 8b985ee | 2014-09-05 19:00:15 -0600 | [diff] [blame] | 23 | settings_data = ''' |
| 24 | # Buildman settings file |
Tom Rini | d7713ad | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 25 | [global] |
Simon Glass | 8b985ee | 2014-09-05 19:00:15 -0600 | [diff] [blame] | 26 | |
| 27 | [toolchain] |
| 28 | |
| 29 | [toolchain-alias] |
| 30 | |
| 31 | [make-flags] |
| 32 | src=/home/sjg/c/src |
| 33 | chroot=/home/sjg/c/chroot |
Masahiro Yamada | 9865543 | 2018-08-06 20:47:38 +0900 | [diff] [blame] | 34 | vboot=VBOOT_DEBUG=1 MAKEFLAGS_VBOOT=DEBUG=1 CFLAGS_EXTRA_VBOOT=-DUNROLL_LOOPS VBOOT_SOURCE=${src}/platform/vboot_reference |
Simon Glass | 8b985ee | 2014-09-05 19:00:15 -0600 | [diff] [blame] | 35 | chromeos_coreboot=VBOOT=${chroot}/build/link/usr ${vboot} |
| 36 | chromeos_daisy=VBOOT=${chroot}/build/daisy/usr ${vboot} |
| 37 | chromeos_peach=VBOOT=${chroot}/build/peach_pit/usr ${vboot} |
| 38 | ''' |
| 39 | |
Simon Glass | 938fa37 | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 40 | BOARDS = [ |
Simon Glass | 823e60b | 2014-09-05 19:00:16 -0600 | [diff] [blame] | 41 | ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board0', ''], |
| 42 | ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 2', 'board1', ''], |
| 43 | ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''], |
Simon Glass | 823e60b | 2014-09-05 19:00:16 -0600 | [diff] [blame] | 44 | ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''], |
| 45 | ] |
| 46 | |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 47 | commit_shortlog = """4aca821 patman: Avoid changing the order of tags |
| 48 | 39403bb patman: Use --no-pager' to stop git from forking a pager |
| 49 | db6e6f2 patman: Remove the -a option |
| 50 | f2ccf03 patman: Correct unit tests to run correctly |
| 51 | 1d097f9 patman: Fix indentation in terminal.py |
| 52 | d073747 patman: Support the 'reverse' option for 'git log |
| 53 | """ |
| 54 | |
| 55 | commit_log = ["""commit 7f6b8315d18f683c5181d0c3694818c1b2a20dcd |
| 56 | Author: Masahiro Yamada <yamada.m@jp.panasonic.com> |
| 57 | Date: Fri Aug 22 19:12:41 2014 +0900 |
| 58 | |
| 59 | buildman: refactor help message |
| 60 | |
| 61 | "buildman [options]" is displayed by default. |
| 62 | |
| 63 | Append the rest of help messages to parser.usage |
| 64 | instead of replacing it. |
| 65 | |
| 66 | Besides, "-b <branch>" is not mandatory since commit fea5858e. |
| 67 | Drop it from the usage. |
| 68 | |
| 69 | Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com> |
| 70 | """, |
| 71 | """commit d0737479be6baf4db5e2cdbee123e96bc5ed0ba8 |
| 72 | Author: Simon Glass <sjg@chromium.org> |
| 73 | Date: Thu Aug 14 16:48:25 2014 -0600 |
| 74 | |
| 75 | patman: Support the 'reverse' option for 'git log' |
| 76 | |
| 77 | This option is currently not supported, but needs to be, for buildman to |
| 78 | operate as expected. |
| 79 | |
| 80 | Series-changes: 7 |
| 81 | - Add new patch to fix the 'reverse' bug |
| 82 | |
Simon Glass | 950a231 | 2014-09-05 19:00:23 -0600 | [diff] [blame] | 83 | Series-version: 8 |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 84 | |
| 85 | Change-Id: I79078f792e8b390b8a1272a8023537821d45feda |
| 86 | Reported-by: York Sun <yorksun@freescale.com> |
| 87 | Signed-off-by: Simon Glass <sjg@chromium.org> |
| 88 | |
| 89 | """, |
| 90 | """commit 1d097f9ab487c5019152fd47bda126839f3bf9fc |
| 91 | Author: Simon Glass <sjg@chromium.org> |
| 92 | Date: Sat Aug 9 11:44:32 2014 -0600 |
| 93 | |
| 94 | patman: Fix indentation in terminal.py |
| 95 | |
| 96 | This code came from a different project with 2-character indentation. Fix |
| 97 | it for U-Boot. |
| 98 | |
| 99 | Series-changes: 6 |
| 100 | - Add new patch to fix indentation in teminal.py |
| 101 | |
| 102 | Change-Id: I5a74d2ebbb3cc12a665f5c725064009ac96e8a34 |
| 103 | Signed-off-by: Simon Glass <sjg@chromium.org> |
| 104 | |
| 105 | """, |
| 106 | """commit f2ccf03869d1e152c836515a3ceb83cdfe04a105 |
| 107 | Author: Simon Glass <sjg@chromium.org> |
| 108 | Date: Sat Aug 9 11:08:24 2014 -0600 |
| 109 | |
| 110 | patman: Correct unit tests to run correctly |
| 111 | |
| 112 | It seems that doctest behaves differently now, and some of the unit tests |
| 113 | do not run. Adjust the tests to work correctly. |
| 114 | |
| 115 | ./tools/patman/patman --test |
| 116 | <unittest.result.TestResult run=10 errors=0 failures=0> |
| 117 | |
| 118 | Series-changes: 6 |
| 119 | - Add new patch to fix patman unit tests |
| 120 | |
| 121 | Change-Id: I3d2ca588f4933e1f9d6b1665a00e4ae58269ff3b |
| 122 | |
| 123 | """, |
| 124 | """commit db6e6f2f9331c5a37647d6668768d4a40b8b0d1c |
| 125 | Author: Simon Glass <sjg@chromium.org> |
| 126 | Date: Sat Aug 9 12:06:02 2014 -0600 |
| 127 | |
| 128 | patman: Remove the -a option |
| 129 | |
| 130 | It seems that this is no longer needed, since checkpatch.pl will catch |
| 131 | whitespace problems in patches. Also the option is not widely used, so |
| 132 | it seems safe to just remove it. |
| 133 | |
| 134 | Series-changes: 6 |
| 135 | - Add new patch to remove patman's -a option |
| 136 | |
| 137 | Suggested-by: Masahiro Yamada <yamada.m@jp.panasonic.com> |
| 138 | Change-Id: I5821a1c75154e532c46513486ca40b808de7e2cc |
| 139 | |
| 140 | """, |
| 141 | """commit 39403bb4f838153028a6f21ca30bf100f3791133 |
| 142 | Author: Simon Glass <sjg@chromium.org> |
| 143 | Date: Thu Aug 14 21:50:52 2014 -0600 |
| 144 | |
| 145 | patman: Use --no-pager' to stop git from forking a pager |
| 146 | |
| 147 | """, |
| 148 | """commit 4aca821e27e97925c039e69fd37375b09c6f129c |
| 149 | Author: Simon Glass <sjg@chromium.org> |
| 150 | Date: Fri Aug 22 15:57:39 2014 -0600 |
| 151 | |
| 152 | patman: Avoid changing the order of tags |
| 153 | |
| 154 | patman collects tags that it sees in the commit and places them nicely |
| 155 | sorted at the end of the patch. However, this is not really necessary and |
| 156 | in fact is apparently not desirable. |
| 157 | |
| 158 | Series-changes: 9 |
| 159 | - Add new patch to avoid changing the order of tags |
| 160 | |
Simon Glass | 950a231 | 2014-09-05 19:00:23 -0600 | [diff] [blame] | 161 | Series-version: 9 |
| 162 | |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 163 | Suggested-by: Masahiro Yamada <yamada.m@jp.panasonic.com> |
| 164 | Change-Id: Ib1518588c1a189ad5c3198aae76f8654aed8d0db |
| 165 | """] |
| 166 | |
| 167 | TEST_BRANCH = '__testbranch' |
| 168 | |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 169 | class TestFunctional(unittest.TestCase): |
| 170 | """Functional test for buildman. |
| 171 | |
| 172 | This aims to test from just below the invocation of buildman (parsing |
| 173 | of arguments) to 'make' and 'git' invocation. It is not a true |
| 174 | emd-to-end test, as it mocks git, make and the tool chain. But this |
| 175 | makes it easier to detect when the builder is doing the wrong thing, |
| 176 | since in many cases this test code will fail. For example, only a |
| 177 | very limited subset of 'git' arguments is supported - anything |
| 178 | unexpected will fail. |
| 179 | """ |
| 180 | def setUp(self): |
| 181 | self._base_dir = tempfile.mkdtemp() |
Tom Rini | aae6258 | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 182 | self._output_dir = tempfile.mkdtemp() |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 183 | self._git_dir = os.path.join(self._base_dir, 'src') |
| 184 | self._buildman_pathname = sys.argv[0] |
Simon Glass | bd6f5d9 | 2016-07-27 20:33:00 -0600 | [diff] [blame] | 185 | self._buildman_dir = os.path.dirname(os.path.realpath(sys.argv[0])) |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 186 | command.test_result = self._HandleCommand |
Simon Glass | 19133b7 | 2022-01-22 05:07:31 -0700 | [diff] [blame] | 187 | bsettings.Setup(None) |
| 188 | bsettings.AddFile(settings_data) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 189 | self.setupToolchains() |
| 190 | self._toolchains.Add('arm-gcc', test=False) |
| 191 | self._toolchains.Add('powerpc-gcc', test=False) |
Simon Glass | c52bd22 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 192 | self._boards = boards.Boards() |
Simon Glass | 938fa37 | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 193 | for brd in BOARDS: |
Simon Glass | 6014db6 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 194 | self._boards.add_board(board.Board(*brd)) |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 195 | |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 196 | # Directories where the source been cloned |
| 197 | self._clone_dirs = [] |
| 198 | self._commits = len(commit_shortlog.splitlines()) + 1 |
Simon Glass | 938fa37 | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 199 | self._total_builds = self._commits * len(BOARDS) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 200 | |
| 201 | # Number of calls to make |
| 202 | self._make_calls = 0 |
| 203 | |
| 204 | # Map of [board, commit] to error messages |
| 205 | self._error = {} |
| 206 | |
Simon Glass | f7582ce | 2014-09-05 19:00:22 -0600 | [diff] [blame] | 207 | self._test_branch = TEST_BRANCH |
| 208 | |
Tom Rini | d7713ad | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 209 | # Set to True to report missing blobs |
| 210 | self._missing = False |
| 211 | |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 212 | # Avoid sending any output and clear all terminal output |
Simon Glass | 098b10f | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 213 | terminal.set_print_test_mode() |
| 214 | terminal.get_print_test_lines() |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 215 | |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 216 | def tearDown(self): |
| 217 | shutil.rmtree(self._base_dir) |
Simon Glass | 5f319fa | 2022-11-09 19:14:52 -0700 | [diff] [blame] | 218 | shutil.rmtree(self._output_dir) |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 219 | |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 220 | def setupToolchains(self): |
| 221 | self._toolchains = toolchain.Toolchains() |
| 222 | self._toolchains.Add('gcc', test=False) |
| 223 | |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 224 | def _RunBuildman(self, *args): |
Simon Glass | d980069 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 225 | return command.run_pipe([[self._buildman_pathname] + list(args)], |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 226 | capture=True, capture_stderr=True) |
| 227 | |
Simon Glass | 938fa37 | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 228 | def _RunControl(self, *args, brds=None, clean_dir=False, |
Simon Glass | 8116c78 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 229 | test_thread_exceptions=False): |
Simon Glass | 2499331 | 2021-04-11 16:27:25 +1200 | [diff] [blame] | 230 | """Run buildman |
| 231 | |
| 232 | Args: |
| 233 | args: List of arguments to pass |
Simon Glass | 938fa37 | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 234 | brds: Boards object |
Simon Glass | 2499331 | 2021-04-11 16:27:25 +1200 | [diff] [blame] | 235 | clean_dir: Used for tests only, indicates that the existing output_dir |
| 236 | should be removed before starting the build |
Simon Glass | 8116c78 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 237 | test_thread_exceptions: Uses for tests only, True to make the threads |
| 238 | raise an exception instead of reporting their result. This simulates |
| 239 | a failure in the code somewhere |
Simon Glass | 2499331 | 2021-04-11 16:27:25 +1200 | [diff] [blame] | 240 | |
| 241 | Returns: |
| 242 | result code from buildman |
| 243 | """ |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 244 | sys.argv = [sys.argv[0]] + list(args) |
| 245 | options, args = cmdline.ParseArgs() |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 246 | result = control.DoBuildman(options, args, toolchains=self._toolchains, |
Simon Glass | cc2c0d1 | 2022-07-11 19:04:00 -0600 | [diff] [blame] | 247 | make_func=self._HandleMake, brds=brds or self._boards, |
Simon Glass | 8116c78 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 248 | clean_dir=clean_dir, |
| 249 | test_thread_exceptions=test_thread_exceptions) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 250 | self._builder = control.builder |
| 251 | return result |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 252 | |
| 253 | def testFullHelp(self): |
| 254 | command.test_result = None |
| 255 | result = self._RunBuildman('-H') |
Simon Glass | 74df491 | 2022-11-09 19:14:43 -0700 | [diff] [blame] | 256 | help_file = os.path.join(self._buildman_dir, 'README.rst') |
Tom Rini | 3759df0 | 2018-01-16 15:29:50 -0500 | [diff] [blame] | 257 | # Remove possible extraneous strings |
| 258 | extra = '::::::::::::::\n' + help_file + '\n::::::::::::::\n' |
| 259 | gothelp = result.stdout.replace(extra, '') |
| 260 | self.assertEqual(len(gothelp), os.path.getsize(help_file)) |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 261 | self.assertEqual(0, len(result.stderr)) |
| 262 | self.assertEqual(0, result.return_code) |
| 263 | |
| 264 | def testHelp(self): |
| 265 | command.test_result = None |
| 266 | result = self._RunBuildman('-h') |
Simon Glass | 74df491 | 2022-11-09 19:14:43 -0700 | [diff] [blame] | 267 | help_file = os.path.join(self._buildman_dir, 'README.rst') |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 268 | self.assertTrue(len(result.stdout) > 1000) |
| 269 | self.assertEqual(0, len(result.stderr)) |
| 270 | self.assertEqual(0, result.return_code) |
| 271 | |
| 272 | def testGitSetup(self): |
| 273 | """Test gitutils.Setup(), from outside the module itself""" |
| 274 | command.test_result = command.CommandResult(return_code=1) |
Simon Glass | 0157b18 | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 275 | gitutil.setup() |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 276 | self.assertEqual(gitutil.use_no_decorate, False) |
| 277 | |
| 278 | command.test_result = command.CommandResult(return_code=0) |
Simon Glass | 0157b18 | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 279 | gitutil.setup() |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 280 | self.assertEqual(gitutil.use_no_decorate, True) |
| 281 | |
| 282 | def _HandleCommandGitLog(self, args): |
Simon Glass | d4c8572 | 2016-03-12 18:50:31 -0700 | [diff] [blame] | 283 | if args[-1] == '--': |
| 284 | args = args[:-1] |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 285 | if '-n0' in args: |
| 286 | return command.CommandResult(return_code=0) |
Simon Glass | f7582ce | 2014-09-05 19:00:22 -0600 | [diff] [blame] | 287 | elif args[-1] == 'upstream/master..%s' % self._test_branch: |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 288 | return command.CommandResult(return_code=0, stdout=commit_shortlog) |
| 289 | elif args[:3] == ['--no-color', '--no-decorate', '--reverse']: |
Simon Glass | f7582ce | 2014-09-05 19:00:22 -0600 | [diff] [blame] | 290 | if args[-1] == self._test_branch: |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 291 | count = int(args[3][2:]) |
| 292 | return command.CommandResult(return_code=0, |
| 293 | stdout=''.join(commit_log[:count])) |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 294 | |
| 295 | # Not handled, so abort |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 296 | print('git log', args) |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 297 | sys.exit(1) |
| 298 | |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 299 | def _HandleCommandGitConfig(self, args): |
| 300 | config = args[0] |
| 301 | if config == 'sendemail.aliasesfile': |
| 302 | return command.CommandResult(return_code=0) |
| 303 | elif config.startswith('branch.badbranch'): |
| 304 | return command.CommandResult(return_code=1) |
Simon Glass | f7582ce | 2014-09-05 19:00:22 -0600 | [diff] [blame] | 305 | elif config == 'branch.%s.remote' % self._test_branch: |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 306 | return command.CommandResult(return_code=0, stdout='upstream\n') |
Simon Glass | f7582ce | 2014-09-05 19:00:22 -0600 | [diff] [blame] | 307 | elif config == 'branch.%s.merge' % self._test_branch: |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 308 | return command.CommandResult(return_code=0, |
| 309 | stdout='refs/heads/master\n') |
| 310 | |
| 311 | # Not handled, so abort |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 312 | print('git config', args) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 313 | sys.exit(1) |
| 314 | |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 315 | def _HandleCommandGit(self, in_args): |
| 316 | """Handle execution of a git command |
| 317 | |
| 318 | This uses a hacked-up parser. |
| 319 | |
| 320 | Args: |
| 321 | in_args: Arguments after 'git' from the command line |
| 322 | """ |
| 323 | git_args = [] # Top-level arguments to git itself |
| 324 | sub_cmd = None # Git sub-command selected |
| 325 | args = [] # Arguments to the git sub-command |
| 326 | for arg in in_args: |
| 327 | if sub_cmd: |
| 328 | args.append(arg) |
| 329 | elif arg[0] == '-': |
| 330 | git_args.append(arg) |
| 331 | else: |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 332 | if git_args and git_args[-1] in ['--git-dir', '--work-tree']: |
| 333 | git_args.append(arg) |
| 334 | else: |
| 335 | sub_cmd = arg |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 336 | if sub_cmd == 'config': |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 337 | return self._HandleCommandGitConfig(args) |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 338 | elif sub_cmd == 'log': |
| 339 | return self._HandleCommandGitLog(args) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 340 | elif sub_cmd == 'clone': |
| 341 | return command.CommandResult(return_code=0) |
| 342 | elif sub_cmd == 'checkout': |
| 343 | return command.CommandResult(return_code=0) |
Alper Nebi Yasak | 76de29f | 2020-09-03 15:51:03 +0300 | [diff] [blame] | 344 | elif sub_cmd == 'worktree': |
| 345 | return command.CommandResult(return_code=0) |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 346 | |
| 347 | # Not handled, so abort |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 348 | print('git', git_args, sub_cmd, args) |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 349 | sys.exit(1) |
| 350 | |
| 351 | def _HandleCommandNm(self, args): |
| 352 | return command.CommandResult(return_code=0) |
| 353 | |
| 354 | def _HandleCommandObjdump(self, args): |
| 355 | return command.CommandResult(return_code=0) |
| 356 | |
Alex Kiernan | 0ddc510 | 2018-05-31 04:48:33 +0000 | [diff] [blame] | 357 | def _HandleCommandObjcopy(self, args): |
| 358 | return command.CommandResult(return_code=0) |
| 359 | |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 360 | def _HandleCommandSize(self, args): |
| 361 | return command.CommandResult(return_code=0) |
| 362 | |
| 363 | def _HandleCommand(self, **kwargs): |
| 364 | """Handle a command execution. |
| 365 | |
| 366 | The command is in kwargs['pipe-list'], as a list of pipes, each a |
| 367 | list of commands. The command should be emulated as required for |
| 368 | testing purposes. |
| 369 | |
| 370 | Returns: |
| 371 | A CommandResult object |
| 372 | """ |
| 373 | pipe_list = kwargs['pipe_list'] |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 374 | wc = False |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 375 | if len(pipe_list) != 1: |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 376 | if pipe_list[1] == ['wc', '-l']: |
| 377 | wc = True |
| 378 | else: |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 379 | print('invalid pipe', kwargs) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 380 | sys.exit(1) |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 381 | cmd = pipe_list[0][0] |
| 382 | args = pipe_list[0][1:] |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 383 | result = None |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 384 | if cmd == 'git': |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 385 | result = self._HandleCommandGit(args) |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 386 | elif cmd == './scripts/show-gnu-make': |
| 387 | return command.CommandResult(return_code=0, stdout='make') |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 388 | elif cmd.endswith('nm'): |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 389 | return self._HandleCommandNm(args) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 390 | elif cmd.endswith('objdump'): |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 391 | return self._HandleCommandObjdump(args) |
Alex Kiernan | 0ddc510 | 2018-05-31 04:48:33 +0000 | [diff] [blame] | 392 | elif cmd.endswith('objcopy'): |
| 393 | return self._HandleCommandObjcopy(args) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 394 | elif cmd.endswith( 'size'): |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 395 | return self._HandleCommandSize(args) |
| 396 | |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 397 | if not result: |
| 398 | # Not handled, so abort |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 399 | print('unknown command', kwargs) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 400 | sys.exit(1) |
| 401 | |
| 402 | if wc: |
| 403 | result.stdout = len(result.stdout.splitlines()) |
| 404 | return result |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 405 | |
| 406 | def _HandleMake(self, commit, brd, stage, cwd, *args, **kwargs): |
| 407 | """Handle execution of 'make' |
| 408 | |
| 409 | Args: |
| 410 | commit: Commit object that is being built |
| 411 | brd: Board object that is being built |
| 412 | stage: Stage that we are at (mrproper, config, build) |
| 413 | cwd: Directory where make should be run |
| 414 | args: Arguments to pass to make |
Simon Glass | d980069 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 415 | kwargs: Arguments to pass to command.run_pipe() |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 416 | """ |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 417 | self._make_calls += 1 |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 418 | if stage == 'mrproper': |
| 419 | return command.CommandResult(return_code=0) |
| 420 | elif stage == 'config': |
| 421 | return command.CommandResult(return_code=0, |
| 422 | combined='Test configuration complete') |
| 423 | elif stage == 'build': |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 424 | stderr = '' |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 425 | out_dir = '' |
| 426 | for arg in args: |
| 427 | if arg.startswith('O='): |
| 428 | out_dir = arg[2:] |
| 429 | fname = os.path.join(cwd or '', out_dir, 'u-boot') |
Simon Glass | c1aa66e | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 430 | tools.write_file(fname, b'U-Boot') |
Tom Rini | d7713ad | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 431 | |
| 432 | # Handle missing blobs |
| 433 | if self._missing: |
| 434 | if 'BINMAN_ALLOW_MISSING=1' in args: |
| 435 | stderr = '''+Image 'main-section' is missing external blobs and is non-functional: intel-descriptor intel-ifwi intel-fsp-m intel-fsp-s intel-vbt |
| 436 | Image 'main-section' has faked external blobs and is non-functional: descriptor.bin fsp_m.bin fsp_s.bin vbt.bin |
| 437 | |
| 438 | Some images are invalid''' |
| 439 | else: |
| 440 | stderr = "binman: Filename 'fsp.bin' not found in input path" |
| 441 | elif type(commit) is not str: |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 442 | stderr = self._error.get((brd.target, commit.sequence)) |
Tom Rini | d7713ad | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 443 | |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 444 | if stderr: |
Tom Rini | d7713ad | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 445 | return command.CommandResult(return_code=2, stderr=stderr) |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 446 | return command.CommandResult(return_code=0) |
| 447 | |
| 448 | # Not handled, so abort |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 449 | print('make', stage) |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 450 | sys.exit(1) |
| 451 | |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 452 | # Example function to print output lines |
| 453 | def print_lines(self, lines): |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 454 | print(len(lines)) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 455 | for line in lines: |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 456 | print(line) |
Simon Glass | 098b10f | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 457 | #self.print_lines(terminal.get_print_test_lines()) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 458 | |
Simon Glass | 823e60b | 2014-09-05 19:00:16 -0600 | [diff] [blame] | 459 | def testNoBoards(self): |
| 460 | """Test that buildman aborts when there are no boards""" |
Simon Glass | c52bd22 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 461 | self._boards = boards.Boards() |
Simon Glass | 823e60b | 2014-09-05 19:00:16 -0600 | [diff] [blame] | 462 | with self.assertRaises(SystemExit): |
| 463 | self._RunControl() |
| 464 | |
Simon Glass | d4144e4 | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 465 | def testCurrentSource(self): |
| 466 | """Very simple test to invoke buildman on the current source""" |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 467 | self.setupToolchains(); |
Tom Rini | aae6258 | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 468 | self._RunControl('-o', self._output_dir) |
Simon Glass | 098b10f | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 469 | lines = terminal.get_print_test_lines() |
Simon Glass | 938fa37 | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 470 | self.assertIn('Building current source for %d boards' % len(BOARDS), |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 471 | lines[0].text) |
| 472 | |
| 473 | def testBadBranch(self): |
| 474 | """Test that we can detect an invalid branch""" |
| 475 | with self.assertRaises(ValueError): |
| 476 | self._RunControl('-b', 'badbranch') |
| 477 | |
| 478 | def testBadToolchain(self): |
| 479 | """Test that missing toolchains are detected""" |
| 480 | self.setupToolchains(); |
Tom Rini | aae6258 | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 481 | ret_code = self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir) |
Simon Glass | 098b10f | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 482 | lines = terminal.get_print_test_lines() |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 483 | |
| 484 | # Buildman always builds the upstream commit as well |
| 485 | self.assertIn('Building %d commits for %d boards' % |
Simon Glass | 938fa37 | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 486 | (self._commits, len(BOARDS)), lines[0].text) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 487 | self.assertEqual(self._builder.count, self._total_builds) |
| 488 | |
| 489 | # Only sandbox should succeed, the others don't have toolchains |
| 490 | self.assertEqual(self._builder.fail, |
| 491 | self._total_builds - self._commits) |
Simon Glass | b1e5e6d | 2020-04-09 10:49:45 -0600 | [diff] [blame] | 492 | self.assertEqual(ret_code, 100) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 493 | |
| 494 | for commit in range(self._commits): |
Simon Glass | 6014db6 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 495 | for brd in self._boards.get_list(): |
Simon Glass | f4ed470 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 496 | if brd.arch != 'sandbox': |
| 497 | errfile = self._builder.GetErrFile(commit, brd.target) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 498 | fd = open(errfile) |
| 499 | self.assertEqual(fd.readlines(), |
Simon Glass | f4ed470 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 500 | ['No tool chain for %s\n' % brd.arch]) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 501 | fd.close() |
| 502 | |
| 503 | def testBranch(self): |
| 504 | """Test building a branch with all toolchains present""" |
Tom Rini | aae6258 | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 505 | self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 506 | self.assertEqual(self._builder.count, self._total_builds) |
| 507 | self.assertEqual(self._builder.fail, 0) |
| 508 | |
| 509 | def testCount(self): |
| 510 | """Test building a specific number of commitst""" |
Tom Rini | aae6258 | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 511 | self._RunControl('-b', TEST_BRANCH, '-c2', '-o', self._output_dir) |
Simon Glass | 938fa37 | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 512 | self.assertEqual(self._builder.count, 2 * len(BOARDS)) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 513 | self.assertEqual(self._builder.fail, 0) |
Simon Glass | eb70a2c | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 514 | # Each board has a config, and then one make per commit |
Simon Glass | 938fa37 | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 515 | self.assertEqual(self._make_calls, len(BOARDS) * (1 + 2)) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 516 | |
| 517 | def testIncremental(self): |
| 518 | """Test building a branch twice - the second time should do nothing""" |
Tom Rini | aae6258 | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 519 | self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 520 | |
| 521 | # Each board has a mrproper, config, and then one make per commit |
Simon Glass | 938fa37 | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 522 | self.assertEqual(self._make_calls, len(BOARDS) * (self._commits + 1)) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 523 | self._make_calls = 0 |
Tom Rini | aae6258 | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 524 | self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir, clean_dir=False) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 525 | self.assertEqual(self._make_calls, 0) |
| 526 | self.assertEqual(self._builder.count, self._total_builds) |
| 527 | self.assertEqual(self._builder.fail, 0) |
| 528 | |
| 529 | def testForceBuild(self): |
| 530 | """The -f flag should force a rebuild""" |
Tom Rini | aae6258 | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 531 | self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 532 | self._make_calls = 0 |
Tom Rini | aae6258 | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 533 | self._RunControl('-b', TEST_BRANCH, '-f', '-o', self._output_dir, clean_dir=False) |
Simon Glass | eb70a2c | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 534 | # Each board has a config and one make per commit |
Simon Glass | 938fa37 | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 535 | self.assertEqual(self._make_calls, len(BOARDS) * (self._commits + 1)) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 536 | |
| 537 | def testForceReconfigure(self): |
| 538 | """The -f flag should force a rebuild""" |
Tom Rini | aae6258 | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 539 | self._RunControl('-b', TEST_BRANCH, '-C', '-o', self._output_dir) |
Simon Glass | eb70a2c | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 540 | # Each commit has a config and make |
Simon Glass | 938fa37 | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 541 | self.assertEqual(self._make_calls, len(BOARDS) * self._commits * 2) |
Simon Glass | eb70a2c | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 542 | |
Simon Glass | eb70a2c | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 543 | def testMrproper(self): |
| 544 | """The -f flag should force a rebuild""" |
| 545 | self._RunControl('-b', TEST_BRANCH, '-m', '-o', self._output_dir) |
| 546 | # Each board has a mkproper, config and then one make per commit |
Simon Glass | 938fa37 | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 547 | self.assertEqual(self._make_calls, len(BOARDS) * (self._commits + 2)) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 548 | |
| 549 | def testErrors(self): |
| 550 | """Test handling of build errors""" |
| 551 | self._error['board2', 1] = 'fred\n' |
Tom Rini | aae6258 | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 552 | self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 553 | self.assertEqual(self._builder.count, self._total_builds) |
| 554 | self.assertEqual(self._builder.fail, 1) |
| 555 | |
| 556 | # Remove the error. This should have no effect since the commit will |
| 557 | # not be rebuilt |
| 558 | del self._error['board2', 1] |
| 559 | self._make_calls = 0 |
Tom Rini | aae6258 | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 560 | self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir, clean_dir=False) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 561 | self.assertEqual(self._builder.count, self._total_builds) |
| 562 | self.assertEqual(self._make_calls, 0) |
| 563 | self.assertEqual(self._builder.fail, 1) |
| 564 | |
| 565 | # Now use the -F flag to force rebuild of the bad commit |
Tom Rini | aae6258 | 2019-10-07 17:17:36 -0400 | [diff] [blame] | 566 | self._RunControl('-b', TEST_BRANCH, '-o', self._output_dir, '-F', clean_dir=False) |
Simon Glass | dfb7e93 | 2014-09-05 19:00:20 -0600 | [diff] [blame] | 567 | self.assertEqual(self._builder.count, self._total_builds) |
| 568 | self.assertEqual(self._builder.fail, 0) |
Simon Glass | eb70a2c | 2020-04-09 15:08:51 -0600 | [diff] [blame] | 569 | self.assertEqual(self._make_calls, 2) |
Simon Glass | f7582ce | 2014-09-05 19:00:22 -0600 | [diff] [blame] | 570 | |
| 571 | def testBranchWithSlash(self): |
| 572 | """Test building a branch with a '/' in the name""" |
| 573 | self._test_branch = '/__dev/__testbranch' |
| 574 | self._RunControl('-b', self._test_branch, clean_dir=False) |
| 575 | self.assertEqual(self._builder.count, self._total_builds) |
| 576 | self.assertEqual(self._builder.fail, 0) |
Lothar Waßmann | 409fc02 | 2018-04-08 05:14:11 -0600 | [diff] [blame] | 577 | |
Simon Glass | 166a98a | 2020-04-17 17:51:33 -0600 | [diff] [blame] | 578 | def testEnvironment(self): |
| 579 | """Test that the done and environment files are written to out-env""" |
| 580 | self._RunControl('-o', self._output_dir) |
| 581 | board0_dir = os.path.join(self._output_dir, 'current', 'board0') |
| 582 | self.assertTrue(os.path.exists(os.path.join(board0_dir, 'done'))) |
| 583 | self.assertTrue(os.path.exists(os.path.join(board0_dir, 'out-env'))) |
| 584 | |
Simon Glass | f1a83ab | 2021-04-11 16:27:28 +1200 | [diff] [blame] | 585 | def testEnvironmentUnicode(self): |
| 586 | """Test there are no unicode errors when the env has non-ASCII chars""" |
| 587 | try: |
| 588 | varname = b'buildman_test_var' |
| 589 | os.environb[varname] = b'strange\x80chars' |
| 590 | self.assertEqual(0, self._RunControl('-o', self._output_dir)) |
| 591 | board0_dir = os.path.join(self._output_dir, 'current', 'board0') |
| 592 | self.assertTrue(os.path.exists(os.path.join(board0_dir, 'done'))) |
| 593 | self.assertTrue(os.path.exists(os.path.join(board0_dir, 'out-env'))) |
| 594 | finally: |
| 595 | del os.environb[varname] |
| 596 | |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 597 | def testWorkInOutput(self): |
| 598 | """Test the -w option which should write directly to the output dir""" |
Simon Glass | c52bd22 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 599 | board_list = boards.Boards() |
Simon Glass | 6014db6 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 600 | board_list.add_board(board.Board(*BOARDS[0])) |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 601 | self._RunControl('-o', self._output_dir, '-w', clean_dir=False, |
Simon Glass | 938fa37 | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 602 | brds=board_list) |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 603 | self.assertTrue( |
| 604 | os.path.exists(os.path.join(self._output_dir, 'u-boot'))) |
Simon Glass | 60b285f | 2020-04-17 17:51:34 -0600 | [diff] [blame] | 605 | self.assertTrue( |
| 606 | os.path.exists(os.path.join(self._output_dir, 'done'))) |
| 607 | self.assertTrue( |
| 608 | os.path.exists(os.path.join(self._output_dir, 'out-env'))) |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 609 | |
| 610 | def testWorkInOutputFail(self): |
| 611 | """Test the -w option failures""" |
| 612 | with self.assertRaises(SystemExit) as e: |
| 613 | self._RunControl('-o', self._output_dir, '-w', clean_dir=False) |
| 614 | self.assertIn("single board", str(e.exception)) |
| 615 | self.assertFalse( |
| 616 | os.path.exists(os.path.join(self._output_dir, 'u-boot'))) |
| 617 | |
Simon Glass | c52bd22 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 618 | board_list = boards.Boards() |
Simon Glass | 6014db6 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 619 | board_list.add_board(board.Board(*BOARDS[0])) |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 620 | with self.assertRaises(SystemExit) as e: |
| 621 | self._RunControl('-b', self._test_branch, '-o', self._output_dir, |
Simon Glass | 938fa37 | 2022-07-11 19:03:58 -0600 | [diff] [blame] | 622 | '-w', clean_dir=False, brds=board_list) |
Simon Glass | d829f12 | 2020-03-18 09:42:42 -0600 | [diff] [blame] | 623 | self.assertIn("single commit", str(e.exception)) |
Simon Glass | 88daaef | 2020-04-17 17:51:32 -0600 | [diff] [blame] | 624 | |
Simon Glass | c52bd22 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 625 | board_list = boards.Boards() |
Simon Glass | 6014db6 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 626 | board_list.add_board(board.Board(*BOARDS[0])) |
Simon Glass | 88daaef | 2020-04-17 17:51:32 -0600 | [diff] [blame] | 627 | with self.assertRaises(SystemExit) as e: |
| 628 | self._RunControl('-w', clean_dir=False) |
| 629 | self.assertIn("specify -o", str(e.exception)) |
Simon Glass | 8116c78 | 2021-04-11 16:27:27 +1200 | [diff] [blame] | 630 | |
| 631 | def testThreadExceptions(self): |
| 632 | """Test that exceptions in threads are reported""" |
| 633 | with test_util.capture_sys_output() as (stdout, stderr): |
| 634 | self.assertEqual(102, self._RunControl('-o', self._output_dir, |
| 635 | test_thread_exceptions=True)) |
Simon Glass | 8ca0931 | 2022-01-22 05:07:32 -0700 | [diff] [blame] | 636 | self.assertIn( |
| 637 | 'Thread exception (use -T0 to run without threads): test exception', |
| 638 | stdout.getvalue()) |
Tom Rini | d7713ad | 2022-11-09 19:14:53 -0700 | [diff] [blame] | 639 | |
| 640 | def testBlobs(self): |
| 641 | """Test handling of missing blobs""" |
| 642 | self._missing = True |
| 643 | |
| 644 | board0_dir = os.path.join(self._output_dir, 'current', 'board0') |
| 645 | errfile = os.path.join(board0_dir, 'err') |
| 646 | logfile = os.path.join(board0_dir, 'log') |
| 647 | |
| 648 | # We expect failure when there are missing blobs |
| 649 | result = self._RunControl('board0', '-o', self._output_dir) |
| 650 | self.assertEqual(100, result) |
| 651 | self.assertTrue(os.path.exists(os.path.join(board0_dir, 'done'))) |
| 652 | self.assertTrue(os.path.exists(errfile)) |
| 653 | self.assertIn(b"Filename 'fsp.bin' not found in input path", |
| 654 | tools.read_file(errfile)) |
| 655 | |
| 656 | def testBlobsAllowMissing(self): |
| 657 | """Allow missing blobs - still failure but a different exit code""" |
| 658 | self._missing = True |
| 659 | result = self._RunControl('board0', '-o', self._output_dir, '-M', |
| 660 | clean_dir=True) |
| 661 | self.assertEqual(101, result) |
| 662 | board0_dir = os.path.join(self._output_dir, 'current', 'board0') |
| 663 | errfile = os.path.join(board0_dir, 'err') |
| 664 | self.assertTrue(os.path.exists(errfile)) |
| 665 | self.assertIn(b'Some images are invalid', tools.read_file(errfile)) |
| 666 | |
| 667 | def testBlobsWarning(self): |
| 668 | """Allow missing blobs and ignore warnings""" |
| 669 | self._missing = True |
| 670 | result = self._RunControl('board0', '-o', self._output_dir, '-MW') |
| 671 | self.assertEqual(0, result) |
| 672 | board0_dir = os.path.join(self._output_dir, 'current', 'board0') |
| 673 | errfile = os.path.join(board0_dir, 'err') |
| 674 | self.assertIn(b'Some images are invalid', tools.read_file(errfile)) |
| 675 | |
| 676 | def testBlobSettings(self): |
| 677 | """Test with no settings""" |
| 678 | self.assertEqual(False, |
| 679 | control.get_allow_missing(False, False, 1, False)) |
| 680 | self.assertEqual(True, |
| 681 | control.get_allow_missing(True, False, 1, False)) |
| 682 | self.assertEqual(False, |
| 683 | control.get_allow_missing(True, True, 1, False)) |
| 684 | |
| 685 | def testBlobSettingsAlways(self): |
| 686 | """Test the 'always' policy""" |
| 687 | bsettings.SetItem('global', 'allow-missing', 'always') |
| 688 | self.assertEqual(True, |
| 689 | control.get_allow_missing(False, False, 1, False)) |
| 690 | self.assertEqual(False, |
| 691 | control.get_allow_missing(False, True, 1, False)) |
| 692 | |
| 693 | def testBlobSettingsBranch(self): |
| 694 | """Test the 'branch' policy""" |
| 695 | bsettings.SetItem('global', 'allow-missing', 'branch') |
| 696 | self.assertEqual(False, |
| 697 | control.get_allow_missing(False, False, 1, False)) |
| 698 | self.assertEqual(True, |
| 699 | control.get_allow_missing(False, False, 1, True)) |
| 700 | self.assertEqual(False, |
| 701 | control.get_allow_missing(False, True, 1, True)) |
| 702 | |
| 703 | def testBlobSettingsMultiple(self): |
| 704 | """Test the 'multiple' policy""" |
| 705 | bsettings.SetItem('global', 'allow-missing', 'multiple') |
| 706 | self.assertEqual(False, |
| 707 | control.get_allow_missing(False, False, 1, False)) |
| 708 | self.assertEqual(True, |
| 709 | control.get_allow_missing(False, False, 2, False)) |
| 710 | self.assertEqual(False, |
| 711 | control.get_allow_missing(False, True, 2, False)) |
| 712 | |
| 713 | def testBlobSettingsBranchMultiple(self): |
| 714 | """Test the 'branch multiple' policy""" |
| 715 | bsettings.SetItem('global', 'allow-missing', 'branch multiple') |
| 716 | self.assertEqual(False, |
| 717 | control.get_allow_missing(False, False, 1, False)) |
| 718 | self.assertEqual(True, |
| 719 | control.get_allow_missing(False, False, 1, True)) |
| 720 | self.assertEqual(True, |
| 721 | control.get_allow_missing(False, False, 2, False)) |
| 722 | self.assertEqual(True, |
| 723 | control.get_allow_missing(False, False, 2, True)) |
| 724 | self.assertEqual(False, |
| 725 | control.get_allow_missing(False, True, 2, True)) |
Simon Glass | cd37d5b | 2023-02-21 12:40:27 -0700 | [diff] [blame] | 726 | |
Simon Glass | 93202d7 | 2023-02-21 12:40:28 -0700 | [diff] [blame^] | 727 | def check_command(self, *extra_args): |
| 728 | """Run a command with the extra arguments and return the commands used |
| 729 | |
| 730 | Args: |
| 731 | extra_args (list of str): List of extra arguments |
| 732 | |
| 733 | Returns: |
| 734 | list of str: Lines returned in the out-cmd file |
| 735 | """ |
| 736 | self._RunControl('-o', self._output_dir, *extra_args) |
Simon Glass | cd37d5b | 2023-02-21 12:40:27 -0700 | [diff] [blame] | 737 | board0_dir = os.path.join(self._output_dir, 'current', 'board0') |
| 738 | self.assertTrue(os.path.exists(os.path.join(board0_dir, 'done'))) |
| 739 | cmd_fname = os.path.join(board0_dir, 'out-cmd') |
| 740 | self.assertTrue(os.path.exists(cmd_fname)) |
| 741 | data = tools.read_file(cmd_fname) |
Simon Glass | 93202d7 | 2023-02-21 12:40:28 -0700 | [diff] [blame^] | 742 | return data.splitlines() |
| 743 | |
| 744 | def testCmdFile(self): |
| 745 | """Test that the -cmd-out file is produced""" |
| 746 | lines = self.check_command() |
Simon Glass | cd37d5b | 2023-02-21 12:40:27 -0700 | [diff] [blame] | 747 | self.assertEqual(2, len(lines)) |
| 748 | self.assertRegex(lines[0], b'make O=/.*board0_defconfig') |
| 749 | self.assertRegex(lines[0], b'make O=/.*-s.*') |
Simon Glass | 93202d7 | 2023-02-21 12:40:28 -0700 | [diff] [blame^] | 750 | |
| 751 | def testNoLto(self): |
| 752 | """Test that the --no-lto flag works""" |
| 753 | lines = self.check_command('-L') |
| 754 | self.assertIn(b'NO_LTO=1', lines[0]) |
| 755 | |