diff options
author | Tom Rini <trini@konsulko.com> | 2020-02-06 23:19:27 -0500 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-02-06 23:19:27 -0500 |
commit | 904ea003c151d8480b2e97b696ebc8f8e051d281 (patch) | |
tree | 589e9d54467dfce08bb1a5cefff436023eb9ac98 | |
parent | 457faef262c5c9533c344f25eafb10e757149a34 (diff) | |
parent | 491e87a79742711a5f747068f76fbbc17d0bc2a0 (diff) | |
download | u-boot-904ea003c151d8480b2e97b696ebc8f8e051d281.tar.gz |
Merge tag 'efi-2020-04-rc2' of https://gitlab.denx.de/u-boot/custodians/u-boot-efiWIP/06Feb2020
Pull request for UEFI sub-system for efi-2020-04-rc2
Fix pylint issues in Python based tests.
-rw-r--r-- | test/py/tests/test_efi_fit.py | 77 | ||||
-rw-r--r-- | test/py/tests/test_efi_selftest.py | 361 |
2 files changed, 226 insertions, 212 deletions
diff --git a/test/py/tests/test_efi_fit.py b/test/py/tests/test_efi_fit.py index 6986b2d35c..beaf4a3c51 100644 --- a/test/py/tests/test_efi_fit.py +++ b/test/py/tests/test_efi_fit.py @@ -9,10 +9,6 @@ # # Test launching UEFI binaries from FIT images. -import os.path -import pytest -import u_boot_utils as util - """ Note: This test relies on boardenv_* containing configuration values to define which network environment is available for testing. Without this, the parts @@ -57,8 +53,12 @@ env__efi_fit_tftp_file = { } """ +import os.path +import pytest +import u_boot_utils as util + # Define the parametrized ITS data to be used for FIT images generation. -its_data = ''' +ITS_DATA = ''' /dts-v1/; / { @@ -101,7 +101,7 @@ its_data = ''' ''' # Define the parametrized FDT data to be used for DTB images generation. -fdt_data = ''' +FDT_DATA = ''' /dts-v1/; / { @@ -199,16 +199,16 @@ def test_efi_fit_launch(u_boot_console): cons.run_command('setenv %s %s' % (var, val)) return True - def make_fpath(fname): + def make_fpath(file_name): """Compute the path of a given (temporary) file. Args: - fname: The name of a file within U-Boot build dir. + file_name: The name of a file within U-Boot build dir. Return: The computed file path. """ - return os.path.join(cons.config.build_dir, fname) + return os.path.join(cons.config.build_dir, file_name) def make_efi(fname, comp): """Create an UEFI binary. @@ -225,7 +225,8 @@ def test_efi_fit_launch(u_boot_console): bin_path = make_fpath(fname) util.run_and_log(cons, - ['cp', make_fpath('lib/efi_loader/helloworld.efi'), bin_path]) + ['cp', make_fpath('lib/efi_loader/helloworld.efi'), + bin_path]) if comp: util.run_and_log(cons, ['gzip', '-f', bin_path]) bin_path += '.gz' @@ -251,8 +252,8 @@ def test_efi_fit_launch(u_boot_console): # Generate a test FDT file. dts = make_fpath('test-efi-fit-%s.dts' % fdt_type) - with open(dts, 'w') as fd: - fd.write(fdt_data % fdt_params) + with open(dts, 'w') as file: + file.write(FDT_DATA % fdt_params) # Build the test FDT. dtb = make_fpath('test-efi-fit-%s.dtb' % fdt_type) @@ -284,65 +285,65 @@ def test_efi_fit_launch(u_boot_console): # Generate a test ITS file. its_path = make_fpath('test-efi-fit-helloworld.its') - with open(its_path, 'w') as fd: - fd.write(its_data % its_params) + with open(its_path, 'w') as file: + file.write(ITS_DATA % its_params) # Build the test ITS. fit_path = make_fpath('test-efi-fit-helloworld.fit') util.run_and_log( - cons, [make_fpath('tools/mkimage'), '-f', its_path, fit_path]) + cons, [make_fpath('tools/mkimage'), '-f', its_path, fit_path]) return fit_path - def load_fit_from_host(f): + def load_fit_from_host(fit): """Load the FIT image using the 'host load' command and return its address. Args: - f: Dictionary describing the FIT image to load, see env__efi_fit_test_file - in the comment at the beginning of this file. + fit: Dictionary describing the FIT image to load, see env__efi_fit_test_file + in the comment at the beginning of this file. Return: The address where the file has been loaded. """ - addr = f.get('addr', None) + addr = fit.get('addr', None) if not addr: addr = util.find_ram_base(cons) output = cons.run_command( - 'host load hostfs - %x %s/%s' % (addr, f['dn'], f['fn'])) + 'host load hostfs - %x %s/%s' % (addr, fit['dn'], fit['fn'])) expected_text = ' bytes read' - sz = f.get('size', None) - if sz: - expected_text = '%d' % sz + expected_text - assert(expected_text in output) + size = fit.get('size', None) + if size: + expected_text = '%d' % size + expected_text + assert expected_text in output return addr - def load_fit_from_tftp(f): + def load_fit_from_tftp(fit): """Load the FIT image using the tftpboot command and return its address. The file is downloaded from the TFTP server, its size and optionally its CRC32 are validated. Args: - f: Dictionary describing the FIT image to load, see env__efi_fit_tftp_file - in the comment at the beginning of this file. + fit: Dictionary describing the FIT image to load, see env__efi_fit_tftp_file + in the comment at the beginning of this file. Return: The address where the file has been loaded. """ - addr = f.get('addr', None) + addr = fit.get('addr', None) if not addr: addr = util.find_ram_base(cons) - fn = f['fn'] - output = cons.run_command('tftpboot %x %s' % (addr, fn)) + file_name = fit['fn'] + output = cons.run_command('tftpboot %x %s' % (addr, file_name)) expected_text = 'Bytes transferred = ' - sz = f.get('size', None) - if sz: - expected_text += '%d' % sz + size = fit.get('size', None) + if size: + expected_text += '%d' % size assert expected_text in output - expected_crc = f.get('crc32', None) + expected_crc = fit.get('crc32', None) if not expected_crc: return addr @@ -398,8 +399,8 @@ def test_efi_fit_launch(u_boot_console): if not fit: pytest.skip('No env__efi_fit_tftp_file binary specified in environment') - sz = fit.get('size', None) - if not sz: + size = fit.get('size', None) + if not size: if not fit.get('dn', None): pytest.skip('Neither "size", nor "dn" info provided in env__efi_fit_tftp_file') @@ -420,12 +421,12 @@ def test_efi_fit_launch(u_boot_console): # Try booting. cons.run_command( - 'bootm %x#%s' % (addr, fit_config), wait_for_prompt=False) + 'bootm %x#%s' % (addr, fit_config), wait_for_prompt=False) if enable_fdt: cons.wait_for('Booting using the fdt blob') cons.wait_for('Hello, world') cons.wait_for('## Application terminated, r = 0') - cons.restart_uboot(); + cons.restart_uboot() cons = u_boot_console # Array slice removes leading/trailing quotes. diff --git a/test/py/tests/test_efi_selftest.py b/test/py/tests/test_efi_selftest.py index ca01542088..971c9f6053 100644 --- a/test/py/tests/test_efi_selftest.py +++ b/test/py/tests/test_efi_selftest.py @@ -1,198 +1,211 @@ # SPDX-License-Identifier: GPL-2.0 # Copyright (c) 2017, Heinrich Schuchardt <xypron.glpk@gmx.de> -# Test efi API implementation +""" +Test UEFI API implementation +""" import pytest -import u_boot_utils @pytest.mark.buildconfigspec('cmd_bootefi_selftest') def test_efi_selftest(u_boot_console): - """Test the UEFI implementation + """Run UEFI unit tests - :param u_boot_console: U-Boot console + :param u_boot_console: U-Boot console - This function executes all selftests that are not marked as on request. - """ - 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: - raise Exception('Failures occurred during the EFI selftest') - u_boot_console.restart_uboot(); + This function executes all selftests that are not marked as on request. + """ + 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: + raise Exception('Failures occurred during the EFI selftest') + u_boot_console.restart_uboot() @pytest.mark.buildconfigspec('cmd_bootefi_selftest') @pytest.mark.buildconfigspec('of_control') @pytest.mark.notbuildconfigspec('generate_acpi_table') def test_efi_selftest_device_tree(u_boot_console): - u_boot_console.run_command(cmd='setenv efi_selftest list') - output = u_boot_console.run_command('bootefi selftest') - assert '\'device tree\'' in output - u_boot_console.run_command(cmd='setenv efi_selftest device tree') - u_boot_console.run_command(cmd='setenv -f serial# Testing DT') - u_boot_console.run_command(cmd='bootefi selftest ${fdtcontroladdr}', wait_for_prompt=False) - m = u_boot_console.p.expect(['serial-number: Testing DT', 'U-Boot']) - if m != 0: - raise Exception('serial-number missing in device tree') - u_boot_console.restart_uboot(); + """Test the device tree support in the UEFI sub-system + + :param u_boot_console: U-Boot console + + This test executes the UEFI unit test by calling 'bootefi selftest'. + """ + u_boot_console.run_command(cmd='setenv efi_selftest list') + output = u_boot_console.run_command('bootefi selftest') + assert '\'device tree\'' in output + u_boot_console.run_command(cmd='setenv efi_selftest device tree') + u_boot_console.run_command(cmd='setenv -f serial# Testing DT') + u_boot_console.run_command(cmd='bootefi selftest ${fdtcontroladdr}', wait_for_prompt=False) + m = u_boot_console.p.expect(['serial-number: Testing DT', 'U-Boot']) + if m != 0: + raise Exception('serial-number missing in device tree') + 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(); + """Test the watchdog timer + + :param u_boot_console: U-Boot console + + This function executes the 'watchdog reboot' unit test. + """ + 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() @pytest.mark.buildconfigspec('cmd_bootefi_selftest') def test_efi_selftest_text_input(u_boot_console): - """Test the EFI_SIMPLE_TEXT_INPUT_PROTOCOL - - :param u_boot_console: U-Boot console - - This function calls the text input EFI selftest. - """ - u_boot_console.run_command(cmd='setenv efi_selftest text input') - output = u_boot_console.run_command(cmd='bootefi selftest', - wait_for_prompt=False) - m = u_boot_console.p.expect([r'To terminate type \'x\'']) - if m != 0: - raise Exception('No prompt for \'text input\' test') - u_boot_console.drain_console() - u_boot_console.p.timeout = 500 - # EOT - u_boot_console.run_command(cmd=chr(4), wait_for_echo=False, - send_nl=False, wait_for_prompt=False) - m = u_boot_console.p.expect( - [r'Unicode char 4 \(unknown\), scan code 0 \(Null\)']) - if m != 0: - raise Exception('EOT failed in \'text input\' test') - u_boot_console.drain_console() - # BS - u_boot_console.run_command(cmd=chr(8), wait_for_echo=False, - send_nl=False, wait_for_prompt=False) - m = u_boot_console.p.expect( - [r'Unicode char 8 \(BS\), scan code 0 \(Null\)']) - if m != 0: - raise Exception('BS failed in \'text input\' test') - u_boot_console.drain_console() - # TAB - u_boot_console.run_command(cmd=chr(9), wait_for_echo=False, - send_nl=False, wait_for_prompt=False) - m = u_boot_console.p.expect( - [r'Unicode char 9 \(TAB\), scan code 0 \(Null\)']) - if m != 0: - raise Exception('BS failed in \'text input\' test') - u_boot_console.drain_console() - # a - u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False, - wait_for_prompt=False) - m = u_boot_console.p.expect( - [r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']) - if m != 0: - raise Exception('\'a\' failed in \'text input\' test') - u_boot_console.drain_console() - # UP escape sequence - u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False, - send_nl=False, wait_for_prompt=False) - m = u_boot_console.p.expect( - [r'Unicode char 0 \(Null\), scan code 1 \(Up\)']) - if m != 0: - raise Exception('UP failed in \'text input\' test') - u_boot_console.drain_console() - # Euro sign - u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False, - send_nl=False, wait_for_prompt=False) - m = u_boot_console.p.expect([r'Unicode char 8364 \(\'']) - if m != 0: - raise Exception('Euro sign failed in \'text input\' test') - u_boot_console.drain_console() - u_boot_console.run_command(cmd='x', wait_for_echo=False, send_nl=False, - wait_for_prompt=False) - m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']) - if m != 0: - raise Exception('Failures occurred during the EFI selftest') - u_boot_console.restart_uboot(); + """Test the EFI_SIMPLE_TEXT_INPUT_PROTOCOL + + :param u_boot_console: U-Boot console + + This function calls the text input EFI selftest. + """ + u_boot_console.run_command(cmd='setenv efi_selftest text input') + output = u_boot_console.run_command(cmd='bootefi selftest', + wait_for_prompt=False) + m = u_boot_console.p.expect([r'To terminate type \'x\'']) + if m != 0: + raise Exception('No prompt for \'text input\' test') + u_boot_console.drain_console() + u_boot_console.p.timeout = 500 + # EOT + u_boot_console.run_command(cmd=chr(4), wait_for_echo=False, + send_nl=False, wait_for_prompt=False) + m = u_boot_console.p.expect( + [r'Unicode char 4 \(unknown\), scan code 0 \(Null\)']) + if m != 0: + raise Exception('EOT failed in \'text input\' test') + u_boot_console.drain_console() + # BS + u_boot_console.run_command(cmd=chr(8), wait_for_echo=False, + send_nl=False, wait_for_prompt=False) + m = u_boot_console.p.expect( + [r'Unicode char 8 \(BS\), scan code 0 \(Null\)']) + if m != 0: + raise Exception('BS failed in \'text input\' test') + u_boot_console.drain_console() + # TAB + u_boot_console.run_command(cmd=chr(9), wait_for_echo=False, + send_nl=False, wait_for_prompt=False) + m = u_boot_console.p.expect( + [r'Unicode char 9 \(TAB\), scan code 0 \(Null\)']) + if m != 0: + raise Exception('BS failed in \'text input\' test') + u_boot_console.drain_console() + # a + u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False, + wait_for_prompt=False) + m = u_boot_console.p.expect( + [r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']) + if m != 0: + raise Exception('\'a\' failed in \'text input\' test') + u_boot_console.drain_console() + # UP escape sequence + u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False, + send_nl=False, wait_for_prompt=False) + m = u_boot_console.p.expect( + [r'Unicode char 0 \(Null\), scan code 1 \(Up\)']) + if m != 0: + raise Exception('UP failed in \'text input\' test') + u_boot_console.drain_console() + # Euro sign + u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False, + send_nl=False, wait_for_prompt=False) + m = u_boot_console.p.expect([r'Unicode char 8364 \(\'']) + if m != 0: + raise Exception('Euro sign failed in \'text input\' test') + u_boot_console.drain_console() + u_boot_console.run_command(cmd='x', wait_for_echo=False, send_nl=False, + wait_for_prompt=False) + m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']) + if m != 0: + raise Exception('Failures occurred during the EFI selftest') + u_boot_console.restart_uboot() @pytest.mark.buildconfigspec('cmd_bootefi_selftest') def test_efi_selftest_text_input_ex(u_boot_console): - """Test the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL - - :param u_boot_console: U-Boot console - - This function calls the extended text input EFI selftest. - """ - u_boot_console.run_command(cmd='setenv efi_selftest extended text input') - output = u_boot_console.run_command(cmd='bootefi selftest', - wait_for_prompt=False) - m = u_boot_console.p.expect([r'To terminate type \'CTRL\+x\'']) - if m != 0: - raise Exception('No prompt for \'text input\' test') - u_boot_console.drain_console() - u_boot_console.p.timeout = 500 - # EOT - u_boot_console.run_command(cmd=chr(4), wait_for_echo=False, - send_nl=False, wait_for_prompt=False) - m = u_boot_console.p.expect( - [r'Unicode char 100 \(\'d\'\), scan code 0 \(CTRL\+Null\)']) - if m != 0: - raise Exception('EOT failed in \'text input\' test') - u_boot_console.drain_console() - # BS - u_boot_console.run_command(cmd=chr(8), wait_for_echo=False, - send_nl=False, wait_for_prompt=False) - m = u_boot_console.p.expect( - [r'Unicode char 8 \(BS\), scan code 0 \(\+Null\)']) - if m != 0: - raise Exception('BS failed in \'text input\' test') - u_boot_console.drain_console() - # TAB - u_boot_console.run_command(cmd=chr(9), wait_for_echo=False, - send_nl=False, wait_for_prompt=False) - m = u_boot_console.p.expect( - [r'Unicode char 9 \(TAB\), scan code 0 \(\+Null\)']) - if m != 0: - raise Exception('TAB failed in \'text input\' test') - u_boot_console.drain_console() - # a - u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False, - wait_for_prompt=False) - m = u_boot_console.p.expect( - [r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']) - if m != 0: - raise Exception('\'a\' failed in \'text input\' test') - u_boot_console.drain_console() - # UP escape sequence - u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False, - send_nl=False, wait_for_prompt=False) - m = u_boot_console.p.expect( - [r'Unicode char 0 \(Null\), scan code 1 \(\+Up\)']) - if m != 0: - raise Exception('UP failed in \'text input\' test') - u_boot_console.drain_console() - # Euro sign - u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False, - send_nl=False, wait_for_prompt=False) - m = u_boot_console.p.expect([r'Unicode char 8364 \(\'']) - if m != 0: - raise Exception('Euro sign failed in \'text input\' test') - u_boot_console.drain_console() - # SHIFT+ALT+FN 5 - u_boot_console.run_command(cmd=b'\x1b\x5b\x31\x35\x3b\x34\x7e'.decode(), - wait_for_echo=False, send_nl=False, - wait_for_prompt=False) - m = u_boot_console.p.expect( - [r'Unicode char 0 \(Null\), scan code 15 \(SHIFT\+ALT\+FN 5\)']) - if m != 0: - raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test') - u_boot_console.drain_console() - u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False, - wait_for_prompt=False) - m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']) - if m != 0: - raise Exception('Failures occurred during the EFI selftest') - u_boot_console.restart_uboot(); + """Test the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL + + :param u_boot_console: U-Boot console + + This function calls the extended text input EFI selftest. + """ + u_boot_console.run_command(cmd='setenv efi_selftest extended text input') + output = u_boot_console.run_command(cmd='bootefi selftest', + wait_for_prompt=False) + m = u_boot_console.p.expect([r'To terminate type \'CTRL\+x\'']) + if m != 0: + raise Exception('No prompt for \'text input\' test') + u_boot_console.drain_console() + u_boot_console.p.timeout = 500 + # EOT + u_boot_console.run_command(cmd=chr(4), wait_for_echo=False, + send_nl=False, wait_for_prompt=False) + m = u_boot_console.p.expect( + [r'Unicode char 100 \(\'d\'\), scan code 0 \(CTRL\+Null\)']) + if m != 0: + raise Exception('EOT failed in \'text input\' test') + u_boot_console.drain_console() + # BS + u_boot_console.run_command(cmd=chr(8), wait_for_echo=False, + send_nl=False, wait_for_prompt=False) + m = u_boot_console.p.expect( + [r'Unicode char 8 \(BS\), scan code 0 \(\+Null\)']) + if m != 0: + raise Exception('BS failed in \'text input\' test') + u_boot_console.drain_console() + # TAB + u_boot_console.run_command(cmd=chr(9), wait_for_echo=False, + send_nl=False, wait_for_prompt=False) + m = u_boot_console.p.expect( + [r'Unicode char 9 \(TAB\), scan code 0 \(\+Null\)']) + if m != 0: + raise Exception('TAB failed in \'text input\' test') + u_boot_console.drain_console() + # a + u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False, + wait_for_prompt=False) + m = u_boot_console.p.expect( + [r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']) + if m != 0: + raise Exception('\'a\' failed in \'text input\' test') + u_boot_console.drain_console() + # UP escape sequence + u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False, + send_nl=False, wait_for_prompt=False) + m = u_boot_console.p.expect( + [r'Unicode char 0 \(Null\), scan code 1 \(\+Up\)']) + if m != 0: + raise Exception('UP failed in \'text input\' test') + u_boot_console.drain_console() + # Euro sign + u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False, + send_nl=False, wait_for_prompt=False) + m = u_boot_console.p.expect([r'Unicode char 8364 \(\'']) + if m != 0: + raise Exception('Euro sign failed in \'text input\' test') + u_boot_console.drain_console() + # SHIFT+ALT+FN 5 + u_boot_console.run_command(cmd=b'\x1b\x5b\x31\x35\x3b\x34\x7e'.decode(), + wait_for_echo=False, send_nl=False, + wait_for_prompt=False) + m = u_boot_console.p.expect( + [r'Unicode char 0 \(Null\), scan code 15 \(SHIFT\+ALT\+FN 5\)']) + if m != 0: + raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test') + u_boot_console.drain_console() + u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False, + wait_for_prompt=False) + m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']) + if m != 0: + raise Exception('Failures occurred during the EFI selftest') + u_boot_console.restart_uboot() |