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 == lines.next()
32 assert 'func() _log %d' % i == lines.next()
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 == lines.next()
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)
88 # TODO(sjg@chromium.org): Consider structuring this as separate tests
101 @pytest.mark.buildconfigspec('cmd_log')
102 def test_log_format(u_boot_console):
103 """Test the 'log format' and 'log rec' commands"""
104 def run_with_format(fmt, expected_output):
105 """Set up the log format and then write a log record
108 fmt: Format to use for 'log format'
109 expected_output: Expected output from the 'log rec' command
111 output = cons.run_command('log format %s' % fmt)
113 output = cons.run_command('log rec arch notice file.c 123 func msg')
114 assert output == expected_output
116 cons = u_boot_console
117 with cons.log.section('format'):
118 run_with_format('all', 'NOTICE.arch,file.c:123-func() msg')
119 output = cons.run_command('log format')
120 assert output == 'Log format: clFLfm'
122 run_with_format('fm', 'func() msg')
123 run_with_format('clfm', 'NOTICE.arch,func() msg')
124 run_with_format('FLfm', 'file.c:123-func() msg')
125 run_with_format('lm', 'NOTICE. msg')
126 run_with_format('m', 'msg')