Simon Glass | 20faa27 | 2017-12-04 13:48:30 -0700 | [diff] [blame] | 1 | # Copyright (c) 2016, Google Inc. |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0+ |
| 4 | # |
| 5 | # U-Boot Verified Boot Test |
| 6 | |
| 7 | """ |
| 8 | This tests U-Boot logging. It uses the 'log test' command with various options |
| 9 | and checks that the output is correct. |
| 10 | """ |
| 11 | |
| 12 | import pytest |
| 13 | |
| 14 | LOGL_FIRST, LOGL_WARNING, LOGL_INFO = (0, 4, 6) |
| 15 | |
| 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 |
| 21 | |
| 22 | Args: |
| 23 | lines: iterator containing lines to check |
| 24 | mask: bit mask to select which lines to check for: |
| 25 | bit 0: standard log line |
| 26 | bit 1: _log line |
| 27 | max_level: maximum log level to expect in the output |
| 28 | """ |
| 29 | for i in range(max_level): |
| 30 | if mask & 1: |
Simon Glass | deca50f | 2017-12-28 13:14:18 -0700 | [diff] [blame^] | 31 | assert 'log_run() log %d' % i == lines.next() |
Simon Glass | 20faa27 | 2017-12-04 13:48:30 -0700 | [diff] [blame] | 32 | if mask & 3: |
Simon Glass | deca50f | 2017-12-28 13:14:18 -0700 | [diff] [blame^] | 33 | assert 'func() _log %d' % i == lines.next() |
Simon Glass | 20faa27 | 2017-12-04 13:48:30 -0700 | [diff] [blame] | 34 | |
| 35 | def run_test(testnum): |
| 36 | """Run a particular test number (the 'log test' command) |
| 37 | |
| 38 | Args: |
| 39 | testnum: Test number to run |
| 40 | Returns: |
| 41 | iterator containing the lines output from the command |
| 42 | """ |
| 43 | |
| 44 | with cons.log.section('basic'): |
| 45 | output = u_boot_console.run_command('log test %d' % testnum) |
| 46 | split = output.replace('\r', '').splitlines() |
| 47 | lines = iter(split) |
| 48 | assert 'test %d' % testnum == lines.next() |
| 49 | return lines |
| 50 | |
| 51 | def test0(): |
| 52 | lines = run_test(0) |
| 53 | check_log_entries(lines, 3) |
| 54 | |
| 55 | def test1(): |
| 56 | lines = run_test(1) |
| 57 | check_log_entries(lines, 3) |
| 58 | |
| 59 | def test2(): |
| 60 | lines = run_test(2) |
| 61 | |
| 62 | def test3(): |
| 63 | lines = run_test(3) |
| 64 | check_log_entries(lines, 2) |
| 65 | |
| 66 | def test4(): |
| 67 | lines = run_test(4) |
| 68 | assert next(lines, None) == None |
| 69 | |
| 70 | def test5(): |
| 71 | lines = run_test(5) |
| 72 | check_log_entries(lines, 2) |
| 73 | |
| 74 | def test6(): |
| 75 | lines = run_test(6) |
| 76 | check_log_entries(lines, 3) |
| 77 | |
| 78 | def test7(): |
| 79 | lines = run_test(7) |
| 80 | check_log_entries(lines, 3, LOGL_WARNING) |
| 81 | |
| 82 | def test8(): |
| 83 | lines = run_test(8) |
| 84 | check_log_entries(lines, 3) |
| 85 | |
| 86 | def test9(): |
| 87 | lines = run_test(9) |
| 88 | check_log_entries(lines, 3) |
| 89 | |
| 90 | # TODO(sjg@chromium.org): Consider structuring this as separate tests |
| 91 | cons = u_boot_console |
| 92 | test0() |
| 93 | test1() |
| 94 | test2() |
| 95 | test3() |
| 96 | test4() |
| 97 | test5() |
| 98 | test6() |
| 99 | test7() |
| 100 | test8() |
| 101 | test9() |