Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 2 | # Copyright (c) 2012 The Chromium OS Authors. |
| 3 | # |
Simon Glass | fc3fe1c | 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 | |
| 12 | # Bring in the patman libraries |
| 13 | our_path = os.path.dirname(os.path.realpath(__file__)) |
| 14 | sys.path.append(os.path.join(our_path, '../patman')) |
| 15 | |
| 16 | import board |
| 17 | import bsettings |
| 18 | import builder |
| 19 | import control |
| 20 | import command |
| 21 | import commit |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 22 | import terminal |
Simon Glass | 4b4bc06 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 23 | import test_util |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 24 | import toolchain |
Simon Glass | 925f6ad | 2020-03-18 09:42:45 -0600 | [diff] [blame] | 25 | import tools |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 26 | |
Simon Glass | cb39a10 | 2017-11-12 21:52:14 -0700 | [diff] [blame] | 27 | use_network = True |
| 28 | |
Simon Glass | cc93529 | 2014-12-01 17:34:04 -0700 | [diff] [blame] | 29 | settings_data = ''' |
| 30 | # Buildman settings file |
| 31 | |
| 32 | [toolchain] |
| 33 | main: /usr/sbin |
| 34 | |
| 35 | [toolchain-alias] |
| 36 | x86: i386 x86_64 |
| 37 | ''' |
| 38 | |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 39 | errors = [ |
| 40 | '''main.c: In function 'main_loop': |
| 41 | main.c:260:6: warning: unused variable 'joe' [-Wunused-variable] |
| 42 | ''', |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 43 | '''main.c: In function 'main_loop2': |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 44 | main.c:295:2: error: 'fred' undeclared (first use in this function) |
| 45 | main.c:295:2: note: each undeclared identifier is reported only once for each function it appears in |
| 46 | make[1]: *** [main.o] Error 1 |
| 47 | make: *** [common/libcommon.o] Error 2 |
| 48 | Make failed |
| 49 | ''', |
Simon Glass | 2d48333 | 2018-11-06 16:02:11 -0700 | [diff] [blame] | 50 | '''arch/arm/dts/socfpga_arria10_socdk_sdmmc.dtb: Warning \ |
| 51 | (avoid_unnecessary_addr_size): /clocks: unnecessary #address-cells/#size-cells \ |
| 52 | without "ranges" or child "reg" property |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 53 | ''', |
| 54 | '''powerpc-linux-ld: warning: dot moved backwards before `.bss' |
| 55 | powerpc-linux-ld: warning: dot moved backwards before `.bss' |
| 56 | powerpc-linux-ld: u-boot: section .text lma 0xfffc0000 overlaps previous sections |
| 57 | powerpc-linux-ld: u-boot: section .rodata lma 0xfffef3ec overlaps previous sections |
| 58 | powerpc-linux-ld: u-boot: section .reloc lma 0xffffa400 overlaps previous sections |
| 59 | powerpc-linux-ld: u-boot: section .data lma 0xffffcd38 overlaps previous sections |
| 60 | powerpc-linux-ld: u-boot: section .u_boot_cmd lma 0xffffeb40 overlaps previous sections |
| 61 | powerpc-linux-ld: u-boot: section .bootpg lma 0xfffff198 overlaps previous sections |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 62 | ''', |
| 63 | '''In file included from %(basedir)sarch/sandbox/cpu/cpu.c:9:0: |
| 64 | %(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default] |
| 65 | %(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition |
| 66 | %(basedir)sarch/sandbox/cpu/cpu.c: In function 'do_reset': |
| 67 | %(basedir)sarch/sandbox/cpu/cpu.c:27:1: error: unknown type name 'blah' |
| 68 | %(basedir)sarch/sandbox/cpu/cpu.c:28:12: error: expected declaration specifiers or '...' before numeric constant |
| 69 | make[2]: *** [arch/sandbox/cpu/cpu.o] Error 1 |
| 70 | make[1]: *** [arch/sandbox/cpu] Error 2 |
| 71 | make[1]: *** Waiting for unfinished jobs.... |
| 72 | In file included from %(basedir)scommon/board_f.c:55:0: |
| 73 | %(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default] |
| 74 | %(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition |
| 75 | make: *** [sub-make] Error 2 |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 76 | ''' |
| 77 | ] |
| 78 | |
| 79 | |
| 80 | # hash, subject, return code, list of errors/warnings |
| 81 | commits = [ |
| 82 | ['1234', 'upstream/master, ok', 0, []], |
| 83 | ['5678', 'Second commit, a warning', 0, errors[0:1]], |
| 84 | ['9012', 'Third commit, error', 1, errors[0:2]], |
| 85 | ['3456', 'Fourth commit, warning', 0, [errors[0], errors[2]]], |
| 86 | ['7890', 'Fifth commit, link errors', 1, [errors[0], errors[3]]], |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 87 | ['abcd', 'Sixth commit, fixes all errors', 0, []], |
| 88 | ['ef01', 'Seventh commit, check directory suppression', 1, [errors[4]]], |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 89 | ] |
| 90 | |
| 91 | boards = [ |
Simon Glass | e19d578 | 2013-09-23 17:35:16 -0600 | [diff] [blame] | 92 | ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board0', ''], |
| 93 | ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 2', 'board1', ''], |
| 94 | ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''], |
Simon Glass | 251f586 | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 95 | ['Active', 'powerpc', 'mpc83xx', '', 'Tester', 'PowerPC board 2', 'board3', ''], |
Simon Glass | e19d578 | 2013-09-23 17:35:16 -0600 | [diff] [blame] | 96 | ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''], |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 97 | ] |
| 98 | |
Simon Glass | 4466c1f | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 99 | BASE_DIR = 'base' |
| 100 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 101 | OUTCOME_OK, OUTCOME_WARN, OUTCOME_ERR = range(3) |
| 102 | |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 103 | class Options: |
| 104 | """Class that holds build options""" |
| 105 | pass |
| 106 | |
| 107 | class TestBuild(unittest.TestCase): |
| 108 | """Test buildman |
| 109 | |
| 110 | TODO: Write tests for the rest of the functionality |
| 111 | """ |
| 112 | def setUp(self): |
| 113 | # Set up commits to build |
| 114 | self.commits = [] |
| 115 | sequence = 0 |
| 116 | for commit_info in commits: |
| 117 | comm = commit.Commit(commit_info[0]) |
| 118 | comm.subject = commit_info[1] |
| 119 | comm.return_code = commit_info[2] |
| 120 | comm.error_list = commit_info[3] |
| 121 | comm.sequence = sequence |
| 122 | sequence += 1 |
| 123 | self.commits.append(comm) |
| 124 | |
| 125 | # Set up boards to build |
| 126 | self.boards = board.Boards() |
| 127 | for brd in boards: |
| 128 | self.boards.AddBoard(board.Board(*brd)) |
| 129 | self.boards.SelectBoards([]) |
| 130 | |
Simon Glass | cc93529 | 2014-12-01 17:34:04 -0700 | [diff] [blame] | 131 | # Add some test settings |
| 132 | bsettings.Setup(None) |
| 133 | bsettings.AddFile(settings_data) |
| 134 | |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 135 | # Set up the toolchains |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 136 | self.toolchains = toolchain.Toolchains() |
| 137 | self.toolchains.Add('arm-linux-gcc', test=False) |
| 138 | self.toolchains.Add('sparc-linux-gcc', test=False) |
| 139 | self.toolchains.Add('powerpc-linux-gcc', test=False) |
| 140 | self.toolchains.Add('gcc', test=False) |
| 141 | |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 142 | # Avoid sending any output |
| 143 | terminal.SetPrintTestMode() |
| 144 | self._col = terminal.Color() |
| 145 | |
Simon Glass | af43065 | 2020-04-09 15:08:31 -0600 | [diff] [blame] | 146 | self.base_dir = tempfile.mkdtemp() |
| 147 | if not os.path.isdir(self.base_dir): |
| 148 | os.mkdir(self.base_dir) |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 149 | |
Simon Glass | af43065 | 2020-04-09 15:08:31 -0600 | [diff] [blame] | 150 | def tearDown(self): |
| 151 | shutil.rmtree(self.base_dir) |
| 152 | |
| 153 | def Make(self, commit, brd, stage, *args, **kwargs): |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 154 | result = command.CommandResult() |
| 155 | boardnum = int(brd.target[-1]) |
| 156 | result.return_code = 0 |
| 157 | result.stderr = '' |
| 158 | result.stdout = ('This is the test output for board %s, commit %s' % |
| 159 | (brd.target, commit.hash)) |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 160 | if ((boardnum >= 1 and boardnum >= commit.sequence) or |
| 161 | boardnum == 4 and commit.sequence == 6): |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 162 | result.return_code = commit.return_code |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 163 | result.stderr = (''.join(commit.error_list) |
Simon Glass | af43065 | 2020-04-09 15:08:31 -0600 | [diff] [blame] | 164 | % {'basedir' : self.base_dir + '/.bm-work/00/'}) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 165 | |
| 166 | result.combined = result.stdout + result.stderr |
| 167 | return result |
| 168 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 169 | def assertSummary(self, text, arch, plus, boards, outcome=OUTCOME_ERR): |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 170 | col = self._col |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 171 | expected_colour = (col.GREEN if outcome == OUTCOME_OK else |
| 172 | col.YELLOW if outcome == OUTCOME_WARN else col.RED) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 173 | expect = '%10s: ' % arch |
| 174 | # TODO(sjg@chromium.org): If plus is '', we shouldn't need this |
Simon Glass | 63c619e | 2015-02-05 22:06:11 -0700 | [diff] [blame] | 175 | expect += ' ' + col.Color(expected_colour, plus) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 176 | expect += ' ' |
| 177 | for board in boards: |
| 178 | expect += col.Color(expected_colour, ' %s' % board) |
| 179 | self.assertEqual(text, expect) |
| 180 | |
Simon Glass | ce558db | 2020-04-09 15:08:32 -0600 | [diff] [blame] | 181 | def _SetupTest(self, echo_lines=False, **kwdisplay_args): |
| 182 | """Set up the test by running a build and summary |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 183 | |
Simon Glass | ce558db | 2020-04-09 15:08:32 -0600 | [diff] [blame] | 184 | Args: |
| 185 | echo_lines: True to echo lines to the terminal to aid test |
| 186 | development |
| 187 | kwdisplay_args: Dict of arguemnts to pass to |
| 188 | Builder.SetDisplayOptions() |
| 189 | |
| 190 | Returns: |
| 191 | Iterator containing the output lines, each a PrintLine() object |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 192 | """ |
Simon Glass | af43065 | 2020-04-09 15:08:31 -0600 | [diff] [blame] | 193 | build = builder.Builder(self.toolchains, self.base_dir, None, 1, 2, |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 194 | checkout=False, show_unknown=False) |
| 195 | build.do_make = self.Make |
| 196 | board_selected = self.boards.GetSelectedDict() |
| 197 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 198 | # Build the boards for the pre-defined commits and warnings/errors |
| 199 | # associated with each. This calls our Make() to inject the fake output. |
Simon Glass | e5a0e5d | 2014-08-09 15:33:03 -0600 | [diff] [blame] | 200 | build.BuildBoards(self.commits, board_selected, keep_outputs=False, |
| 201 | verbose=False) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 202 | lines = terminal.GetPrintTestLines() |
| 203 | count = 0 |
| 204 | for line in lines: |
| 205 | if line.text.strip(): |
| 206 | count += 1 |
| 207 | |
Simon Glass | 745b395 | 2016-09-18 16:48:33 -0600 | [diff] [blame] | 208 | # We should get two starting messages, then an update for every commit |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 209 | # built. |
Simon Glass | 745b395 | 2016-09-18 16:48:33 -0600 | [diff] [blame] | 210 | self.assertEqual(count, len(commits) * len(boards) + 2) |
Simon Glass | ce558db | 2020-04-09 15:08:32 -0600 | [diff] [blame] | 211 | build.SetDisplayOptions(**kwdisplay_args); |
Simon Glass | b2ea7ab | 2014-08-09 15:33:02 -0600 | [diff] [blame] | 212 | build.ShowSummary(self.commits, board_selected) |
Simon Glass | ce558db | 2020-04-09 15:08:32 -0600 | [diff] [blame] | 213 | if echo_lines: |
| 214 | terminal.EchoPrintTestLines() |
| 215 | return iter(terminal.GetPrintTestLines()) |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 216 | |
Simon Glass | e631a2b | 2020-04-09 15:08:34 -0600 | [diff] [blame^] | 217 | def _CheckOutput(self, lines, list_error_boards): |
Simon Glass | ce558db | 2020-04-09 15:08:32 -0600 | [diff] [blame] | 218 | """Check for expected output from the build summary |
| 219 | |
| 220 | Args: |
| 221 | lines: Iterator containing the lines returned from the summary |
Simon Glass | e631a2b | 2020-04-09 15:08:34 -0600 | [diff] [blame^] | 222 | list_error_boards: Adjust the check for output produced with the |
| 223 | --list-error-boards flag |
Simon Glass | ce558db | 2020-04-09 15:08:32 -0600 | [diff] [blame] | 224 | """ |
Simon Glass | e631a2b | 2020-04-09 15:08:34 -0600 | [diff] [blame^] | 225 | def add_line_prefix(prefix, boards, error_str): |
Simon Glass | c9dd80b | 2020-04-09 15:08:33 -0600 | [diff] [blame] | 226 | """Add a prefix to each line of a string |
| 227 | |
| 228 | The training \n in error_str is removed before processing |
| 229 | |
| 230 | Args: |
| 231 | prefix: String prefix to add |
| 232 | error_str: Error string containing the lines |
| 233 | |
| 234 | Returns: |
| 235 | New string where each line has the prefix added |
| 236 | """ |
Simon Glass | e631a2b | 2020-04-09 15:08:34 -0600 | [diff] [blame^] | 237 | if boards: |
| 238 | boards = '(%s) ' % boards |
Simon Glass | c9dd80b | 2020-04-09 15:08:33 -0600 | [diff] [blame] | 239 | lines = error_str.strip().splitlines() |
Simon Glass | e631a2b | 2020-04-09 15:08:34 -0600 | [diff] [blame^] | 240 | new_lines = [prefix + boards + line for line in lines] |
Simon Glass | c9dd80b | 2020-04-09 15:08:33 -0600 | [diff] [blame] | 241 | return '\n'.join(new_lines) |
| 242 | |
Simon Glass | e631a2b | 2020-04-09 15:08:34 -0600 | [diff] [blame^] | 243 | boards1234 = 'board1,board2,board3,board4' if list_error_boards else '' |
| 244 | boards234 = 'board2,board3,board4' if list_error_boards else '' |
| 245 | boards34 = 'board3,board4' if list_error_boards else '' |
| 246 | boards4 = 'board4' if list_error_boards else '' |
| 247 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 248 | # Upstream commit: no errors |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 249 | self.assertEqual(next(lines).text, '01: %s' % commits[0][1]) |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 250 | |
| 251 | # Second commit: all archs should fail with warnings |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 252 | self.assertEqual(next(lines).text, '02: %s' % commits[1][1]) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 253 | |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 254 | col = terminal.Color() |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 255 | self.assertSummary(next(lines).text, 'arm', 'w+', ['board1'], |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 256 | outcome=OUTCOME_WARN) |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 257 | self.assertSummary(next(lines).text, 'powerpc', 'w+', |
| 258 | ['board2', 'board3'], outcome=OUTCOME_WARN) |
| 259 | self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'], |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 260 | outcome=OUTCOME_WARN) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 261 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 262 | # Second commit: The warnings should be listed |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 263 | line = next(lines) |
Simon Glass | c9dd80b | 2020-04-09 15:08:33 -0600 | [diff] [blame] | 264 | |
Simon Glass | e631a2b | 2020-04-09 15:08:34 -0600 | [diff] [blame^] | 265 | self.assertEqual(line.text, |
| 266 | add_line_prefix('w+', boards1234, errors[0])) |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 267 | self.assertEqual(line.colour, col.MAGENTA) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 268 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 269 | # Third commit: Still fails |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 270 | self.assertEqual(next(lines).text, '03: %s' % commits[2][1]) |
| 271 | self.assertSummary(next(lines).text, 'arm', '', ['board1'], |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 272 | outcome=OUTCOME_OK) |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 273 | self.assertSummary(next(lines).text, 'powerpc', '+', |
| 274 | ['board2', 'board3']) |
| 275 | self.assertSummary(next(lines).text, 'sandbox', '+', ['board4']) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 276 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 277 | # Expect a compiler error |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 278 | line = next(lines) |
Simon Glass | e631a2b | 2020-04-09 15:08:34 -0600 | [diff] [blame^] | 279 | self.assertEqual(line.text, add_line_prefix('+', boards234, errors[1])) |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 280 | self.assertEqual(line.colour, col.RED) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 281 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 282 | # Fourth commit: Compile errors are fixed, just have warning for board3 |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 283 | self.assertEqual(next(lines).text, '04: %s' % commits[3][1]) |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 284 | expect = '%10s: ' % 'powerpc' |
| 285 | expect += ' ' + col.Color(col.GREEN, '') |
| 286 | expect += ' ' |
| 287 | expect += col.Color(col.GREEN, ' %s' % 'board2') |
| 288 | expect += ' ' + col.Color(col.YELLOW, 'w+') |
| 289 | expect += ' ' |
| 290 | expect += col.Color(col.YELLOW, ' %s' % 'board3') |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 291 | self.assertEqual(next(lines).text, expect) |
| 292 | self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'], |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 293 | outcome=OUTCOME_WARN) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 294 | |
| 295 | # Compile error fixed |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 296 | line = next(lines) |
Simon Glass | e631a2b | 2020-04-09 15:08:34 -0600 | [diff] [blame^] | 297 | self.assertEqual(line.text, add_line_prefix('-', boards234, errors[1])) |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 298 | self.assertEqual(line.colour, col.GREEN) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 299 | |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 300 | line = next(lines) |
Simon Glass | e631a2b | 2020-04-09 15:08:34 -0600 | [diff] [blame^] | 301 | self.assertEqual(line.text, add_line_prefix('w+', boards34, errors[2])) |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 302 | self.assertEqual(line.colour, col.MAGENTA) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 303 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 304 | # Fifth commit |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 305 | self.assertEqual(next(lines).text, '05: %s' % commits[4][1]) |
| 306 | self.assertSummary(next(lines).text, 'powerpc', '', ['board3'], |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 307 | outcome=OUTCOME_OK) |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 308 | self.assertSummary(next(lines).text, 'sandbox', '+', ['board4']) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 309 | |
| 310 | # The second line of errors[3] is a duplicate, so buildman will drop it |
| 311 | expect = errors[3].rstrip().split('\n') |
| 312 | expect = [expect[0]] + expect[2:] |
Simon Glass | c9dd80b | 2020-04-09 15:08:33 -0600 | [diff] [blame] | 313 | expect = '\n'.join(expect) |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 314 | line = next(lines) |
Simon Glass | e631a2b | 2020-04-09 15:08:34 -0600 | [diff] [blame^] | 315 | self.assertEqual(line.text, add_line_prefix('+', boards4, expect)) |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 316 | self.assertEqual(line.colour, col.RED) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 317 | |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 318 | line = next(lines) |
Simon Glass | e631a2b | 2020-04-09 15:08:34 -0600 | [diff] [blame^] | 319 | self.assertEqual(line.text, add_line_prefix('w-', boards34, errors[2])) |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 320 | self.assertEqual(line.colour, col.CYAN) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 321 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 322 | # Sixth commit |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 323 | self.assertEqual(next(lines).text, '06: %s' % commits[5][1]) |
| 324 | self.assertSummary(next(lines).text, 'sandbox', '', ['board4'], |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 325 | outcome=OUTCOME_OK) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 326 | |
| 327 | # The second line of errors[3] is a duplicate, so buildman will drop it |
| 328 | expect = errors[3].rstrip().split('\n') |
| 329 | expect = [expect[0]] + expect[2:] |
Simon Glass | c9dd80b | 2020-04-09 15:08:33 -0600 | [diff] [blame] | 330 | expect = '\n'.join(expect) |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 331 | line = next(lines) |
Simon Glass | e631a2b | 2020-04-09 15:08:34 -0600 | [diff] [blame^] | 332 | self.assertEqual(line.text, add_line_prefix('-', boards4, expect)) |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 333 | self.assertEqual(line.colour, col.GREEN) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 334 | |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 335 | line = next(lines) |
Simon Glass | e631a2b | 2020-04-09 15:08:34 -0600 | [diff] [blame^] | 336 | self.assertEqual(line.text, add_line_prefix('w-', boards4, errors[0])) |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 337 | self.assertEqual(line.colour, col.CYAN) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 338 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 339 | # Seventh commit |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 340 | self.assertEqual(next(lines).text, '07: %s' % commits[6][1]) |
| 341 | self.assertSummary(next(lines).text, 'sandbox', '+', ['board4']) |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 342 | |
| 343 | # Pick out the correct error lines |
| 344 | expect_str = errors[4].rstrip().replace('%(basedir)s', '').split('\n') |
| 345 | expect = expect_str[3:8] + [expect_str[-1]] |
Simon Glass | c9dd80b | 2020-04-09 15:08:33 -0600 | [diff] [blame] | 346 | expect = '\n'.join(expect) |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 347 | line = next(lines) |
Simon Glass | e631a2b | 2020-04-09 15:08:34 -0600 | [diff] [blame^] | 348 | self.assertEqual(line.text, add_line_prefix('+', boards4, expect)) |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 349 | self.assertEqual(line.colour, col.RED) |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 350 | |
| 351 | # Now the warnings lines |
| 352 | expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]] |
Simon Glass | c9dd80b | 2020-04-09 15:08:33 -0600 | [diff] [blame] | 353 | expect = '\n'.join(expect) |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 354 | line = next(lines) |
Simon Glass | e631a2b | 2020-04-09 15:08:34 -0600 | [diff] [blame^] | 355 | self.assertEqual(line.text, add_line_prefix('w+', boards4, expect)) |
Simon Glass | c3bc4f1 | 2020-04-09 15:08:30 -0600 | [diff] [blame] | 356 | self.assertEqual(line.colour, col.MAGENTA) |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 357 | |
Simon Glass | ce558db | 2020-04-09 15:08:32 -0600 | [diff] [blame] | 358 | def testOutput(self): |
| 359 | """Test basic builder operation and output |
| 360 | |
| 361 | This does a line-by-line verification of the summary output. |
| 362 | """ |
| 363 | lines = self._SetupTest(show_errors=True) |
Simon Glass | e631a2b | 2020-04-09 15:08:34 -0600 | [diff] [blame^] | 364 | self._CheckOutput(lines, list_error_boards=False) |
| 365 | |
| 366 | def testErrorBoards(self): |
| 367 | """Test output with --list-error-boards |
| 368 | |
| 369 | This does a line-by-line verification of the summary output. |
| 370 | """ |
| 371 | lines = self._SetupTest(show_errors=True, list_error_boards=True) |
| 372 | self._CheckOutput(lines, list_error_boards=True) |
Simon Glass | ce558db | 2020-04-09 15:08:32 -0600 | [diff] [blame] | 373 | |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 374 | def _testGit(self): |
| 375 | """Test basic builder operation by building a branch""" |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 376 | options = Options() |
| 377 | options.git = os.getcwd() |
| 378 | options.summary = False |
| 379 | options.jobs = None |
| 380 | options.dry_run = False |
Simon Glass | af43065 | 2020-04-09 15:08:31 -0600 | [diff] [blame] | 381 | #options.git = os.path.join(self.base_dir, 'repo') |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 382 | options.branch = 'test-buildman' |
| 383 | options.force_build = False |
| 384 | options.list_tool_chains = False |
| 385 | options.count = -1 |
| 386 | options.git_dir = None |
| 387 | options.threads = None |
| 388 | options.show_unknown = False |
| 389 | options.quick = False |
| 390 | options.show_errors = False |
| 391 | options.keep_outputs = False |
| 392 | args = ['tegra20'] |
| 393 | control.DoBuildman(options, args) |
| 394 | |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 395 | def testBoardSingle(self): |
| 396 | """Test single board selection""" |
| 397 | self.assertEqual(self.boards.SelectBoards(['sandbox']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 398 | ({'all': ['board4'], 'sandbox': ['board4']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 399 | |
| 400 | def testBoardArch(self): |
| 401 | """Test single board selection""" |
| 402 | self.assertEqual(self.boards.SelectBoards(['arm']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 403 | ({'all': ['board0', 'board1'], |
| 404 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 405 | |
| 406 | def testBoardArchSingle(self): |
| 407 | """Test single board selection""" |
| 408 | self.assertEqual(self.boards.SelectBoards(['arm sandbox']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 409 | ({'sandbox': ['board4'], |
Simon Glass | 251f586 | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 410 | 'all': ['board0', 'board1', 'board4'], |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 411 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | 251f586 | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 412 | |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 413 | |
| 414 | def testBoardArchSingleMultiWord(self): |
| 415 | """Test single board selection""" |
| 416 | self.assertEqual(self.boards.SelectBoards(['arm', 'sandbox']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 417 | ({'sandbox': ['board4'], |
| 418 | 'all': ['board0', 'board1', 'board4'], |
| 419 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 420 | |
| 421 | def testBoardSingleAnd(self): |
| 422 | """Test single board selection""" |
| 423 | self.assertEqual(self.boards.SelectBoards(['Tester & arm']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 424 | ({'Tester&arm': ['board0', 'board1'], |
| 425 | 'all': ['board0', 'board1']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 426 | |
| 427 | def testBoardTwoAnd(self): |
| 428 | """Test single board selection""" |
| 429 | self.assertEqual(self.boards.SelectBoards(['Tester', '&', 'arm', |
| 430 | 'Tester' '&', 'powerpc', |
| 431 | 'sandbox']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 432 | ({'sandbox': ['board4'], |
Simon Glass | 251f586 | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 433 | 'all': ['board0', 'board1', 'board2', 'board3', |
| 434 | 'board4'], |
| 435 | 'Tester&powerpc': ['board2', 'board3'], |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 436 | 'Tester&arm': ['board0', 'board1']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 437 | |
| 438 | def testBoardAll(self): |
| 439 | """Test single board selection""" |
Simon Glass | 251f586 | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 440 | self.assertEqual(self.boards.SelectBoards([]), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 441 | ({'all': ['board0', 'board1', 'board2', 'board3', |
| 442 | 'board4']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 443 | |
| 444 | def testBoardRegularExpression(self): |
| 445 | """Test single board selection""" |
| 446 | self.assertEqual(self.boards.SelectBoards(['T.*r&^Po']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 447 | ({'all': ['board2', 'board3'], |
| 448 | 'T.*r&^Po': ['board2', 'board3']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 449 | |
| 450 | def testBoardDuplicate(self): |
| 451 | """Test single board selection""" |
| 452 | self.assertEqual(self.boards.SelectBoards(['sandbox sandbox', |
| 453 | 'sandbox']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 454 | ({'all': ['board4'], 'sandbox': ['board4']}, [])) |
Simon Glass | 4466c1f | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 455 | def CheckDirs(self, build, dirname): |
| 456 | self.assertEqual('base%s' % dirname, build._GetOutputDir(1)) |
| 457 | self.assertEqual('base%s/fred' % dirname, |
| 458 | build.GetBuildDir(1, 'fred')) |
| 459 | self.assertEqual('base%s/fred/done' % dirname, |
| 460 | build.GetDoneFile(1, 'fred')) |
| 461 | self.assertEqual('base%s/fred/u-boot.sizes' % dirname, |
| 462 | build.GetFuncSizesFile(1, 'fred', 'u-boot')) |
| 463 | self.assertEqual('base%s/fred/u-boot.objdump' % dirname, |
| 464 | build.GetObjdumpFile(1, 'fred', 'u-boot')) |
| 465 | self.assertEqual('base%s/fred/err' % dirname, |
| 466 | build.GetErrFile(1, 'fred')) |
| 467 | |
| 468 | def testOutputDir(self): |
| 469 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 470 | checkout=False, show_unknown=False) |
| 471 | build.commits = self.commits |
| 472 | build.commit_count = len(self.commits) |
| 473 | subject = self.commits[1].subject.translate(builder.trans_valid_chars) |
| 474 | dirname ='/%02d_of_%02d_g%s_%s' % (2, build.commit_count, commits[1][0], |
| 475 | subject[:20]) |
| 476 | self.CheckDirs(build, dirname) |
| 477 | |
| 478 | def testOutputDirCurrent(self): |
| 479 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 480 | checkout=False, show_unknown=False) |
| 481 | build.commits = None |
| 482 | build.commit_count = 0 |
| 483 | self.CheckDirs(build, '/current') |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 484 | |
Simon Glass | 5971ab5 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 485 | def testOutputDirNoSubdirs(self): |
| 486 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 487 | checkout=False, show_unknown=False, |
| 488 | no_subdirs=True) |
| 489 | build.commits = None |
| 490 | build.commit_count = 0 |
| 491 | self.CheckDirs(build, '') |
| 492 | |
Simon Glass | 9b83bfd | 2014-12-01 17:34:05 -0700 | [diff] [blame] | 493 | def testToolchainAliases(self): |
| 494 | self.assertTrue(self.toolchains.Select('arm') != None) |
| 495 | with self.assertRaises(ValueError): |
| 496 | self.toolchains.Select('no-arch') |
| 497 | with self.assertRaises(ValueError): |
| 498 | self.toolchains.Select('x86') |
| 499 | |
| 500 | self.toolchains = toolchain.Toolchains() |
| 501 | self.toolchains.Add('x86_64-linux-gcc', test=False) |
| 502 | self.assertTrue(self.toolchains.Select('x86') != None) |
| 503 | |
| 504 | self.toolchains = toolchain.Toolchains() |
| 505 | self.toolchains.Add('i386-linux-gcc', test=False) |
| 506 | self.assertTrue(self.toolchains.Select('x86') != None) |
| 507 | |
Simon Glass | 827e37b | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 508 | def testToolchainDownload(self): |
| 509 | """Test that we can download toolchains""" |
Simon Glass | cb39a10 | 2017-11-12 21:52:14 -0700 | [diff] [blame] | 510 | if use_network: |
Simon Glass | 4b4bc06 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 511 | with test_util.capture_sys_output() as (stdout, stderr): |
| 512 | url = self.toolchains.LocateArchUrl('arm') |
Simon Glass | da753e3 | 2018-10-01 21:12:35 -0600 | [diff] [blame] | 513 | self.assertRegexpMatches(url, 'https://www.kernel.org/pub/tools/' |
| 514 | 'crosstool/files/bin/x86_64/.*/' |
| 515 | 'x86_64-gcc-.*-nolibc_arm-.*linux-gnueabi.tar.xz') |
Simon Glass | 827e37b | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 516 | |
Simon Glass | 57cb9d5 | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 517 | def testGetEnvArgs(self): |
| 518 | """Test the GetEnvArgs() function""" |
| 519 | tc = self.toolchains.Select('arm') |
| 520 | self.assertEqual('arm-linux-', |
| 521 | tc.GetEnvArgs(toolchain.VAR_CROSS_COMPILE)) |
| 522 | self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_PATH)) |
| 523 | self.assertEqual('arm', |
| 524 | tc.GetEnvArgs(toolchain.VAR_ARCH)) |
| 525 | self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS)) |
| 526 | |
| 527 | self.toolchains.Add('/path/to/x86_64-linux-gcc', test=False) |
| 528 | tc = self.toolchains.Select('x86') |
| 529 | self.assertEqual('/path/to', |
| 530 | tc.GetEnvArgs(toolchain.VAR_PATH)) |
| 531 | tc.override_toolchain = 'clang' |
| 532 | self.assertEqual('HOSTCC=clang CC=clang', |
| 533 | tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS)) |
| 534 | |
Simon Glass | 925f6ad | 2020-03-18 09:42:45 -0600 | [diff] [blame] | 535 | def testPrepareOutputSpace(self): |
| 536 | def _Touch(fname): |
| 537 | tools.WriteFile(os.path.join(base_dir, fname), b'') |
| 538 | |
| 539 | base_dir = tempfile.mkdtemp() |
| 540 | |
| 541 | # Add various files that we want removed and left alone |
| 542 | to_remove = ['01_of_22_g0982734987_title', '102_of_222_g92bf_title', |
| 543 | '01_of_22_g2938abd8_title'] |
| 544 | to_leave = ['something_else', '01-something.patch', '01_of_22_another'] |
| 545 | for name in to_remove + to_leave: |
| 546 | _Touch(name) |
| 547 | |
| 548 | build = builder.Builder(self.toolchains, base_dir, None, 1, 2) |
| 549 | build.commits = self.commits |
| 550 | build.commit_count = len(commits) |
| 551 | result = set(build._GetOutputSpaceRemovals()) |
| 552 | expected = set([os.path.join(base_dir, f) for f in to_remove]) |
| 553 | self.assertEqual(expected, result) |
Simon Glass | 827e37b | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 554 | |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 555 | if __name__ == "__main__": |
| 556 | unittest.main() |