diff options
Diffstat (limited to 'test/py')
-rw-r--r-- | test/py/conftest.py | 2 | ||||
-rw-r--r-- | test/py/tests/test_efi_loader.py | 4 | ||||
-rw-r--r-- | test/py/tests/test_efi_selftest.py | 14 | ||||
-rw-r--r-- | test/py/tests/test_env.py | 11 | ||||
-rw-r--r-- | test/py/tests/test_gpt.py | 32 | ||||
-rw-r--r-- | test/py/tests/test_log.py | 101 | ||||
-rw-r--r-- | test/py/tests/test_sleep.py | 13 |
7 files changed, 158 insertions, 19 deletions
diff --git a/test/py/conftest.py b/test/py/conftest.py index 6e66a48c15..3fe91e8746 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -200,7 +200,7 @@ def pytest_configure(config): import u_boot_console_exec_attach console = u_boot_console_exec_attach.ConsoleExecAttach(log, ubconfig) -re_ut_test_list = re.compile(r'_u_boot_list_2_(dm|env)_test_2_\1_test_(.*)\s*$') +re_ut_test_list = re.compile(r'_u_boot_list_2_(.*)_test_2_\1_test_(.*)\s*$') def generate_ut_subtest(metafunc, fixture_name): """Provide parametrization for a ut_subtest fixture. diff --git a/test/py/tests/test_efi_loader.py b/test/py/tests/test_efi_loader.py index 5d7f5dbfb2..906ef2feaa 100644 --- a/test/py/tests/test_efi_loader.py +++ b/test/py/tests/test_efi_loader.py @@ -12,7 +12,7 @@ import u_boot_utils """ Note: This test relies on boardenv_* containing configuration values to define -which the network environment available for testing. Without this, the parts +which network environment is available for testing. Without this, the parts that rely on network will be automatically skipped. For example: @@ -154,6 +154,8 @@ def test_efi_helloworld_net(u_boot_console): output = u_boot_console.run_command('bootefi %x' % addr) expected_text = 'Hello, world' assert expected_text in output + expected_text = '## Application terminated, r = 0' + assert expected_text in output @pytest.mark.buildconfigspec('cmd_bootefi_hello') def test_efi_helloworld_builtin(u_boot_console): diff --git a/test/py/tests/test_efi_selftest.py b/test/py/tests/test_efi_selftest.py index 76e282a6c7..66b799bed6 100644 --- a/test/py/tests/test_efi_selftest.py +++ b/test/py/tests/test_efi_selftest.py @@ -1,4 +1,3 @@ -# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. # Copyright (c) 2017, Heinrich Schuchardt <xypron.glpk@gmx.de> # # SPDX-License-Identifier: GPL-2.0 @@ -14,6 +13,7 @@ def test_efi_selftest(u_boot_console): Run bootefi selftest """ + u_boot_console.run_command(cmd='setenv efi_selftest') u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False) m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']) if m != 0: @@ -23,3 +23,15 @@ def test_efi_selftest(u_boot_console): if m != 0: raise Exception('Reset failed during the EFI selftest') u_boot_console.restart_uboot(); + +@pytest.mark.buildconfigspec('cmd_bootefi_selftest') +def test_efi_selftest_watchdog_reboot(u_boot_console): + u_boot_console.run_command(cmd='setenv efi_selftest list') + output = u_boot_console.run_command('bootefi selftest') + assert '\'watchdog reboot\'' in output + u_boot_console.run_command(cmd='setenv efi_selftest watchdog reboot') + u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False) + m = u_boot_console.p.expect(['resetting', 'U-Boot']) + if m != 0: + raise Exception('Reset failed in \'watchdog reboot\' test') + u_boot_console.restart_uboot(); diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py index b7f960c755..f8694017b4 100644 --- a/test/py/tests/test_env.py +++ b/test/py/tests/test_env.py @@ -125,7 +125,16 @@ def set_var(state_test_env, var, value): Nothing. """ - state_test_env.u_boot_console.run_command('setenv %s "%s"' % (var, value)) + bc = state_test_env.u_boot_console.config.buildconfig + if bc.get('config_hush_parser', None): + quote = '"' + else: + quote = '' + if ' ' in value: + pytest.skip('Space in variable value on non-Hush shell') + + state_test_env.u_boot_console.run_command( + 'setenv %s %s%s%s' % (var, quote, value, quote)) state_test_env.env[var] = value def validate_empty(state_test_env, var): diff --git a/test/py/tests/test_gpt.py b/test/py/tests/test_gpt.py index 4329b69b7a..886df43f8b 100644 --- a/test/py/tests/test_gpt.py +++ b/test/py/tests/test_gpt.py @@ -44,9 +44,11 @@ class GptTestDiskImage(object): cmd = ('sgdisk', '-U', '375a56f7-d6c9-4e81-b5f0-09d41ca89efe', persistent) u_boot_utils.run_and_log(u_boot_console, cmd) - cmd = ('sgdisk', '--new=1:2048:2560', '-c 1:part1', persistent) + # part1 offset 1MB size 1MB + cmd = ('sgdisk', '--new=1:2048:4095', '-c 1:part1', persistent) + # part2 offset 2MB size 1.5MB u_boot_utils.run_and_log(u_boot_console, cmd) - cmd = ('sgdisk', '--new=2:4096:4608', '-c 2:part2', persistent) + cmd = ('sgdisk', '--new=2:4096:7167', '-c 2:part2', persistent) u_boot_utils.run_and_log(u_boot_console, cmd) cmd = ('sgdisk', '-l', persistent) u_boot_utils.run_and_log(u_boot_console, cmd) @@ -76,13 +78,13 @@ def test_gpt_read(state_disk_image, u_boot_console): u_boot_console.run_command('host bind 0 ' + state_disk_image.path) output = u_boot_console.run_command('gpt read host 0') - assert 'Start 1MiB, size 0MiB' in output + assert 'Start 1MiB, size 1MiB' in output assert 'Block size 512, name part1' in output - assert 'Start 2MiB, size 0MiB' in output + assert 'Start 2MiB, size 1MiB' in output assert 'Block size 512, name part2' in output output = u_boot_console.run_command('part list host 0') - assert '0x00000800 0x00000a00 "part1"' in output - assert '0x00001000 0x00001200 "part2"' in output + assert '0x00000800 0x00000fff "part1"' in output + assert '0x00001000 0x00001bff "part2"' in output @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('cmd_gpt') @@ -133,8 +135,8 @@ def test_gpt_rename_partition(state_disk_image, u_boot_console): output = u_boot_console.run_command('gpt read host 0') assert 'name second' in output output = u_boot_console.run_command('part list host 0') - assert '0x00000800 0x00000a00 "first"' in output - assert '0x00001000 0x00001200 "second"' in output + assert '0x00000800 0x00000fff "first"' in output + assert '0x00001000 0x00001bff "second"' in output @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('cmd_gpt') @@ -146,12 +148,12 @@ def test_gpt_swap_partitions(state_disk_image, u_boot_console): u_boot_console.run_command('host bind 0 ' + state_disk_image.path) output = u_boot_console.run_command('part list host 0') - assert '0x00000800 0x00000a00 "first"' in output - assert '0x00001000 0x00001200 "second"' in output + assert '0x00000800 0x00000fff "first"' in output + assert '0x00001000 0x00001bff "second"' in output u_boot_console.run_command('gpt swap host 0 first second') output = u_boot_console.run_command('part list host 0') - assert '0x00000800 0x00000a00 "second"' in output - assert '0x00001000 0x00001200 "first"' in output + assert '0x00000800 0x00000fff "second"' in output + assert '0x00001000 0x00001bff "first"' in output @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('cmd_gpt') @@ -165,10 +167,10 @@ def test_gpt_write(state_disk_image, u_boot_console): assert 'Writing GPT: success!' in output output = u_boot_console.run_command('part list host 0') assert '0x00000022 0x00001fde "all"' in output - output = u_boot_console.run_command('gpt write host 0 "uuid_disk=375a56f7-d6c9-4e81-b5f0-09d41ca89efe;name=first,start=0x100000,size=0x40200;name=second,start=0x200000,size=0x40200;"') + output = u_boot_console.run_command('gpt write host 0 "uuid_disk=375a56f7-d6c9-4e81-b5f0-09d41ca89efe;name=first,start=1M,size=1M;name=second,start=0x200000,size=0x180000;"') assert 'Writing GPT: success!' in output output = u_boot_console.run_command('part list host 0') - assert '0x00000800 0x00000a00 "first"' in output - assert '0x00001000 0x00001200 "second"' in output + assert '0x00000800 0x00000fff "first"' in output + assert '0x00001000 0x00001bff "second"' in output output = u_boot_console.run_command('gpt guid host 0') assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py new file mode 100644 index 0000000000..fa9a25e8dc --- /dev/null +++ b/test/py/tests/test_log.py @@ -0,0 +1,101 @@ +# Copyright (c) 2016, Google Inc. +# +# SPDX-License-Identifier: GPL-2.0+ +# +# U-Boot Verified Boot Test + +""" +This tests U-Boot logging. It uses the 'log test' command with various options +and checks that the output is correct. +""" + +import pytest + +LOGL_FIRST, LOGL_WARNING, LOGL_INFO = (0, 4, 6) + +@pytest.mark.buildconfigspec('log') +def test_log(u_boot_console): + """Test that U-Boot logging works correctly.""" + def check_log_entries(lines, mask, max_level=LOGL_INFO): + """Check that the expected log records appear in the output + + Args: + lines: iterator containing lines to check + mask: bit mask to select which lines to check for: + bit 0: standard log line + bit 1: _log line + max_level: maximum log level to expect in the output + """ + for i in range(max_level): + if mask & 1: + assert 'log %d' % i == lines.next() + if mask & 3: + assert '_log %d' % i == lines.next() + + def run_test(testnum): + """Run a particular test number (the 'log test' command) + + Args: + testnum: Test number to run + Returns: + iterator containing the lines output from the command + """ + + with cons.log.section('basic'): + output = u_boot_console.run_command('log test %d' % testnum) + split = output.replace('\r', '').splitlines() + lines = iter(split) + assert 'test %d' % testnum == lines.next() + return lines + + def test0(): + lines = run_test(0) + check_log_entries(lines, 3) + + def test1(): + lines = run_test(1) + check_log_entries(lines, 3) + + def test2(): + lines = run_test(2) + + def test3(): + lines = run_test(3) + check_log_entries(lines, 2) + + def test4(): + lines = run_test(4) + assert next(lines, None) == None + + def test5(): + lines = run_test(5) + check_log_entries(lines, 2) + + def test6(): + lines = run_test(6) + check_log_entries(lines, 3) + + def test7(): + lines = run_test(7) + check_log_entries(lines, 3, LOGL_WARNING) + + def test8(): + lines = run_test(8) + check_log_entries(lines, 3) + + def test9(): + lines = run_test(9) + check_log_entries(lines, 3) + + # TODO(sjg@chromium.org): Consider structuring this as separate tests + cons = u_boot_console + test0() + test1() + test2() + test3() + test4() + test5() + test6() + test7() + test8() + test9() diff --git a/test/py/tests/test_sleep.py b/test/py/tests/test_sleep.py index 64e0571326..ccef24d7f7 100644 --- a/test/py/tests/test_sleep.py +++ b/test/py/tests/test_sleep.py @@ -5,10 +5,23 @@ import pytest import time +""" +Note: This test doesn't rely on boardenv_* configuration values but they can +change test behavior. + +# Setup env__sleep_accurate to False if time is not accurate on your platform +env__sleep_accurate = False + +""" + def test_sleep(u_boot_console): """Test the sleep command, and validate that it sleeps for approximately the correct amount of time.""" + sleep_skip = u_boot_console.config.env.get('env__sleep_accurate', True) + if not sleep_skip: + pytest.skip('sleep is not accurate') + if u_boot_console.config.buildconfig.get('config_cmd_misc', 'n') != 'y': pytest.skip('sleep command not supported') # 3s isn't too long, but is enough to cross a few second boundaries. |