blob: 4558b037e2ae433d6d542067c3f9ed834401883c [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 """
Simon Glass32701112025-02-09 09:07:17 -070023 output = ubman.run_command('log format %s' % fmt)
Simon Glass32e9b162017-12-28 13:14:21 -070024 assert output == ''
Simon Glass32701112025-02-09 09:07:17 -070025 output = ubman.run_command('log rec arch notice file.c 123 func msg')
Simon Glass32e9b162017-12-28 13:14:21 -070026 assert output == expected_output
27
Simon Glass32701112025-02-09 09:07:17 -070028 with ubman.log.section('format'):
Simon Glassddba5202025-02-09 09:07:14 -070029 pad = int(ubman.config.buildconfig.get('config_logf_func_pad'))
Simon Glass2829bbf2024-06-23 14:30:28 -060030 padding = ' ' * (pad - len('func'))
31
32 run_with_format('all', f'NOTICE.arch,file.c:123-{padding}func() msg')
Simon Glass32701112025-02-09 09:07:17 -070033 output = ubman.run_command('log format')
Simon Glass32e9b162017-12-28 13:14:21 -070034 assert output == 'Log format: clFLfm'
35
Simon Glass2829bbf2024-06-23 14:30:28 -060036 run_with_format('fm', f'{padding}func() msg')
37 run_with_format('clfm', f'NOTICE.arch,{padding}func() msg')
38 run_with_format('FLfm', f'file.c:123-{padding}func() msg')
Simon Glass32e9b162017-12-28 13:14:21 -070039 run_with_format('lm', 'NOTICE. msg')
40 run_with_format('m', 'msg')
Patrick Delaunay053156d2020-11-27 11:20:55 +010041
42@pytest.mark.buildconfigspec('debug_uart')
43@pytest.mark.boardspec('sandbox')
Simon Glassddba5202025-02-09 09:07:14 -070044def test_log_dropped(ubman):
Patrick Delaunay053156d2020-11-27 11:20:55 +010045 """Test dropped 'log' message when debug_uart is activated"""
46
Simon Glass32701112025-02-09 09:07:17 -070047 ubman.restart_uboot()
48 output = ubman.get_spawn_output().replace('\r', '')
Patrick Delaunay053156d2020-11-27 11:20:55 +010049 assert (not 'debug: main' in output)