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