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 |
| 25 | |
Simon Glass | 2bfc697 | 2017-11-12 21:52:14 -0700 | [diff] [blame] | 26 | use_network = True |
| 27 | |
Simon Glass | 4bea81e | 2014-12-01 17:34:04 -0700 | [diff] [blame] | 28 | settings_data = ''' |
| 29 | # Buildman settings file |
| 30 | |
| 31 | [toolchain] |
| 32 | main: /usr/sbin |
| 33 | |
| 34 | [toolchain-alias] |
| 35 | x86: i386 x86_64 |
| 36 | ''' |
| 37 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 38 | errors = [ |
| 39 | '''main.c: In function 'main_loop': |
| 40 | main.c:260:6: warning: unused variable 'joe' [-Wunused-variable] |
| 41 | ''', |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 42 | '''main.c: In function 'main_loop2': |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 43 | main.c:295:2: error: 'fred' undeclared (first use in this function) |
| 44 | main.c:295:2: note: each undeclared identifier is reported only once for each function it appears in |
| 45 | make[1]: *** [main.o] Error 1 |
| 46 | make: *** [common/libcommon.o] Error 2 |
| 47 | Make failed |
| 48 | ''', |
Simon Glass | 0db9443 | 2018-11-06 16:02:11 -0700 | [diff] [blame] | 49 | '''arch/arm/dts/socfpga_arria10_socdk_sdmmc.dtb: Warning \ |
| 50 | (avoid_unnecessary_addr_size): /clocks: unnecessary #address-cells/#size-cells \ |
| 51 | without "ranges" or child "reg" property |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 52 | ''', |
| 53 | '''powerpc-linux-ld: warning: dot moved backwards before `.bss' |
| 54 | powerpc-linux-ld: warning: dot moved backwards before `.bss' |
| 55 | powerpc-linux-ld: u-boot: section .text lma 0xfffc0000 overlaps previous sections |
| 56 | powerpc-linux-ld: u-boot: section .rodata lma 0xfffef3ec overlaps previous sections |
| 57 | powerpc-linux-ld: u-boot: section .reloc lma 0xffffa400 overlaps previous sections |
| 58 | powerpc-linux-ld: u-boot: section .data lma 0xffffcd38 overlaps previous sections |
| 59 | powerpc-linux-ld: u-boot: section .u_boot_cmd lma 0xffffeb40 overlaps previous sections |
| 60 | powerpc-linux-ld: u-boot: section .bootpg lma 0xfffff198 overlaps previous sections |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 61 | ''', |
| 62 | '''In file included from %(basedir)sarch/sandbox/cpu/cpu.c:9:0: |
| 63 | %(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default] |
| 64 | %(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition |
| 65 | %(basedir)sarch/sandbox/cpu/cpu.c: In function 'do_reset': |
| 66 | %(basedir)sarch/sandbox/cpu/cpu.c:27:1: error: unknown type name 'blah' |
| 67 | %(basedir)sarch/sandbox/cpu/cpu.c:28:12: error: expected declaration specifiers or '...' before numeric constant |
| 68 | make[2]: *** [arch/sandbox/cpu/cpu.o] Error 1 |
| 69 | make[1]: *** [arch/sandbox/cpu] Error 2 |
| 70 | make[1]: *** Waiting for unfinished jobs.... |
| 71 | In file included from %(basedir)scommon/board_f.c:55:0: |
| 72 | %(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default] |
| 73 | %(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition |
| 74 | make: *** [sub-make] Error 2 |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 75 | ''' |
| 76 | ] |
| 77 | |
| 78 | |
| 79 | # hash, subject, return code, list of errors/warnings |
| 80 | commits = [ |
| 81 | ['1234', 'upstream/master, ok', 0, []], |
| 82 | ['5678', 'Second commit, a warning', 0, errors[0:1]], |
| 83 | ['9012', 'Third commit, error', 1, errors[0:2]], |
| 84 | ['3456', 'Fourth commit, warning', 0, [errors[0], errors[2]]], |
| 85 | ['7890', 'Fifth commit, link errors', 1, [errors[0], errors[3]]], |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 86 | ['abcd', 'Sixth commit, fixes all errors', 0, []], |
| 87 | ['ef01', 'Seventh commit, check directory suppression', 1, [errors[4]]], |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 88 | ] |
| 89 | |
| 90 | boards = [ |
Simon Glass | 584cf86 | 2013-09-23 17:35:16 -0600 | [diff] [blame] | 91 | ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board0', ''], |
| 92 | ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 2', 'board1', ''], |
| 93 | ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''], |
Simon Glass | 5e0f06d | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 94 | ['Active', 'powerpc', 'mpc83xx', '', 'Tester', 'PowerPC board 2', 'board3', ''], |
Simon Glass | 584cf86 | 2013-09-23 17:35:16 -0600 | [diff] [blame] | 95 | ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''], |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 96 | ] |
| 97 | |
Simon Glass | 2e1646c | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 98 | BASE_DIR = 'base' |
| 99 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 100 | OUTCOME_OK, OUTCOME_WARN, OUTCOME_ERR = range(3) |
| 101 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 102 | class Options: |
| 103 | """Class that holds build options""" |
| 104 | pass |
| 105 | |
| 106 | class TestBuild(unittest.TestCase): |
| 107 | """Test buildman |
| 108 | |
| 109 | TODO: Write tests for the rest of the functionality |
| 110 | """ |
| 111 | def setUp(self): |
| 112 | # Set up commits to build |
| 113 | self.commits = [] |
| 114 | sequence = 0 |
| 115 | for commit_info in commits: |
| 116 | comm = commit.Commit(commit_info[0]) |
| 117 | comm.subject = commit_info[1] |
| 118 | comm.return_code = commit_info[2] |
| 119 | comm.error_list = commit_info[3] |
| 120 | comm.sequence = sequence |
| 121 | sequence += 1 |
| 122 | self.commits.append(comm) |
| 123 | |
| 124 | # Set up boards to build |
| 125 | self.boards = board.Boards() |
| 126 | for brd in boards: |
| 127 | self.boards.AddBoard(board.Board(*brd)) |
| 128 | self.boards.SelectBoards([]) |
| 129 | |
Simon Glass | 4bea81e | 2014-12-01 17:34:04 -0700 | [diff] [blame] | 130 | # Add some test settings |
| 131 | bsettings.Setup(None) |
| 132 | bsettings.AddFile(settings_data) |
| 133 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 134 | # Set up the toolchains |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 135 | self.toolchains = toolchain.Toolchains() |
| 136 | self.toolchains.Add('arm-linux-gcc', test=False) |
| 137 | self.toolchains.Add('sparc-linux-gcc', test=False) |
| 138 | self.toolchains.Add('powerpc-linux-gcc', test=False) |
| 139 | self.toolchains.Add('gcc', test=False) |
| 140 | |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 141 | # Avoid sending any output |
| 142 | terminal.SetPrintTestMode() |
| 143 | self._col = terminal.Color() |
| 144 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 145 | def Make(self, commit, brd, stage, *args, **kwargs): |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 146 | global base_dir |
| 147 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 148 | result = command.CommandResult() |
| 149 | boardnum = int(brd.target[-1]) |
| 150 | result.return_code = 0 |
| 151 | result.stderr = '' |
| 152 | result.stdout = ('This is the test output for board %s, commit %s' % |
| 153 | (brd.target, commit.hash)) |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 154 | if ((boardnum >= 1 and boardnum >= commit.sequence) or |
| 155 | boardnum == 4 and commit.sequence == 6): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 156 | result.return_code = commit.return_code |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 157 | result.stderr = (''.join(commit.error_list) |
| 158 | % {'basedir' : base_dir + '/.bm-work/00/'}) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 159 | |
| 160 | result.combined = result.stdout + result.stderr |
| 161 | return result |
| 162 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 163 | def assertSummary(self, text, arch, plus, boards, outcome=OUTCOME_ERR): |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 164 | col = self._col |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 165 | expected_colour = (col.GREEN if outcome == OUTCOME_OK else |
| 166 | col.YELLOW if outcome == OUTCOME_WARN else col.RED) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 167 | expect = '%10s: ' % arch |
| 168 | # TODO(sjg@chromium.org): If plus is '', we shouldn't need this |
Simon Glass | 26f7237 | 2015-02-05 22:06:11 -0700 | [diff] [blame] | 169 | expect += ' ' + col.Color(expected_colour, plus) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 170 | expect += ' ' |
| 171 | for board in boards: |
| 172 | expect += col.Color(expected_colour, ' %s' % board) |
| 173 | self.assertEqual(text, expect) |
| 174 | |
| 175 | def testOutput(self): |
| 176 | """Test basic builder operation and output |
| 177 | |
| 178 | This does a line-by-line verification of the summary output. |
| 179 | """ |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 180 | global base_dir |
| 181 | |
| 182 | base_dir = tempfile.mkdtemp() |
| 183 | if not os.path.isdir(base_dir): |
| 184 | os.mkdir(base_dir) |
| 185 | build = builder.Builder(self.toolchains, base_dir, None, 1, 2, |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 186 | checkout=False, show_unknown=False) |
| 187 | build.do_make = self.Make |
| 188 | board_selected = self.boards.GetSelectedDict() |
| 189 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 190 | # Build the boards for the pre-defined commits and warnings/errors |
| 191 | # associated with each. This calls our Make() to inject the fake output. |
Simon Glass | 78e418e | 2014-08-09 15:33:03 -0600 | [diff] [blame] | 192 | build.BuildBoards(self.commits, board_selected, keep_outputs=False, |
| 193 | verbose=False) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 194 | lines = terminal.GetPrintTestLines() |
| 195 | count = 0 |
| 196 | for line in lines: |
| 197 | if line.text.strip(): |
| 198 | count += 1 |
| 199 | |
Simon Glass | e0f2360 | 2016-09-18 16:48:33 -0600 | [diff] [blame] | 200 | # We should get two starting messages, then an update for every commit |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 201 | # built. |
Simon Glass | e0f2360 | 2016-09-18 16:48:33 -0600 | [diff] [blame] | 202 | self.assertEqual(count, len(commits) * len(boards) + 2) |
Simon Glass | eb48bbc | 2014-08-09 15:33:02 -0600 | [diff] [blame] | 203 | build.SetDisplayOptions(show_errors=True); |
| 204 | build.ShowSummary(self.commits, board_selected) |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 205 | #terminal.EchoPrintTestLines() |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 206 | lines = terminal.GetPrintTestLines() |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 207 | |
| 208 | # Upstream commit: no errors |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 209 | self.assertEqual(lines[0].text, '01: %s' % commits[0][1]) |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 210 | |
| 211 | # Second commit: all archs should fail with warnings |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 212 | self.assertEqual(lines[1].text, '02: %s' % commits[1][1]) |
| 213 | |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 214 | col = terminal.Color() |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 215 | self.assertSummary(lines[2].text, 'arm', 'w+', ['board1'], |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 216 | outcome=OUTCOME_WARN) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 217 | self.assertSummary(lines[3].text, 'powerpc', 'w+', ['board2', 'board3'], |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 218 | outcome=OUTCOME_WARN) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 219 | self.assertSummary(lines[4].text, 'sandbox', 'w+', ['board4'], |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 220 | outcome=OUTCOME_WARN) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 221 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 222 | # Second commit: The warnings should be listed |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 223 | self.assertEqual(lines[5].text, 'w+%s' % |
| 224 | errors[0].rstrip().replace('\n', '\nw+')) |
| 225 | self.assertEqual(lines[5].colour, col.MAGENTA) |
| 226 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 227 | # Third commit: Still fails |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 228 | self.assertEqual(lines[6].text, '03: %s' % commits[2][1]) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 229 | self.assertSummary(lines[7].text, 'arm', '', ['board1'], |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 230 | outcome=OUTCOME_OK) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 231 | self.assertSummary(lines[8].text, 'powerpc', '+', ['board2', 'board3']) |
| 232 | self.assertSummary(lines[9].text, 'sandbox', '+', ['board4']) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 233 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 234 | # Expect a compiler error |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 235 | self.assertEqual(lines[10].text, '+%s' % |
| 236 | errors[1].rstrip().replace('\n', '\n+')) |
| 237 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 238 | # Fourth commit: Compile errors are fixed, just have warning for board3 |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 239 | self.assertEqual(lines[11].text, '04: %s' % commits[3][1]) |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 240 | expect = '%10s: ' % 'powerpc' |
| 241 | expect += ' ' + col.Color(col.GREEN, '') |
| 242 | expect += ' ' |
| 243 | expect += col.Color(col.GREEN, ' %s' % 'board2') |
| 244 | expect += ' ' + col.Color(col.YELLOW, 'w+') |
| 245 | expect += ' ' |
| 246 | expect += col.Color(col.YELLOW, ' %s' % 'board3') |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 247 | self.assertEqual(lines[12].text, expect) |
| 248 | self.assertSummary(lines[13].text, 'sandbox', 'w+', ['board4'], |
| 249 | outcome=OUTCOME_WARN) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 250 | |
| 251 | # Compile error fixed |
| 252 | self.assertEqual(lines[14].text, '-%s' % |
| 253 | errors[1].rstrip().replace('\n', '\n-')) |
| 254 | self.assertEqual(lines[14].colour, col.GREEN) |
| 255 | |
| 256 | self.assertEqual(lines[15].text, 'w+%s' % |
| 257 | errors[2].rstrip().replace('\n', '\nw+')) |
| 258 | self.assertEqual(lines[15].colour, col.MAGENTA) |
| 259 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 260 | # Fifth commit |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 261 | self.assertEqual(lines[16].text, '05: %s' % commits[4][1]) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 262 | self.assertSummary(lines[17].text, 'powerpc', '', ['board3'], |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 263 | outcome=OUTCOME_OK) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 264 | self.assertSummary(lines[18].text, 'sandbox', '+', ['board4']) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 265 | |
| 266 | # The second line of errors[3] is a duplicate, so buildman will drop it |
| 267 | expect = errors[3].rstrip().split('\n') |
| 268 | expect = [expect[0]] + expect[2:] |
| 269 | self.assertEqual(lines[19].text, '+%s' % |
| 270 | '\n'.join(expect).replace('\n', '\n+')) |
| 271 | |
| 272 | self.assertEqual(lines[20].text, 'w-%s' % |
| 273 | errors[2].rstrip().replace('\n', '\nw-')) |
| 274 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 275 | # Sixth commit |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 276 | self.assertEqual(lines[21].text, '06: %s' % commits[5][1]) |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 277 | self.assertSummary(lines[22].text, 'sandbox', '', ['board4'], |
| 278 | outcome=OUTCOME_OK) |
Simon Glass | 7fb8aa2 | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 279 | |
| 280 | # The second line of errors[3] is a duplicate, so buildman will drop it |
| 281 | expect = errors[3].rstrip().split('\n') |
| 282 | expect = [expect[0]] + expect[2:] |
| 283 | self.assertEqual(lines[23].text, '-%s' % |
| 284 | '\n'.join(expect).replace('\n', '\n-')) |
| 285 | |
| 286 | self.assertEqual(lines[24].text, 'w-%s' % |
| 287 | errors[0].rstrip().replace('\n', '\nw-')) |
| 288 | |
Simon Glass | 071a178 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 289 | # Seventh commit |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 290 | self.assertEqual(lines[25].text, '07: %s' % commits[6][1]) |
| 291 | self.assertSummary(lines[26].text, 'sandbox', '+', ['board4']) |
| 292 | |
| 293 | # Pick out the correct error lines |
| 294 | expect_str = errors[4].rstrip().replace('%(basedir)s', '').split('\n') |
| 295 | expect = expect_str[3:8] + [expect_str[-1]] |
| 296 | self.assertEqual(lines[27].text, '+%s' % |
| 297 | '\n'.join(expect).replace('\n', '\n+')) |
| 298 | |
| 299 | # Now the warnings lines |
| 300 | expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]] |
| 301 | self.assertEqual(lines[28].text, 'w+%s' % |
| 302 | '\n'.join(expect).replace('\n', '\nw+')) |
| 303 | |
| 304 | self.assertEqual(len(lines), 29) |
| 305 | shutil.rmtree(base_dir) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 306 | |
| 307 | def _testGit(self): |
| 308 | """Test basic builder operation by building a branch""" |
| 309 | base_dir = tempfile.mkdtemp() |
| 310 | if not os.path.isdir(base_dir): |
| 311 | os.mkdir(base_dir) |
| 312 | options = Options() |
| 313 | options.git = os.getcwd() |
| 314 | options.summary = False |
| 315 | options.jobs = None |
| 316 | options.dry_run = False |
| 317 | #options.git = os.path.join(base_dir, 'repo') |
| 318 | options.branch = 'test-buildman' |
| 319 | options.force_build = False |
| 320 | options.list_tool_chains = False |
| 321 | options.count = -1 |
| 322 | options.git_dir = None |
| 323 | options.threads = None |
| 324 | options.show_unknown = False |
| 325 | options.quick = False |
| 326 | options.show_errors = False |
| 327 | options.keep_outputs = False |
| 328 | args = ['tegra20'] |
| 329 | control.DoBuildman(options, args) |
Simon Glass | a8b7b1b | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 330 | shutil.rmtree(base_dir) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 331 | |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 332 | def testBoardSingle(self): |
| 333 | """Test single board selection""" |
| 334 | self.assertEqual(self.boards.SelectBoards(['sandbox']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 335 | ({'all': ['board4'], 'sandbox': ['board4']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 336 | |
| 337 | def testBoardArch(self): |
| 338 | """Test single board selection""" |
| 339 | self.assertEqual(self.boards.SelectBoards(['arm']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 340 | ({'all': ['board0', 'board1'], |
| 341 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 342 | |
| 343 | def testBoardArchSingle(self): |
| 344 | """Test single board selection""" |
| 345 | self.assertEqual(self.boards.SelectBoards(['arm sandbox']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 346 | ({'sandbox': ['board4'], |
Simon Glass | 5e0f06d | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 347 | 'all': ['board0', 'board1', 'board4'], |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 348 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | 5e0f06d | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 349 | |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 350 | |
| 351 | def testBoardArchSingleMultiWord(self): |
| 352 | """Test single board selection""" |
| 353 | self.assertEqual(self.boards.SelectBoards(['arm', 'sandbox']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 354 | ({'sandbox': ['board4'], |
| 355 | 'all': ['board0', 'board1', 'board4'], |
| 356 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 357 | |
| 358 | def testBoardSingleAnd(self): |
| 359 | """Test single board selection""" |
| 360 | self.assertEqual(self.boards.SelectBoards(['Tester & arm']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 361 | ({'Tester&arm': ['board0', 'board1'], |
| 362 | 'all': ['board0', 'board1']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 363 | |
| 364 | def testBoardTwoAnd(self): |
| 365 | """Test single board selection""" |
| 366 | self.assertEqual(self.boards.SelectBoards(['Tester', '&', 'arm', |
| 367 | 'Tester' '&', 'powerpc', |
| 368 | 'sandbox']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 369 | ({'sandbox': ['board4'], |
Simon Glass | 5e0f06d | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 370 | 'all': ['board0', 'board1', 'board2', 'board3', |
| 371 | 'board4'], |
| 372 | 'Tester&powerpc': ['board2', 'board3'], |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 373 | 'Tester&arm': ['board0', 'board1']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 374 | |
| 375 | def testBoardAll(self): |
| 376 | """Test single board selection""" |
Simon Glass | 5e0f06d | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 377 | self.assertEqual(self.boards.SelectBoards([]), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 378 | ({'all': ['board0', 'board1', 'board2', 'board3', |
| 379 | 'board4']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 380 | |
| 381 | def testBoardRegularExpression(self): |
| 382 | """Test single board selection""" |
| 383 | self.assertEqual(self.boards.SelectBoards(['T.*r&^Po']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 384 | ({'all': ['board2', 'board3'], |
| 385 | 'T.*r&^Po': ['board2', 'board3']}, [])) |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 386 | |
| 387 | def testBoardDuplicate(self): |
| 388 | """Test single board selection""" |
| 389 | self.assertEqual(self.boards.SelectBoards(['sandbox sandbox', |
| 390 | 'sandbox']), |
Simon Glass | d9eb9f0 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 391 | ({'all': ['board4'], 'sandbox': ['board4']}, [])) |
Simon Glass | 2e1646c | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 392 | def CheckDirs(self, build, dirname): |
| 393 | self.assertEqual('base%s' % dirname, build._GetOutputDir(1)) |
| 394 | self.assertEqual('base%s/fred' % dirname, |
| 395 | build.GetBuildDir(1, 'fred')) |
| 396 | self.assertEqual('base%s/fred/done' % dirname, |
| 397 | build.GetDoneFile(1, 'fred')) |
| 398 | self.assertEqual('base%s/fred/u-boot.sizes' % dirname, |
| 399 | build.GetFuncSizesFile(1, 'fred', 'u-boot')) |
| 400 | self.assertEqual('base%s/fred/u-boot.objdump' % dirname, |
| 401 | build.GetObjdumpFile(1, 'fred', 'u-boot')) |
| 402 | self.assertEqual('base%s/fred/err' % dirname, |
| 403 | build.GetErrFile(1, 'fred')) |
| 404 | |
| 405 | def testOutputDir(self): |
| 406 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 407 | checkout=False, show_unknown=False) |
| 408 | build.commits = self.commits |
| 409 | build.commit_count = len(self.commits) |
| 410 | subject = self.commits[1].subject.translate(builder.trans_valid_chars) |
| 411 | dirname ='/%02d_of_%02d_g%s_%s' % (2, build.commit_count, commits[1][0], |
| 412 | subject[:20]) |
| 413 | self.CheckDirs(build, dirname) |
| 414 | |
| 415 | def testOutputDirCurrent(self): |
| 416 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 417 | checkout=False, show_unknown=False) |
| 418 | build.commits = None |
| 419 | build.commit_count = 0 |
| 420 | self.CheckDirs(build, '/current') |
Simon Glass | aa40f9a | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 421 | |
Simon Glass | e87bde1 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 422 | def testOutputDirNoSubdirs(self): |
| 423 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 424 | checkout=False, show_unknown=False, |
| 425 | no_subdirs=True) |
| 426 | build.commits = None |
| 427 | build.commit_count = 0 |
| 428 | self.CheckDirs(build, '') |
| 429 | |
Simon Glass | c1528c1 | 2014-12-01 17:34:05 -0700 | [diff] [blame] | 430 | def testToolchainAliases(self): |
| 431 | self.assertTrue(self.toolchains.Select('arm') != None) |
| 432 | with self.assertRaises(ValueError): |
| 433 | self.toolchains.Select('no-arch') |
| 434 | with self.assertRaises(ValueError): |
| 435 | self.toolchains.Select('x86') |
| 436 | |
| 437 | self.toolchains = toolchain.Toolchains() |
| 438 | self.toolchains.Add('x86_64-linux-gcc', test=False) |
| 439 | self.assertTrue(self.toolchains.Select('x86') != None) |
| 440 | |
| 441 | self.toolchains = toolchain.Toolchains() |
| 442 | self.toolchains.Add('i386-linux-gcc', test=False) |
| 443 | self.assertTrue(self.toolchains.Select('x86') != None) |
| 444 | |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 445 | def testToolchainDownload(self): |
| 446 | """Test that we can download toolchains""" |
Simon Glass | 2bfc697 | 2017-11-12 21:52:14 -0700 | [diff] [blame] | 447 | if use_network: |
Simon Glass | 0415002 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 448 | with test_util.capture_sys_output() as (stdout, stderr): |
| 449 | url = self.toolchains.LocateArchUrl('arm') |
Simon Glass | 72e358c | 2018-10-01 21:12:35 -0600 | [diff] [blame] | 450 | self.assertRegexpMatches(url, 'https://www.kernel.org/pub/tools/' |
| 451 | 'crosstool/files/bin/x86_64/.*/' |
| 452 | 'x86_64-gcc-.*-nolibc_arm-.*linux-gnueabi.tar.xz') |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 453 | |
| 454 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 455 | if __name__ == "__main__": |
| 456 | unittest.main() |