1 # Copyright (c) 2016, Google Inc.
3 # SPDX-License-Identifier: GPL-2.0+
5 # U-Boot Verified Boot Test
8 This tests U-Boot logging. It uses the 'log test' command with various options
9 and checks that the output is correct.
14 LOGL_FIRST, LOGL_WARNING, LOGL_INFO = (0, 4, 6)
16 @pytest.mark.buildconfigspec('log')
17 def test_log(u_boot_console):
18 """Test that U-Boot logging works correctly."""
19 def check_log_entries(lines, mask, max_level=LOGL_INFO):
20 """Check that the expected log records appear in the output
23 lines: iterator containing lines to check
24 mask: bit mask to select which lines to check for:
25 bit 0: standard log line
27 max_level: maximum log level to expect in the output
29 for i in range(max_level):
31 assert 'log_run() log %d' % i == lines.next()
33 assert 'func() _log %d' % i == lines.next()
35 def run_test(testnum):
36 """Run a particular test number (the 'log test' command)
39 testnum: Test number to run
41 iterator containing the lines output from the command
43 with cons.log.section('basic'):
44 output = u_boot_console.run_command('log test %d' % testnum)
45 split = output.replace('\r', '').splitlines()
47 assert 'test %d' % testnum == lines.next()
52 check_log_entries(lines, 3)
56 check_log_entries(lines, 3)
63 check_log_entries(lines, 2)
67 assert next(lines, None) == None
71 check_log_entries(lines, 2)
75 check_log_entries(lines, 3)
79 check_log_entries(lines, 3, LOGL_WARNING)
83 check_log_entries(lines, 3)
87 check_log_entries(lines, 3)
89 # TODO(sjg@chromium.org): Consider structuring this as separate tests
102 @pytest.mark.buildconfigspec('log')
103 def test_log_format(u_boot_console):
104 """Test the 'log format' and 'log rec' commands"""
105 def run_with_format(fmt, expected_output):
106 """Set up the log format and then write a log record
109 fmt: Format to use for 'log format'
110 expected_output: Expected output from the 'log rec' command
112 output = cons.run_command('log format %s' % fmt)
114 output = cons.run_command('log rec arch notice file.c 123 func msg')
115 assert output == expected_output
117 cons = u_boot_console
118 with cons.log.section('format'):
119 run_with_format('all', 'NOTICE.arch,file.c:123-func() msg')
120 output = cons.run_command('log format')
121 assert output == 'Log format: clFLfm'
123 run_with_format('fm', 'func() msg')
124 run_with_format('clfm', 'NOTICE.arch,func() msg')
125 run_with_format('FLfm', 'file.c:123-func() msg')
126 run_with_format('lm', 'NOTICE. msg')
127 run_with_format('m', 'msg')