Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 2 | # Copyright (c) 2012 The Chromium OS Authors. |
| 3 | # |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 4 | |
Simon Glass | c229d32 | 2024-06-23 11:55:15 -0600 | [diff] [blame] | 5 | from filelock import FileLock |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 6 | import os |
| 7 | import shutil |
| 8 | import sys |
| 9 | import tempfile |
| 10 | import time |
| 11 | import unittest |
Simon Glass | c229d32 | 2024-06-23 11:55:15 -0600 | [diff] [blame] | 12 | from unittest.mock import patch |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 13 | |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 14 | from buildman import board |
Simon Glass | 20751d6 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 15 | from buildman import boards |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 16 | from buildman import bsettings |
| 17 | from buildman import builder |
Simon Glass | 22901f9 | 2022-01-22 05:07:31 -0700 | [diff] [blame] | 18 | from buildman import cfgutil |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 19 | from buildman import control |
| 20 | from buildman import toolchain |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 21 | from patman import commit |
Simon Glass | 131444f | 2023-02-23 18:18:04 -0700 | [diff] [blame] | 22 | from u_boot_pylib import command |
| 23 | from u_boot_pylib import terminal |
| 24 | from u_boot_pylib import test_util |
| 25 | from u_boot_pylib import tools |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 26 | |
Simon Glass | 2bfc697 | 2017-11-12 21:52:14 -0700 | [diff] [blame] | 27 | use_network = True |
| 28 | |
Simon Glass | 4bea81e | 2014-12-01 17:34:04 -0700 | [diff] [blame] | 29 | settings_data = ''' |
| 30 | # Buildman settings file |
| 31 | |
| 32 | [toolchain] |
| 33 | main: /usr/sbin |
| 34 | |
| 35 | [toolchain-alias] |
| 36 | x86: i386 x86_64 |
| 37 | ''' |
| 38 | |
Jerome Forissier | aa27695 | 2024-09-11 11:58:14 +0200 | [diff] [blame] | 39 | settings_data_wrapper = ''' |
| 40 | # Buildman settings file |
| 41 | |
| 42 | [toolchain] |
| 43 | main: /usr/sbin |
| 44 | |
| 45 | [toolchain-wrapper] |
| 46 | wrapper = ccache |
| 47 | ''' |
| 48 | |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 49 | migration = '''===================== WARNING ====================== |
| 50 | This board does not use CONFIG_DM. CONFIG_DM will be |
| 51 | compulsory starting with the v2020.01 release. |
| 52 | Failure to update may result in board removal. |
Johannes Krottmayer | ce53c8b | 2022-03-01 04:49:51 +0100 | [diff] [blame] | 53 | See doc/develop/driver-model/migration.rst for more info. |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 54 | ==================================================== |
| 55 | ''' |
| 56 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 57 | errors = [ |
| 58 | '''main.c: In function 'main_loop': |
| 59 | main.c:260:6: warning: unused variable 'joe' [-Wunused-variable] |
| 60 | ''', |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 61 | '''main.c: In function 'main_loop2': |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 62 | main.c:295:2: error: 'fred' undeclared (first use in this function) |
| 63 | main.c:295:2: note: each undeclared identifier is reported only once for each function it appears in |
| 64 | make[1]: *** [main.o] Error 1 |
| 65 | make: *** [common/libcommon.o] Error 2 |
| 66 | Make failed |
| 67 | ''', |
Simon Glass | 0db9443 | 2018-11-06 16:02:11 -0700 | [diff] [blame] | 68 | '''arch/arm/dts/socfpga_arria10_socdk_sdmmc.dtb: Warning \ |
| 69 | (avoid_unnecessary_addr_size): /clocks: unnecessary #address-cells/#size-cells \ |
| 70 | without "ranges" or child "reg" property |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 71 | ''', |
| 72 | '''powerpc-linux-ld: warning: dot moved backwards before `.bss' |
| 73 | powerpc-linux-ld: warning: dot moved backwards before `.bss' |
| 74 | powerpc-linux-ld: u-boot: section .text lma 0xfffc0000 overlaps previous sections |
| 75 | powerpc-linux-ld: u-boot: section .rodata lma 0xfffef3ec overlaps previous sections |
| 76 | powerpc-linux-ld: u-boot: section .reloc lma 0xffffa400 overlaps previous sections |
| 77 | powerpc-linux-ld: u-boot: section .data lma 0xffffcd38 overlaps previous sections |
| 78 | powerpc-linux-ld: u-boot: section .u_boot_cmd lma 0xffffeb40 overlaps previous sections |
| 79 | powerpc-linux-ld: u-boot: section .bootpg lma 0xfffff198 overlaps previous sections |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 80 | ''', |
| 81 | '''In file included from %(basedir)sarch/sandbox/cpu/cpu.c:9:0: |
| 82 | %(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default] |
| 83 | %(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition |
| 84 | %(basedir)sarch/sandbox/cpu/cpu.c: In function 'do_reset': |
| 85 | %(basedir)sarch/sandbox/cpu/cpu.c:27:1: error: unknown type name 'blah' |
| 86 | %(basedir)sarch/sandbox/cpu/cpu.c:28:12: error: expected declaration specifiers or '...' before numeric constant |
| 87 | make[2]: *** [arch/sandbox/cpu/cpu.o] Error 1 |
| 88 | make[1]: *** [arch/sandbox/cpu] Error 2 |
| 89 | make[1]: *** Waiting for unfinished jobs.... |
| 90 | In file included from %(basedir)scommon/board_f.c:55:0: |
| 91 | %(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default] |
| 92 | %(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition |
| 93 | make: *** [sub-make] Error 2 |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 94 | ''' |
| 95 | ] |
| 96 | |
| 97 | |
| 98 | # hash, subject, return code, list of errors/warnings |
| 99 | commits = [ |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 100 | ['1234', 'upstream/master, migration warning', 0, []], |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 101 | ['5678', 'Second commit, a warning', 0, errors[0:1]], |
| 102 | ['9012', 'Third commit, error', 1, errors[0:2]], |
| 103 | ['3456', 'Fourth commit, warning', 0, [errors[0], errors[2]]], |
| 104 | ['7890', 'Fifth commit, link errors', 1, [errors[0], errors[3]]], |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 105 | ['abcd', 'Sixth commit, fixes all errors', 0, []], |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 106 | ['ef01', 'Seventh commit, fix migration, check directory suppression', 1, |
| 107 | [errors[4]]], |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 108 | ] |
| 109 | |
Simon Glass | b0786df | 2022-07-11 19:03:59 -0600 | [diff] [blame] | 110 | BOARDS = [ |
Simon Glass | 584cf86 | 2013-09-23 17:35:16 -0600 | [diff] [blame] | 111 | ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board0', ''], |
| 112 | ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 2', 'board1', ''], |
| 113 | ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''], |
Simon Glass | 5e0f06d | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 114 | ['Active', 'powerpc', 'mpc83xx', '', 'Tester', 'PowerPC board 2', 'board3', ''], |
Simon Glass | 584cf86 | 2013-09-23 17:35:16 -0600 | [diff] [blame] | 115 | ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''], |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 116 | ] |
| 117 | |
Simon Glass | 2e1646c | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 118 | BASE_DIR = 'base' |
| 119 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 120 | OUTCOME_OK, OUTCOME_WARN, OUTCOME_ERR = range(3) |
| 121 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 122 | class Options: |
| 123 | """Class that holds build options""" |
| 124 | pass |
| 125 | |
| 126 | class TestBuild(unittest.TestCase): |
| 127 | """Test buildman |
| 128 | |
| 129 | TODO: Write tests for the rest of the functionality |
| 130 | """ |
| 131 | def setUp(self): |
| 132 | # Set up commits to build |
| 133 | self.commits = [] |
| 134 | sequence = 0 |
| 135 | for commit_info in commits: |
| 136 | comm = commit.Commit(commit_info[0]) |
| 137 | comm.subject = commit_info[1] |
| 138 | comm.return_code = commit_info[2] |
| 139 | comm.error_list = commit_info[3] |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 140 | if sequence < 6: |
| 141 | comm.error_list += [migration] |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 142 | comm.sequence = sequence |
| 143 | sequence += 1 |
| 144 | self.commits.append(comm) |
| 145 | |
| 146 | # Set up boards to build |
Simon Glass | 20751d6 | 2022-07-11 19:04:03 -0600 | [diff] [blame] | 147 | self.brds = boards.Boards() |
Simon Glass | b0786df | 2022-07-11 19:03:59 -0600 | [diff] [blame] | 148 | for brd in BOARDS: |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 149 | self.brds.add_board(board.Board(*brd)) |
| 150 | self.brds.select_boards([]) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 151 | |
Simon Glass | 4bea81e | 2014-12-01 17:34:04 -0700 | [diff] [blame] | 152 | # Add some test settings |
Simon Glass | 06b83a5 | 2023-07-19 17:49:05 -0600 | [diff] [blame] | 153 | bsettings.setup(None) |
| 154 | bsettings.add_file(settings_data) |
Simon Glass | 4bea81e | 2014-12-01 17:34:04 -0700 | [diff] [blame] | 155 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 156 | # Set up the toolchains |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 157 | self.toolchains = toolchain.Toolchains() |
| 158 | self.toolchains.Add('arm-linux-gcc', test=False) |
| 159 | self.toolchains.Add('sparc-linux-gcc', test=False) |
| 160 | self.toolchains.Add('powerpc-linux-gcc', test=False) |
Simon Glass | 038a3dd | 2024-08-15 13:57:44 -0600 | [diff] [blame] | 161 | self.toolchains.Add('/path/to/aarch64-linux-gcc', test=False) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 162 | self.toolchains.Add('gcc', test=False) |
| 163 | |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 164 | # Avoid sending any output |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 165 | terminal.set_print_test_mode() |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 166 | self._col = terminal.Color() |
| 167 | |
Simon Glass | 09bbfcd | 2020-04-09 15:08:31 -0600 | [diff] [blame] | 168 | self.base_dir = tempfile.mkdtemp() |
| 169 | if not os.path.isdir(self.base_dir): |
| 170 | os.mkdir(self.base_dir) |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 171 | |
Simon Glass | c229d32 | 2024-06-23 11:55:15 -0600 | [diff] [blame] | 172 | self.cur_time = 0 |
| 173 | self.valid_pids = [] |
| 174 | self.finish_time = None |
| 175 | self.finish_pid = None |
| 176 | |
Simon Glass | 09bbfcd | 2020-04-09 15:08:31 -0600 | [diff] [blame] | 177 | def tearDown(self): |
| 178 | shutil.rmtree(self.base_dir) |
| 179 | |
| 180 | def Make(self, commit, brd, stage, *args, **kwargs): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 181 | result = command.CommandResult() |
| 182 | boardnum = int(brd.target[-1]) |
| 183 | result.return_code = 0 |
| 184 | result.stderr = '' |
| 185 | result.stdout = ('This is the test output for board %s, commit %s' % |
| 186 | (brd.target, commit.hash)) |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 187 | if ((boardnum >= 1 and boardnum >= commit.sequence) or |
| 188 | boardnum == 4 and commit.sequence == 6): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 189 | result.return_code = commit.return_code |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 190 | result.stderr = (''.join(commit.error_list) |
Simon Glass | 09bbfcd | 2020-04-09 15:08:31 -0600 | [diff] [blame] | 191 | % {'basedir' : self.base_dir + '/.bm-work/00/'}) |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 192 | elif commit.sequence < 6: |
| 193 | result.stderr = migration |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 194 | |
| 195 | result.combined = result.stdout + result.stderr |
| 196 | return result |
| 197 | |
Simon Glass | b0786df | 2022-07-11 19:03:59 -0600 | [diff] [blame] | 198 | def assertSummary(self, text, arch, plus, brds, outcome=OUTCOME_ERR): |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 199 | col = self._col |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 200 | expected_colour = (col.GREEN if outcome == OUTCOME_OK else |
| 201 | col.YELLOW if outcome == OUTCOME_WARN else col.RED) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 202 | expect = '%10s: ' % arch |
| 203 | # TODO(sjg@chromium.org): If plus is '', we shouldn't need this |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 204 | expect += ' ' + col.build(expected_colour, plus) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 205 | expect += ' ' |
Simon Glass | b0786df | 2022-07-11 19:03:59 -0600 | [diff] [blame] | 206 | for brd in brds: |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 207 | expect += col.build(expected_colour, ' %s' % brd) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 208 | self.assertEqual(text, expect) |
| 209 | |
Simon Glass | c635d89 | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 210 | def _SetupTest(self, echo_lines=False, threads=1, **kwdisplay_args): |
Simon Glass | 724c175 | 2020-04-09 15:08:32 -0600 | [diff] [blame] | 211 | """Set up the test by running a build and summary |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 212 | |
Simon Glass | 724c175 | 2020-04-09 15:08:32 -0600 | [diff] [blame] | 213 | Args: |
| 214 | echo_lines: True to echo lines to the terminal to aid test |
| 215 | development |
Heinrich Schuchardt | 3715311 | 2024-04-19 13:37:46 +0200 | [diff] [blame] | 216 | kwdisplay_args: Dict of arguments to pass to |
Simon Glass | 724c175 | 2020-04-09 15:08:32 -0600 | [diff] [blame] | 217 | Builder.SetDisplayOptions() |
| 218 | |
| 219 | Returns: |
| 220 | Iterator containing the output lines, each a PrintLine() object |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 221 | """ |
Simon Glass | c635d89 | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 222 | build = builder.Builder(self.toolchains, self.base_dir, None, threads, |
| 223 | 2, checkout=False, show_unknown=False) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 224 | build.do_make = self.Make |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 225 | board_selected = self.brds.get_selected_dict() |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 226 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 227 | # Build the boards for the pre-defined commits and warnings/errors |
| 228 | # associated with each. This calls our Make() to inject the fake output. |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 229 | build.build_boards(self.commits, board_selected, keep_outputs=False, |
| 230 | verbose=False) |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 231 | lines = terminal.get_print_test_lines() |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 232 | count = 0 |
| 233 | for line in lines: |
| 234 | if line.text.strip(): |
| 235 | count += 1 |
| 236 | |
Simon Glass | 726ae81 | 2020-04-09 15:08:47 -0600 | [diff] [blame] | 237 | # We should get two starting messages, an update for every commit built |
| 238 | # and a summary message |
Simon Glass | b0786df | 2022-07-11 19:03:59 -0600 | [diff] [blame] | 239 | self.assertEqual(count, len(commits) * len(BOARDS) + 3) |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 240 | build.set_display_options(**kwdisplay_args); |
| 241 | build.show_summary(self.commits, board_selected) |
Simon Glass | 724c175 | 2020-04-09 15:08:32 -0600 | [diff] [blame] | 242 | if echo_lines: |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 243 | terminal.echo_print_test_lines() |
| 244 | return iter(terminal.get_print_test_lines()) |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 245 | |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 246 | def _CheckOutput(self, lines, list_error_boards=False, |
| 247 | filter_dtb_warnings=False, |
| 248 | filter_migration_warnings=False): |
Simon Glass | 724c175 | 2020-04-09 15:08:32 -0600 | [diff] [blame] | 249 | """Check for expected output from the build summary |
| 250 | |
| 251 | Args: |
| 252 | lines: Iterator containing the lines returned from the summary |
Simon Glass | dacbe1e | 2020-04-09 15:08:34 -0600 | [diff] [blame] | 253 | list_error_boards: Adjust the check for output produced with the |
| 254 | --list-error-boards flag |
Simon Glass | 9ea9381 | 2020-04-09 15:08:52 -0600 | [diff] [blame] | 255 | filter_dtb_warnings: Adjust the check for output produced with the |
| 256 | --filter-dtb-warnings flag |
Simon Glass | 724c175 | 2020-04-09 15:08:32 -0600 | [diff] [blame] | 257 | """ |
Simon Glass | b0786df | 2022-07-11 19:03:59 -0600 | [diff] [blame] | 258 | def add_line_prefix(prefix, brds, error_str, colour): |
Simon Glass | 6643eb4 | 2020-04-09 15:08:33 -0600 | [diff] [blame] | 259 | """Add a prefix to each line of a string |
| 260 | |
| 261 | The training \n in error_str is removed before processing |
| 262 | |
| 263 | Args: |
| 264 | prefix: String prefix to add |
| 265 | error_str: Error string containing the lines |
Simon Glass | ea49f9b | 2020-04-09 15:08:37 -0600 | [diff] [blame] | 266 | colour: Expected colour for the line. Note that the board list, |
| 267 | if present, always appears in magenta |
Simon Glass | 6643eb4 | 2020-04-09 15:08:33 -0600 | [diff] [blame] | 268 | |
| 269 | Returns: |
| 270 | New string where each line has the prefix added |
| 271 | """ |
| 272 | lines = error_str.strip().splitlines() |
Simon Glass | ea49f9b | 2020-04-09 15:08:37 -0600 | [diff] [blame] | 273 | new_lines = [] |
| 274 | for line in lines: |
Simon Glass | b0786df | 2022-07-11 19:03:59 -0600 | [diff] [blame] | 275 | if brds: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 276 | expect = self._col.build(colour, prefix + '(') |
Simon Glass | b0786df | 2022-07-11 19:03:59 -0600 | [diff] [blame] | 277 | expect += self._col.build(self._col.MAGENTA, brds, |
Simon Glass | ea49f9b | 2020-04-09 15:08:37 -0600 | [diff] [blame] | 278 | bright=False) |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 279 | expect += self._col.build(colour, ') %s' % line) |
Simon Glass | ea49f9b | 2020-04-09 15:08:37 -0600 | [diff] [blame] | 280 | else: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 281 | expect = self._col.build(colour, prefix + line) |
Simon Glass | ea49f9b | 2020-04-09 15:08:37 -0600 | [diff] [blame] | 282 | new_lines.append(expect) |
Simon Glass | 6643eb4 | 2020-04-09 15:08:33 -0600 | [diff] [blame] | 283 | return '\n'.join(new_lines) |
| 284 | |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 285 | col = terminal.Color() |
| 286 | boards01234 = ('board0 board1 board2 board3 board4' |
| 287 | if list_error_boards else '') |
Simon Glass | 070589b | 2020-04-09 15:08:38 -0600 | [diff] [blame] | 288 | boards1234 = 'board1 board2 board3 board4' if list_error_boards else '' |
| 289 | boards234 = 'board2 board3 board4' if list_error_boards else '' |
| 290 | boards34 = 'board3 board4' if list_error_boards else '' |
Simon Glass | dacbe1e | 2020-04-09 15:08:34 -0600 | [diff] [blame] | 291 | boards4 = 'board4' if list_error_boards else '' |
| 292 | |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 293 | # Upstream commit: migration warnings only |
Simon Glass | 575ce51 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 294 | self.assertEqual(next(lines).text, '01: %s' % commits[0][1]) |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 295 | |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 296 | if not filter_migration_warnings: |
| 297 | self.assertSummary(next(lines).text, 'arm', 'w+', |
| 298 | ['board0', 'board1'], outcome=OUTCOME_WARN) |
| 299 | self.assertSummary(next(lines).text, 'powerpc', 'w+', |
| 300 | ['board2', 'board3'], outcome=OUTCOME_WARN) |
| 301 | self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'], |
| 302 | outcome=OUTCOME_WARN) |
| 303 | |
| 304 | self.assertEqual(next(lines).text, |
| 305 | add_line_prefix('+', boards01234, migration, col.RED)) |
| 306 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 307 | # Second commit: all archs should fail with warnings |
Simon Glass | 575ce51 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 308 | self.assertEqual(next(lines).text, '02: %s' % commits[1][1]) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 309 | |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 310 | if filter_migration_warnings: |
| 311 | self.assertSummary(next(lines).text, 'arm', 'w+', |
| 312 | ['board1'], outcome=OUTCOME_WARN) |
| 313 | self.assertSummary(next(lines).text, 'powerpc', 'w+', |
| 314 | ['board2', 'board3'], outcome=OUTCOME_WARN) |
| 315 | self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'], |
| 316 | outcome=OUTCOME_WARN) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 317 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 318 | # Second commit: The warnings should be listed |
Simon Glass | ea49f9b | 2020-04-09 15:08:37 -0600 | [diff] [blame] | 319 | self.assertEqual(next(lines).text, |
| 320 | add_line_prefix('w+', boards1234, errors[0], col.YELLOW)) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 321 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 322 | # Third commit: Still fails |
Simon Glass | 575ce51 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 323 | self.assertEqual(next(lines).text, '03: %s' % commits[2][1]) |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 324 | if filter_migration_warnings: |
| 325 | self.assertSummary(next(lines).text, 'arm', '', |
| 326 | ['board1'], outcome=OUTCOME_OK) |
Simon Glass | 575ce51 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 327 | self.assertSummary(next(lines).text, 'powerpc', '+', |
| 328 | ['board2', 'board3']) |
| 329 | self.assertSummary(next(lines).text, 'sandbox', '+', ['board4']) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 330 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 331 | # Expect a compiler error |
Simon Glass | ea49f9b | 2020-04-09 15:08:37 -0600 | [diff] [blame] | 332 | self.assertEqual(next(lines).text, |
| 333 | add_line_prefix('+', boards234, errors[1], col.RED)) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 334 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 335 | # Fourth commit: Compile errors are fixed, just have warning for board3 |
Simon Glass | 575ce51 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 336 | self.assertEqual(next(lines).text, '04: %s' % commits[3][1]) |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 337 | if filter_migration_warnings: |
| 338 | expect = '%10s: ' % 'powerpc' |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 339 | expect += ' ' + col.build(col.GREEN, '') |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 340 | expect += ' ' |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 341 | expect += col.build(col.GREEN, ' %s' % 'board2') |
| 342 | expect += ' ' + col.build(col.YELLOW, 'w+') |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 343 | expect += ' ' |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 344 | expect += col.build(col.YELLOW, ' %s' % 'board3') |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 345 | self.assertEqual(next(lines).text, expect) |
| 346 | else: |
| 347 | self.assertSummary(next(lines).text, 'powerpc', 'w+', |
| 348 | ['board2', 'board3'], outcome=OUTCOME_WARN) |
Simon Glass | 575ce51 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 349 | self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'], |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 350 | outcome=OUTCOME_WARN) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 351 | |
| 352 | # Compile error fixed |
Simon Glass | ea49f9b | 2020-04-09 15:08:37 -0600 | [diff] [blame] | 353 | self.assertEqual(next(lines).text, |
| 354 | add_line_prefix('-', boards234, errors[1], col.GREEN)) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 355 | |
Simon Glass | 9ea9381 | 2020-04-09 15:08:52 -0600 | [diff] [blame] | 356 | if not filter_dtb_warnings: |
| 357 | self.assertEqual( |
| 358 | next(lines).text, |
| 359 | add_line_prefix('w+', boards34, errors[2], col.YELLOW)) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 360 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 361 | # Fifth commit |
Simon Glass | 575ce51 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 362 | self.assertEqual(next(lines).text, '05: %s' % commits[4][1]) |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 363 | if filter_migration_warnings: |
| 364 | self.assertSummary(next(lines).text, 'powerpc', '', ['board3'], |
| 365 | outcome=OUTCOME_OK) |
Simon Glass | 575ce51 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 366 | self.assertSummary(next(lines).text, 'sandbox', '+', ['board4']) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 367 | |
| 368 | # The second line of errors[3] is a duplicate, so buildman will drop it |
| 369 | expect = errors[3].rstrip().split('\n') |
| 370 | expect = [expect[0]] + expect[2:] |
Simon Glass | 6643eb4 | 2020-04-09 15:08:33 -0600 | [diff] [blame] | 371 | expect = '\n'.join(expect) |
Simon Glass | ea49f9b | 2020-04-09 15:08:37 -0600 | [diff] [blame] | 372 | self.assertEqual(next(lines).text, |
| 373 | add_line_prefix('+', boards4, expect, col.RED)) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 374 | |
Simon Glass | 9ea9381 | 2020-04-09 15:08:52 -0600 | [diff] [blame] | 375 | if not filter_dtb_warnings: |
| 376 | self.assertEqual( |
| 377 | next(lines).text, |
| 378 | add_line_prefix('w-', boards34, errors[2], col.CYAN)) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 379 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 380 | # Sixth commit |
Simon Glass | 575ce51 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 381 | self.assertEqual(next(lines).text, '06: %s' % commits[5][1]) |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 382 | if filter_migration_warnings: |
| 383 | self.assertSummary(next(lines).text, 'sandbox', '', ['board4'], |
| 384 | outcome=OUTCOME_OK) |
| 385 | else: |
| 386 | self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'], |
| 387 | outcome=OUTCOME_WARN) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 388 | |
| 389 | # The second line of errors[3] is a duplicate, so buildman will drop it |
| 390 | expect = errors[3].rstrip().split('\n') |
| 391 | expect = [expect[0]] + expect[2:] |
Simon Glass | 6643eb4 | 2020-04-09 15:08:33 -0600 | [diff] [blame] | 392 | expect = '\n'.join(expect) |
Simon Glass | ea49f9b | 2020-04-09 15:08:37 -0600 | [diff] [blame] | 393 | self.assertEqual(next(lines).text, |
| 394 | add_line_prefix('-', boards4, expect, col.GREEN)) |
| 395 | self.assertEqual(next(lines).text, |
| 396 | add_line_prefix('w-', boards4, errors[0], col.CYAN)) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 397 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 398 | # Seventh commit |
Simon Glass | 575ce51 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 399 | self.assertEqual(next(lines).text, '07: %s' % commits[6][1]) |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 400 | if filter_migration_warnings: |
| 401 | self.assertSummary(next(lines).text, 'sandbox', '+', ['board4']) |
| 402 | else: |
| 403 | self.assertSummary(next(lines).text, 'arm', '', ['board0', 'board1'], |
| 404 | outcome=OUTCOME_OK) |
| 405 | self.assertSummary(next(lines).text, 'powerpc', '', |
| 406 | ['board2', 'board3'], outcome=OUTCOME_OK) |
| 407 | self.assertSummary(next(lines).text, 'sandbox', '+', ['board4']) |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 408 | |
| 409 | # Pick out the correct error lines |
| 410 | expect_str = errors[4].rstrip().replace('%(basedir)s', '').split('\n') |
| 411 | expect = expect_str[3:8] + [expect_str[-1]] |
Simon Glass | 6643eb4 | 2020-04-09 15:08:33 -0600 | [diff] [blame] | 412 | expect = '\n'.join(expect) |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 413 | if not filter_migration_warnings: |
| 414 | self.assertEqual( |
| 415 | next(lines).text, |
| 416 | add_line_prefix('-', boards01234, migration, col.GREEN)) |
| 417 | |
Simon Glass | ea49f9b | 2020-04-09 15:08:37 -0600 | [diff] [blame] | 418 | self.assertEqual(next(lines).text, |
| 419 | add_line_prefix('+', boards4, expect, col.RED)) |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 420 | |
| 421 | # Now the warnings lines |
| 422 | expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]] |
Simon Glass | 6643eb4 | 2020-04-09 15:08:33 -0600 | [diff] [blame] | 423 | expect = '\n'.join(expect) |
Simon Glass | ea49f9b | 2020-04-09 15:08:37 -0600 | [diff] [blame] | 424 | self.assertEqual(next(lines).text, |
| 425 | add_line_prefix('w+', boards4, expect, col.YELLOW)) |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 426 | |
Simon Glass | 724c175 | 2020-04-09 15:08:32 -0600 | [diff] [blame] | 427 | def testOutput(self): |
| 428 | """Test basic builder operation and output |
| 429 | |
| 430 | This does a line-by-line verification of the summary output. |
| 431 | """ |
| 432 | lines = self._SetupTest(show_errors=True) |
Simon Glass | 9ea9381 | 2020-04-09 15:08:52 -0600 | [diff] [blame] | 433 | self._CheckOutput(lines, list_error_boards=False, |
| 434 | filter_dtb_warnings=False) |
Simon Glass | dacbe1e | 2020-04-09 15:08:34 -0600 | [diff] [blame] | 435 | |
| 436 | def testErrorBoards(self): |
| 437 | """Test output with --list-error-boards |
| 438 | |
| 439 | This does a line-by-line verification of the summary output. |
| 440 | """ |
| 441 | lines = self._SetupTest(show_errors=True, list_error_boards=True) |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 442 | self._CheckOutput(lines, list_error_boards=True) |
Simon Glass | 9ea9381 | 2020-04-09 15:08:52 -0600 | [diff] [blame] | 443 | |
| 444 | def testFilterDtb(self): |
| 445 | """Test output with --filter-dtb-warnings |
| 446 | |
| 447 | This does a line-by-line verification of the summary output. |
| 448 | """ |
| 449 | lines = self._SetupTest(show_errors=True, filter_dtb_warnings=True) |
Simon Glass | f4ebfba | 2020-04-09 15:08:53 -0600 | [diff] [blame] | 450 | self._CheckOutput(lines, filter_dtb_warnings=True) |
| 451 | |
| 452 | def testFilterMigration(self): |
| 453 | """Test output with --filter-migration-warnings |
| 454 | |
| 455 | This does a line-by-line verification of the summary output. |
| 456 | """ |
| 457 | lines = self._SetupTest(show_errors=True, |
| 458 | filter_migration_warnings=True) |
| 459 | self._CheckOutput(lines, filter_migration_warnings=True) |
Simon Glass | 724c175 | 2020-04-09 15:08:32 -0600 | [diff] [blame] | 460 | |
Simon Glass | c635d89 | 2021-01-30 22:17:46 -0700 | [diff] [blame] | 461 | def testSingleThread(self): |
| 462 | """Test operation without threading""" |
| 463 | lines = self._SetupTest(show_errors=True, threads=0) |
| 464 | self._CheckOutput(lines, list_error_boards=False, |
| 465 | filter_dtb_warnings=False) |
| 466 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 467 | def _testGit(self): |
| 468 | """Test basic builder operation by building a branch""" |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 469 | options = Options() |
| 470 | options.git = os.getcwd() |
| 471 | options.summary = False |
| 472 | options.jobs = None |
| 473 | options.dry_run = False |
Simon Glass | 09bbfcd | 2020-04-09 15:08:31 -0600 | [diff] [blame] | 474 | #options.git = os.path.join(self.base_dir, 'repo') |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 475 | options.branch = 'test-buildman' |
| 476 | options.force_build = False |
| 477 | options.list_tool_chains = False |
| 478 | options.count = -1 |
| 479 | options.git_dir = None |
| 480 | options.threads = None |
| 481 | options.show_unknown = False |
| 482 | options.quick = False |
| 483 | options.show_errors = False |
| 484 | options.keep_outputs = False |
| 485 | args = ['tegra20'] |
Simon Glass | c1e1e1d | 2023-07-19 17:48:30 -0600 | [diff] [blame] | 486 | control.do_buildman(options, args) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 487 | |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 488 | def testBoardSingle(self): |
| 489 | """Test single board selection""" |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 490 | self.assertEqual(self.brds.select_boards(['sandbox']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 491 | ({'all': ['board4'], 'sandbox': ['board4']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 492 | |
| 493 | def testBoardArch(self): |
| 494 | """Test single board selection""" |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 495 | self.assertEqual(self.brds.select_boards(['arm']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 496 | ({'all': ['board0', 'board1'], |
| 497 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 498 | |
| 499 | def testBoardArchSingle(self): |
| 500 | """Test single board selection""" |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 501 | self.assertEqual(self.brds.select_boards(['arm sandbox']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 502 | ({'sandbox': ['board4'], |
Simon Glass | 5e0f06d | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 503 | 'all': ['board0', 'board1', 'board4'], |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 504 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | 5e0f06d | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 505 | |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 506 | |
| 507 | def testBoardArchSingleMultiWord(self): |
| 508 | """Test single board selection""" |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 509 | self.assertEqual(self.brds.select_boards(['arm', 'sandbox']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 510 | ({'sandbox': ['board4'], |
| 511 | 'all': ['board0', 'board1', 'board4'], |
| 512 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 513 | |
| 514 | def testBoardSingleAnd(self): |
| 515 | """Test single board selection""" |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 516 | self.assertEqual(self.brds.select_boards(['Tester & arm']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 517 | ({'Tester&arm': ['board0', 'board1'], |
| 518 | 'all': ['board0', 'board1']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 519 | |
| 520 | def testBoardTwoAnd(self): |
| 521 | """Test single board selection""" |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 522 | self.assertEqual(self.brds.select_boards(['Tester', '&', 'arm', |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 523 | 'Tester' '&', 'powerpc', |
| 524 | 'sandbox']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 525 | ({'sandbox': ['board4'], |
Simon Glass | 5e0f06d | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 526 | 'all': ['board0', 'board1', 'board2', 'board3', |
| 527 | 'board4'], |
| 528 | 'Tester&powerpc': ['board2', 'board3'], |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 529 | 'Tester&arm': ['board0', 'board1']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 530 | |
| 531 | def testBoardAll(self): |
| 532 | """Test single board selection""" |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 533 | self.assertEqual(self.brds.select_boards([]), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 534 | ({'all': ['board0', 'board1', 'board2', 'board3', |
| 535 | 'board4']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 536 | |
| 537 | def testBoardRegularExpression(self): |
| 538 | """Test single board selection""" |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 539 | self.assertEqual(self.brds.select_boards(['T.*r&^Po']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 540 | ({'all': ['board2', 'board3'], |
| 541 | 'T.*r&^Po': ['board2', 'board3']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 542 | |
| 543 | def testBoardDuplicate(self): |
| 544 | """Test single board selection""" |
Simon Glass | 127a239 | 2022-07-11 19:04:02 -0600 | [diff] [blame] | 545 | self.assertEqual(self.brds.select_boards(['sandbox sandbox', |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 546 | 'sandbox']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 547 | ({'all': ['board4'], 'sandbox': ['board4']}, [])) |
Simon Glass | 2e1646c | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 548 | def CheckDirs(self, build, dirname): |
Simon Glass | 4cb5468 | 2023-07-19 17:49:10 -0600 | [diff] [blame] | 549 | self.assertEqual('base%s' % dirname, build.get_output_dir(1)) |
Simon Glass | 2e1646c | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 550 | self.assertEqual('base%s/fred' % dirname, |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 551 | build.get_build_dir(1, 'fred')) |
Simon Glass | 2e1646c | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 552 | self.assertEqual('base%s/fred/done' % dirname, |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 553 | build.get_done_file(1, 'fred')) |
Simon Glass | 2e1646c | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 554 | self.assertEqual('base%s/fred/u-boot.sizes' % dirname, |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 555 | build.get_func_sizes_file(1, 'fred', 'u-boot')) |
Simon Glass | 2e1646c | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 556 | self.assertEqual('base%s/fred/u-boot.objdump' % dirname, |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 557 | build.get_objdump_file(1, 'fred', 'u-boot')) |
Simon Glass | 2e1646c | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 558 | self.assertEqual('base%s/fred/err' % dirname, |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 559 | build.get_err_file(1, 'fred')) |
Simon Glass | 2e1646c | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 560 | |
| 561 | def testOutputDir(self): |
| 562 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 563 | checkout=False, show_unknown=False) |
| 564 | build.commits = self.commits |
| 565 | build.commit_count = len(self.commits) |
| 566 | subject = self.commits[1].subject.translate(builder.trans_valid_chars) |
Simon Glass | 3697171 | 2020-07-19 12:28:11 -0600 | [diff] [blame] | 567 | dirname ='/%02d_g%s_%s' % (2, commits[1][0], subject[:20]) |
Simon Glass | 2e1646c | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 568 | self.CheckDirs(build, dirname) |
| 569 | |
| 570 | def testOutputDirCurrent(self): |
| 571 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 572 | checkout=False, show_unknown=False) |
| 573 | build.commits = None |
| 574 | build.commit_count = 0 |
| 575 | self.CheckDirs(build, '/current') |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 576 | |
Simon Glass | e87bde1 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 577 | def testOutputDirNoSubdirs(self): |
| 578 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 579 | checkout=False, show_unknown=False, |
| 580 | no_subdirs=True) |
| 581 | build.commits = None |
| 582 | build.commit_count = 0 |
| 583 | self.CheckDirs(build, '') |
| 584 | |
Simon Glass | c1528c1 | 2014-12-01 17:34:05 -0700 | [diff] [blame] | 585 | def testToolchainAliases(self): |
| 586 | self.assertTrue(self.toolchains.Select('arm') != None) |
| 587 | with self.assertRaises(ValueError): |
| 588 | self.toolchains.Select('no-arch') |
| 589 | with self.assertRaises(ValueError): |
| 590 | self.toolchains.Select('x86') |
| 591 | |
| 592 | self.toolchains = toolchain.Toolchains() |
| 593 | self.toolchains.Add('x86_64-linux-gcc', test=False) |
| 594 | self.assertTrue(self.toolchains.Select('x86') != None) |
| 595 | |
| 596 | self.toolchains = toolchain.Toolchains() |
| 597 | self.toolchains.Add('i386-linux-gcc', test=False) |
| 598 | self.assertTrue(self.toolchains.Select('x86') != None) |
| 599 | |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 600 | def testToolchainDownload(self): |
| 601 | """Test that we can download toolchains""" |
Simon Glass | 2bfc697 | 2017-11-12 21:52:14 -0700 | [diff] [blame] | 602 | if use_network: |
Simon Glass | 0415002 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 603 | with test_util.capture_sys_output() as (stdout, stderr): |
| 604 | url = self.toolchains.LocateArchUrl('arm') |
Brandon Maier | a657bc6 | 2024-06-04 16:16:05 +0000 | [diff] [blame] | 605 | self.assertRegex(url, 'https://www.kernel.org/pub/tools/' |
Simon Glass | 72e358c | 2018-10-01 21:12:35 -0600 | [diff] [blame] | 606 | 'crosstool/files/bin/x86_64/.*/' |
Simon Glass | dd65c5f | 2020-04-17 17:51:30 -0600 | [diff] [blame] | 607 | 'x86_64-gcc-.*-nolibc[-_]arm-.*linux-gnueabi.tar.xz') |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 608 | |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 609 | def testGetEnvArgs(self): |
| 610 | """Test the GetEnvArgs() function""" |
| 611 | tc = self.toolchains.Select('arm') |
| 612 | self.assertEqual('arm-linux-', |
| 613 | tc.GetEnvArgs(toolchain.VAR_CROSS_COMPILE)) |
| 614 | self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_PATH)) |
| 615 | self.assertEqual('arm', |
| 616 | tc.GetEnvArgs(toolchain.VAR_ARCH)) |
| 617 | self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS)) |
| 618 | |
Jerome Forissier | aa27695 | 2024-09-11 11:58:14 +0200 | [diff] [blame] | 619 | tc = self.toolchains.Select('sandbox') |
| 620 | self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_CROSS_COMPILE)) |
| 621 | |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 622 | self.toolchains.Add('/path/to/x86_64-linux-gcc', test=False) |
| 623 | tc = self.toolchains.Select('x86') |
| 624 | self.assertEqual('/path/to', |
| 625 | tc.GetEnvArgs(toolchain.VAR_PATH)) |
| 626 | tc.override_toolchain = 'clang' |
| 627 | self.assertEqual('HOSTCC=clang CC=clang', |
| 628 | tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS)) |
| 629 | |
Jerome Forissier | aa27695 | 2024-09-11 11:58:14 +0200 | [diff] [blame] | 630 | # Test config with ccache wrapper |
| 631 | bsettings.setup(None) |
| 632 | bsettings.add_file(settings_data_wrapper) |
| 633 | |
| 634 | tc = self.toolchains.Select('arm') |
| 635 | self.assertEqual('ccache arm-linux-', |
| 636 | tc.GetEnvArgs(toolchain.VAR_CROSS_COMPILE)) |
| 637 | |
| 638 | tc = self.toolchains.Select('sandbox') |
| 639 | self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_CROSS_COMPILE)) |
| 640 | |
| 641 | def testMakeEnvironment(self): |
| 642 | """Test the MakeEnvironment function""" |
| 643 | tc = self.toolchains.Select('arm') |
| 644 | env = tc.MakeEnvironment(False) |
| 645 | self.assertEqual(env[b'CROSS_COMPILE'], b'arm-linux-') |
| 646 | |
| 647 | tc = self.toolchains.Select('sandbox') |
| 648 | env = tc.MakeEnvironment(False) |
| 649 | self.assertTrue(b'CROSS_COMPILE' not in env) |
| 650 | |
| 651 | # Test config with ccache wrapper |
| 652 | bsettings.setup(None) |
| 653 | bsettings.add_file(settings_data_wrapper) |
| 654 | |
| 655 | tc = self.toolchains.Select('arm') |
| 656 | env = tc.MakeEnvironment(False) |
| 657 | self.assertEqual(env[b'CROSS_COMPILE'], b'ccache arm-linux-') |
| 658 | |
| 659 | tc = self.toolchains.Select('sandbox') |
| 660 | env = tc.MakeEnvironment(False) |
| 661 | self.assertTrue(b'CROSS_COMPILE' not in env) |
| 662 | |
Simon Glass | 5dc1ca7 | 2020-03-18 09:42:45 -0600 | [diff] [blame] | 663 | def testPrepareOutputSpace(self): |
| 664 | def _Touch(fname): |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 665 | tools.write_file(os.path.join(base_dir, fname), b'') |
Simon Glass | 5dc1ca7 | 2020-03-18 09:42:45 -0600 | [diff] [blame] | 666 | |
| 667 | base_dir = tempfile.mkdtemp() |
| 668 | |
| 669 | # Add various files that we want removed and left alone |
Ovidiu Panait | ee8e9cb | 2020-05-15 09:30:12 +0300 | [diff] [blame] | 670 | to_remove = ['01_g0982734987_title', '102_g92bf_title', |
| 671 | '01_g2938abd8_title'] |
| 672 | to_leave = ['something_else', '01-something.patch', '01_another'] |
Simon Glass | 5dc1ca7 | 2020-03-18 09:42:45 -0600 | [diff] [blame] | 673 | for name in to_remove + to_leave: |
| 674 | _Touch(name) |
| 675 | |
| 676 | build = builder.Builder(self.toolchains, base_dir, None, 1, 2) |
| 677 | build.commits = self.commits |
| 678 | build.commit_count = len(commits) |
Simon Glass | bc74d94 | 2023-07-19 17:49:06 -0600 | [diff] [blame] | 679 | result = set(build._get_output_space_removals()) |
Simon Glass | 5dc1ca7 | 2020-03-18 09:42:45 -0600 | [diff] [blame] | 680 | expected = set([os.path.join(base_dir, f) for f in to_remove]) |
| 681 | self.assertEqual(expected, result) |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 682 | |
Simon Glass | 22901f9 | 2022-01-22 05:07:31 -0700 | [diff] [blame] | 683 | def test_adjust_cfg_nop(self): |
| 684 | """check various adjustments of config that are nops""" |
| 685 | # enable an enabled CONFIG |
| 686 | self.assertEqual( |
| 687 | 'CONFIG_FRED=y', |
| 688 | cfgutil.adjust_cfg_line('CONFIG_FRED=y', {'FRED':'FRED'})[0]) |
| 689 | |
| 690 | # disable a disabled CONFIG |
| 691 | self.assertEqual( |
| 692 | '# CONFIG_FRED is not set', |
| 693 | cfgutil.adjust_cfg_line( |
| 694 | '# CONFIG_FRED is not set', {'FRED':'~FRED'})[0]) |
| 695 | |
| 696 | # use the adjust_cfg_lines() function |
| 697 | self.assertEqual( |
| 698 | ['CONFIG_FRED=y'], |
| 699 | cfgutil.adjust_cfg_lines(['CONFIG_FRED=y'], {'FRED':'FRED'})) |
| 700 | self.assertEqual( |
| 701 | ['# CONFIG_FRED is not set'], |
| 702 | cfgutil.adjust_cfg_lines(['CONFIG_FRED=y'], {'FRED':'~FRED'})) |
| 703 | |
| 704 | # handling an empty line |
| 705 | self.assertEqual('#', cfgutil.adjust_cfg_line('#', {'FRED':'~FRED'})[0]) |
| 706 | |
| 707 | def test_adjust_cfg(self): |
| 708 | """check various adjustments of config""" |
| 709 | # disable a CONFIG |
| 710 | self.assertEqual( |
| 711 | '# CONFIG_FRED is not set', |
| 712 | cfgutil.adjust_cfg_line('CONFIG_FRED=1' , {'FRED':'~FRED'})[0]) |
| 713 | |
| 714 | # enable a disabled CONFIG |
| 715 | self.assertEqual( |
| 716 | 'CONFIG_FRED=y', |
| 717 | cfgutil.adjust_cfg_line( |
| 718 | '# CONFIG_FRED is not set', {'FRED':'FRED'})[0]) |
| 719 | |
| 720 | # enable a CONFIG that doesn't exist |
| 721 | self.assertEqual( |
| 722 | ['CONFIG_FRED=y'], |
| 723 | cfgutil.adjust_cfg_lines([], {'FRED':'FRED'})) |
| 724 | |
| 725 | # disable a CONFIG that doesn't exist |
| 726 | self.assertEqual( |
| 727 | ['# CONFIG_FRED is not set'], |
| 728 | cfgutil.adjust_cfg_lines([], {'FRED':'~FRED'})) |
| 729 | |
| 730 | # disable a value CONFIG |
| 731 | self.assertEqual( |
| 732 | '# CONFIG_FRED is not set', |
| 733 | cfgutil.adjust_cfg_line('CONFIG_FRED="fred"' , {'FRED':'~FRED'})[0]) |
| 734 | |
| 735 | # setting a value CONFIG |
| 736 | self.assertEqual( |
| 737 | 'CONFIG_FRED="fred"', |
| 738 | cfgutil.adjust_cfg_line('# CONFIG_FRED is not set' , |
| 739 | {'FRED':'FRED="fred"'})[0]) |
| 740 | |
| 741 | # changing a value CONFIG |
| 742 | self.assertEqual( |
| 743 | 'CONFIG_FRED="fred"', |
| 744 | cfgutil.adjust_cfg_line('CONFIG_FRED="ernie"' , |
| 745 | {'FRED':'FRED="fred"'})[0]) |
| 746 | |
| 747 | # setting a value for a CONFIG that doesn't exist |
| 748 | self.assertEqual( |
| 749 | ['CONFIG_FRED="fred"'], |
| 750 | cfgutil.adjust_cfg_lines([], {'FRED':'FRED="fred"'})) |
| 751 | |
| 752 | def test_convert_adjust_cfg_list(self): |
| 753 | """Check conversion of the list of changes into a dict""" |
| 754 | self.assertEqual({}, cfgutil.convert_list_to_dict(None)) |
| 755 | |
| 756 | expect = { |
| 757 | 'FRED':'FRED', |
| 758 | 'MARY':'~MARY', |
| 759 | 'JOHN':'JOHN=0x123', |
| 760 | 'ALICE':'ALICE="alice"', |
| 761 | 'AMY':'AMY', |
| 762 | 'ABE':'~ABE', |
| 763 | 'MARK':'MARK=0x456', |
| 764 | 'ANNA':'ANNA="anna"', |
| 765 | } |
| 766 | actual = cfgutil.convert_list_to_dict( |
| 767 | ['FRED', '~MARY', 'JOHN=0x123', 'ALICE="alice"', |
| 768 | 'CONFIG_AMY', '~CONFIG_ABE', 'CONFIG_MARK=0x456', |
| 769 | 'CONFIG_ANNA="anna"']) |
| 770 | self.assertEqual(expect, actual) |
| 771 | |
| 772 | def test_check_cfg_file(self): |
| 773 | """Test check_cfg_file detects conflicts as expected""" |
| 774 | # Check failure to disable CONFIG |
| 775 | result = cfgutil.check_cfg_lines(['CONFIG_FRED=1'], {'FRED':'~FRED'}) |
| 776 | self.assertEqual([['~FRED', 'CONFIG_FRED=1']], result) |
| 777 | |
| 778 | result = cfgutil.check_cfg_lines( |
| 779 | ['CONFIG_FRED=1', 'CONFIG_MARY="mary"'], {'FRED':'~FRED'}) |
| 780 | self.assertEqual([['~FRED', 'CONFIG_FRED=1']], result) |
| 781 | |
| 782 | result = cfgutil.check_cfg_lines( |
| 783 | ['CONFIG_FRED=1', 'CONFIG_MARY="mary"'], {'MARY':'~MARY'}) |
| 784 | self.assertEqual([['~MARY', 'CONFIG_MARY="mary"']], result) |
| 785 | |
| 786 | # Check failure to enable CONFIG |
| 787 | result = cfgutil.check_cfg_lines( |
| 788 | ['# CONFIG_FRED is not set'], {'FRED':'FRED'}) |
| 789 | self.assertEqual([['FRED', '# CONFIG_FRED is not set']], result) |
| 790 | |
| 791 | # Check failure to set CONFIG value |
| 792 | result = cfgutil.check_cfg_lines( |
| 793 | ['# CONFIG_FRED is not set', 'CONFIG_MARY="not"'], |
| 794 | {'MARY':'MARY="mary"', 'FRED':'FRED'}) |
| 795 | self.assertEqual([ |
| 796 | ['FRED', '# CONFIG_FRED is not set'], |
| 797 | ['MARY="mary"', 'CONFIG_MARY="not"']], result) |
| 798 | |
| 799 | # Check failure to add CONFIG value |
| 800 | result = cfgutil.check_cfg_lines([], {'MARY':'MARY="mary"'}) |
| 801 | self.assertEqual([ |
| 802 | ['MARY="mary"', 'Missing expected line: CONFIG_MARY="mary"']], result) |
| 803 | |
Simon Glass | c229d32 | 2024-06-23 11:55:15 -0600 | [diff] [blame] | 804 | def get_procs(self): |
| 805 | running_fname = os.path.join(self.base_dir, control.RUNNING_FNAME) |
| 806 | items = tools.read_file(running_fname, binary=False).split() |
| 807 | return [int(x) for x in items] |
| 808 | |
| 809 | def get_time(self): |
| 810 | return self.cur_time |
| 811 | |
| 812 | def inc_time(self, amount): |
| 813 | self.cur_time += amount |
| 814 | |
| 815 | # Handle a process exiting |
| 816 | if self.finish_time == self.cur_time: |
| 817 | self.valid_pids = [pid for pid in self.valid_pids |
| 818 | if pid != self.finish_pid] |
| 819 | |
| 820 | def kill(self, pid, signal): |
| 821 | if pid not in self.valid_pids: |
| 822 | raise OSError('Invalid PID') |
| 823 | |
| 824 | def test_process_limit(self): |
| 825 | """Test wait_for_process_limit() function""" |
| 826 | tmpdir = self.base_dir |
| 827 | |
| 828 | with (patch('time.time', side_effect=self.get_time), |
Simon Glass | f4f0acc | 2024-08-22 07:57:46 -0600 | [diff] [blame] | 829 | patch('time.monotonic', side_effect=self.get_time), |
Simon Glass | c229d32 | 2024-06-23 11:55:15 -0600 | [diff] [blame] | 830 | patch('time.sleep', side_effect=self.inc_time), |
| 831 | patch('os.kill', side_effect=self.kill)): |
| 832 | # Grab the process. Since there is no other profcess, this should |
| 833 | # immediately succeed |
| 834 | control.wait_for_process_limit(1, tmpdir=tmpdir, pid=1) |
| 835 | lines = terminal.get_print_test_lines() |
| 836 | self.assertEqual(0, self.cur_time) |
| 837 | self.assertEqual('Waiting for other buildman processes...', |
| 838 | lines[0].text) |
| 839 | self.assertEqual(self._col.RED, lines[0].colour) |
| 840 | self.assertEqual(False, lines[0].newline) |
| 841 | self.assertEqual(True, lines[0].bright) |
| 842 | |
| 843 | self.assertEqual('done...', lines[1].text) |
| 844 | self.assertEqual(None, lines[1].colour) |
| 845 | self.assertEqual(False, lines[1].newline) |
| 846 | self.assertEqual(True, lines[1].bright) |
| 847 | |
| 848 | self.assertEqual('starting build', lines[2].text) |
| 849 | self.assertEqual([1], control.read_procs(tmpdir)) |
| 850 | self.assertEqual(None, lines[2].colour) |
| 851 | self.assertEqual(False, lines[2].newline) |
| 852 | self.assertEqual(True, lines[2].bright) |
| 853 | |
| 854 | # Try again, with a different PID...this should eventually timeout |
| 855 | # and start the build anyway |
| 856 | self.cur_time = 0 |
| 857 | self.valid_pids = [1] |
| 858 | control.wait_for_process_limit(1, tmpdir=tmpdir, pid=2) |
| 859 | lines = terminal.get_print_test_lines() |
| 860 | self.assertEqual('Waiting for other buildman processes...', |
| 861 | lines[0].text) |
| 862 | self.assertEqual('timeout...', lines[1].text) |
| 863 | self.assertEqual(None, lines[1].colour) |
| 864 | self.assertEqual(False, lines[1].newline) |
| 865 | self.assertEqual(True, lines[1].bright) |
| 866 | self.assertEqual('starting build', lines[2].text) |
| 867 | self.assertEqual([1, 2], control.read_procs(tmpdir)) |
| 868 | self.assertEqual(control.RUN_WAIT_S, self.cur_time) |
| 869 | |
| 870 | # Check lock-busting |
| 871 | self.cur_time = 0 |
| 872 | self.valid_pids = [1, 2] |
| 873 | lock_fname = os.path.join(tmpdir, control.LOCK_FNAME) |
| 874 | lock = FileLock(lock_fname) |
| 875 | lock.acquire(timeout=1) |
| 876 | control.wait_for_process_limit(1, tmpdir=tmpdir, pid=3) |
| 877 | lines = terminal.get_print_test_lines() |
| 878 | self.assertEqual('Waiting for other buildman processes...', |
| 879 | lines[0].text) |
| 880 | self.assertEqual('failed to get lock: busting...', lines[1].text) |
| 881 | self.assertEqual(None, lines[1].colour) |
| 882 | self.assertEqual(False, lines[1].newline) |
| 883 | self.assertEqual(True, lines[1].bright) |
| 884 | self.assertEqual('timeout...', lines[2].text) |
| 885 | self.assertEqual('starting build', lines[3].text) |
| 886 | self.assertEqual([1, 2, 3], control.read_procs(tmpdir)) |
| 887 | self.assertEqual(control.RUN_WAIT_S, self.cur_time) |
| 888 | lock.release() |
| 889 | |
| 890 | # Check handling of dead processes. Here we have PID 2 as a running |
| 891 | # process, even though the PID file contains 1, 2 and 3. So we can |
| 892 | # add one more PID, to make 2 and 4 |
| 893 | self.cur_time = 0 |
| 894 | self.valid_pids = [2] |
| 895 | control.wait_for_process_limit(2, tmpdir=tmpdir, pid=4) |
| 896 | lines = terminal.get_print_test_lines() |
| 897 | self.assertEqual('Waiting for other buildman processes...', |
| 898 | lines[0].text) |
| 899 | self.assertEqual('done...', lines[1].text) |
| 900 | self.assertEqual('starting build', lines[2].text) |
| 901 | self.assertEqual([2, 4], control.read_procs(tmpdir)) |
| 902 | self.assertEqual(0, self.cur_time) |
| 903 | |
| 904 | # Try again, with PID 2 quitting at time 50. This allows the new |
| 905 | # build to start |
| 906 | self.cur_time = 0 |
| 907 | self.valid_pids = [2, 4] |
| 908 | self.finish_pid = 2 |
| 909 | self.finish_time = 50 |
| 910 | control.wait_for_process_limit(2, tmpdir=tmpdir, pid=5) |
| 911 | lines = terminal.get_print_test_lines() |
| 912 | self.assertEqual('Waiting for other buildman processes...', |
| 913 | lines[0].text) |
| 914 | self.assertEqual('done...', lines[1].text) |
| 915 | self.assertEqual('starting build', lines[2].text) |
| 916 | self.assertEqual([4, 5], control.read_procs(tmpdir)) |
| 917 | self.assertEqual(self.finish_time, self.cur_time) |
| 918 | |
Simon Glass | 038a3dd | 2024-08-15 13:57:44 -0600 | [diff] [blame] | 919 | def call_make_environment(self, tchn, full_path, in_env=None): |
| 920 | """Call Toolchain.MakeEnvironment() and process the result |
| 921 | |
| 922 | Args: |
| 923 | tchn (Toolchain): Toolchain to use |
| 924 | full_path (bool): True to return the full path in CROSS_COMPILE |
| 925 | rather than adding it to the PATH variable |
| 926 | in_env (dict): Input environment to use, None to use current env |
| 927 | |
| 928 | Returns: |
| 929 | tuple: |
| 930 | dict: Changes that MakeEnvironment has made to the environment |
| 931 | key: Environment variable that was changed |
| 932 | value: New value (for PATH this only includes components |
| 933 | which were added) |
| 934 | str: Full value of the new PATH variable |
| 935 | """ |
| 936 | env = tchn.MakeEnvironment(full_path, env=in_env) |
| 937 | |
| 938 | # Get the original environment |
| 939 | orig_env = dict(os.environb if in_env is None else in_env) |
| 940 | orig_path = orig_env[b'PATH'].split(b':') |
| 941 | |
| 942 | # Find new variables |
| 943 | diff = dict((k, env[k]) for k in env if orig_env.get(k) != env[k]) |
| 944 | |
| 945 | # Find new / different path components |
| 946 | diff_path = None |
| 947 | new_path = None |
| 948 | if b'PATH' in diff: |
| 949 | new_path = diff[b'PATH'].split(b':') |
| 950 | diff_paths = [p for p in new_path if p not in orig_path] |
| 951 | diff_path = b':'.join(p for p in new_path if p not in orig_path) |
| 952 | if diff_path: |
| 953 | diff[b'PATH'] = diff_path |
| 954 | else: |
| 955 | del diff[b'PATH'] |
| 956 | return diff, new_path |
| 957 | |
| 958 | def test_toolchain_env(self): |
| 959 | """Test PATH and other environment settings for toolchains""" |
| 960 | # Use a toolchain which has a path, so that full_path makes a difference |
| 961 | tchn = self.toolchains.Select('aarch64') |
| 962 | |
| 963 | # Normal cases |
| 964 | diff = self.call_make_environment(tchn, full_path=False)[0] |
| 965 | self.assertEqual( |
| 966 | {b'CROSS_COMPILE': b'aarch64-linux-', b'LC_ALL': b'C', |
| 967 | b'PATH': b'/path/to'}, diff) |
| 968 | |
| 969 | diff = self.call_make_environment(tchn, full_path=True)[0] |
| 970 | self.assertEqual( |
| 971 | {b'CROSS_COMPILE': b'/path/to/aarch64-linux-', b'LC_ALL': b'C'}, |
| 972 | diff) |
| 973 | |
| 974 | # When overriding the toolchain, only LC_ALL should be set |
| 975 | tchn.override_toolchain = True |
| 976 | diff = self.call_make_environment(tchn, full_path=True)[0] |
| 977 | self.assertEqual({b'LC_ALL': b'C'}, diff) |
| 978 | |
| 979 | # Test that virtualenv is handled correctly |
| 980 | tchn.override_toolchain = False |
| 981 | sys.prefix = '/some/venv' |
| 982 | env = dict(os.environb) |
| 983 | env[b'PATH'] = b'/some/venv/bin:other/things' |
| 984 | tchn.path = '/my/path' |
| 985 | diff, diff_path = self.call_make_environment(tchn, False, env) |
| 986 | |
| 987 | self.assertIn(b'PATH', diff) |
| 988 | self.assertEqual([b'/some/venv/bin', b'/my/path', b'other/things'], |
| 989 | diff_path) |
| 990 | self.assertEqual( |
| 991 | {b'CROSS_COMPILE': b'aarch64-linux-', b'LC_ALL': b'C', |
| 992 | b'PATH': b'/my/path'}, diff) |
| 993 | |
| 994 | # Handle a toolchain wrapper |
| 995 | tchn.path = '' |
| 996 | bsettings.add_section('toolchain-wrapper') |
| 997 | bsettings.set_item('toolchain-wrapper', 'my-wrapper', 'fred') |
| 998 | diff = self.call_make_environment(tchn, full_path=True)[0] |
| 999 | self.assertEqual( |
| 1000 | {b'CROSS_COMPILE': b'fred aarch64-linux-', b'LC_ALL': b'C'}, diff) |
| 1001 | |
Simon Glass | 600ede9 | 2024-08-15 13:57:45 -0600 | [diff] [blame^] | 1002 | def test_skip_dtc(self): |
| 1003 | """Test skipping building the dtc tool""" |
| 1004 | old_path = os.getenv('PATH') |
| 1005 | try: |
| 1006 | os.environ['PATH'] = self.base_dir |
| 1007 | |
| 1008 | # Check a missing tool |
| 1009 | with self.assertRaises(ValueError) as exc: |
| 1010 | builder.Builder(self.toolchains, self.base_dir, None, 0, 2, |
| 1011 | dtc_skip=True) |
| 1012 | self.assertIn('Cannot find dtc', str(exc.exception)) |
| 1013 | |
| 1014 | # Create a fake tool to use |
| 1015 | dtc = os.path.join(self.base_dir, 'dtc') |
| 1016 | tools.write_file(dtc, b'xx') |
| 1017 | os.chmod(dtc, 0o777) |
| 1018 | |
| 1019 | build = builder.Builder(self.toolchains, self.base_dir, None, 0, 2, |
| 1020 | dtc_skip=True) |
| 1021 | toolchain = self.toolchains.Select('arm') |
| 1022 | env = build.make_environment(toolchain) |
| 1023 | self.assertIn(b'DTC', env) |
| 1024 | |
| 1025 | # Try the normal case, i.e. not skipping the dtc build |
| 1026 | build = builder.Builder(self.toolchains, self.base_dir, None, 0, 2) |
| 1027 | toolchain = self.toolchains.Select('arm') |
| 1028 | env = build.make_environment(toolchain) |
| 1029 | self.assertNotIn(b'DTC', env) |
| 1030 | finally: |
| 1031 | os.environ['PATH'] = old_path |
| 1032 | |
Simon Glass | 22901f9 | 2022-01-22 05:07:31 -0700 | [diff] [blame] | 1033 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1034 | if __name__ == "__main__": |
| 1035 | unittest.main() |