blob: 84dd608127ed48a9884058f0c3b50b0d6da0d01b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Simon Glassfc3fe1c2013-04-03 11:07:16 +00002# Copyright (c) 2012 The Chromium OS Authors.
3#
Simon Glassfc3fe1c2013-04-03 11:07:16 +00004
5import os
6import shutil
7import sys
8import tempfile
9import time
10import unittest
11
12# Bring in the patman libraries
13our_path = os.path.dirname(os.path.realpath(__file__))
14sys.path.append(os.path.join(our_path, '../patman'))
15
16import board
17import bsettings
18import builder
19import control
20import command
21import commit
Simon Glass6208fce2014-09-05 19:00:08 -060022import terminal
Simon Glass4b4bc062018-10-01 21:12:43 -060023import test_util
Simon Glassfc3fe1c2013-04-03 11:07:16 +000024import toolchain
Simon Glass925f6ad2020-03-18 09:42:45 -060025import tools
Simon Glassfc3fe1c2013-04-03 11:07:16 +000026
Simon Glasscb39a102017-11-12 21:52:14 -070027use_network = True
28
Simon Glasscc935292014-12-01 17:34:04 -070029settings_data = '''
30# Buildman settings file
31
32[toolchain]
33main: /usr/sbin
34
35[toolchain-alias]
36x86: i386 x86_64
37'''
38
Simon Glassfc3fe1c2013-04-03 11:07:16 +000039errors = [
40 '''main.c: In function 'main_loop':
41main.c:260:6: warning: unused variable 'joe' [-Wunused-variable]
42''',
Simon Glass6208fce2014-09-05 19:00:08 -060043 '''main.c: In function 'main_loop2':
Simon Glassfc3fe1c2013-04-03 11:07:16 +000044main.c:295:2: error: 'fred' undeclared (first use in this function)
45main.c:295:2: note: each undeclared identifier is reported only once for each function it appears in
46make[1]: *** [main.o] Error 1
47make: *** [common/libcommon.o] Error 2
48Make failed
49''',
Simon Glass2d483332018-11-06 16:02:11 -070050 '''arch/arm/dts/socfpga_arria10_socdk_sdmmc.dtb: Warning \
51(avoid_unnecessary_addr_size): /clocks: unnecessary #address-cells/#size-cells \
52without "ranges" or child "reg" property
Simon Glassfc3fe1c2013-04-03 11:07:16 +000053''',
54 '''powerpc-linux-ld: warning: dot moved backwards before `.bss'
55powerpc-linux-ld: warning: dot moved backwards before `.bss'
56powerpc-linux-ld: u-boot: section .text lma 0xfffc0000 overlaps previous sections
57powerpc-linux-ld: u-boot: section .rodata lma 0xfffef3ec overlaps previous sections
58powerpc-linux-ld: u-boot: section .reloc lma 0xffffa400 overlaps previous sections
59powerpc-linux-ld: u-boot: section .data lma 0xffffcd38 overlaps previous sections
60powerpc-linux-ld: u-boot: section .u_boot_cmd lma 0xffffeb40 overlaps previous sections
61powerpc-linux-ld: u-boot: section .bootpg lma 0xfffff198 overlaps previous sections
Simon Glass930c8d42014-09-05 19:00:21 -060062''',
63 '''In file included from %(basedir)sarch/sandbox/cpu/cpu.c:9:0:
64%(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default]
65%(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition
66%(basedir)sarch/sandbox/cpu/cpu.c: In function 'do_reset':
67%(basedir)sarch/sandbox/cpu/cpu.c:27:1: error: unknown type name 'blah'
68%(basedir)sarch/sandbox/cpu/cpu.c:28:12: error: expected declaration specifiers or '...' before numeric constant
69make[2]: *** [arch/sandbox/cpu/cpu.o] Error 1
70make[1]: *** [arch/sandbox/cpu] Error 2
71make[1]: *** Waiting for unfinished jobs....
72In file included from %(basedir)scommon/board_f.c:55:0:
73%(basedir)sarch/sandbox/include/asm/state.h:44:0: warning: "xxxx" redefined [enabled by default]
74%(basedir)sarch/sandbox/include/asm/state.h:43:0: note: this is the location of the previous definition
75make: *** [sub-make] Error 2
Simon Glassfc3fe1c2013-04-03 11:07:16 +000076'''
77]
78
79
80# hash, subject, return code, list of errors/warnings
81commits = [
82 ['1234', 'upstream/master, ok', 0, []],
83 ['5678', 'Second commit, a warning', 0, errors[0:1]],
84 ['9012', 'Third commit, error', 1, errors[0:2]],
85 ['3456', 'Fourth commit, warning', 0, [errors[0], errors[2]]],
86 ['7890', 'Fifth commit, link errors', 1, [errors[0], errors[3]]],
Simon Glass930c8d42014-09-05 19:00:21 -060087 ['abcd', 'Sixth commit, fixes all errors', 0, []],
88 ['ef01', 'Seventh commit, check directory suppression', 1, [errors[4]]],
Simon Glassfc3fe1c2013-04-03 11:07:16 +000089]
90
91boards = [
Simon Glasse19d5782013-09-23 17:35:16 -060092 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board0', ''],
93 ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 2', 'board1', ''],
94 ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''],
Simon Glass251f5862017-11-12 21:52:15 -070095 ['Active', 'powerpc', 'mpc83xx', '', 'Tester', 'PowerPC board 2', 'board3', ''],
Simon Glasse19d5782013-09-23 17:35:16 -060096 ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''],
Simon Glassfc3fe1c2013-04-03 11:07:16 +000097]
98
Simon Glass4466c1f2014-12-01 17:33:51 -070099BASE_DIR = 'base'
100
Simon Glass6af71012018-11-06 16:02:13 -0700101OUTCOME_OK, OUTCOME_WARN, OUTCOME_ERR = range(3)
102
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000103class Options:
104 """Class that holds build options"""
105 pass
106
107class TestBuild(unittest.TestCase):
108 """Test buildman
109
110 TODO: Write tests for the rest of the functionality
111 """
112 def setUp(self):
113 # Set up commits to build
114 self.commits = []
115 sequence = 0
116 for commit_info in commits:
117 comm = commit.Commit(commit_info[0])
118 comm.subject = commit_info[1]
119 comm.return_code = commit_info[2]
120 comm.error_list = commit_info[3]
121 comm.sequence = sequence
122 sequence += 1
123 self.commits.append(comm)
124
125 # Set up boards to build
126 self.boards = board.Boards()
127 for brd in boards:
128 self.boards.AddBoard(board.Board(*brd))
129 self.boards.SelectBoards([])
130
Simon Glasscc935292014-12-01 17:34:04 -0700131 # Add some test settings
132 bsettings.Setup(None)
133 bsettings.AddFile(settings_data)
134
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000135 # Set up the toolchains
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000136 self.toolchains = toolchain.Toolchains()
137 self.toolchains.Add('arm-linux-gcc', test=False)
138 self.toolchains.Add('sparc-linux-gcc', test=False)
139 self.toolchains.Add('powerpc-linux-gcc', test=False)
140 self.toolchains.Add('gcc', test=False)
141
Simon Glass6208fce2014-09-05 19:00:08 -0600142 # Avoid sending any output
143 terminal.SetPrintTestMode()
144 self._col = terminal.Color()
145
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000146 def Make(self, commit, brd, stage, *args, **kwargs):
Simon Glass930c8d42014-09-05 19:00:21 -0600147 global base_dir
148
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000149 result = command.CommandResult()
150 boardnum = int(brd.target[-1])
151 result.return_code = 0
152 result.stderr = ''
153 result.stdout = ('This is the test output for board %s, commit %s' %
154 (brd.target, commit.hash))
Simon Glass930c8d42014-09-05 19:00:21 -0600155 if ((boardnum >= 1 and boardnum >= commit.sequence) or
156 boardnum == 4 and commit.sequence == 6):
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000157 result.return_code = commit.return_code
Simon Glass930c8d42014-09-05 19:00:21 -0600158 result.stderr = (''.join(commit.error_list)
159 % {'basedir' : base_dir + '/.bm-work/00/'})
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000160
161 result.combined = result.stdout + result.stderr
162 return result
163
Simon Glass6af71012018-11-06 16:02:13 -0700164 def assertSummary(self, text, arch, plus, boards, outcome=OUTCOME_ERR):
Simon Glass6208fce2014-09-05 19:00:08 -0600165 col = self._col
Simon Glass6af71012018-11-06 16:02:13 -0700166 expected_colour = (col.GREEN if outcome == OUTCOME_OK else
167 col.YELLOW if outcome == OUTCOME_WARN else col.RED)
Simon Glass6208fce2014-09-05 19:00:08 -0600168 expect = '%10s: ' % arch
169 # TODO(sjg@chromium.org): If plus is '', we shouldn't need this
Simon Glass63c619e2015-02-05 22:06:11 -0700170 expect += ' ' + col.Color(expected_colour, plus)
Simon Glass6208fce2014-09-05 19:00:08 -0600171 expect += ' '
172 for board in boards:
173 expect += col.Color(expected_colour, ' %s' % board)
174 self.assertEqual(text, expect)
175
176 def testOutput(self):
177 """Test basic builder operation and output
178
179 This does a line-by-line verification of the summary output.
180 """
Simon Glass930c8d42014-09-05 19:00:21 -0600181 global base_dir
182
183 base_dir = tempfile.mkdtemp()
184 if not os.path.isdir(base_dir):
185 os.mkdir(base_dir)
186 build = builder.Builder(self.toolchains, base_dir, None, 1, 2,
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000187 checkout=False, show_unknown=False)
188 build.do_make = self.Make
189 board_selected = self.boards.GetSelectedDict()
190
Simon Glass6af71012018-11-06 16:02:13 -0700191 # Build the boards for the pre-defined commits and warnings/errors
192 # associated with each. This calls our Make() to inject the fake output.
Simon Glasse5a0e5d2014-08-09 15:33:03 -0600193 build.BuildBoards(self.commits, board_selected, keep_outputs=False,
194 verbose=False)
Simon Glass6208fce2014-09-05 19:00:08 -0600195 lines = terminal.GetPrintTestLines()
196 count = 0
197 for line in lines:
198 if line.text.strip():
199 count += 1
200
Simon Glass745b3952016-09-18 16:48:33 -0600201 # We should get two starting messages, then an update for every commit
Simon Glass6208fce2014-09-05 19:00:08 -0600202 # built.
Simon Glass745b3952016-09-18 16:48:33 -0600203 self.assertEqual(count, len(commits) * len(boards) + 2)
Simon Glassb2ea7ab2014-08-09 15:33:02 -0600204 build.SetDisplayOptions(show_errors=True);
205 build.ShowSummary(self.commits, board_selected)
Simon Glass930c8d42014-09-05 19:00:21 -0600206 #terminal.EchoPrintTestLines()
Simon Glassc3bc4f12020-04-09 15:08:30 -0600207 lines = iter(terminal.GetPrintTestLines())
Simon Glass6af71012018-11-06 16:02:13 -0700208
209 # Upstream commit: no errors
Simon Glassc3bc4f12020-04-09 15:08:30 -0600210 self.assertEqual(next(lines).text, '01: %s' % commits[0][1])
Simon Glass6af71012018-11-06 16:02:13 -0700211
212 # Second commit: all archs should fail with warnings
Simon Glassc3bc4f12020-04-09 15:08:30 -0600213 self.assertEqual(next(lines).text, '02: %s' % commits[1][1])
Simon Glass6208fce2014-09-05 19:00:08 -0600214
Simon Glass6208fce2014-09-05 19:00:08 -0600215 col = terminal.Color()
Simon Glassc3bc4f12020-04-09 15:08:30 -0600216 self.assertSummary(next(lines).text, 'arm', 'w+', ['board1'],
Simon Glass6af71012018-11-06 16:02:13 -0700217 outcome=OUTCOME_WARN)
Simon Glassc3bc4f12020-04-09 15:08:30 -0600218 self.assertSummary(next(lines).text, 'powerpc', 'w+',
219 ['board2', 'board3'], outcome=OUTCOME_WARN)
220 self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
Simon Glass6af71012018-11-06 16:02:13 -0700221 outcome=OUTCOME_WARN)
Simon Glass6208fce2014-09-05 19:00:08 -0600222
Simon Glass6af71012018-11-06 16:02:13 -0700223 # Second commit: The warnings should be listed
Simon Glassc3bc4f12020-04-09 15:08:30 -0600224 line = next(lines)
225 self.assertEqual(line.text, 'w+%s' %
Simon Glass6208fce2014-09-05 19:00:08 -0600226 errors[0].rstrip().replace('\n', '\nw+'))
Simon Glassc3bc4f12020-04-09 15:08:30 -0600227 self.assertEqual(line.colour, col.MAGENTA)
Simon Glass6208fce2014-09-05 19:00:08 -0600228
Simon Glass6af71012018-11-06 16:02:13 -0700229 # Third commit: Still fails
Simon Glassc3bc4f12020-04-09 15:08:30 -0600230 self.assertEqual(next(lines).text, '03: %s' % commits[2][1])
231 self.assertSummary(next(lines).text, 'arm', '', ['board1'],
Simon Glass6af71012018-11-06 16:02:13 -0700232 outcome=OUTCOME_OK)
Simon Glassc3bc4f12020-04-09 15:08:30 -0600233 self.assertSummary(next(lines).text, 'powerpc', '+',
234 ['board2', 'board3'])
235 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
Simon Glass6208fce2014-09-05 19:00:08 -0600236
Simon Glass6af71012018-11-06 16:02:13 -0700237 # Expect a compiler error
Simon Glassc3bc4f12020-04-09 15:08:30 -0600238 line = next(lines)
239 self.assertEqual(line.text, '+%s' %
Simon Glass6208fce2014-09-05 19:00:08 -0600240 errors[1].rstrip().replace('\n', '\n+'))
Simon Glassc3bc4f12020-04-09 15:08:30 -0600241 self.assertEqual(line.colour, col.RED)
Simon Glass6208fce2014-09-05 19:00:08 -0600242
Simon Glass6af71012018-11-06 16:02:13 -0700243 # Fourth commit: Compile errors are fixed, just have warning for board3
Simon Glassc3bc4f12020-04-09 15:08:30 -0600244 self.assertEqual(next(lines).text, '04: %s' % commits[3][1])
Simon Glass6af71012018-11-06 16:02:13 -0700245 expect = '%10s: ' % 'powerpc'
246 expect += ' ' + col.Color(col.GREEN, '')
247 expect += ' '
248 expect += col.Color(col.GREEN, ' %s' % 'board2')
249 expect += ' ' + col.Color(col.YELLOW, 'w+')
250 expect += ' '
251 expect += col.Color(col.YELLOW, ' %s' % 'board3')
Simon Glassc3bc4f12020-04-09 15:08:30 -0600252 self.assertEqual(next(lines).text, expect)
253 self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
Simon Glassc05aa032019-10-31 07:42:53 -0600254 outcome=OUTCOME_WARN)
Simon Glass6208fce2014-09-05 19:00:08 -0600255
256 # Compile error fixed
Simon Glassc3bc4f12020-04-09 15:08:30 -0600257 line = next(lines)
258 self.assertEqual(line.text, '-%s' %
Simon Glass6208fce2014-09-05 19:00:08 -0600259 errors[1].rstrip().replace('\n', '\n-'))
Simon Glassc3bc4f12020-04-09 15:08:30 -0600260 self.assertEqual(line.colour, col.GREEN)
Simon Glass6208fce2014-09-05 19:00:08 -0600261
Simon Glassc3bc4f12020-04-09 15:08:30 -0600262 line = next(lines)
263 self.assertEqual(line.text, 'w+%s' %
Simon Glass6208fce2014-09-05 19:00:08 -0600264 errors[2].rstrip().replace('\n', '\nw+'))
Simon Glassc3bc4f12020-04-09 15:08:30 -0600265 self.assertEqual(line.colour, col.MAGENTA)
Simon Glass6208fce2014-09-05 19:00:08 -0600266
Simon Glass6af71012018-11-06 16:02:13 -0700267 # Fifth commit
Simon Glassc3bc4f12020-04-09 15:08:30 -0600268 self.assertEqual(next(lines).text, '05: %s' % commits[4][1])
269 self.assertSummary(next(lines).text, 'powerpc', '', ['board3'],
Simon Glass6af71012018-11-06 16:02:13 -0700270 outcome=OUTCOME_OK)
Simon Glassc3bc4f12020-04-09 15:08:30 -0600271 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
Simon Glass6208fce2014-09-05 19:00:08 -0600272
273 # The second line of errors[3] is a duplicate, so buildman will drop it
274 expect = errors[3].rstrip().split('\n')
275 expect = [expect[0]] + expect[2:]
Simon Glassc3bc4f12020-04-09 15:08:30 -0600276 line = next(lines)
277 self.assertEqual(line.text, '+%s' %
Simon Glass6208fce2014-09-05 19:00:08 -0600278 '\n'.join(expect).replace('\n', '\n+'))
Simon Glassc3bc4f12020-04-09 15:08:30 -0600279 self.assertEqual(line.colour, col.RED)
Simon Glass6208fce2014-09-05 19:00:08 -0600280
Simon Glassc3bc4f12020-04-09 15:08:30 -0600281 line = next(lines)
282 self.assertEqual(line.text, 'w-%s' %
Simon Glass6208fce2014-09-05 19:00:08 -0600283 errors[2].rstrip().replace('\n', '\nw-'))
Simon Glassc3bc4f12020-04-09 15:08:30 -0600284 self.assertEqual(line.colour, col.CYAN)
Simon Glass6208fce2014-09-05 19:00:08 -0600285
Simon Glass6af71012018-11-06 16:02:13 -0700286 # Sixth commit
Simon Glassc3bc4f12020-04-09 15:08:30 -0600287 self.assertEqual(next(lines).text, '06: %s' % commits[5][1])
288 self.assertSummary(next(lines).text, 'sandbox', '', ['board4'],
Simon Glass6af71012018-11-06 16:02:13 -0700289 outcome=OUTCOME_OK)
Simon Glass6208fce2014-09-05 19:00:08 -0600290
291 # The second line of errors[3] is a duplicate, so buildman will drop it
292 expect = errors[3].rstrip().split('\n')
293 expect = [expect[0]] + expect[2:]
Simon Glassc3bc4f12020-04-09 15:08:30 -0600294 line = next(lines)
295 self.assertEqual(line.text, '-%s' %
Simon Glass6208fce2014-09-05 19:00:08 -0600296 '\n'.join(expect).replace('\n', '\n-'))
Simon Glassc3bc4f12020-04-09 15:08:30 -0600297 self.assertEqual(line.colour, col.GREEN)
Simon Glass6208fce2014-09-05 19:00:08 -0600298
Simon Glassc3bc4f12020-04-09 15:08:30 -0600299 line = next(lines)
300 self.assertEqual(line.text, 'w-%s' %
Simon Glass6208fce2014-09-05 19:00:08 -0600301 errors[0].rstrip().replace('\n', '\nw-'))
Simon Glassc3bc4f12020-04-09 15:08:30 -0600302 self.assertEqual(line.colour, col.CYAN)
Simon Glass6208fce2014-09-05 19:00:08 -0600303
Simon Glass6af71012018-11-06 16:02:13 -0700304 # Seventh commit
Simon Glassc3bc4f12020-04-09 15:08:30 -0600305 self.assertEqual(next(lines).text, '07: %s' % commits[6][1])
306 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
Simon Glass930c8d42014-09-05 19:00:21 -0600307
308 # Pick out the correct error lines
309 expect_str = errors[4].rstrip().replace('%(basedir)s', '').split('\n')
310 expect = expect_str[3:8] + [expect_str[-1]]
Simon Glassc3bc4f12020-04-09 15:08:30 -0600311 line = next(lines)
312 self.assertEqual(line.text, '+%s' %
Simon Glass930c8d42014-09-05 19:00:21 -0600313 '\n'.join(expect).replace('\n', '\n+'))
Simon Glassc3bc4f12020-04-09 15:08:30 -0600314 self.assertEqual(line.colour, col.RED)
Simon Glass930c8d42014-09-05 19:00:21 -0600315
316 # Now the warnings lines
317 expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]]
Simon Glassc3bc4f12020-04-09 15:08:30 -0600318 line = next(lines)
319 self.assertEqual(line.text, 'w+%s' %
Simon Glass930c8d42014-09-05 19:00:21 -0600320 '\n'.join(expect).replace('\n', '\nw+'))
Simon Glassc3bc4f12020-04-09 15:08:30 -0600321 self.assertEqual(line.colour, col.MAGENTA)
Simon Glass930c8d42014-09-05 19:00:21 -0600322
Simon Glass930c8d42014-09-05 19:00:21 -0600323 shutil.rmtree(base_dir)
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000324
325 def _testGit(self):
326 """Test basic builder operation by building a branch"""
327 base_dir = tempfile.mkdtemp()
328 if not os.path.isdir(base_dir):
329 os.mkdir(base_dir)
330 options = Options()
331 options.git = os.getcwd()
332 options.summary = False
333 options.jobs = None
334 options.dry_run = False
335 #options.git = os.path.join(base_dir, 'repo')
336 options.branch = 'test-buildman'
337 options.force_build = False
338 options.list_tool_chains = False
339 options.count = -1
340 options.git_dir = None
341 options.threads = None
342 options.show_unknown = False
343 options.quick = False
344 options.show_errors = False
345 options.keep_outputs = False
346 args = ['tegra20']
347 control.DoBuildman(options, args)
Simon Glass930c8d42014-09-05 19:00:21 -0600348 shutil.rmtree(base_dir)
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000349
Simon Glass6131bea2014-08-09 15:33:08 -0600350 def testBoardSingle(self):
351 """Test single board selection"""
352 self.assertEqual(self.boards.SelectBoards(['sandbox']),
Simon Glass06890362018-06-11 23:26:46 -0600353 ({'all': ['board4'], 'sandbox': ['board4']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600354
355 def testBoardArch(self):
356 """Test single board selection"""
357 self.assertEqual(self.boards.SelectBoards(['arm']),
Simon Glass06890362018-06-11 23:26:46 -0600358 ({'all': ['board0', 'board1'],
359 'arm': ['board0', 'board1']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600360
361 def testBoardArchSingle(self):
362 """Test single board selection"""
363 self.assertEqual(self.boards.SelectBoards(['arm sandbox']),
Simon Glass06890362018-06-11 23:26:46 -0600364 ({'sandbox': ['board4'],
Simon Glass251f5862017-11-12 21:52:15 -0700365 'all': ['board0', 'board1', 'board4'],
Simon Glass06890362018-06-11 23:26:46 -0600366 'arm': ['board0', 'board1']}, []))
Simon Glass251f5862017-11-12 21:52:15 -0700367
Simon Glass6131bea2014-08-09 15:33:08 -0600368
369 def testBoardArchSingleMultiWord(self):
370 """Test single board selection"""
371 self.assertEqual(self.boards.SelectBoards(['arm', 'sandbox']),
Simon Glass06890362018-06-11 23:26:46 -0600372 ({'sandbox': ['board4'],
373 'all': ['board0', 'board1', 'board4'],
374 'arm': ['board0', 'board1']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600375
376 def testBoardSingleAnd(self):
377 """Test single board selection"""
378 self.assertEqual(self.boards.SelectBoards(['Tester & arm']),
Simon Glass06890362018-06-11 23:26:46 -0600379 ({'Tester&arm': ['board0', 'board1'],
380 'all': ['board0', 'board1']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600381
382 def testBoardTwoAnd(self):
383 """Test single board selection"""
384 self.assertEqual(self.boards.SelectBoards(['Tester', '&', 'arm',
385 'Tester' '&', 'powerpc',
386 'sandbox']),
Simon Glass06890362018-06-11 23:26:46 -0600387 ({'sandbox': ['board4'],
Simon Glass251f5862017-11-12 21:52:15 -0700388 'all': ['board0', 'board1', 'board2', 'board3',
389 'board4'],
390 'Tester&powerpc': ['board2', 'board3'],
Simon Glass06890362018-06-11 23:26:46 -0600391 'Tester&arm': ['board0', 'board1']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600392
393 def testBoardAll(self):
394 """Test single board selection"""
Simon Glass251f5862017-11-12 21:52:15 -0700395 self.assertEqual(self.boards.SelectBoards([]),
Simon Glass06890362018-06-11 23:26:46 -0600396 ({'all': ['board0', 'board1', 'board2', 'board3',
397 'board4']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600398
399 def testBoardRegularExpression(self):
400 """Test single board selection"""
401 self.assertEqual(self.boards.SelectBoards(['T.*r&^Po']),
Simon Glass06890362018-06-11 23:26:46 -0600402 ({'all': ['board2', 'board3'],
403 'T.*r&^Po': ['board2', 'board3']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600404
405 def testBoardDuplicate(self):
406 """Test single board selection"""
407 self.assertEqual(self.boards.SelectBoards(['sandbox sandbox',
408 'sandbox']),
Simon Glass06890362018-06-11 23:26:46 -0600409 ({'all': ['board4'], 'sandbox': ['board4']}, []))
Simon Glass4466c1f2014-12-01 17:33:51 -0700410 def CheckDirs(self, build, dirname):
411 self.assertEqual('base%s' % dirname, build._GetOutputDir(1))
412 self.assertEqual('base%s/fred' % dirname,
413 build.GetBuildDir(1, 'fred'))
414 self.assertEqual('base%s/fred/done' % dirname,
415 build.GetDoneFile(1, 'fred'))
416 self.assertEqual('base%s/fred/u-boot.sizes' % dirname,
417 build.GetFuncSizesFile(1, 'fred', 'u-boot'))
418 self.assertEqual('base%s/fred/u-boot.objdump' % dirname,
419 build.GetObjdumpFile(1, 'fred', 'u-boot'))
420 self.assertEqual('base%s/fred/err' % dirname,
421 build.GetErrFile(1, 'fred'))
422
423 def testOutputDir(self):
424 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
425 checkout=False, show_unknown=False)
426 build.commits = self.commits
427 build.commit_count = len(self.commits)
428 subject = self.commits[1].subject.translate(builder.trans_valid_chars)
429 dirname ='/%02d_of_%02d_g%s_%s' % (2, build.commit_count, commits[1][0],
430 subject[:20])
431 self.CheckDirs(build, dirname)
432
433 def testOutputDirCurrent(self):
434 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
435 checkout=False, show_unknown=False)
436 build.commits = None
437 build.commit_count = 0
438 self.CheckDirs(build, '/current')
Simon Glass6131bea2014-08-09 15:33:08 -0600439
Simon Glass5971ab52014-12-01 17:33:55 -0700440 def testOutputDirNoSubdirs(self):
441 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
442 checkout=False, show_unknown=False,
443 no_subdirs=True)
444 build.commits = None
445 build.commit_count = 0
446 self.CheckDirs(build, '')
447
Simon Glass9b83bfd2014-12-01 17:34:05 -0700448 def testToolchainAliases(self):
449 self.assertTrue(self.toolchains.Select('arm') != None)
450 with self.assertRaises(ValueError):
451 self.toolchains.Select('no-arch')
452 with self.assertRaises(ValueError):
453 self.toolchains.Select('x86')
454
455 self.toolchains = toolchain.Toolchains()
456 self.toolchains.Add('x86_64-linux-gcc', test=False)
457 self.assertTrue(self.toolchains.Select('x86') != None)
458
459 self.toolchains = toolchain.Toolchains()
460 self.toolchains.Add('i386-linux-gcc', test=False)
461 self.assertTrue(self.toolchains.Select('x86') != None)
462
Simon Glass827e37b2014-12-01 17:34:06 -0700463 def testToolchainDownload(self):
464 """Test that we can download toolchains"""
Simon Glasscb39a102017-11-12 21:52:14 -0700465 if use_network:
Simon Glass4b4bc062018-10-01 21:12:43 -0600466 with test_util.capture_sys_output() as (stdout, stderr):
467 url = self.toolchains.LocateArchUrl('arm')
Simon Glassda753e32018-10-01 21:12:35 -0600468 self.assertRegexpMatches(url, 'https://www.kernel.org/pub/tools/'
469 'crosstool/files/bin/x86_64/.*/'
470 'x86_64-gcc-.*-nolibc_arm-.*linux-gnueabi.tar.xz')
Simon Glass827e37b2014-12-01 17:34:06 -0700471
Simon Glass57cb9d52019-12-05 15:59:14 -0700472 def testGetEnvArgs(self):
473 """Test the GetEnvArgs() function"""
474 tc = self.toolchains.Select('arm')
475 self.assertEqual('arm-linux-',
476 tc.GetEnvArgs(toolchain.VAR_CROSS_COMPILE))
477 self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_PATH))
478 self.assertEqual('arm',
479 tc.GetEnvArgs(toolchain.VAR_ARCH))
480 self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS))
481
482 self.toolchains.Add('/path/to/x86_64-linux-gcc', test=False)
483 tc = self.toolchains.Select('x86')
484 self.assertEqual('/path/to',
485 tc.GetEnvArgs(toolchain.VAR_PATH))
486 tc.override_toolchain = 'clang'
487 self.assertEqual('HOSTCC=clang CC=clang',
488 tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS))
489
Simon Glass925f6ad2020-03-18 09:42:45 -0600490 def testPrepareOutputSpace(self):
491 def _Touch(fname):
492 tools.WriteFile(os.path.join(base_dir, fname), b'')
493
494 base_dir = tempfile.mkdtemp()
495
496 # Add various files that we want removed and left alone
497 to_remove = ['01_of_22_g0982734987_title', '102_of_222_g92bf_title',
498 '01_of_22_g2938abd8_title']
499 to_leave = ['something_else', '01-something.patch', '01_of_22_another']
500 for name in to_remove + to_leave:
501 _Touch(name)
502
503 build = builder.Builder(self.toolchains, base_dir, None, 1, 2)
504 build.commits = self.commits
505 build.commit_count = len(commits)
506 result = set(build._GetOutputSpaceRemovals())
507 expected = set([os.path.join(base_dir, f) for f in to_remove])
508 self.assertEqual(expected, result)
Simon Glass827e37b2014-12-01 17:34:06 -0700509
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000510if __name__ == "__main__":
511 unittest.main()