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