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 |
| 25 | |
Simon Glass | cb39a10 | 2017-11-12 21:52:14 -0700 | [diff] [blame] | 26 | use_network = True |
| 27 | |
Simon Glass | cc93529 | 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 | fc3fe1c | 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 | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 42 | '''main.c: In function 'main_loop2': |
Simon Glass | fc3fe1c | 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 | 2d48333 | 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 | fc3fe1c | 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 | 930c8d4 | 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 | fc3fe1c | 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 | 930c8d4 | 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 | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 88 | ] |
| 89 | |
| 90 | boards = [ |
Simon Glass | e19d578 | 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 | 251f586 | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 94 | ['Active', 'powerpc', 'mpc83xx', '', 'Tester', 'PowerPC board 2', 'board3', ''], |
Simon Glass | e19d578 | 2013-09-23 17:35:16 -0600 | [diff] [blame] | 95 | ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''], |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 96 | ] |
| 97 | |
Simon Glass | 4466c1f | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 98 | BASE_DIR = 'base' |
| 99 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 100 | OUTCOME_OK, OUTCOME_WARN, OUTCOME_ERR = range(3) |
| 101 | |
Simon Glass | fc3fe1c | 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 | cc93529 | 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 | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 134 | # Set up the toolchains |
Simon Glass | fc3fe1c | 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 | 6208fce | 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 | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 145 | def Make(self, commit, brd, stage, *args, **kwargs): |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 146 | global base_dir |
| 147 | |
Simon Glass | fc3fe1c | 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 | 930c8d4 | 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 | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 156 | result.return_code = commit.return_code |
Simon Glass | 930c8d4 | 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 | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 159 | if stage == 'build': |
| 160 | target_dir = None |
| 161 | for arg in args: |
| 162 | if arg.startswith('O='): |
| 163 | target_dir = arg[2:] |
| 164 | |
| 165 | if not os.path.isdir(target_dir): |
| 166 | os.mkdir(target_dir) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 167 | |
| 168 | result.combined = result.stdout + result.stderr |
| 169 | return result |
| 170 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 171 | def assertSummary(self, text, arch, plus, boards, outcome=OUTCOME_ERR): |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 172 | col = self._col |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 173 | expected_colour = (col.GREEN if outcome == OUTCOME_OK else |
| 174 | col.YELLOW if outcome == OUTCOME_WARN else col.RED) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 175 | expect = '%10s: ' % arch |
| 176 | # TODO(sjg@chromium.org): If plus is '', we shouldn't need this |
Simon Glass | 63c619e | 2015-02-05 22:06:11 -0700 | [diff] [blame] | 177 | expect += ' ' + col.Color(expected_colour, plus) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 178 | expect += ' ' |
| 179 | for board in boards: |
| 180 | expect += col.Color(expected_colour, ' %s' % board) |
| 181 | self.assertEqual(text, expect) |
| 182 | |
| 183 | def testOutput(self): |
| 184 | """Test basic builder operation and output |
| 185 | |
| 186 | This does a line-by-line verification of the summary output. |
| 187 | """ |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 188 | global base_dir |
| 189 | |
| 190 | base_dir = tempfile.mkdtemp() |
| 191 | if not os.path.isdir(base_dir): |
| 192 | os.mkdir(base_dir) |
| 193 | build = builder.Builder(self.toolchains, 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 | b2ea7ab | 2014-08-09 15:33:02 -0600 | [diff] [blame] | 211 | build.SetDisplayOptions(show_errors=True); |
| 212 | build.ShowSummary(self.commits, board_selected) |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 213 | #terminal.EchoPrintTestLines() |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 214 | lines = terminal.GetPrintTestLines() |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 215 | |
| 216 | # Upstream commit: no errors |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 217 | self.assertEqual(lines[0].text, '01: %s' % commits[0][1]) |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 218 | |
| 219 | # Second commit: all archs should fail with warnings |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 220 | self.assertEqual(lines[1].text, '02: %s' % commits[1][1]) |
| 221 | |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 222 | col = terminal.Color() |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 223 | self.assertSummary(lines[2].text, 'sandbox', 'w+', ['board4'], |
| 224 | outcome=OUTCOME_WARN) |
| 225 | self.assertSummary(lines[3].text, 'arm', 'w+', ['board1'], |
| 226 | outcome=OUTCOME_WARN) |
| 227 | self.assertSummary(lines[4].text, 'powerpc', 'w+', ['board2', 'board3'], |
| 228 | outcome=OUTCOME_WARN) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 229 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 230 | # Second commit: The warnings should be listed |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 231 | self.assertEqual(lines[5].text, 'w+%s' % |
| 232 | errors[0].rstrip().replace('\n', '\nw+')) |
| 233 | self.assertEqual(lines[5].colour, col.MAGENTA) |
| 234 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 235 | # Third commit: Still fails |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 236 | self.assertEqual(lines[6].text, '03: %s' % commits[2][1]) |
| 237 | self.assertSummary(lines[7].text, 'sandbox', '+', ['board4']) |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 238 | self.assertSummary(lines[8].text, 'arm', '', ['board1'], |
| 239 | outcome=OUTCOME_OK) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 240 | self.assertSummary(lines[9].text, 'powerpc', '+', ['board2', 'board3']) |
| 241 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 242 | # Expect a compiler error |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 243 | self.assertEqual(lines[10].text, '+%s' % |
| 244 | errors[1].rstrip().replace('\n', '\n+')) |
| 245 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 246 | # Fourth commit: Compile errors are fixed, just have warning for board3 |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 247 | self.assertEqual(lines[11].text, '04: %s' % commits[3][1]) |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 248 | self.assertSummary(lines[12].text, 'sandbox', 'w+', ['board4'], |
| 249 | outcome=OUTCOME_WARN) |
| 250 | expect = '%10s: ' % 'powerpc' |
| 251 | expect += ' ' + col.Color(col.GREEN, '') |
| 252 | expect += ' ' |
| 253 | expect += col.Color(col.GREEN, ' %s' % 'board2') |
| 254 | expect += ' ' + col.Color(col.YELLOW, 'w+') |
| 255 | expect += ' ' |
| 256 | expect += col.Color(col.YELLOW, ' %s' % 'board3') |
| 257 | self.assertEqual(lines[13].text, expect) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 258 | |
| 259 | # Compile error fixed |
| 260 | self.assertEqual(lines[14].text, '-%s' % |
| 261 | errors[1].rstrip().replace('\n', '\n-')) |
| 262 | self.assertEqual(lines[14].colour, col.GREEN) |
| 263 | |
| 264 | self.assertEqual(lines[15].text, 'w+%s' % |
| 265 | errors[2].rstrip().replace('\n', '\nw+')) |
| 266 | self.assertEqual(lines[15].colour, col.MAGENTA) |
| 267 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 268 | # Fifth commit |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 269 | self.assertEqual(lines[16].text, '05: %s' % commits[4][1]) |
| 270 | self.assertSummary(lines[17].text, 'sandbox', '+', ['board4']) |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 271 | self.assertSummary(lines[18].text, 'powerpc', '', ['board3'], |
| 272 | outcome=OUTCOME_OK) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 273 | |
| 274 | # The second line of errors[3] is a duplicate, so buildman will drop it |
| 275 | expect = errors[3].rstrip().split('\n') |
| 276 | expect = [expect[0]] + expect[2:] |
| 277 | self.assertEqual(lines[19].text, '+%s' % |
| 278 | '\n'.join(expect).replace('\n', '\n+')) |
| 279 | |
| 280 | self.assertEqual(lines[20].text, 'w-%s' % |
| 281 | errors[2].rstrip().replace('\n', '\nw-')) |
| 282 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 283 | # Sixth commit |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 284 | self.assertEqual(lines[21].text, '06: %s' % commits[5][1]) |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 285 | self.assertSummary(lines[22].text, 'sandbox', '', ['board4'], |
| 286 | outcome=OUTCOME_OK) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 287 | |
| 288 | # The second line of errors[3] is a duplicate, so buildman will drop it |
| 289 | expect = errors[3].rstrip().split('\n') |
| 290 | expect = [expect[0]] + expect[2:] |
| 291 | self.assertEqual(lines[23].text, '-%s' % |
| 292 | '\n'.join(expect).replace('\n', '\n-')) |
| 293 | |
| 294 | self.assertEqual(lines[24].text, 'w-%s' % |
| 295 | errors[0].rstrip().replace('\n', '\nw-')) |
| 296 | |
Simon Glass | 6af7101 | 2018-11-06 16:02:13 -0700 | [diff] [blame] | 297 | # Seventh commit |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 298 | self.assertEqual(lines[25].text, '07: %s' % commits[6][1]) |
| 299 | self.assertSummary(lines[26].text, 'sandbox', '+', ['board4']) |
| 300 | |
| 301 | # Pick out the correct error lines |
| 302 | expect_str = errors[4].rstrip().replace('%(basedir)s', '').split('\n') |
| 303 | expect = expect_str[3:8] + [expect_str[-1]] |
| 304 | self.assertEqual(lines[27].text, '+%s' % |
| 305 | '\n'.join(expect).replace('\n', '\n+')) |
| 306 | |
| 307 | # Now the warnings lines |
| 308 | expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]] |
| 309 | self.assertEqual(lines[28].text, 'w+%s' % |
| 310 | '\n'.join(expect).replace('\n', '\nw+')) |
| 311 | |
| 312 | self.assertEqual(len(lines), 29) |
| 313 | shutil.rmtree(base_dir) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 314 | |
| 315 | def _testGit(self): |
| 316 | """Test basic builder operation by building a branch""" |
| 317 | base_dir = tempfile.mkdtemp() |
| 318 | if not os.path.isdir(base_dir): |
| 319 | os.mkdir(base_dir) |
| 320 | options = Options() |
| 321 | options.git = os.getcwd() |
| 322 | options.summary = False |
| 323 | options.jobs = None |
| 324 | options.dry_run = False |
| 325 | #options.git = os.path.join(base_dir, 'repo') |
| 326 | options.branch = 'test-buildman' |
| 327 | options.force_build = False |
| 328 | options.list_tool_chains = False |
| 329 | options.count = -1 |
| 330 | options.git_dir = None |
| 331 | options.threads = None |
| 332 | options.show_unknown = False |
| 333 | options.quick = False |
| 334 | options.show_errors = False |
| 335 | options.keep_outputs = False |
| 336 | args = ['tegra20'] |
| 337 | control.DoBuildman(options, args) |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 338 | shutil.rmtree(base_dir) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 339 | |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 340 | def testBoardSingle(self): |
| 341 | """Test single board selection""" |
| 342 | self.assertEqual(self.boards.SelectBoards(['sandbox']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 343 | ({'all': ['board4'], 'sandbox': ['board4']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 344 | |
| 345 | def testBoardArch(self): |
| 346 | """Test single board selection""" |
| 347 | self.assertEqual(self.boards.SelectBoards(['arm']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 348 | ({'all': ['board0', 'board1'], |
| 349 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 350 | |
| 351 | def testBoardArchSingle(self): |
| 352 | """Test single board selection""" |
| 353 | self.assertEqual(self.boards.SelectBoards(['arm sandbox']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 354 | ({'sandbox': ['board4'], |
Simon Glass | 251f586 | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 355 | 'all': ['board0', 'board1', 'board4'], |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 356 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | 251f586 | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 357 | |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 358 | |
| 359 | def testBoardArchSingleMultiWord(self): |
| 360 | """Test single board selection""" |
| 361 | self.assertEqual(self.boards.SelectBoards(['arm', 'sandbox']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 362 | ({'sandbox': ['board4'], |
| 363 | 'all': ['board0', 'board1', 'board4'], |
| 364 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 365 | |
| 366 | def testBoardSingleAnd(self): |
| 367 | """Test single board selection""" |
| 368 | self.assertEqual(self.boards.SelectBoards(['Tester & arm']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 369 | ({'Tester&arm': ['board0', 'board1'], |
| 370 | 'all': ['board0', 'board1']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 371 | |
| 372 | def testBoardTwoAnd(self): |
| 373 | """Test single board selection""" |
| 374 | self.assertEqual(self.boards.SelectBoards(['Tester', '&', 'arm', |
| 375 | 'Tester' '&', 'powerpc', |
| 376 | 'sandbox']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 377 | ({'sandbox': ['board4'], |
Simon Glass | 251f586 | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 378 | 'all': ['board0', 'board1', 'board2', 'board3', |
| 379 | 'board4'], |
| 380 | 'Tester&powerpc': ['board2', 'board3'], |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 381 | 'Tester&arm': ['board0', 'board1']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 382 | |
| 383 | def testBoardAll(self): |
| 384 | """Test single board selection""" |
Simon Glass | 251f586 | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 385 | self.assertEqual(self.boards.SelectBoards([]), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 386 | ({'all': ['board0', 'board1', 'board2', 'board3', |
| 387 | 'board4']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 388 | |
| 389 | def testBoardRegularExpression(self): |
| 390 | """Test single board selection""" |
| 391 | self.assertEqual(self.boards.SelectBoards(['T.*r&^Po']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 392 | ({'all': ['board2', 'board3'], |
| 393 | 'T.*r&^Po': ['board2', 'board3']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 394 | |
| 395 | def testBoardDuplicate(self): |
| 396 | """Test single board selection""" |
| 397 | self.assertEqual(self.boards.SelectBoards(['sandbox sandbox', |
| 398 | 'sandbox']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 399 | ({'all': ['board4'], 'sandbox': ['board4']}, [])) |
Simon Glass | 4466c1f | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 400 | def CheckDirs(self, build, dirname): |
| 401 | self.assertEqual('base%s' % dirname, build._GetOutputDir(1)) |
| 402 | self.assertEqual('base%s/fred' % dirname, |
| 403 | build.GetBuildDir(1, 'fred')) |
| 404 | self.assertEqual('base%s/fred/done' % dirname, |
| 405 | build.GetDoneFile(1, 'fred')) |
| 406 | self.assertEqual('base%s/fred/u-boot.sizes' % dirname, |
| 407 | build.GetFuncSizesFile(1, 'fred', 'u-boot')) |
| 408 | self.assertEqual('base%s/fred/u-boot.objdump' % dirname, |
| 409 | build.GetObjdumpFile(1, 'fred', 'u-boot')) |
| 410 | self.assertEqual('base%s/fred/err' % dirname, |
| 411 | build.GetErrFile(1, 'fred')) |
| 412 | |
| 413 | def testOutputDir(self): |
| 414 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 415 | checkout=False, show_unknown=False) |
| 416 | build.commits = self.commits |
| 417 | build.commit_count = len(self.commits) |
| 418 | subject = self.commits[1].subject.translate(builder.trans_valid_chars) |
| 419 | dirname ='/%02d_of_%02d_g%s_%s' % (2, build.commit_count, commits[1][0], |
| 420 | subject[:20]) |
| 421 | self.CheckDirs(build, dirname) |
| 422 | |
| 423 | def testOutputDirCurrent(self): |
| 424 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 425 | checkout=False, show_unknown=False) |
| 426 | build.commits = None |
| 427 | build.commit_count = 0 |
| 428 | self.CheckDirs(build, '/current') |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 429 | |
Simon Glass | 5971ab5 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 430 | def testOutputDirNoSubdirs(self): |
| 431 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 432 | checkout=False, show_unknown=False, |
| 433 | no_subdirs=True) |
| 434 | build.commits = None |
| 435 | build.commit_count = 0 |
| 436 | self.CheckDirs(build, '') |
| 437 | |
Simon Glass | 9b83bfd | 2014-12-01 17:34:05 -0700 | [diff] [blame] | 438 | def testToolchainAliases(self): |
| 439 | self.assertTrue(self.toolchains.Select('arm') != None) |
| 440 | with self.assertRaises(ValueError): |
| 441 | self.toolchains.Select('no-arch') |
| 442 | with self.assertRaises(ValueError): |
| 443 | self.toolchains.Select('x86') |
| 444 | |
| 445 | self.toolchains = toolchain.Toolchains() |
| 446 | self.toolchains.Add('x86_64-linux-gcc', test=False) |
| 447 | self.assertTrue(self.toolchains.Select('x86') != None) |
| 448 | |
| 449 | self.toolchains = toolchain.Toolchains() |
| 450 | self.toolchains.Add('i386-linux-gcc', test=False) |
| 451 | self.assertTrue(self.toolchains.Select('x86') != None) |
| 452 | |
Simon Glass | 827e37b | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 453 | def testToolchainDownload(self): |
| 454 | """Test that we can download toolchains""" |
Simon Glass | cb39a10 | 2017-11-12 21:52:14 -0700 | [diff] [blame] | 455 | if use_network: |
Simon Glass | 4b4bc06 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 456 | with test_util.capture_sys_output() as (stdout, stderr): |
| 457 | url = self.toolchains.LocateArchUrl('arm') |
Simon Glass | da753e3 | 2018-10-01 21:12:35 -0600 | [diff] [blame] | 458 | self.assertRegexpMatches(url, 'https://www.kernel.org/pub/tools/' |
| 459 | 'crosstool/files/bin/x86_64/.*/' |
| 460 | 'x86_64-gcc-.*-nolibc_arm-.*linux-gnueabi.tar.xz') |
Simon Glass | 827e37b | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 461 | |
| 462 | |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 463 | if __name__ == "__main__": |
| 464 | unittest.main() |