blob: 5c19af1d5034cf53a34df15933d77c4f6d2eaf55 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0
Stephen Warren10e50632016-01-15 11:15:24 -07002# Copyright (c) 2015 Stephen Warren
3# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
Stephen Warren10e50632016-01-15 11:15:24 -07004
5# Implementation of pytest run-time hook functions. These are invoked by
6# pytest at certain points during operation, e.g. startup, for each executed
7# test, at shutdown etc. These hooks perform functions such as:
8# - Parsing custom command-line options.
9# - Pullilng in user-specified board configuration.
10# - Creating the U-Boot console test fixture.
11# - Creating the HTML log file.
12# - Monitoring each test's results.
13# - Implementing custom pytest markers.
14
15import atexit
16import errno
17import os
18import os.path
Stephen Warren10e50632016-01-15 11:15:24 -070019import pytest
20from _pytest.runner import runtestprotocol
Stephen Warren770fe172016-02-08 14:44:16 -070021import re
Tom Rini7f24c192019-10-24 11:59:20 -040022import io
Stephen Warren10e50632016-01-15 11:15:24 -070023import sys
24
Tom Rini7f24c192019-10-24 11:59:20 -040025import configparser
Paul Burton5ddc2872017-09-14 14:34:45 -070026
Stephen Warren10e50632016-01-15 11:15:24 -070027# Globals: The HTML log file, and the connection to the U-Boot console.
28log = None
29console = None
30
31def mkdir_p(path):
Stephen Warren75e731e2016-01-26 13:41:30 -070032 """Create a directory path.
Stephen Warren10e50632016-01-15 11:15:24 -070033
34 This includes creating any intermediate/parent directories. Any errors
35 caused due to already extant directories are ignored.
36
37 Args:
38 path: The directory path to create.
39
40 Returns:
41 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -070042 """
Stephen Warren10e50632016-01-15 11:15:24 -070043
44 try:
45 os.makedirs(path)
46 except OSError as exc:
47 if exc.errno == errno.EEXIST and os.path.isdir(path):
48 pass
49 else:
50 raise
51
52def pytest_addoption(parser):
Stephen Warren75e731e2016-01-26 13:41:30 -070053 """pytest hook: Add custom command-line options to the cmdline parser.
Stephen Warren10e50632016-01-15 11:15:24 -070054
55 Args:
56 parser: The pytest command-line parser.
57
58 Returns:
59 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -070060 """
Stephen Warren10e50632016-01-15 11:15:24 -070061
62 parser.addoption('--build-dir', default=None,
63 help='U-Boot build directory (O=)')
64 parser.addoption('--result-dir', default=None,
65 help='U-Boot test result/tmp directory')
66 parser.addoption('--persistent-data-dir', default=None,
67 help='U-Boot test persistent generated data directory')
68 parser.addoption('--board-type', '--bd', '-B', default='sandbox',
69 help='U-Boot board type')
70 parser.addoption('--board-identity', '--id', default='na',
71 help='U-Boot board identity/instance')
72 parser.addoption('--build', default=False, action='store_true',
73 help='Compile U-Boot before running tests')
Stephen Warren33db1ee2016-02-04 16:11:50 -070074 parser.addoption('--gdbserver', default=None,
75 help='Run sandbox under gdbserver. The argument is the channel '+
76 'over which gdbserver should communicate, e.g. localhost:1234')
Stephen Warren10e50632016-01-15 11:15:24 -070077
78def pytest_configure(config):
Stephen Warren75e731e2016-01-26 13:41:30 -070079 """pytest hook: Perform custom initialization at startup time.
Stephen Warren10e50632016-01-15 11:15:24 -070080
81 Args:
82 config: The pytest configuration.
83
84 Returns:
85 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -070086 """
Stephen Warren10e50632016-01-15 11:15:24 -070087
88 global log
89 global console
90 global ubconfig
91
92 test_py_dir = os.path.dirname(os.path.abspath(__file__))
93 source_dir = os.path.dirname(os.path.dirname(test_py_dir))
94
95 board_type = config.getoption('board_type')
96 board_type_filename = board_type.replace('-', '_')
97
98 board_identity = config.getoption('board_identity')
99 board_identity_filename = board_identity.replace('-', '_')
100
101 build_dir = config.getoption('build_dir')
102 if not build_dir:
103 build_dir = source_dir + '/build-' + board_type
104 mkdir_p(build_dir)
105
106 result_dir = config.getoption('result_dir')
107 if not result_dir:
108 result_dir = build_dir
109 mkdir_p(result_dir)
110
111 persistent_data_dir = config.getoption('persistent_data_dir')
112 if not persistent_data_dir:
113 persistent_data_dir = build_dir + '/persistent-data'
114 mkdir_p(persistent_data_dir)
115
Stephen Warren33db1ee2016-02-04 16:11:50 -0700116 gdbserver = config.getoption('gdbserver')
Igor Opaniukea5f17d2019-02-12 16:18:14 +0200117 if gdbserver and not board_type.startswith('sandbox'):
118 raise Exception('--gdbserver only supported with sandbox targets')
Stephen Warren33db1ee2016-02-04 16:11:50 -0700119
Stephen Warren10e50632016-01-15 11:15:24 -0700120 import multiplexed_log
121 log = multiplexed_log.Logfile(result_dir + '/test-log.html')
122
123 if config.getoption('build'):
124 if build_dir != source_dir:
125 o_opt = 'O=%s' % build_dir
126 else:
127 o_opt = ''
128 cmds = (
129 ['make', o_opt, '-s', board_type + '_defconfig'],
130 ['make', o_opt, '-s', '-j8'],
131 )
Stephen Warrene3f2a502016-02-03 16:46:34 -0700132 with log.section('make'):
133 runner = log.get_runner('make', sys.stdout)
134 for cmd in cmds:
135 runner.run(cmd, cwd=source_dir)
136 runner.close()
137 log.status_pass('OK')
Stephen Warren10e50632016-01-15 11:15:24 -0700138
139 class ArbitraryAttributeContainer(object):
140 pass
141
142 ubconfig = ArbitraryAttributeContainer()
143 ubconfig.brd = dict()
144 ubconfig.env = dict()
145
146 modules = [
147 (ubconfig.brd, 'u_boot_board_' + board_type_filename),
148 (ubconfig.env, 'u_boot_boardenv_' + board_type_filename),
149 (ubconfig.env, 'u_boot_boardenv_' + board_type_filename + '_' +
150 board_identity_filename),
151 ]
152 for (dict_to_fill, module_name) in modules:
153 try:
154 module = __import__(module_name)
155 except ImportError:
156 continue
157 dict_to_fill.update(module.__dict__)
158
159 ubconfig.buildconfig = dict()
160
161 for conf_file in ('.config', 'include/autoconf.mk'):
162 dot_config = build_dir + '/' + conf_file
163 if not os.path.exists(dot_config):
164 raise Exception(conf_file + ' does not exist; ' +
165 'try passing --build option?')
166
167 with open(dot_config, 'rt') as f:
168 ini_str = '[root]\n' + f.read()
Tom Rini7f24c192019-10-24 11:59:20 -0400169 ini_sio = io.StringIO(ini_str)
Paul Burton5ddc2872017-09-14 14:34:45 -0700170 parser = configparser.RawConfigParser()
Stephen Warren10e50632016-01-15 11:15:24 -0700171 parser.readfp(ini_sio)
172 ubconfig.buildconfig.update(parser.items('root'))
173
174 ubconfig.test_py_dir = test_py_dir
175 ubconfig.source_dir = source_dir
176 ubconfig.build_dir = build_dir
177 ubconfig.result_dir = result_dir
178 ubconfig.persistent_data_dir = persistent_data_dir
179 ubconfig.board_type = board_type
180 ubconfig.board_identity = board_identity
Stephen Warren33db1ee2016-02-04 16:11:50 -0700181 ubconfig.gdbserver = gdbserver
Simon Glass3b097872016-07-03 09:40:36 -0600182 ubconfig.dtb = build_dir + '/arch/sandbox/dts/test.dtb'
Stephen Warren10e50632016-01-15 11:15:24 -0700183
184 env_vars = (
185 'board_type',
186 'board_identity',
187 'source_dir',
188 'test_py_dir',
189 'build_dir',
190 'result_dir',
191 'persistent_data_dir',
192 )
193 for v in env_vars:
194 os.environ['U_BOOT_' + v.upper()] = getattr(ubconfig, v)
195
Simon Glass13f422e2016-07-04 11:58:37 -0600196 if board_type.startswith('sandbox'):
Stephen Warren10e50632016-01-15 11:15:24 -0700197 import u_boot_console_sandbox
198 console = u_boot_console_sandbox.ConsoleSandbox(log, ubconfig)
199 else:
200 import u_boot_console_exec_attach
201 console = u_boot_console_exec_attach.ConsoleExecAttach(log, ubconfig)
202
Simon Glass71861672017-11-25 11:57:32 -0700203re_ut_test_list = re.compile(r'_u_boot_list_2_(.*)_test_2_\1_test_(.*)\s*$')
Stephen Warren770fe172016-02-08 14:44:16 -0700204def generate_ut_subtest(metafunc, fixture_name):
205 """Provide parametrization for a ut_subtest fixture.
206
207 Determines the set of unit tests built into a U-Boot binary by parsing the
208 list of symbols generated by the build process. Provides this information
209 to test functions by parameterizing their ut_subtest fixture parameter.
210
211 Args:
212 metafunc: The pytest test function.
213 fixture_name: The fixture name to test.
214
215 Returns:
216 Nothing.
217 """
218
219 fn = console.config.build_dir + '/u-boot.sym'
220 try:
221 with open(fn, 'rt') as f:
222 lines = f.readlines()
223 except:
224 lines = []
225 lines.sort()
226
227 vals = []
228 for l in lines:
229 m = re_ut_test_list.search(l)
230 if not m:
231 continue
232 vals.append(m.group(1) + ' ' + m.group(2))
233
234 ids = ['ut_' + s.replace(' ', '_') for s in vals]
235 metafunc.parametrize(fixture_name, vals, ids=ids)
236
237def generate_config(metafunc, fixture_name):
238 """Provide parametrization for {env,brd}__ fixtures.
Stephen Warren10e50632016-01-15 11:15:24 -0700239
240 If a test function takes parameter(s) (fixture names) of the form brd__xxx
241 or env__xxx, the brd and env configuration dictionaries are consulted to
242 find the list of values to use for those parameters, and the test is
243 parametrized so that it runs once for each combination of values.
244
245 Args:
246 metafunc: The pytest test function.
Stephen Warren770fe172016-02-08 14:44:16 -0700247 fixture_name: The fixture name to test.
Stephen Warren10e50632016-01-15 11:15:24 -0700248
249 Returns:
250 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -0700251 """
Stephen Warren10e50632016-01-15 11:15:24 -0700252
253 subconfigs = {
254 'brd': console.config.brd,
255 'env': console.config.env,
256 }
Stephen Warren770fe172016-02-08 14:44:16 -0700257 parts = fixture_name.split('__')
258 if len(parts) < 2:
259 return
260 if parts[0] not in subconfigs:
261 return
262 subconfig = subconfigs[parts[0]]
263 vals = []
264 val = subconfig.get(fixture_name, [])
265 # If that exact name is a key in the data source:
266 if val:
267 # ... use the dict value as a single parameter value.
268 vals = (val, )
269 else:
270 # ... otherwise, see if there's a key that contains a list of
271 # values to use instead.
272 vals = subconfig.get(fixture_name+ 's', [])
273 def fixture_id(index, val):
274 try:
275 return val['fixture_id']
276 except:
277 return fixture_name + str(index)
278 ids = [fixture_id(index, val) for (index, val) in enumerate(vals)]
279 metafunc.parametrize(fixture_name, vals, ids=ids)
280
281def pytest_generate_tests(metafunc):
282 """pytest hook: parameterize test functions based on custom rules.
283
284 Check each test function parameter (fixture name) to see if it is one of
285 our custom names, and if so, provide the correct parametrization for that
286 parameter.
287
288 Args:
289 metafunc: The pytest test function.
290
291 Returns:
292 Nothing.
293 """
294
Stephen Warren10e50632016-01-15 11:15:24 -0700295 for fn in metafunc.fixturenames:
Stephen Warren770fe172016-02-08 14:44:16 -0700296 if fn == 'ut_subtest':
297 generate_ut_subtest(metafunc, fn)
Stephen Warren10e50632016-01-15 11:15:24 -0700298 continue
Stephen Warren770fe172016-02-08 14:44:16 -0700299 generate_config(metafunc, fn)
Stephen Warren10e50632016-01-15 11:15:24 -0700300
Stefan Brüns364ea872016-11-05 17:45:32 +0100301@pytest.fixture(scope='session')
302def u_boot_log(request):
303 """Generate the value of a test's log fixture.
304
305 Args:
306 request: The pytest request.
307
308 Returns:
309 The fixture value.
310 """
311
312 return console.log
313
314@pytest.fixture(scope='session')
315def u_boot_config(request):
316 """Generate the value of a test's u_boot_config fixture.
317
318 Args:
319 request: The pytest request.
320
321 Returns:
322 The fixture value.
323 """
324
325 return console.config
326
Stephen Warrene1d24d02016-01-22 12:30:08 -0700327@pytest.fixture(scope='function')
Stephen Warren10e50632016-01-15 11:15:24 -0700328def u_boot_console(request):
Stephen Warren75e731e2016-01-26 13:41:30 -0700329 """Generate the value of a test's u_boot_console fixture.
Stephen Warren10e50632016-01-15 11:15:24 -0700330
331 Args:
332 request: The pytest request.
333
334 Returns:
335 The fixture value.
Stephen Warren75e731e2016-01-26 13:41:30 -0700336 """
Stephen Warren10e50632016-01-15 11:15:24 -0700337
Stephen Warrene1d24d02016-01-22 12:30:08 -0700338 console.ensure_spawned()
Stephen Warren10e50632016-01-15 11:15:24 -0700339 return console
340
Stephen Warrene3f2a502016-02-03 16:46:34 -0700341anchors = {}
Stephen Warrenaaf4e912016-02-10 13:47:37 -0700342tests_not_run = []
343tests_failed = []
344tests_xpassed = []
345tests_xfailed = []
346tests_skipped = []
Stephen Warrene27a6ae2018-02-20 12:51:55 -0700347tests_warning = []
Stephen Warrenaaf4e912016-02-10 13:47:37 -0700348tests_passed = []
Stephen Warren10e50632016-01-15 11:15:24 -0700349
350def pytest_itemcollected(item):
Stephen Warren75e731e2016-01-26 13:41:30 -0700351 """pytest hook: Called once for each test found during collection.
Stephen Warren10e50632016-01-15 11:15:24 -0700352
353 This enables our custom result analysis code to see the list of all tests
354 that should eventually be run.
355
356 Args:
357 item: The item that was collected.
358
359 Returns:
360 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -0700361 """
Stephen Warren10e50632016-01-15 11:15:24 -0700362
Stephen Warrenaaf4e912016-02-10 13:47:37 -0700363 tests_not_run.append(item.name)
Stephen Warren10e50632016-01-15 11:15:24 -0700364
365def cleanup():
Stephen Warren75e731e2016-01-26 13:41:30 -0700366 """Clean up all global state.
Stephen Warren10e50632016-01-15 11:15:24 -0700367
368 Executed (via atexit) once the entire test process is complete. This
369 includes logging the status of all tests, and the identity of any failed
370 or skipped tests.
371
372 Args:
373 None.
374
375 Returns:
376 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -0700377 """
Stephen Warren10e50632016-01-15 11:15:24 -0700378
379 if console:
380 console.close()
381 if log:
Stephen Warrene3f2a502016-02-03 16:46:34 -0700382 with log.section('Status Report', 'status_report'):
383 log.status_pass('%d passed' % len(tests_passed))
Stephen Warrene27a6ae2018-02-20 12:51:55 -0700384 if tests_warning:
385 log.status_warning('%d passed with warning' % len(tests_warning))
386 for test in tests_warning:
387 anchor = anchors.get(test, None)
388 log.status_warning('... ' + test, anchor)
Stephen Warrene3f2a502016-02-03 16:46:34 -0700389 if tests_skipped:
390 log.status_skipped('%d skipped' % len(tests_skipped))
391 for test in tests_skipped:
392 anchor = anchors.get(test, None)
393 log.status_skipped('... ' + test, anchor)
394 if tests_xpassed:
395 log.status_xpass('%d xpass' % len(tests_xpassed))
396 for test in tests_xpassed:
397 anchor = anchors.get(test, None)
398 log.status_xpass('... ' + test, anchor)
399 if tests_xfailed:
400 log.status_xfail('%d xfail' % len(tests_xfailed))
401 for test in tests_xfailed:
402 anchor = anchors.get(test, None)
403 log.status_xfail('... ' + test, anchor)
404 if tests_failed:
405 log.status_fail('%d failed' % len(tests_failed))
406 for test in tests_failed:
407 anchor = anchors.get(test, None)
408 log.status_fail('... ' + test, anchor)
409 if tests_not_run:
410 log.status_fail('%d not run' % len(tests_not_run))
411 for test in tests_not_run:
412 anchor = anchors.get(test, None)
413 log.status_fail('... ' + test, anchor)
Stephen Warren10e50632016-01-15 11:15:24 -0700414 log.close()
415atexit.register(cleanup)
416
417def setup_boardspec(item):
Stephen Warren75e731e2016-01-26 13:41:30 -0700418 """Process any 'boardspec' marker for a test.
Stephen Warren10e50632016-01-15 11:15:24 -0700419
420 Such a marker lists the set of board types that a test does/doesn't
421 support. If tests are being executed on an unsupported board, the test is
422 marked to be skipped.
423
424 Args:
425 item: The pytest test item.
426
427 Returns:
428 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -0700429 """
Stephen Warren10e50632016-01-15 11:15:24 -0700430
Stephen Warren10e50632016-01-15 11:15:24 -0700431 required_boards = []
Marek Vasut9dfdf6e2019-10-24 11:59:19 -0400432 for boards in item.iter_markers('boardspec'):
433 board = boards.args[0]
Stephen Warren10e50632016-01-15 11:15:24 -0700434 if board.startswith('!'):
435 if ubconfig.board_type == board[1:]:
Stephen Warren0f0eeac2017-09-18 11:11:48 -0600436 pytest.skip('board "%s" not supported' % ubconfig.board_type)
Stephen Warren10e50632016-01-15 11:15:24 -0700437 return
438 else:
439 required_boards.append(board)
440 if required_boards and ubconfig.board_type not in required_boards:
Stephen Warren0f0eeac2017-09-18 11:11:48 -0600441 pytest.skip('board "%s" not supported' % ubconfig.board_type)
Stephen Warren10e50632016-01-15 11:15:24 -0700442
443def setup_buildconfigspec(item):
Stephen Warren75e731e2016-01-26 13:41:30 -0700444 """Process any 'buildconfigspec' marker for a test.
Stephen Warren10e50632016-01-15 11:15:24 -0700445
446 Such a marker lists some U-Boot configuration feature that the test
447 requires. If tests are being executed on an U-Boot build that doesn't
448 have the required feature, the test is marked to be skipped.
449
450 Args:
451 item: The pytest test item.
452
453 Returns:
454 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -0700455 """
Stephen Warren10e50632016-01-15 11:15:24 -0700456
Marek Vasut9dfdf6e2019-10-24 11:59:19 -0400457 for options in item.iter_markers('buildconfigspec'):
458 option = options.args[0]
459 if not ubconfig.buildconfig.get('config_' + option.lower(), None):
460 pytest.skip('.config feature "%s" not enabled' % option.lower())
461 for option in item.iter_markers('notbuildconfigspec'):
462 option = options.args[0]
463 if ubconfig.buildconfig.get('config_' + option.lower(), None):
464 pytest.skip('.config feature "%s" enabled' % option.lower())
Stephen Warren10e50632016-01-15 11:15:24 -0700465
Stephen Warren2079db32017-09-18 11:11:49 -0600466def tool_is_in_path(tool):
467 for path in os.environ["PATH"].split(os.pathsep):
468 fn = os.path.join(path, tool)
469 if os.path.isfile(fn) and os.access(fn, os.X_OK):
470 return True
471 return False
472
473def setup_requiredtool(item):
474 """Process any 'requiredtool' marker for a test.
475
476 Such a marker lists some external tool (binary, executable, application)
477 that the test requires. If tests are being executed on a system that
478 doesn't have the required tool, the test is marked to be skipped.
479
480 Args:
481 item: The pytest test item.
482
483 Returns:
484 Nothing.
485 """
486
Marek Vasut9dfdf6e2019-10-24 11:59:19 -0400487 for tools in item.iter_markers('requiredtool'):
488 tool = tools.args[0]
Stephen Warren2079db32017-09-18 11:11:49 -0600489 if not tool_is_in_path(tool):
490 pytest.skip('tool "%s" not in $PATH' % tool)
491
Stephen Warren3e3d1432016-10-17 17:25:52 -0600492def start_test_section(item):
493 anchors[item.name] = log.start_section(item.name)
494
Stephen Warren10e50632016-01-15 11:15:24 -0700495def pytest_runtest_setup(item):
Stephen Warren75e731e2016-01-26 13:41:30 -0700496 """pytest hook: Configure (set up) a test item.
Stephen Warren10e50632016-01-15 11:15:24 -0700497
498 Called once for each test to perform any custom configuration. This hook
499 is used to skip the test if certain conditions apply.
500
501 Args:
502 item: The pytest test item.
503
504 Returns:
505 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -0700506 """
Stephen Warren10e50632016-01-15 11:15:24 -0700507
Stephen Warren3e3d1432016-10-17 17:25:52 -0600508 start_test_section(item)
Stephen Warren10e50632016-01-15 11:15:24 -0700509 setup_boardspec(item)
510 setup_buildconfigspec(item)
Stephen Warren2079db32017-09-18 11:11:49 -0600511 setup_requiredtool(item)
Stephen Warren10e50632016-01-15 11:15:24 -0700512
513def pytest_runtest_protocol(item, nextitem):
Stephen Warren75e731e2016-01-26 13:41:30 -0700514 """pytest hook: Called to execute a test.
Stephen Warren10e50632016-01-15 11:15:24 -0700515
516 This hook wraps the standard pytest runtestprotocol() function in order
517 to acquire visibility into, and record, each test function's result.
518
519 Args:
520 item: The pytest test item to execute.
521 nextitem: The pytest test item that will be executed after this one.
522
523 Returns:
524 A list of pytest reports (test result data).
Stephen Warren75e731e2016-01-26 13:41:30 -0700525 """
Stephen Warren10e50632016-01-15 11:15:24 -0700526
Stephen Warrene27a6ae2018-02-20 12:51:55 -0700527 log.get_and_reset_warning()
Stephen Warren10e50632016-01-15 11:15:24 -0700528 reports = runtestprotocol(item, nextitem=nextitem)
Stephen Warrene27a6ae2018-02-20 12:51:55 -0700529 was_warning = log.get_and_reset_warning()
Stephen Warren25b05242016-01-27 23:57:51 -0700530
Stephen Warren3e3d1432016-10-17 17:25:52 -0600531 # In pytest 3, runtestprotocol() may not call pytest_runtest_setup() if
532 # the test is skipped. That call is required to create the test's section
533 # in the log file. The call to log.end_section() requires that the log
534 # contain a section for this test. Create a section for the test if it
535 # doesn't already exist.
536 if not item.name in anchors:
537 start_test_section(item)
538
Stephen Warren25b05242016-01-27 23:57:51 -0700539 failure_cleanup = False
Stephen Warrene27a6ae2018-02-20 12:51:55 -0700540 if not was_warning:
541 test_list = tests_passed
542 msg = 'OK'
543 msg_log = log.status_pass
544 else:
545 test_list = tests_warning
546 msg = 'OK (with warning)'
547 msg_log = log.status_warning
Stephen Warren10e50632016-01-15 11:15:24 -0700548 for report in reports:
549 if report.outcome == 'failed':
Stephen Warren25b05242016-01-27 23:57:51 -0700550 if hasattr(report, 'wasxfail'):
551 test_list = tests_xpassed
552 msg = 'XPASSED'
553 msg_log = log.status_xpass
554 else:
555 failure_cleanup = True
556 test_list = tests_failed
557 msg = 'FAILED:\n' + str(report.longrepr)
558 msg_log = log.status_fail
Stephen Warren10e50632016-01-15 11:15:24 -0700559 break
560 if report.outcome == 'skipped':
Stephen Warren25b05242016-01-27 23:57:51 -0700561 if hasattr(report, 'wasxfail'):
562 failure_cleanup = True
563 test_list = tests_xfailed
564 msg = 'XFAILED:\n' + str(report.longrepr)
565 msg_log = log.status_xfail
566 break
567 test_list = tests_skipped
568 msg = 'SKIPPED:\n' + str(report.longrepr)
569 msg_log = log.status_skipped
Stephen Warren10e50632016-01-15 11:15:24 -0700570
Stephen Warren25b05242016-01-27 23:57:51 -0700571 if failure_cleanup:
Stephen Warren97a54662016-01-22 12:30:09 -0700572 console.drain_console()
Stephen Warren25b05242016-01-27 23:57:51 -0700573
Stephen Warrenaaf4e912016-02-10 13:47:37 -0700574 test_list.append(item.name)
Stephen Warren10e50632016-01-15 11:15:24 -0700575 tests_not_run.remove(item.name)
576
577 try:
Stephen Warren25b05242016-01-27 23:57:51 -0700578 msg_log(msg)
Stephen Warren10e50632016-01-15 11:15:24 -0700579 except:
580 # If something went wrong with logging, it's better to let the test
581 # process continue, which may report other exceptions that triggered
582 # the logging issue (e.g. console.log wasn't created). Hence, just
583 # squash the exception. If the test setup failed due to e.g. syntax
584 # error somewhere else, this won't be seen. However, once that issue
585 # is fixed, if this exception still exists, it will then be logged as
586 # part of the test's stdout.
587 import traceback
Paul Burton00f2d202017-09-14 14:34:43 -0700588 print('Exception occurred while logging runtest status:')
Stephen Warren10e50632016-01-15 11:15:24 -0700589 traceback.print_exc()
590 # FIXME: Can we force a test failure here?
591
592 log.end_section(item.name)
593
Stephen Warren25b05242016-01-27 23:57:51 -0700594 if failure_cleanup:
Stephen Warren10e50632016-01-15 11:15:24 -0700595 console.cleanup_spawn()
596
597 return reports