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