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