blob: e6698ce86ca07d023bd2e7c0ab704fa406ae29de [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 Glassaf430652020-04-09 15:08:31 -0600146 self.base_dir = tempfile.mkdtemp()
147 if not os.path.isdir(self.base_dir):
148 os.mkdir(self.base_dir)
Simon Glass930c8d42014-09-05 19:00:21 -0600149
Simon Glassaf430652020-04-09 15:08:31 -0600150 def tearDown(self):
151 shutil.rmtree(self.base_dir)
152
153 def Make(self, commit, brd, stage, *args, **kwargs):
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000154 result = command.CommandResult()
155 boardnum = int(brd.target[-1])
156 result.return_code = 0
157 result.stderr = ''
158 result.stdout = ('This is the test output for board %s, commit %s' %
159 (brd.target, commit.hash))
Simon Glass930c8d42014-09-05 19:00:21 -0600160 if ((boardnum >= 1 and boardnum >= commit.sequence) or
161 boardnum == 4 and commit.sequence == 6):
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000162 result.return_code = commit.return_code
Simon Glass930c8d42014-09-05 19:00:21 -0600163 result.stderr = (''.join(commit.error_list)
Simon Glassaf430652020-04-09 15:08:31 -0600164 % {'basedir' : self.base_dir + '/.bm-work/00/'})
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000165
166 result.combined = result.stdout + result.stderr
167 return result
168
Simon Glass6af71012018-11-06 16:02:13 -0700169 def assertSummary(self, text, arch, plus, boards, outcome=OUTCOME_ERR):
Simon Glass6208fce2014-09-05 19:00:08 -0600170 col = self._col
Simon Glass6af71012018-11-06 16:02:13 -0700171 expected_colour = (col.GREEN if outcome == OUTCOME_OK else
172 col.YELLOW if outcome == OUTCOME_WARN else col.RED)
Simon Glass6208fce2014-09-05 19:00:08 -0600173 expect = '%10s: ' % arch
174 # TODO(sjg@chromium.org): If plus is '', we shouldn't need this
Simon Glass63c619e2015-02-05 22:06:11 -0700175 expect += ' ' + col.Color(expected_colour, plus)
Simon Glass6208fce2014-09-05 19:00:08 -0600176 expect += ' '
177 for board in boards:
178 expect += col.Color(expected_colour, ' %s' % board)
179 self.assertEqual(text, expect)
180
Simon Glassce558db2020-04-09 15:08:32 -0600181 def _SetupTest(self, echo_lines=False, **kwdisplay_args):
182 """Set up the test by running a build and summary
Simon Glass6208fce2014-09-05 19:00:08 -0600183
Simon Glassce558db2020-04-09 15:08:32 -0600184 Args:
185 echo_lines: True to echo lines to the terminal to aid test
186 development
187 kwdisplay_args: Dict of arguemnts to pass to
188 Builder.SetDisplayOptions()
189
190 Returns:
191 Iterator containing the output lines, each a PrintLine() object
Simon Glass6208fce2014-09-05 19:00:08 -0600192 """
Simon Glassaf430652020-04-09 15:08:31 -0600193 build = builder.Builder(self.toolchains, self.base_dir, None, 1, 2,
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000194 checkout=False, show_unknown=False)
195 build.do_make = self.Make
196 board_selected = self.boards.GetSelectedDict()
197
Simon Glass6af71012018-11-06 16:02:13 -0700198 # 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 Glasse5a0e5d2014-08-09 15:33:03 -0600200 build.BuildBoards(self.commits, board_selected, keep_outputs=False,
201 verbose=False)
Simon Glass6208fce2014-09-05 19:00:08 -0600202 lines = terminal.GetPrintTestLines()
203 count = 0
204 for line in lines:
205 if line.text.strip():
206 count += 1
207
Simon Glass7b33f212020-04-09 15:08:47 -0600208 # We should get two starting messages, an update for every commit built
209 # and a summary message
210 self.assertEqual(count, len(commits) * len(boards) + 3)
Simon Glassce558db2020-04-09 15:08:32 -0600211 build.SetDisplayOptions(**kwdisplay_args);
Simon Glassb2ea7ab2014-08-09 15:33:02 -0600212 build.ShowSummary(self.commits, board_selected)
Simon Glassce558db2020-04-09 15:08:32 -0600213 if echo_lines:
214 terminal.EchoPrintTestLines()
215 return iter(terminal.GetPrintTestLines())
Simon Glass6af71012018-11-06 16:02:13 -0700216
Simon Glass174592b2020-04-09 15:08:52 -0600217 def _CheckOutput(self, lines, list_error_boards, filter_dtb_warnings):
Simon Glassce558db2020-04-09 15:08:32 -0600218 """Check for expected output from the build summary
219
220 Args:
221 lines: Iterator containing the lines returned from the summary
Simon Glasse631a2b2020-04-09 15:08:34 -0600222 list_error_boards: Adjust the check for output produced with the
223 --list-error-boards flag
Simon Glass174592b2020-04-09 15:08:52 -0600224 filter_dtb_warnings: Adjust the check for output produced with the
225 --filter-dtb-warnings flag
Simon Glassce558db2020-04-09 15:08:32 -0600226 """
Simon Glass8c9a2672020-04-09 15:08:37 -0600227 def add_line_prefix(prefix, boards, error_str, colour):
Simon Glassc9dd80b2020-04-09 15:08:33 -0600228 """Add a prefix to each line of a string
229
230 The training \n in error_str is removed before processing
231
232 Args:
233 prefix: String prefix to add
234 error_str: Error string containing the lines
Simon Glass8c9a2672020-04-09 15:08:37 -0600235 colour: Expected colour for the line. Note that the board list,
236 if present, always appears in magenta
Simon Glassc9dd80b2020-04-09 15:08:33 -0600237
238 Returns:
239 New string where each line has the prefix added
240 """
241 lines = error_str.strip().splitlines()
Simon Glass8c9a2672020-04-09 15:08:37 -0600242 new_lines = []
243 for line in lines:
244 if boards:
245 expect = self._col.Color(colour, prefix + '(')
246 expect += self._col.Color(self._col.MAGENTA, boards,
247 bright=False)
248 expect += self._col.Color(colour, ') %s' % line)
249 else:
250 expect = self._col.Color(colour, prefix + line)
251 new_lines.append(expect)
Simon Glassc9dd80b2020-04-09 15:08:33 -0600252 return '\n'.join(new_lines)
253
Simon Glass9ef0ceb2020-04-09 15:08:38 -0600254 boards1234 = 'board1 board2 board3 board4' if list_error_boards else ''
255 boards234 = 'board2 board3 board4' if list_error_boards else ''
256 boards34 = 'board3 board4' if list_error_boards else ''
Simon Glasse631a2b2020-04-09 15:08:34 -0600257 boards4 = 'board4' if list_error_boards else ''
258
Simon Glass6af71012018-11-06 16:02:13 -0700259 # Upstream commit: no errors
Simon Glassc3bc4f12020-04-09 15:08:30 -0600260 self.assertEqual(next(lines).text, '01: %s' % commits[0][1])
Simon Glass6af71012018-11-06 16:02:13 -0700261
262 # Second commit: all archs should fail with warnings
Simon Glassc3bc4f12020-04-09 15:08:30 -0600263 self.assertEqual(next(lines).text, '02: %s' % commits[1][1])
Simon Glass6208fce2014-09-05 19:00:08 -0600264
Simon Glass6208fce2014-09-05 19:00:08 -0600265 col = terminal.Color()
Simon Glassc3bc4f12020-04-09 15:08:30 -0600266 self.assertSummary(next(lines).text, 'arm', 'w+', ['board1'],
Simon Glass6af71012018-11-06 16:02:13 -0700267 outcome=OUTCOME_WARN)
Simon Glassc3bc4f12020-04-09 15:08:30 -0600268 self.assertSummary(next(lines).text, 'powerpc', 'w+',
269 ['board2', 'board3'], outcome=OUTCOME_WARN)
270 self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
Simon Glass6af71012018-11-06 16:02:13 -0700271 outcome=OUTCOME_WARN)
Simon Glass6208fce2014-09-05 19:00:08 -0600272
Simon Glass6af71012018-11-06 16:02:13 -0700273 # Second commit: The warnings should be listed
Simon Glass8c9a2672020-04-09 15:08:37 -0600274 self.assertEqual(next(lines).text,
275 add_line_prefix('w+', boards1234, errors[0], col.YELLOW))
Simon Glass6208fce2014-09-05 19:00:08 -0600276
Simon Glass6af71012018-11-06 16:02:13 -0700277 # Third commit: Still fails
Simon Glassc3bc4f12020-04-09 15:08:30 -0600278 self.assertEqual(next(lines).text, '03: %s' % commits[2][1])
279 self.assertSummary(next(lines).text, 'arm', '', ['board1'],
Simon Glass6af71012018-11-06 16:02:13 -0700280 outcome=OUTCOME_OK)
Simon Glassc3bc4f12020-04-09 15:08:30 -0600281 self.assertSummary(next(lines).text, 'powerpc', '+',
282 ['board2', 'board3'])
283 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
Simon Glass6208fce2014-09-05 19:00:08 -0600284
Simon Glass6af71012018-11-06 16:02:13 -0700285 # Expect a compiler error
Simon Glass8c9a2672020-04-09 15:08:37 -0600286 self.assertEqual(next(lines).text,
287 add_line_prefix('+', boards234, errors[1], col.RED))
Simon Glass6208fce2014-09-05 19:00:08 -0600288
Simon Glass6af71012018-11-06 16:02:13 -0700289 # Fourth commit: Compile errors are fixed, just have warning for board3
Simon Glassc3bc4f12020-04-09 15:08:30 -0600290 self.assertEqual(next(lines).text, '04: %s' % commits[3][1])
Simon Glass6af71012018-11-06 16:02:13 -0700291 expect = '%10s: ' % 'powerpc'
292 expect += ' ' + col.Color(col.GREEN, '')
293 expect += ' '
294 expect += col.Color(col.GREEN, ' %s' % 'board2')
295 expect += ' ' + col.Color(col.YELLOW, 'w+')
296 expect += ' '
297 expect += col.Color(col.YELLOW, ' %s' % 'board3')
Simon Glassc3bc4f12020-04-09 15:08:30 -0600298 self.assertEqual(next(lines).text, expect)
299 self.assertSummary(next(lines).text, 'sandbox', 'w+', ['board4'],
Simon Glassc05aa032019-10-31 07:42:53 -0600300 outcome=OUTCOME_WARN)
Simon Glass6208fce2014-09-05 19:00:08 -0600301
302 # Compile error fixed
Simon Glass8c9a2672020-04-09 15:08:37 -0600303 self.assertEqual(next(lines).text,
304 add_line_prefix('-', boards234, errors[1], col.GREEN))
Simon Glass6208fce2014-09-05 19:00:08 -0600305
Simon Glass174592b2020-04-09 15:08:52 -0600306 if not filter_dtb_warnings:
307 self.assertEqual(
308 next(lines).text,
309 add_line_prefix('w+', boards34, errors[2], col.YELLOW))
Simon Glass6208fce2014-09-05 19:00:08 -0600310
Simon Glass6af71012018-11-06 16:02:13 -0700311 # Fifth commit
Simon Glassc3bc4f12020-04-09 15:08:30 -0600312 self.assertEqual(next(lines).text, '05: %s' % commits[4][1])
313 self.assertSummary(next(lines).text, 'powerpc', '', ['board3'],
Simon Glass6af71012018-11-06 16:02:13 -0700314 outcome=OUTCOME_OK)
Simon Glassc3bc4f12020-04-09 15:08:30 -0600315 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
Simon Glass6208fce2014-09-05 19:00:08 -0600316
317 # The second line of errors[3] is a duplicate, so buildman will drop it
318 expect = errors[3].rstrip().split('\n')
319 expect = [expect[0]] + expect[2:]
Simon Glassc9dd80b2020-04-09 15:08:33 -0600320 expect = '\n'.join(expect)
Simon Glass8c9a2672020-04-09 15:08:37 -0600321 self.assertEqual(next(lines).text,
322 add_line_prefix('+', boards4, expect, col.RED))
Simon Glass6208fce2014-09-05 19:00:08 -0600323
Simon Glass174592b2020-04-09 15:08:52 -0600324 if not filter_dtb_warnings:
325 self.assertEqual(
326 next(lines).text,
327 add_line_prefix('w-', boards34, errors[2], col.CYAN))
Simon Glass6208fce2014-09-05 19:00:08 -0600328
Simon Glass6af71012018-11-06 16:02:13 -0700329 # Sixth commit
Simon Glassc3bc4f12020-04-09 15:08:30 -0600330 self.assertEqual(next(lines).text, '06: %s' % commits[5][1])
331 self.assertSummary(next(lines).text, 'sandbox', '', ['board4'],
Simon Glass6af71012018-11-06 16:02:13 -0700332 outcome=OUTCOME_OK)
Simon Glass6208fce2014-09-05 19:00:08 -0600333
334 # The second line of errors[3] is a duplicate, so buildman will drop it
335 expect = errors[3].rstrip().split('\n')
336 expect = [expect[0]] + expect[2:]
Simon Glassc9dd80b2020-04-09 15:08:33 -0600337 expect = '\n'.join(expect)
Simon Glass8c9a2672020-04-09 15:08:37 -0600338 self.assertEqual(next(lines).text,
339 add_line_prefix('-', boards4, expect, col.GREEN))
340 self.assertEqual(next(lines).text,
341 add_line_prefix('w-', boards4, errors[0], col.CYAN))
Simon Glass6208fce2014-09-05 19:00:08 -0600342
Simon Glass6af71012018-11-06 16:02:13 -0700343 # Seventh commit
Simon Glassc3bc4f12020-04-09 15:08:30 -0600344 self.assertEqual(next(lines).text, '07: %s' % commits[6][1])
345 self.assertSummary(next(lines).text, 'sandbox', '+', ['board4'])
Simon Glass930c8d42014-09-05 19:00:21 -0600346
347 # Pick out the correct error lines
348 expect_str = errors[4].rstrip().replace('%(basedir)s', '').split('\n')
349 expect = expect_str[3:8] + [expect_str[-1]]
Simon Glassc9dd80b2020-04-09 15:08:33 -0600350 expect = '\n'.join(expect)
Simon Glass8c9a2672020-04-09 15:08:37 -0600351 self.assertEqual(next(lines).text,
352 add_line_prefix('+', boards4, expect, col.RED))
Simon Glass930c8d42014-09-05 19:00:21 -0600353
354 # Now the warnings lines
355 expect = [expect_str[0]] + expect_str[10:12] + [expect_str[9]]
Simon Glassc9dd80b2020-04-09 15:08:33 -0600356 expect = '\n'.join(expect)
Simon Glass8c9a2672020-04-09 15:08:37 -0600357 self.assertEqual(next(lines).text,
358 add_line_prefix('w+', boards4, expect, col.YELLOW))
Simon Glass930c8d42014-09-05 19:00:21 -0600359
Simon Glassce558db2020-04-09 15:08:32 -0600360 def testOutput(self):
361 """Test basic builder operation and output
362
363 This does a line-by-line verification of the summary output.
364 """
365 lines = self._SetupTest(show_errors=True)
Simon Glass174592b2020-04-09 15:08:52 -0600366 self._CheckOutput(lines, list_error_boards=False,
367 filter_dtb_warnings=False)
Simon Glasse631a2b2020-04-09 15:08:34 -0600368
369 def testErrorBoards(self):
370 """Test output with --list-error-boards
371
372 This does a line-by-line verification of the summary output.
373 """
374 lines = self._SetupTest(show_errors=True, list_error_boards=True)
Simon Glass174592b2020-04-09 15:08:52 -0600375 self._CheckOutput(lines, list_error_boards=True,
376 filter_dtb_warnings=False)
377
378 def testFilterDtb(self):
379 """Test output with --filter-dtb-warnings
380
381 This does a line-by-line verification of the summary output.
382 """
383 lines = self._SetupTest(show_errors=True, filter_dtb_warnings=True)
384 self._CheckOutput(lines, list_error_boards=False,
385 filter_dtb_warnings=True)
Simon Glassce558db2020-04-09 15:08:32 -0600386
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000387 def _testGit(self):
388 """Test basic builder operation by building a branch"""
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000389 options = Options()
390 options.git = os.getcwd()
391 options.summary = False
392 options.jobs = None
393 options.dry_run = False
Simon Glassaf430652020-04-09 15:08:31 -0600394 #options.git = os.path.join(self.base_dir, 'repo')
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000395 options.branch = 'test-buildman'
396 options.force_build = False
397 options.list_tool_chains = False
398 options.count = -1
399 options.git_dir = None
400 options.threads = None
401 options.show_unknown = False
402 options.quick = False
403 options.show_errors = False
404 options.keep_outputs = False
405 args = ['tegra20']
406 control.DoBuildman(options, args)
407
Simon Glass6131bea2014-08-09 15:33:08 -0600408 def testBoardSingle(self):
409 """Test single board selection"""
410 self.assertEqual(self.boards.SelectBoards(['sandbox']),
Simon Glass06890362018-06-11 23:26:46 -0600411 ({'all': ['board4'], 'sandbox': ['board4']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600412
413 def testBoardArch(self):
414 """Test single board selection"""
415 self.assertEqual(self.boards.SelectBoards(['arm']),
Simon Glass06890362018-06-11 23:26:46 -0600416 ({'all': ['board0', 'board1'],
417 'arm': ['board0', 'board1']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600418
419 def testBoardArchSingle(self):
420 """Test single board selection"""
421 self.assertEqual(self.boards.SelectBoards(['arm sandbox']),
Simon Glass06890362018-06-11 23:26:46 -0600422 ({'sandbox': ['board4'],
Simon Glass251f5862017-11-12 21:52:15 -0700423 'all': ['board0', 'board1', 'board4'],
Simon Glass06890362018-06-11 23:26:46 -0600424 'arm': ['board0', 'board1']}, []))
Simon Glass251f5862017-11-12 21:52:15 -0700425
Simon Glass6131bea2014-08-09 15:33:08 -0600426
427 def testBoardArchSingleMultiWord(self):
428 """Test single board selection"""
429 self.assertEqual(self.boards.SelectBoards(['arm', 'sandbox']),
Simon Glass06890362018-06-11 23:26:46 -0600430 ({'sandbox': ['board4'],
431 'all': ['board0', 'board1', 'board4'],
432 'arm': ['board0', 'board1']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600433
434 def testBoardSingleAnd(self):
435 """Test single board selection"""
436 self.assertEqual(self.boards.SelectBoards(['Tester & arm']),
Simon Glass06890362018-06-11 23:26:46 -0600437 ({'Tester&arm': ['board0', 'board1'],
438 'all': ['board0', 'board1']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600439
440 def testBoardTwoAnd(self):
441 """Test single board selection"""
442 self.assertEqual(self.boards.SelectBoards(['Tester', '&', 'arm',
443 'Tester' '&', 'powerpc',
444 'sandbox']),
Simon Glass06890362018-06-11 23:26:46 -0600445 ({'sandbox': ['board4'],
Simon Glass251f5862017-11-12 21:52:15 -0700446 'all': ['board0', 'board1', 'board2', 'board3',
447 'board4'],
448 'Tester&powerpc': ['board2', 'board3'],
Simon Glass06890362018-06-11 23:26:46 -0600449 'Tester&arm': ['board0', 'board1']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600450
451 def testBoardAll(self):
452 """Test single board selection"""
Simon Glass251f5862017-11-12 21:52:15 -0700453 self.assertEqual(self.boards.SelectBoards([]),
Simon Glass06890362018-06-11 23:26:46 -0600454 ({'all': ['board0', 'board1', 'board2', 'board3',
455 'board4']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600456
457 def testBoardRegularExpression(self):
458 """Test single board selection"""
459 self.assertEqual(self.boards.SelectBoards(['T.*r&^Po']),
Simon Glass06890362018-06-11 23:26:46 -0600460 ({'all': ['board2', 'board3'],
461 'T.*r&^Po': ['board2', 'board3']}, []))
Simon Glass6131bea2014-08-09 15:33:08 -0600462
463 def testBoardDuplicate(self):
464 """Test single board selection"""
465 self.assertEqual(self.boards.SelectBoards(['sandbox sandbox',
466 'sandbox']),
Simon Glass06890362018-06-11 23:26:46 -0600467 ({'all': ['board4'], 'sandbox': ['board4']}, []))
Simon Glass4466c1f2014-12-01 17:33:51 -0700468 def CheckDirs(self, build, dirname):
469 self.assertEqual('base%s' % dirname, build._GetOutputDir(1))
470 self.assertEqual('base%s/fred' % dirname,
471 build.GetBuildDir(1, 'fred'))
472 self.assertEqual('base%s/fred/done' % dirname,
473 build.GetDoneFile(1, 'fred'))
474 self.assertEqual('base%s/fred/u-boot.sizes' % dirname,
475 build.GetFuncSizesFile(1, 'fred', 'u-boot'))
476 self.assertEqual('base%s/fred/u-boot.objdump' % dirname,
477 build.GetObjdumpFile(1, 'fred', 'u-boot'))
478 self.assertEqual('base%s/fred/err' % dirname,
479 build.GetErrFile(1, 'fred'))
480
481 def testOutputDir(self):
482 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
483 checkout=False, show_unknown=False)
484 build.commits = self.commits
485 build.commit_count = len(self.commits)
486 subject = self.commits[1].subject.translate(builder.trans_valid_chars)
487 dirname ='/%02d_of_%02d_g%s_%s' % (2, build.commit_count, commits[1][0],
488 subject[:20])
489 self.CheckDirs(build, dirname)
490
491 def testOutputDirCurrent(self):
492 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
493 checkout=False, show_unknown=False)
494 build.commits = None
495 build.commit_count = 0
496 self.CheckDirs(build, '/current')
Simon Glass6131bea2014-08-09 15:33:08 -0600497
Simon Glass5971ab52014-12-01 17:33:55 -0700498 def testOutputDirNoSubdirs(self):
499 build = builder.Builder(self.toolchains, BASE_DIR, None, 1, 2,
500 checkout=False, show_unknown=False,
501 no_subdirs=True)
502 build.commits = None
503 build.commit_count = 0
504 self.CheckDirs(build, '')
505
Simon Glass9b83bfd2014-12-01 17:34:05 -0700506 def testToolchainAliases(self):
507 self.assertTrue(self.toolchains.Select('arm') != None)
508 with self.assertRaises(ValueError):
509 self.toolchains.Select('no-arch')
510 with self.assertRaises(ValueError):
511 self.toolchains.Select('x86')
512
513 self.toolchains = toolchain.Toolchains()
514 self.toolchains.Add('x86_64-linux-gcc', test=False)
515 self.assertTrue(self.toolchains.Select('x86') != None)
516
517 self.toolchains = toolchain.Toolchains()
518 self.toolchains.Add('i386-linux-gcc', test=False)
519 self.assertTrue(self.toolchains.Select('x86') != None)
520
Simon Glass827e37b2014-12-01 17:34:06 -0700521 def testToolchainDownload(self):
522 """Test that we can download toolchains"""
Simon Glasscb39a102017-11-12 21:52:14 -0700523 if use_network:
Simon Glass4b4bc062018-10-01 21:12:43 -0600524 with test_util.capture_sys_output() as (stdout, stderr):
525 url = self.toolchains.LocateArchUrl('arm')
Simon Glassda753e32018-10-01 21:12:35 -0600526 self.assertRegexpMatches(url, 'https://www.kernel.org/pub/tools/'
527 'crosstool/files/bin/x86_64/.*/'
528 'x86_64-gcc-.*-nolibc_arm-.*linux-gnueabi.tar.xz')
Simon Glass827e37b2014-12-01 17:34:06 -0700529
Simon Glass57cb9d52019-12-05 15:59:14 -0700530 def testGetEnvArgs(self):
531 """Test the GetEnvArgs() function"""
532 tc = self.toolchains.Select('arm')
533 self.assertEqual('arm-linux-',
534 tc.GetEnvArgs(toolchain.VAR_CROSS_COMPILE))
535 self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_PATH))
536 self.assertEqual('arm',
537 tc.GetEnvArgs(toolchain.VAR_ARCH))
538 self.assertEqual('', tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS))
539
540 self.toolchains.Add('/path/to/x86_64-linux-gcc', test=False)
541 tc = self.toolchains.Select('x86')
542 self.assertEqual('/path/to',
543 tc.GetEnvArgs(toolchain.VAR_PATH))
544 tc.override_toolchain = 'clang'
545 self.assertEqual('HOSTCC=clang CC=clang',
546 tc.GetEnvArgs(toolchain.VAR_MAKE_ARGS))
547
Simon Glass925f6ad2020-03-18 09:42:45 -0600548 def testPrepareOutputSpace(self):
549 def _Touch(fname):
550 tools.WriteFile(os.path.join(base_dir, fname), b'')
551
552 base_dir = tempfile.mkdtemp()
553
554 # Add various files that we want removed and left alone
555 to_remove = ['01_of_22_g0982734987_title', '102_of_222_g92bf_title',
556 '01_of_22_g2938abd8_title']
557 to_leave = ['something_else', '01-something.patch', '01_of_22_another']
558 for name in to_remove + to_leave:
559 _Touch(name)
560
561 build = builder.Builder(self.toolchains, base_dir, None, 1, 2)
562 build.commits = self.commits
563 build.commit_count = len(commits)
564 result = set(build._GetOutputSpaceRemovals())
565 expected = set([os.path.join(base_dir, f) for f in to_remove])
566 self.assertEqual(expected, result)
Simon Glass827e37b2014-12-01 17:34:06 -0700567
Simon Glassfc3fe1c2013-04-03 11:07:16 +0000568if __name__ == "__main__":
569 unittest.main()