blob: 292f5b3167569d8351dd79ba495c8a30bbfeb928 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Simon Glass5f0e0c82017-12-04 13:48:30 -07002# Copyright (c) 2016, Google Inc.
3#
Simon Glass5f0e0c82017-12-04 13:48:30 -07004# U-Boot Verified Boot Test
5
6"""
7This tests U-Boot logging. It uses the 'log test' command with various options
8and checks that the output is correct.
9"""
10
11import pytest
12
Tom Rini686dc7e2018-05-25 08:28:45 -040013@pytest.mark.buildconfigspec('cmd_log')
Simon Glassddba5202025-02-09 09:07:14 -070014def test_log_format(ubman):
Simon Glass32e9b162017-12-28 13:14:21 -070015 """Test the 'log format' and 'log rec' commands"""
16 def run_with_format(fmt, expected_output):
17 """Set up the log format and then write a log record
18
19 Args:
20 fmt: Format to use for 'log format'
21 expected_output: Expected output from the 'log rec' command
22 """
23 output = cons.run_command('log format %s' % fmt)
24 assert output == ''
25 output = cons.run_command('log rec arch notice file.c 123 func msg')
26 assert output == expected_output
27
Simon Glassddba5202025-02-09 09:07:14 -070028 cons = ubman
Simon Glass32e9b162017-12-28 13:14:21 -070029 with cons.log.section('format'):
Simon Glassddba5202025-02-09 09:07:14 -070030 pad = int(ubman.config.buildconfig.get('config_logf_func_pad'))
Simon Glass2829bbf2024-06-23 14:30:28 -060031 padding = ' ' * (pad - len('func'))
32
33 run_with_format('all', f'NOTICE.arch,file.c:123-{padding}func() msg')
Simon Glass32e9b162017-12-28 13:14:21 -070034 output = cons.run_command('log format')
35 assert output == 'Log format: clFLfm'
36
Simon Glass2829bbf2024-06-23 14:30:28 -060037 run_with_format('fm', f'{padding}func() msg')
38 run_with_format('clfm', f'NOTICE.arch,{padding}func() msg')
39 run_with_format('FLfm', f'file.c:123-{padding}func() msg')
Simon Glass32e9b162017-12-28 13:14:21 -070040 run_with_format('lm', 'NOTICE. msg')
41 run_with_format('m', 'msg')
Patrick Delaunay053156d2020-11-27 11:20:55 +010042
43@pytest.mark.buildconfigspec('debug_uart')
44@pytest.mark.boardspec('sandbox')
Simon Glassddba5202025-02-09 09:07:14 -070045def test_log_dropped(ubman):
Patrick Delaunay053156d2020-11-27 11:20:55 +010046 """Test dropped 'log' message when debug_uart is activated"""
47
Simon Glassddba5202025-02-09 09:07:14 -070048 cons = ubman
Patrick Delaunay053156d2020-11-27 11:20:55 +010049 cons.restart_uboot()
50 output = cons.get_spawn_output().replace('\r', '')
Patrick Delaunay053156d2020-11-27 11:20:55 +010051 assert (not 'debug: main' in output)