1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2016, Google Inc.
4 # U-Boot Verified Boot Test
7 This tests U-Boot logging. It uses the 'log test' command with various options
8 and checks that the output is correct.
13 LOGL_FIRST, LOGL_WARNING, LOGL_INFO = (0, 4, 6)
15 @pytest.mark.buildconfigspec('cmd_log')
16 def test_log(u_boot_console):
17 """Test that U-Boot logging works correctly."""
18 def check_log_entries(lines, mask, max_level=LOGL_INFO):
19 """Check that the expected log records appear in the output
22 lines: iterator containing lines to check
23 mask: bit mask to select which lines to check for:
24 bit 0: standard log line
26 max_level: maximum log level to expect in the output
28 for i in range(max_level):
30 assert 'log_run() log %d' % i == next(lines)
32 assert 'func() _log %d' % i == next(lines)
34 def run_test(testnum):
35 """Run a particular test number (the 'log test' command)
38 testnum: Test number to run
40 iterator containing the lines output from the command
42 with cons.log.section('basic'):
43 output = u_boot_console.run_command('log test %d' % testnum)
44 split = output.replace('\r', '').splitlines()
46 assert 'test %d' % testnum == next(lines)
51 check_log_entries(lines, 3)
55 check_log_entries(lines, 3)
62 check_log_entries(lines, 2)
66 assert next(lines, None) == None
70 check_log_entries(lines, 2)
74 check_log_entries(lines, 3)
78 check_log_entries(lines, 3, LOGL_WARNING)
82 check_log_entries(lines, 3)
86 check_log_entries(lines, 3)
91 assert 'log_test() level %d' % i == next(lines)
93 # TODO(sjg@chromium.org): Consider structuring this as separate tests
107 @pytest.mark.buildconfigspec('cmd_log')
108 def test_log_format(u_boot_console):
109 """Test the 'log format' and 'log rec' commands"""
110 def run_with_format(fmt, expected_output):
111 """Set up the log format and then write a log record
114 fmt: Format to use for 'log format'
115 expected_output: Expected output from the 'log rec' command
117 output = cons.run_command('log format %s' % fmt)
119 output = cons.run_command('log rec arch notice file.c 123 func msg')
120 assert output == expected_output
122 cons = u_boot_console
123 with cons.log.section('format'):
124 run_with_format('all', 'NOTICE.arch,file.c:123-func() msg')
125 output = cons.run_command('log format')
126 assert output == 'Log format: clFLfm'
128 run_with_format('fm', 'func() msg')
129 run_with_format('clfm', 'NOTICE.arch,func() msg')
130 run_with_format('FLfm', 'file.c:123-func() msg')
131 run_with_format('lm', 'NOTICE. msg')
132 run_with_format('m', 'msg')