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 | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 100 | class Options: |
| 101 | """Class that holds build options""" |
| 102 | pass |
| 103 | |
| 104 | class TestBuild(unittest.TestCase): |
| 105 | """Test buildman |
| 106 | |
| 107 | TODO: Write tests for the rest of the functionality |
| 108 | """ |
| 109 | def setUp(self): |
| 110 | # Set up commits to build |
| 111 | self.commits = [] |
| 112 | sequence = 0 |
| 113 | for commit_info in commits: |
| 114 | comm = commit.Commit(commit_info[0]) |
| 115 | comm.subject = commit_info[1] |
| 116 | comm.return_code = commit_info[2] |
| 117 | comm.error_list = commit_info[3] |
| 118 | comm.sequence = sequence |
| 119 | sequence += 1 |
| 120 | self.commits.append(comm) |
| 121 | |
| 122 | # Set up boards to build |
| 123 | self.boards = board.Boards() |
| 124 | for brd in boards: |
| 125 | self.boards.AddBoard(board.Board(*brd)) |
| 126 | self.boards.SelectBoards([]) |
| 127 | |
Simon Glass | cc93529 | 2014-12-01 17:34:04 -0700 | [diff] [blame] | 128 | # Add some test settings |
| 129 | bsettings.Setup(None) |
| 130 | bsettings.AddFile(settings_data) |
| 131 | |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 132 | # Set up the toolchains |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 133 | self.toolchains = toolchain.Toolchains() |
| 134 | self.toolchains.Add('arm-linux-gcc', test=False) |
| 135 | self.toolchains.Add('sparc-linux-gcc', test=False) |
| 136 | self.toolchains.Add('powerpc-linux-gcc', test=False) |
| 137 | self.toolchains.Add('gcc', test=False) |
| 138 | |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 139 | # Avoid sending any output |
| 140 | terminal.SetPrintTestMode() |
| 141 | self._col = terminal.Color() |
| 142 | |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 143 | def Make(self, commit, brd, stage, *args, **kwargs): |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 144 | global base_dir |
| 145 | |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 146 | result = command.CommandResult() |
| 147 | boardnum = int(brd.target[-1]) |
| 148 | result.return_code = 0 |
| 149 | result.stderr = '' |
| 150 | result.stdout = ('This is the test output for board %s, commit %s' % |
| 151 | (brd.target, commit.hash)) |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 152 | if ((boardnum >= 1 and boardnum >= commit.sequence) or |
| 153 | boardnum == 4 and commit.sequence == 6): |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 154 | result.return_code = commit.return_code |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 155 | result.stderr = (''.join(commit.error_list) |
| 156 | % {'basedir' : base_dir + '/.bm-work/00/'}) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 157 | if stage == 'build': |
| 158 | target_dir = None |
| 159 | for arg in args: |
| 160 | if arg.startswith('O='): |
| 161 | target_dir = arg[2:] |
| 162 | |
| 163 | if not os.path.isdir(target_dir): |
| 164 | os.mkdir(target_dir) |
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 | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 169 | def assertSummary(self, text, arch, plus, boards, ok=False): |
| 170 | col = self._col |
| 171 | expected_colour = col.GREEN if ok else col.RED |
| 172 | expect = '%10s: ' % arch |
| 173 | # TODO(sjg@chromium.org): If plus is '', we shouldn't need this |
Simon Glass | 63c619e | 2015-02-05 22:06:11 -0700 | [diff] [blame] | 174 | expect += ' ' + col.Color(expected_colour, plus) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 175 | expect += ' ' |
| 176 | for board in boards: |
| 177 | expect += col.Color(expected_colour, ' %s' % board) |
| 178 | self.assertEqual(text, expect) |
| 179 | |
| 180 | def testOutput(self): |
| 181 | """Test basic builder operation and output |
| 182 | |
| 183 | This does a line-by-line verification of the summary output. |
| 184 | """ |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 185 | global base_dir |
| 186 | |
| 187 | base_dir = tempfile.mkdtemp() |
| 188 | if not os.path.isdir(base_dir): |
| 189 | os.mkdir(base_dir) |
| 190 | build = builder.Builder(self.toolchains, base_dir, None, 1, 2, |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 191 | checkout=False, show_unknown=False) |
| 192 | build.do_make = self.Make |
| 193 | board_selected = self.boards.GetSelectedDict() |
| 194 | |
Simon Glass | e5a0e5d | 2014-08-09 15:33:03 -0600 | [diff] [blame] | 195 | build.BuildBoards(self.commits, board_selected, keep_outputs=False, |
| 196 | verbose=False) |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 197 | lines = terminal.GetPrintTestLines() |
| 198 | count = 0 |
| 199 | for line in lines: |
| 200 | if line.text.strip(): |
| 201 | count += 1 |
| 202 | |
Simon Glass | 745b395 | 2016-09-18 16:48:33 -0600 | [diff] [blame] | 203 | # We should get two starting messages, then an update for every commit |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 204 | # built. |
Simon Glass | 745b395 | 2016-09-18 16:48:33 -0600 | [diff] [blame] | 205 | self.assertEqual(count, len(commits) * len(boards) + 2) |
Simon Glass | b2ea7ab | 2014-08-09 15:33:02 -0600 | [diff] [blame] | 206 | build.SetDisplayOptions(show_errors=True); |
| 207 | build.ShowSummary(self.commits, board_selected) |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 208 | #terminal.EchoPrintTestLines() |
Simon Glass | 6208fce | 2014-09-05 19:00:08 -0600 | [diff] [blame] | 209 | lines = terminal.GetPrintTestLines() |
| 210 | self.assertEqual(lines[0].text, '01: %s' % commits[0][1]) |
| 211 | self.assertEqual(lines[1].text, '02: %s' % commits[1][1]) |
| 212 | |
| 213 | # We expect all archs to fail |
| 214 | col = terminal.Color() |
| 215 | self.assertSummary(lines[2].text, 'sandbox', '+', ['board4']) |
| 216 | self.assertSummary(lines[3].text, 'arm', '+', ['board1']) |
| 217 | self.assertSummary(lines[4].text, 'powerpc', '+', ['board2', 'board3']) |
| 218 | |
| 219 | # Now we should have the compiler warning |
| 220 | self.assertEqual(lines[5].text, 'w+%s' % |
| 221 | errors[0].rstrip().replace('\n', '\nw+')) |
| 222 | self.assertEqual(lines[5].colour, col.MAGENTA) |
| 223 | |
| 224 | self.assertEqual(lines[6].text, '03: %s' % commits[2][1]) |
| 225 | self.assertSummary(lines[7].text, 'sandbox', '+', ['board4']) |
| 226 | self.assertSummary(lines[8].text, 'arm', '', ['board1'], ok=True) |
| 227 | self.assertSummary(lines[9].text, 'powerpc', '+', ['board2', 'board3']) |
| 228 | |
| 229 | # Compiler error |
| 230 | self.assertEqual(lines[10].text, '+%s' % |
| 231 | errors[1].rstrip().replace('\n', '\n+')) |
| 232 | |
| 233 | self.assertEqual(lines[11].text, '04: %s' % commits[3][1]) |
| 234 | self.assertSummary(lines[12].text, 'sandbox', '', ['board4'], ok=True) |
| 235 | self.assertSummary(lines[13].text, 'powerpc', '', ['board2', 'board3'], |
| 236 | ok=True) |
| 237 | |
| 238 | # Compile error fixed |
| 239 | self.assertEqual(lines[14].text, '-%s' % |
| 240 | errors[1].rstrip().replace('\n', '\n-')) |
| 241 | self.assertEqual(lines[14].colour, col.GREEN) |
| 242 | |
| 243 | self.assertEqual(lines[15].text, 'w+%s' % |
| 244 | errors[2].rstrip().replace('\n', '\nw+')) |
| 245 | self.assertEqual(lines[15].colour, col.MAGENTA) |
| 246 | |
| 247 | self.assertEqual(lines[16].text, '05: %s' % commits[4][1]) |
| 248 | self.assertSummary(lines[17].text, 'sandbox', '+', ['board4']) |
| 249 | self.assertSummary(lines[18].text, 'powerpc', '', ['board3'], ok=True) |
| 250 | |
| 251 | # The second line of errors[3] is a duplicate, so buildman will drop it |
| 252 | expect = errors[3].rstrip().split('\n') |
| 253 | expect = [expect[0]] + expect[2:] |
| 254 | self.assertEqual(lines[19].text, '+%s' % |
| 255 | '\n'.join(expect).replace('\n', '\n+')) |
| 256 | |
| 257 | self.assertEqual(lines[20].text, 'w-%s' % |
| 258 | errors[2].rstrip().replace('\n', '\nw-')) |
| 259 | |
| 260 | self.assertEqual(lines[21].text, '06: %s' % commits[5][1]) |
| 261 | self.assertSummary(lines[22].text, 'sandbox', '', ['board4'], ok=True) |
| 262 | |
| 263 | # The second line of errors[3] is a duplicate, so buildman will drop it |
| 264 | expect = errors[3].rstrip().split('\n') |
| 265 | expect = [expect[0]] + expect[2:] |
| 266 | self.assertEqual(lines[23].text, '-%s' % |
| 267 | '\n'.join(expect).replace('\n', '\n-')) |
| 268 | |
| 269 | self.assertEqual(lines[24].text, 'w-%s' % |
| 270 | errors[0].rstrip().replace('\n', '\nw-')) |
| 271 | |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 272 | self.assertEqual(lines[25].text, '07: %s' % commits[6][1]) |
| 273 | self.assertSummary(lines[26].text, 'sandbox', '+', ['board4']) |
| 274 | |
| 275 | # Pick out the correct error lines |
| 276 | expect_str = errors[4].rstrip().replace('%(basedir)s', '').split('\n') |
| 277 | expect = expect_str[3:8] + [expect_str[-1]] |
| 278 | self.assertEqual(lines[27].text, '+%s' % |
| 279 | '\n'.join(expect).replace('\n', '\n+')) |
| 280 | |
| 281 | # Now the warnings lines |
| 282 | expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]] |
| 283 | self.assertEqual(lines[28].text, 'w+%s' % |
| 284 | '\n'.join(expect).replace('\n', '\nw+')) |
| 285 | |
| 286 | self.assertEqual(len(lines), 29) |
| 287 | shutil.rmtree(base_dir) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 288 | |
| 289 | def _testGit(self): |
| 290 | """Test basic builder operation by building a branch""" |
| 291 | base_dir = tempfile.mkdtemp() |
| 292 | if not os.path.isdir(base_dir): |
| 293 | os.mkdir(base_dir) |
| 294 | options = Options() |
| 295 | options.git = os.getcwd() |
| 296 | options.summary = False |
| 297 | options.jobs = None |
| 298 | options.dry_run = False |
| 299 | #options.git = os.path.join(base_dir, 'repo') |
| 300 | options.branch = 'test-buildman' |
| 301 | options.force_build = False |
| 302 | options.list_tool_chains = False |
| 303 | options.count = -1 |
| 304 | options.git_dir = None |
| 305 | options.threads = None |
| 306 | options.show_unknown = False |
| 307 | options.quick = False |
| 308 | options.show_errors = False |
| 309 | options.keep_outputs = False |
| 310 | args = ['tegra20'] |
| 311 | control.DoBuildman(options, args) |
Simon Glass | 930c8d4 | 2014-09-05 19:00:21 -0600 | [diff] [blame] | 312 | shutil.rmtree(base_dir) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 313 | |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 314 | def testBoardSingle(self): |
| 315 | """Test single board selection""" |
| 316 | self.assertEqual(self.boards.SelectBoards(['sandbox']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 317 | ({'all': ['board4'], 'sandbox': ['board4']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 318 | |
| 319 | def testBoardArch(self): |
| 320 | """Test single board selection""" |
| 321 | self.assertEqual(self.boards.SelectBoards(['arm']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 322 | ({'all': ['board0', 'board1'], |
| 323 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 324 | |
| 325 | def testBoardArchSingle(self): |
| 326 | """Test single board selection""" |
| 327 | self.assertEqual(self.boards.SelectBoards(['arm sandbox']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 328 | ({'sandbox': ['board4'], |
Simon Glass | 251f586 | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 329 | 'all': ['board0', 'board1', 'board4'], |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 330 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | 251f586 | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 331 | |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 332 | |
| 333 | def testBoardArchSingleMultiWord(self): |
| 334 | """Test single board selection""" |
| 335 | self.assertEqual(self.boards.SelectBoards(['arm', 'sandbox']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 336 | ({'sandbox': ['board4'], |
| 337 | 'all': ['board0', 'board1', 'board4'], |
| 338 | 'arm': ['board0', 'board1']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 339 | |
| 340 | def testBoardSingleAnd(self): |
| 341 | """Test single board selection""" |
| 342 | self.assertEqual(self.boards.SelectBoards(['Tester & arm']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 343 | ({'Tester&arm': ['board0', 'board1'], |
| 344 | 'all': ['board0', 'board1']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 345 | |
| 346 | def testBoardTwoAnd(self): |
| 347 | """Test single board selection""" |
| 348 | self.assertEqual(self.boards.SelectBoards(['Tester', '&', 'arm', |
| 349 | 'Tester' '&', 'powerpc', |
| 350 | 'sandbox']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 351 | ({'sandbox': ['board4'], |
Simon Glass | 251f586 | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 352 | 'all': ['board0', 'board1', 'board2', 'board3', |
| 353 | 'board4'], |
| 354 | 'Tester&powerpc': ['board2', 'board3'], |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 355 | 'Tester&arm': ['board0', 'board1']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 356 | |
| 357 | def testBoardAll(self): |
| 358 | """Test single board selection""" |
Simon Glass | 251f586 | 2017-11-12 21:52:15 -0700 | [diff] [blame] | 359 | self.assertEqual(self.boards.SelectBoards([]), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 360 | ({'all': ['board0', 'board1', 'board2', 'board3', |
| 361 | 'board4']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 362 | |
| 363 | def testBoardRegularExpression(self): |
| 364 | """Test single board selection""" |
| 365 | self.assertEqual(self.boards.SelectBoards(['T.*r&^Po']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 366 | ({'all': ['board2', 'board3'], |
| 367 | 'T.*r&^Po': ['board2', 'board3']}, [])) |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 368 | |
| 369 | def testBoardDuplicate(self): |
| 370 | """Test single board selection""" |
| 371 | self.assertEqual(self.boards.SelectBoards(['sandbox sandbox', |
| 372 | 'sandbox']), |
Simon Glass | 0689036 | 2018-06-11 23:26:46 -0600 | [diff] [blame] | 373 | ({'all': ['board4'], 'sandbox': ['board4']}, [])) |
Simon Glass | 4466c1f | 2014-12-01 17:33:51 -0700 | [diff] [blame] | 374 | def CheckDirs(self, build, dirname): |
| 375 | self.assertEqual('base%s' % dirname, build._GetOutputDir(1)) |
| 376 | self.assertEqual('base%s/fred' % dirname, |
| 377 | build.GetBuildDir(1, 'fred')) |
| 378 | self.assertEqual('base%s/fred/done' % dirname, |
| 379 | build.GetDoneFile(1, 'fred')) |
| 380 | self.assertEqual('base%s/fred/u-boot.sizes' % dirname, |
| 381 | build.GetFuncSizesFile(1, 'fred', 'u-boot')) |
| 382 | self.assertEqual('base%s/fred/u-boot.objdump' % dirname, |
| 383 | build.GetObjdumpFile(1, 'fred', 'u-boot')) |
| 384 | self.assertEqual('base%s/fred/err' % dirname, |
| 385 | build.GetErrFile(1, 'fred')) |
| 386 | |
| 387 | def testOutputDir(self): |
| 388 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 389 | checkout=False, show_unknown=False) |
| 390 | build.commits = self.commits |
| 391 | build.commit_count = len(self.commits) |
| 392 | subject = self.commits[1].subject.translate(builder.trans_valid_chars) |
| 393 | dirname ='/%02d_of_%02d_g%s_%s' % (2, build.commit_count, commits[1][0], |
| 394 | subject[:20]) |
| 395 | self.CheckDirs(build, dirname) |
| 396 | |
| 397 | def testOutputDirCurrent(self): |
| 398 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 399 | checkout=False, show_unknown=False) |
| 400 | build.commits = None |
| 401 | build.commit_count = 0 |
| 402 | self.CheckDirs(build, '/current') |
Simon Glass | 6131bea | 2014-08-09 15:33:08 -0600 | [diff] [blame] | 403 | |
Simon Glass | 5971ab5 | 2014-12-01 17:33:55 -0700 | [diff] [blame] | 404 | def testOutputDirNoSubdirs(self): |
| 405 | build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2, |
| 406 | checkout=False, show_unknown=False, |
| 407 | no_subdirs=True) |
| 408 | build.commits = None |
| 409 | build.commit_count = 0 |
| 410 | self.CheckDirs(build, '') |
| 411 | |
Simon Glass | 9b83bfd | 2014-12-01 17:34:05 -0700 | [diff] [blame] | 412 | def testToolchainAliases(self): |
| 413 | self.assertTrue(self.toolchains.Select('arm') != None) |
| 414 | with self.assertRaises(ValueError): |
| 415 | self.toolchains.Select('no-arch') |
| 416 | with self.assertRaises(ValueError): |
| 417 | self.toolchains.Select('x86') |
| 418 | |
| 419 | self.toolchains = toolchain.Toolchains() |
| 420 | self.toolchains.Add('x86_64-linux-gcc', test=False) |
| 421 | self.assertTrue(self.toolchains.Select('x86') != None) |
| 422 | |
| 423 | self.toolchains = toolchain.Toolchains() |
| 424 | self.toolchains.Add('i386-linux-gcc', test=False) |
| 425 | self.assertTrue(self.toolchains.Select('x86') != None) |
| 426 | |
Simon Glass | 827e37b | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 427 | def testToolchainDownload(self): |
| 428 | """Test that we can download toolchains""" |
Simon Glass | cb39a10 | 2017-11-12 21:52:14 -0700 | [diff] [blame] | 429 | if use_network: |
Simon Glass | 4b4bc06 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 430 | with test_util.capture_sys_output() as (stdout, stderr): |
| 431 | url = self.toolchains.LocateArchUrl('arm') |
Simon Glass | da753e3 | 2018-10-01 21:12:35 -0600 | [diff] [blame] | 432 | self.assertRegexpMatches(url, 'https://www.kernel.org/pub/tools/' |
| 433 | 'crosstool/files/bin/x86_64/.*/' |
| 434 | 'x86_64-gcc-.*-nolibc_arm-.*linux-gnueabi.tar.xz') |
Simon Glass | 827e37b | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 435 | |
| 436 | |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 437 | if __name__ == "__main__": |
| 438 | unittest.main() |