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 | |
| 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 | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 22 | import terminal |
Simon Glass | 0415002 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 23 | import test_util |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 24 | import toolchain |
Simon Glass | 5dc1ca7 | 2020-03-18 09:42:45 -0600 | [diff] [blame] | 25 | import tools |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 26 | |
Simon Glass | 2bfc697 | 2017-11-12 21:52:14 -0700 | [diff] [blame] | 27 | use_network = True |
| 28 | |
Simon Glass | 4bea81e | 2014-12-01 17:34:04 -0700 | [diff] [blame] | 29 | settings_data = ''' |
| 30 | # Buildman settings file |
| 31 | |
| 32 | [toolchain] |
| 33 | main: /usr/sbin |
| 34 | |
| 35 | [toolchain-alias] |
| 36 | x86: i386 x86_64 |
| 37 | ''' |
| 38 | |
Simon Glass | c05694f | 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 | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 43 | '''main.c: In function 'main_loop2': |
Simon Glass | c05694f | 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 | 0db9443 | 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 | c05694f | 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 | a8b7b1b | 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 | c05694f | 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 | a8b7b1b | 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 | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 89 | ] |
| 90 | |
| 91 | boards = [ |
Simon Glass | 584cf86 | 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 | 5e0f06d | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 95 | ['Active', 'powerpc', 'mpc83xx', '', 'Tester', 'PowerPC board 2', 'board3', ''], |
Simon Glass | 584cf86 | 2013-09-23 17:35:16 -0600 | [diff] [blame] | 96 | ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''], |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 97 | ] |
| 98 | |
Simon Glass | 2e1646c | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 99 | BASE_DIR = 'base' |
| 100 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 101 | OUTCOME_OK, OUTCOME_WARN, OUTCOME_ERR = range(3) |
| 102 | |
Simon Glass | c05694f | 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 | 4bea81e | 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 | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 135 | # Set up the toolchains |
Simon Glass | c05694f | 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 | 7fb8aa2 | 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 | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 146 | def Make(self, commit, brd, stage, *args, **kwargs): |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 147 | global base_dir |
| 148 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 149 | result = command.CommandResult() |
| 150 | boardnum = int(brd.target[-1]) |
| 151 | result.return_code = 0 |
| 152 | result.stderr = '' |
| 153 | result.stdout = ('This is the test output for board %s, commit %s' % |
| 154 | (brd.target, commit.hash)) |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 155 | if ((boardnum >= 1 and boardnum >= commit.sequence) or |
| 156 | boardnum == 4 and commit.sequence == 6): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 157 | result.return_code = commit.return_code |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 158 | result.stderr = (''.join(commit.error_list) |
| 159 | % {'basedir' : base_dir + '/.bm-work/00/'}) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 160 | |
| 161 | result.combined = result.stdout + result.stderr |
| 162 | return result |
| 163 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 164 | def assertSummary(self, text, arch, plus, boards, outcome=OUTCOME_ERR): |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 165 | col = self._col |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 166 | expected_colour = (col.GREEN if outcome == OUTCOME_OK else |
| 167 | col.YELLOW if outcome == OUTCOME_WARN else col.RED) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 168 | expect = '%10s: ' % arch |
| 169 | # TODO(sjg@chromium.org): If plus is '', we shouldn't need this |
Simon Glass | 26f7237 | 2015-02-05 22:06:11 -0700 | [diff] [blame] | 170 | expect += ' ' + col.Color(expected_colour, plus) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 171 | expect += ' ' |
| 172 | for board in boards: |
| 173 | expect += col.Color(expected_colour, ' %s' % board) |
| 174 | self.assertEqual(text, expect) |
| 175 | |
| 176 | def testOutput(self): |
| 177 | """Test basic builder operation and output |
| 178 | |
| 179 | This does a line-by-line verification of the summary output. |
| 180 | """ |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 181 | global base_dir |
| 182 | |
| 183 | base_dir = tempfile.mkdtemp() |
| 184 | if not os.path.isdir(base_dir): |
| 185 | os.mkdir(base_dir) |
| 186 | build = builder.Builder(self.toolchains, base_dir, None, 1, 2, |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 187 | checkout=False, show_unknown=False) |
| 188 | build.do_make = self.Make |
| 189 | board_selected = self.boards.GetSelectedDict() |
| 190 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 191 | # Build the boards for the pre-defined commits and warnings/errors |
| 192 | # associated with each. This calls our Make() to inject the fake output. |
Simon Glass | 78e418e | 2014-08-09 15:33:03 -0600 | [diff] [blame] | 193 | build.BuildBoards(self.commits, board_selected, keep_outputs=False, |
| 194 | verbose=False) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 195 | lines = terminal.GetPrintTestLines() |
| 196 | count = 0 |
| 197 | for line in lines: |
| 198 | if line.text.strip(): |
| 199 | count += 1 |
| 200 | |
Simon Glass | e0f2360 | 2016-09-18 16:48:33 -0600 | [diff] [blame] | 201 | # We should get two starting messages, then an update for every commit |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 202 | # built. |
Simon Glass | e0f2360 | 2016-09-18 16:48:33 -0600 | [diff] [blame] | 203 | self.assertEqual(count, len(commits) * len(boards) + 2) |
Simon Glass | eb48bbc | 2014-08-09 15:33:02 -0600 | [diff] [blame] | 204 | build.SetDisplayOptions(show_errors=True); |
| 205 | build.ShowSummary(self.commits, board_selected) |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 206 | #terminal.EchoPrintTestLines() |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 207 | lines = terminal.GetPrintTestLines() |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 208 | |
| 209 | # Upstream commit: no errors |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 210 | self.assertEqual(lines[0].text, '01: %s' % commits[0][1]) |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 211 | |
| 212 | # Second commit: all archs should fail with warnings |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 213 | self.assertEqual(lines[1].text, '02: %s' % commits[1][1]) |
| 214 | |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 215 | col = terminal.Color() |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 216 | self.assertSummary(lines[2].text, 'arm', 'w+', ['board1'], |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 217 | outcome=OUTCOME_WARN) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 218 | self.assertSummary(lines[3].text, 'powerpc', 'w+', ['board2', 'board3'], |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 219 | outcome=OUTCOME_WARN) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 220 | self.assertSummary(lines[4].text, 'sandbox', 'w+', ['board4'], |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 221 | outcome=OUTCOME_WARN) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 222 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 223 | # Second commit: The warnings should be listed |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 224 | self.assertEqual(lines[5].text, 'w+%s' % |
| 225 | errors[0].rstrip().replace('\n', '\nw+')) |
| 226 | self.assertEqual(lines[5].colour, col.MAGENTA) |
| 227 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 228 | # Third commit: Still fails |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 229 | self.assertEqual(lines[6].text, '03: %s' % commits[2][1]) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 230 | self.assertSummary(lines[7].text, 'arm', '', ['board1'], |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 231 | outcome=OUTCOME_OK) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 232 | self.assertSummary(lines[8].text, 'powerpc', '+', ['board2', 'board3']) |
| 233 | self.assertSummary(lines[9].text, 'sandbox', '+', ['board4']) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 234 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 235 | # Expect a compiler error |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 236 | self.assertEqual(lines[10].text, '+%s' % |
| 237 | errors[1].rstrip().replace('\n', '\n+')) |
| 238 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 239 | # Fourth commit: Compile errors are fixed, just have warning for board3 |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 240 | self.assertEqual(lines[11].text, '04: %s' % commits[3][1]) |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 241 | expect = '%10s: ' % 'powerpc' |
| 242 | expect += ' ' + col.Color(col.GREEN, '') |
| 243 | expect += ' ' |
| 244 | expect += col.Color(col.GREEN, ' %s' % 'board2') |
| 245 | expect += ' ' + col.Color(col.YELLOW, 'w+') |
| 246 | expect += ' ' |
| 247 | expect += col.Color(col.YELLOW, ' %s' % 'board3') |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 248 | self.assertEqual(lines[12].text, expect) |
| 249 | self.assertSummary(lines[13].text, 'sandbox', 'w+', ['board4'], |
| 250 | outcome=OUTCOME_WARN) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 251 | |
| 252 | # Compile error fixed |
| 253 | self.assertEqual(lines[14].text, '-%s' % |
| 254 | errors[1].rstrip().replace('\n', '\n-')) |
| 255 | self.assertEqual(lines[14].colour, col.GREEN) |
| 256 | |
| 257 | self.assertEqual(lines[15].text, 'w+%s' % |
| 258 | errors[2].rstrip().replace('\n', '\nw+')) |
| 259 | self.assertEqual(lines[15].colour, col.MAGENTA) |
| 260 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 261 | # Fifth commit |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 262 | self.assertEqual(lines[16].text, '05: %s' % commits[4][1]) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 263 | self.assertSummary(lines[17].text, 'powerpc', '', ['board3'], |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 264 | outcome=OUTCOME_OK) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 265 | self.assertSummary(lines[18].text, 'sandbox', '+', ['board4']) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 266 | |
| 267 | # The second line of errors[3] is a duplicate, so buildman will drop it |
| 268 | expect = errors[3].rstrip().split('\n') |
| 269 | expect = [expect[0]] + expect[2:] |
| 270 | self.assertEqual(lines[19].text, '+%s' % |
| 271 | '\n'.join(expect).replace('\n', '\n+')) |
| 272 | |
| 273 | self.assertEqual(lines[20].text, 'w-%s' % |
| 274 | errors[2].rstrip().replace('\n', '\nw-')) |
| 275 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 276 | # Sixth commit |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 277 | self.assertEqual(lines[21].text, '06: %s' % commits[5][1]) |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 278 | self.assertSummary(lines[22].text, 'sandbox', '', ['board4'], |
| 279 | outcome=OUTCOME_OK) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 280 | |
| 281 | # The second line of errors[3] is a duplicate, so buildman will drop it |
| 282 | expect = errors[3].rstrip().split('\n') |
| 283 | expect = [expect[0]] + expect[2:] |
| 284 | self.assertEqual(lines[23].text, '-%s' % |
| 285 | '\n'.join(expect).replace('\n', '\n-')) |
| 286 | |
| 287 | self.assertEqual(lines[24].text, 'w-%s' % |
| 288 | errors[0].rstrip().replace('\n', '\nw-')) |
| 289 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 290 | # Seventh commit |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 291 | self.assertEqual(lines[25].text, '07: %s' % commits[6][1]) |
| 292 | self.assertSummary(lines[26].text, 'sandbox', '+', ['board4']) |
| 293 | |
| 294 | # Pick out the correct error lines |
| 295 | expect_str = errors[4].rstrip().replace('%(basedir)s', '').split('\n') |
| 296 | expect = expect_str[3:8] + [expect_str[-1]] |
| 297 | self.assertEqual(lines[27].text, '+%s' % |
| 298 | '\n'.join(expect).replace('\n', '\n+')) |
| 299 | |
| 300 | # Now the warnings lines |
| 301 | expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]] |
| 302 | self.assertEqual(lines[28].text, 'w+%s' % |
| 303 | '\n'.join(expect).replace('\n', '\nw+')) |
| 304 | |
| 305 | self.assertEqual(len(lines), 29) |
| 306 | shutil.rmtree(base_dir) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 307 | |
| 308 | def _testGit(self): |
| 309 | """Test basic builder operation by building a branch""" |
| 310 | base_dir = tempfile.mkdtemp() |
| 311 | if not os.path.isdir(base_dir): |
| 312 | os.mkdir(base_dir) |
| 313 | options = Options() |
| 314 | options.git = os.getcwd() |
| 315 | options.summary = False |
| 316 | options.jobs = None |
| 317 | options.dry_run = False |
| 318 | #options.git = os.path.join(base_dir, 'repo') |
| 319 | options.branch = 'test-buildman' |
| 320 | options.force_build = False |
| 321 | options.list_tool_chains = False |
| 322 | options.count = -1 |
| 323 | options.git_dir = None |
| 324 | options.threads = None |
| 325 | options.show_unknown = False |
| 326 | options.quick = False |
| 327 | options.show_errors = False |
| 328 | options.keep_outputs = False |
| 329 | args = ['tegra20'] |
| 330 | control.DoBuildman(options, args) |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 331 | shutil.rmtree(base_dir) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 332 | |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 333 | def testBoardSingle(self): |
| 334 | """Test single board selection""" |
| 335 | self.assertEqual(self.boards.SelectBoards(['sandbox']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 336 | ({'all': ['board4'], 'sandbox': ['board4']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 337 | |
| 338 | def testBoardArch(self): |
| 339 | """Test single board selection""" |
| 340 | self.assertEqual(self.boards.SelectBoards(['arm']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 341 | ({'all': ['board0', 'board1'], |
| 342 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 343 | |
| 344 | def testBoardArchSingle(self): |
| 345 | """Test single board selection""" |
| 346 | self.assertEqual(self.boards.SelectBoards(['arm sandbox']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 347 | ({'sandbox': ['board4'], |
Simon Glass | 5e0f06d | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 348 | 'all': ['board0', 'board1', 'board4'], |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 349 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | 5e0f06d | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 350 | |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 351 | |
| 352 | def testBoardArchSingleMultiWord(self): |
| 353 | """Test single board selection""" |
| 354 | self.assertEqual(self.boards.SelectBoards(['arm', 'sandbox']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 355 | ({'sandbox': ['board4'], |
| 356 | 'all': ['board0', 'board1', 'board4'], |
| 357 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 358 | |
| 359 | def testBoardSingleAnd(self): |
| 360 | """Test single board selection""" |
| 361 | self.assertEqual(self.boards.SelectBoards(['Tester & arm']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 362 | ({'Tester&arm': ['board0', 'board1'], |
| 363 | 'all': ['board0', 'board1']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 364 | |
| 365 | def testBoardTwoAnd(self): |
| 366 | """Test single board selection""" |
| 367 | self.assertEqual(self.boards.SelectBoards(['Tester', '&', 'arm', |
| 368 | 'Tester' '&', 'powerpc', |
| 369 | 'sandbox']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 370 | ({'sandbox': ['board4'], |
Simon Glass | 5e0f06d | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 371 | 'all': ['board0', 'board1', 'board2', 'board3', |
| 372 | 'board4'], |
| 373 | 'Tester&powerpc': ['board2', 'board3'], |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 374 | 'Tester&arm': ['board0', 'board1']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 375 | |
| 376 | def testBoardAll(self): |
| 377 | """Test single board selection""" |
Simon Glass | 5e0f06d | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 378 | self.assertEqual(self.boards.SelectBoards([]), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 379 | ({'all': ['board0', 'board1', 'board2', 'board3', |
| 380 | 'board4']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 381 | |
| 382 | def testBoardRegularExpression(self): |
| 383 | """Test single board selection""" |
| 384 | self.assertEqual(self.boards.SelectBoards(['T.*r&^Po']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 385 | ({'all': ['board2', 'board3'], |
| 386 | 'T.*r&^Po': ['board2', 'board3']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 387 | |
| 388 | def testBoardDuplicate(self): |
| 389 | """Test single board selection""" |
| 390 | self.assertEqual(self.boards.SelectBoards(['sandbox sandbox', |
| 391 | 'sandbox']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 392 | ({'all': ['board4'], 'sandbox': ['board4']}, [])) |
Simon Glass | 2e1646c | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 393 | def CheckDirs(self, build, dirname): |
| 394 | self.assertEqual('base%s' % dirname, build._GetOutputDir(1)) |
| 395 | self.assertEqual('base%s/fred' % dirname, |
| 396 | build.GetBuildDir(1, 'fred')) |
| 397 | self.assertEqual('base%s/fred/done' % dirname, |
| 398 | build.GetDoneFile(1, 'fred')) |
| 399 | self.assertEqual('base%s/fred/u-boot.sizes' % dirname, |
| 400 | build.GetFuncSizesFile(1, 'fred', 'u-boot')) |
| 401 | self.assertEqual('base%s/fred/u-boot.objdump' % dirname, |
| 402 | build.GetObjdumpFile(1, 'fred', 'u-boot')) |
| 403 | self.assertEqual('base%s/fred/err' % dirname, |
| 404 | build.GetErrFile(1, 'fred')) |
| 405 | |
| 406 | def testOutputDir(self): |
| 407 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 408 | checkout=False, show_unknown=False) |
| 409 | build.commits = self.commits |
| 410 | build.commit_count = len(self.commits) |
| 411 | subject = self.commits[1].subject.translate(builder.trans_valid_chars) |
| 412 | dirname ='/%02d_of_%02d_g%s_%s' % (2, build.commit_count, commits[1][0], |
| 413 | subject[:20]) |
| 414 | self.CheckDirs(build, dirname) |
| 415 | |
| 416 | def testOutputDirCurrent(self): |
| 417 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 418 | checkout=False, show_unknown=False) |
| 419 | build.commits = None |
| 420 | build.commit_count = 0 |
| 421 | self.CheckDirs(build, '/current') |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 422 | |
Simon Glass | e87bde1 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 423 | def testOutputDirNoSubdirs(self): |
| 424 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 425 | checkout=False, show_unknown=False, |
| 426 | no_subdirs=True) |
| 427 | build.commits = None |
| 428 | build.commit_count = 0 |
| 429 | self.CheckDirs(build, '') |
| 430 | |
Simon Glass | c1528c1 | 2014-12-01 17:34:05 -0700 | [diff] [blame] | 431 | def testToolchainAliases(self): |
| 432 | self.assertTrue(self.toolchains.Select('arm') != None) |
| 433 | with self.assertRaises(ValueError): |
| 434 | self.toolchains.Select('no-arch') |
| 435 | with self.assertRaises(ValueError): |
| 436 | self.toolchains.Select('x86') |
| 437 | |
| 438 | self.toolchains = toolchain.Toolchains() |
| 439 | self.toolchains.Add('x86_64-linux-gcc', test=False) |
| 440 | self.assertTrue(self.toolchains.Select('x86') != None) |
| 441 | |
| 442 | self.toolchains = toolchain.Toolchains() |
| 443 | self.toolchains.Add('i386-linux-gcc', test=False) |
| 444 | self.assertTrue(self.toolchains.Select('x86') != None) |
| 445 | |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 446 | def testToolchainDownload(self): |
| 447 | """Test that we can download toolchains""" |
Simon Glass | 2bfc697 | 2017-11-12 21:52:14 -0700 | [diff] [blame] | 448 | if use_network: |
Simon Glass | 0415002 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 449 | with test_util.capture_sys_output() as (stdout, stderr): |
| 450 | url = self.toolchains.LocateArchUrl('arm') |
Simon Glass | 72e358c | 2018-10-01 21:12:35 -0600 | [diff] [blame] | 451 | self.assertRegexpMatches(url, 'https://www.kernel.org/pub/tools/' |
| 452 | 'crosstool/files/bin/x86_64/.*/' |
| 453 | 'x86_64-gcc-.*-nolibc_arm-.*linux-gnueabi.tar.xz') |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 454 | |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 455 | def testGetEnvArgs(self): |
| 456 | """Test the GetEnvArgs() function""" |
| 457 | tc = self.toolchains.Select('arm') |
| 458 | self.assertEqual('arm-linux-', |
| 459 | tc.GetEnvArgs(toolchain.VAR_CROSS_COMPILE)) |
| 460 | self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_PATH)) |
| 461 | self.assertEqual('arm', |
| 462 | tc.GetEnvArgs(toolchain.VAR_ARCH)) |
| 463 | self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS)) |
| 464 | |
| 465 | self.toolchains.Add('/path/to/x86_64-linux-gcc', test=False) |
| 466 | tc = self.toolchains.Select('x86') |
| 467 | self.assertEqual('/path/to', |
| 468 | tc.GetEnvArgs(toolchain.VAR_PATH)) |
| 469 | tc.override_toolchain = 'clang' |
| 470 | self.assertEqual('HOSTCC=clang CC=clang', |
| 471 | tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS)) |
| 472 | |
Simon Glass | 5dc1ca7 | 2020-03-18 09:42:45 -0600 | [diff] [blame] | 473 | def testPrepareOutputSpace(self): |
| 474 | def _Touch(fname): |
| 475 | tools.WriteFile(os.path.join(base_dir, fname), b'') |
| 476 | |
| 477 | base_dir = tempfile.mkdtemp() |
| 478 | |
| 479 | # Add various files that we want removed and left alone |
| 480 | to_remove = ['01_of_22_g0982734987_title', '102_of_222_g92bf_title', |
| 481 | '01_of_22_g2938abd8_title'] |
| 482 | to_leave = ['something_else', '01-something.patch', '01_of_22_another'] |
| 483 | for name in to_remove + to_leave: |
| 484 | _Touch(name) |
| 485 | |
| 486 | build = builder.Builder(self.toolchains, base_dir, None, 1, 2) |
| 487 | build.commits = self.commits |
| 488 | build.commit_count = len(commits) |
| 489 | result = set(build._GetOutputSpaceRemovals()) |
| 490 | expected = set([os.path.join(base_dir, f) for f in to_remove]) |
| 491 | self.assertEqual(expected, result) |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 492 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 493 | if __name__ == "__main__": |
| 494 | unittest.main() |