
From: Simon Glass <sjg@chromium.org> At present some tests are directly calling the Spawn() object in order to check for required output. This is a bit messy. Add a function to the ubman fixture to handle this. Signed-off-by: Simon Glass <sjg@chromium.org> --- test/py/console_base.py | 7 +++++ test/py/tests/test_bootmenu.py | 8 +++--- test/py/tests/test_distro.py | 10 +++---- test/py/tests/test_efi_selftest.py | 42 +++++++++++++++--------------- test/py/tests/test_eficonfig.py | 34 ++++++++++++------------ test/py/tests/test_net_boot.py | 6 ++--- test/py/tests/test_sandbox_exit.py | 4 +-- test/py/tests/test_saveenv.py | 2 +- 8 files changed, 60 insertions(+), 53 deletions(-) diff --git a/test/py/console_base.py b/test/py/console_base.py index 8fbad5a32b6..194db5fedf2 100644 --- a/test/py/console_base.py +++ b/test/py/console_base.py @@ -625,3 +625,10 @@ class ConsoleBase(): A context manager object. """ return ConsoleSetupTimeout(self, timeout) + + def expect(self, patterns): + """Call the Spawn.expect() function + + This is provided as a way for tests to check board output. + """ + self.p.expect(patterns) diff --git a/test/py/tests/test_bootmenu.py b/test/py/tests/test_bootmenu.py index 66f3fb8a131..a9b8f0c685e 100644 --- a/test/py/tests/test_bootmenu.py +++ b/test/py/tests/test_bootmenu.py @@ -18,24 +18,24 @@ def test_bootmenu(ubman): ubman.run_command('setenv bootmenu_2 test 3=echo ok 3') ubman.run_command('bootmenu 2', wait_for_prompt=False) for i in ('U-Boot Boot Menu', 'test 1', 'test 2', 'test 3', 'autoboot'): - ubman.p.expect([i]) + ubman.expect([i]) # Press enter key to execute default entry response = ubman.run_command(cmd='\x0d', wait_for_echo=False, send_nl=False) assert 'ok 2' in response ubman.run_command('bootmenu 2', wait_for_prompt=False) - ubman.p.expect(['autoboot']) + ubman.expect(['autoboot']) # Press up key to select prior entry followed by the enter key response = ubman.run_command(cmd='\x1b\x5b\x41\x0d', wait_for_echo=False, send_nl=False) assert 'ok 1' in response ubman.run_command('bootmenu 2', wait_for_prompt=False) - ubman.p.expect(['autoboot']) + ubman.expect(['autoboot']) # Press down key to select next entry followed by the enter key response = ubman.run_command(cmd='\x1b\x5b\x42\x0d', wait_for_echo=False, send_nl=False) assert 'ok 3' in response ubman.run_command('bootmenu 2; echo rc:$?', wait_for_prompt=False) - ubman.p.expect(['autoboot']) + ubman.expect(['autoboot']) # Press the escape key response = ubman.run_command(cmd='\x1b', wait_for_echo=False, send_nl=False) assert 'ok' not in response diff --git a/test/py/tests/test_distro.py b/test/py/tests/test_distro.py index e0874d75e35..3e67d30a3f7 100644 --- a/test/py/tests/test_distro.py +++ b/test/py/tests/test_distro.py @@ -16,14 +16,14 @@ def test_distro(ubman): with ubman.log.section('Grub'): # Wait for grub to come up and offset a menu - ubman.p.expect(['Try or Install Ubuntu']) + ubman.expect(['Try or Install Ubuntu']) # Press 'e' to edit the command line ubman.log.info("Pressing 'e'") ubman.run_command('e', wait_for_prompt=False, send_nl=False) # Wait until we see the editor appear - ubman.p.expect(['/casper/initrd']) + ubman.expect(['/casper/initrd']) # Go down to the 'linux' line. Avoid using down-arrow as that includes # an Escape character, which may be parsed by Grub as such, causing it @@ -48,15 +48,15 @@ def test_distro(ubman): # Tell grub to boot ubman.log.info("boot") ubman.ctrl('X') - ubman.p.expect(['Booting a command list']) + ubman.expect(['Booting a command list']) with ubman.log.section('Linux'): # Linux should start immediately - ubman.p.expect(['Linux version']) + ubman.expect(['Linux version']) with ubman.log.section('Ubuntu'): # Shortly later, we should see this banner - ubman.p.expect(['Welcome to .*Ubuntu 24.04.1 LTS.*!']) + ubman.expect(['Welcome to .*Ubuntu 24.04.1 LTS.*!']) ubman.restart_uboot() diff --git a/test/py/tests/test_efi_selftest.py b/test/py/tests/test_efi_selftest.py index 12cbe5caa9b..4ee1124e0ff 100644 --- a/test/py/tests/test_efi_selftest.py +++ b/test/py/tests/test_efi_selftest.py @@ -16,7 +16,7 @@ def test_efi_selftest_base(ubman): """ ubman.run_command(cmd='setenv efi_selftest') ubman.run_command(cmd='bootefi selftest', wait_for_prompt=False) - if ubman.p.expect(['Summary: 0 failures', 'Press any key']): + if ubman.expect(['Summary: 0 failures', 'Press any key']): raise Exception('Failures occurred during the EFI selftest') ubman.restart_uboot() @@ -39,7 +39,7 @@ def test_efi_selftest_device_tree(ubman): ubman.run_command(cmd='setenv efi_test "${serial#}x"') ubman.run_command(cmd='test "${efi_test}" = x && setenv serial# 0') ubman.run_command(cmd='bootefi selftest ${fdtcontroladdr}', wait_for_prompt=False) - if ubman.p.expect(['serial-number:', 'U-Boot']): + if ubman.expect(['serial-number:', 'U-Boot']): raise Exception('serial-number missing in device tree') ubman.restart_uboot() @@ -56,7 +56,7 @@ def test_efi_selftest_watchdog_reboot(ubman): assert '\'watchdog reboot\'' in output ubman.run_command(cmd='setenv efi_selftest watchdog reboot') ubman.run_command(cmd='bootefi selftest', wait_for_prompt=False) - if ubman.p.expect(['resetting', 'U-Boot']): + if ubman.expect(['resetting', 'U-Boot']): raise Exception('Reset failed in \'watchdog reboot\' test') ubman.run_command(cmd='', send_nl=False, wait_for_reboot=True) @@ -70,48 +70,48 @@ def test_efi_selftest_text_input(ubman): """ ubman.run_command(cmd='setenv efi_selftest text input') ubman.run_command(cmd='bootefi selftest', wait_for_prompt=False) - if ubman.p.expect([r'To terminate type \'x\'']): + if ubman.expect([r'To terminate type \'x\'']): raise Exception('No prompt for \'text input\' test') ubman.drain_console() # EOT ubman.run_command(cmd=chr(4), wait_for_echo=False, send_nl=False, wait_for_prompt=False) - if ubman.p.expect([r'Unicode char 4 \(unknown\), scan code 0 \(Null\)']): + if ubman.expect([r'Unicode char 4 \(unknown\), scan code 0 \(Null\)']): raise Exception('EOT failed in \'text input\' test') ubman.drain_console() # BS ubman.run_command(cmd=chr(8), wait_for_echo=False, send_nl=False, wait_for_prompt=False) - if ubman.p.expect([r'Unicode char 8 \(BS\), scan code 0 \(Null\)']): + if ubman.expect([r'Unicode char 8 \(BS\), scan code 0 \(Null\)']): raise Exception('BS failed in \'text input\' test') ubman.drain_console() # TAB ubman.run_command(cmd=chr(9), wait_for_echo=False, send_nl=False, wait_for_prompt=False) - if ubman.p.expect([r'Unicode char 9 \(TAB\), scan code 0 \(Null\)']): + if ubman.expect([r'Unicode char 9 \(TAB\), scan code 0 \(Null\)']): raise Exception('BS failed in \'text input\' test') ubman.drain_console() # a ubman.run_command(cmd='a', wait_for_echo=False, send_nl=False, wait_for_prompt=False) - if ubman.p.expect([r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']): + if ubman.expect([r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']): raise Exception('\'a\' failed in \'text input\' test') ubman.drain_console() # UP escape sequence ubman.run_command(cmd=chr(27) + '[A', wait_for_echo=False, send_nl=False, wait_for_prompt=False) - if ubman.p.expect([r'Unicode char 0 \(Null\), scan code 1 \(Up\)']): + if ubman.expect([r'Unicode char 0 \(Null\), scan code 1 \(Up\)']): raise Exception('UP failed in \'text input\' test') ubman.drain_console() # Euro sign ubman.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False, send_nl=False, wait_for_prompt=False) - if ubman.p.expect([r'Unicode char 8364 \(\'']): + if ubman.expect([r'Unicode char 8364 \(\'']): raise Exception('Euro sign failed in \'text input\' test') ubman.drain_console() ubman.run_command(cmd='x', wait_for_echo=False, send_nl=False, wait_for_prompt=False) - if ubman.p.expect(['Summary: 0 failures', 'Press any key']): + if ubman.expect(['Summary: 0 failures', 'Press any key']): raise Exception('Failures occurred during the EFI selftest') ubman.restart_uboot() @@ -125,55 +125,55 @@ def test_efi_selftest_text_input_ex(ubman): """ ubman.run_command(cmd='setenv efi_selftest extended text input') ubman.run_command(cmd='bootefi selftest', wait_for_prompt=False) - if ubman.p.expect([r'To terminate type \'CTRL\+x\'']): + if ubman.expect([r'To terminate type \'CTRL\+x\'']): raise Exception('No prompt for \'text input\' test') ubman.drain_console() # EOT ubman.run_command(cmd=chr(4), wait_for_echo=False, send_nl=False, wait_for_prompt=False) - if ubman.p.expect([r'Unicode char 100 \(\'d\'\), scan code 0 \(CTRL\+Null\)']): + if ubman.expect([r'Unicode char 100 \(\'d\'\), scan code 0 \(CTRL\+Null\)']): raise Exception('EOT failed in \'text input\' test') ubman.drain_console() # BS ubman.run_command(cmd=chr(8), wait_for_echo=False, send_nl=False, wait_for_prompt=False) - if ubman.p.expect([r'Unicode char 8 \(BS\), scan code 0 \(\+Null\)']): + if ubman.expect([r'Unicode char 8 \(BS\), scan code 0 \(\+Null\)']): raise Exception('BS failed in \'text input\' test') ubman.drain_console() # TAB ubman.run_command(cmd=chr(9), wait_for_echo=False, send_nl=False, wait_for_prompt=False) - if ubman.p.expect([r'Unicode char 9 \(TAB\), scan code 0 \(\+Null\)']): + if ubman.expect([r'Unicode char 9 \(TAB\), scan code 0 \(\+Null\)']): raise Exception('TAB failed in \'text input\' test') ubman.drain_console() # a ubman.run_command(cmd='a', wait_for_echo=False, send_nl=False, wait_for_prompt=False) - if ubman.p.expect([r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']): + if ubman.expect([r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']): raise Exception('\'a\' failed in \'text input\' test') ubman.drain_console() # UP escape sequence ubman.run_command(cmd=chr(27) + '[A', wait_for_echo=False, send_nl=False, wait_for_prompt=False) - if ubman.p.expect([r'Unicode char 0 \(Null\), scan code 1 \(\+Up\)']): + if ubman.expect([r'Unicode char 0 \(Null\), scan code 1 \(\+Up\)']): raise Exception('UP failed in \'text input\' test') ubman.drain_console() # Euro sign ubman.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False, send_nl=False, wait_for_prompt=False) - if ubman.p.expect([r'Unicode char 8364 \(\'']): + if ubman.expect([r'Unicode char 8364 \(\'']): raise Exception('Euro sign failed in \'text input\' test') ubman.drain_console() # SHIFT+ALT+FN 5 ubman.run_command(cmd=b'\x1b\x5b\x31\x35\x3b\x34\x7e'.decode(), wait_for_echo=False, send_nl=False, wait_for_prompt=False) - if ubman.p.expect([r'Unicode char 0 \(Null\), scan code 15 \(SHIFT\+ALT\+FN 5\)']): + if ubman.expect([r'Unicode char 0 \(Null\), scan code 15 \(SHIFT\+ALT\+FN 5\)']): raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test') ubman.drain_console() ubman.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False, wait_for_prompt=False) - if ubman.p.expect(['Summary: 0 failures', 'Press any key']): + if ubman.expect(['Summary: 0 failures', 'Press any key']): raise Exception('Failures occurred during the EFI selftest') ubman.restart_uboot() @@ -192,6 +192,6 @@ def test_efi_selftest_tcg2(ubman): assert '\'tcg2\'' in output ubman.run_command(cmd='setenv efi_selftest tcg2') ubman.run_command(cmd='bootefi selftest', wait_for_prompt=False) - if ubman.p.expect(['Summary: 0 failures', 'Press any key']): + if ubman.expect(['Summary: 0 failures', 'Press any key']): raise Exception('Failures occurred during the EFI selftest') ubman.restart_uboot() diff --git a/test/py/tests/test_eficonfig.py b/test/py/tests/test_eficonfig.py index ac1600ec252..20ea8d9f28f 100644 --- a/test/py/tests/test_eficonfig.py +++ b/test/py/tests/test_eficonfig.py @@ -62,7 +62,7 @@ def test_efi_eficonfig(ubman): wait_for_echo=False, send_nl=False) if expect_str is not None: for i in expect_str: - ubman.p.expect([i]) + ubman.expect([i]) def press_up_down_enter_and_wait(up_count, down_count, enter, expect_str): # press UP key @@ -80,7 +80,7 @@ def test_efi_eficonfig(ubman): # wait expected output if expect_str is not None: for i in expect_str: - ubman.p.expect([i]) + ubman.expect([i]) def press_escape_key(wait_prompt): ubman.run_command(cmd='\x1b', wait_for_prompt=wait_prompt, wait_for_echo=False, send_nl=False) @@ -92,7 +92,7 @@ def test_efi_eficonfig(ubman): def check_current_is_maintenance_menu(): for i in ('UEFI Maintenance Menu', 'Add Boot Option', 'Edit Boot Option', 'Change Boot Order', 'Delete Boot Option', 'Quit'): - ubman.p.expect([i]) + ubman.expect([i]) """ Unit test for "eficonfig" command The menu-driven interface is used to set up UEFI load options. @@ -117,12 +117,12 @@ def test_efi_eficonfig(ubman): ubman.run_command('eficonfig', wait_for_prompt=False) for i in ('UEFI Maintenance Menu', 'Add Boot Option', 'Edit Boot Option', 'Change Boot Order', 'Delete Boot Option', 'Quit'): - ubman.p.expect([i]) + ubman.expect([i]) # Select "Add Boot Option" press_enter_key(False) for i in ('Add Boot Option', 'Description:', 'File', 'Initrd File', 'Optional Data', 'Save', 'Quit'): - ubman.p.expect([i]) + ubman.expect([i]) press_escape_key(False) check_current_is_maintenance_menu() # return to U-Boot console @@ -140,7 +140,7 @@ def test_efi_eficonfig(ubman): # Change the Boot Order press_up_down_enter_and_wait(0, 2, True, 'Quit') for i in ('host 0:1', 'Save', 'Quit'): - ubman.p.expect([i]) + ubman.expect([i]) # disable auto generated boot option for succeeding test ubman.run_command(cmd=' ', wait_for_prompt=False, wait_for_echo=False, send_nl=False) @@ -182,7 +182,7 @@ def test_efi_eficonfig(ubman): send_user_input_and_wait('nocolor', None) for i in ('Description: test 1', 'File: host 0:1/initrddump.efi', 'Initrd File: host 0:1/initrd-1.img', 'Optional Data: nocolor', 'Save', 'Quit'): - ubman.p.expect([i]) + ubman.expect([i]) # Save the Boot Option press_up_down_enter_and_wait(0, 4, True, None) @@ -231,7 +231,7 @@ def test_efi_eficonfig(ubman): send_user_input_and_wait('nocolor', None) for i in ('Description: test 2', 'File: host 0:1/initrddump.efi', 'Initrd File: host 0:1/initrd-2.img', 'Optional Data: nocolor', 'Save', 'Quit'): - ubman.p.expect([i]) + ubman.expect([i]) # Save the Boot Option press_up_down_enter_and_wait(0, 4, True, 'Quit') @@ -243,7 +243,7 @@ def test_efi_eficonfig(ubman): ubman.run_command(cmd='+', wait_for_prompt=False, wait_for_echo=False, send_nl=False) for i in ('test 2', 'test 1', 'host 0:1', 'Save', 'Quit'): - ubman.p.expect([i]) + ubman.expect([i]) # Save the BootOrder press_up_down_enter_and_wait(0, 3, True, None) check_current_is_maintenance_menu() @@ -265,12 +265,12 @@ def test_efi_eficonfig(ubman): press_up_down_enter_and_wait(0, 2, True, None) # Check the current BootOrder for i in ('test 2', 'test 1', 'host 0:1', 'Save', 'Quit'): - ubman.p.expect([i]) + ubman.expect([i]) # move 'test 2' to the second entry ubman.run_command(cmd='-', wait_for_prompt=False, wait_for_echo=False, send_nl=False) for i in ('test 1', 'test 2', 'host 0:1', 'Save', 'Quit'): - ubman.p.expect([i]) + ubman.expect([i]) # Save the BootOrder press_up_down_enter_and_wait(0, 2, True, None) check_current_is_maintenance_menu() @@ -291,12 +291,12 @@ def test_efi_eficonfig(ubman): press_up_down_enter_and_wait(0, 3, True, None) # Check the current BootOrder for i in ('test 1', 'test 2', 'Quit'): - ubman.p.expect([i]) + ubman.expect([i]) # Delete 'test 2' press_up_down_enter_and_wait(0, 1, True, None) for i in ('test 1', 'Quit'): - ubman.p.expect([i]) + ubman.expect([i]) press_escape_key(False) check_current_is_maintenance_menu() # Return to U-Boot console @@ -310,11 +310,11 @@ def test_efi_eficonfig(ubman): press_up_down_enter_and_wait(0, 1, True, None) # Check the current BootOrder for i in ('test 1', 'Quit'): - ubman.p.expect([i]) + ubman.expect([i]) press_up_down_enter_and_wait(0, 0, True, None) for i in ('Description: test 1', 'File: host 0:1/initrddump.efi', 'Initrd File: host 0:1/initrd-1.img', 'Optional Data: nocolor', 'Save', 'Quit'): - ubman.p.expect([i]) + ubman.expect([i]) # Press the enter key to select 'Description:' entry, then enter Description press_up_down_enter_and_wait(0, 0, True, 'Enter description:') @@ -343,7 +343,7 @@ def test_efi_eficonfig(ubman): send_user_input_and_wait('', None) for i in ('Description: test 3', 'File: host 0:1/initrddump.efi', 'Initrd File: host 0:1/initrd-2.img', 'Optional Data:', 'Save', 'Quit'): - ubman.p.expect([i]) + ubman.expect([i]) # Save the Boot Option press_up_down_enter_and_wait(0, 4, True, 'Quit') @@ -367,7 +367,7 @@ def test_efi_eficonfig(ubman): press_up_down_enter_and_wait(0, 3, True, None) # Check the current BootOrder for i in ('test 3', 'Quit'): - ubman.p.expect([i]) + ubman.expect([i]) # Delete 'test 3' press_up_down_enter_and_wait(0, 0, True, 'Quit') diff --git a/test/py/tests/test_net_boot.py b/test/py/tests/test_net_boot.py index abf6dfbaf5e..d9473777111 100644 --- a/test/py/tests/test_net_boot.py +++ b/test/py/tests/test_net_boot.py @@ -318,7 +318,7 @@ def test_net_pxe_boot_config(ubman): # should not boot it and come out to u-boot prompt ubman.wait_for('Enter choice:') ubman.run_command(local_label, wait_for_prompt=False) - expected_str = ubman.p.expect([exp_str_local]) + expected_str = ubman.expect([exp_str_local]) assert ( expected_str == 0 ), f'Expected string: {exp_str_local} did not match!' @@ -329,7 +329,7 @@ def test_net_pxe_boot_config(ubman): ubman.run_command(pxe_boot_cmd, wait_for_prompt=False) ubman.wait_for('Enter choice:') ubman.run_command(empty_label, wait_for_prompt=False) - expected_str = ubman.p.expect([exp_str_empty]) + expected_str = ubman.expect([exp_str_empty]) assert ( expected_str == 0 ), f'Expected string: {exp_str_empty} did not match!' @@ -389,7 +389,7 @@ def test_net_pxe_boot_config_invalid(ubman): # label and if it fails it should load the default label to boot ubman.wait_for('Enter choice:') ubman.run_command(invalid_label, wait_for_prompt=False) - expected_str = ubman.p.expect([exp_str_invalid]) + expected_str = ubman.expect([exp_str_invalid]) assert ( expected_str == 0 ), f'Expected string: {exp_str_invalid} did not match!' diff --git a/test/py/tests/test_sandbox_exit.py b/test/py/tests/test_sandbox_exit.py index 9610adf1fe7..849fd477941 100644 --- a/test/py/tests/test_sandbox_exit.py +++ b/test/py/tests/test_sandbox_exit.py @@ -27,10 +27,10 @@ def test_exception_reset(ubman): """Test that SIGILL causes a reset.""" ubman.run_command('exception undefined', wait_for_prompt=False) - m = ubman.p.expect(['resetting ...', 'U-Boot']) + m = ubman.expect(['resetting ...', 'U-Boot']) if m != 0: raise Exception('SIGILL did not lead to reset') - m = ubman.p.expect(['U-Boot', '=>']) + m = ubman.expect(['U-Boot', '=>']) if m != 0: raise Exception('SIGILL did not lead to reset') ubman.restart_uboot() diff --git a/test/py/tests/test_saveenv.py b/test/py/tests/test_saveenv.py index 019b229d30e..555284906da 100644 --- a/test/py/tests/test_saveenv.py +++ b/test/py/tests/test_saveenv.py @@ -61,7 +61,7 @@ def check_env(ubman, var_name, var_value): assert ret_code(ubman).endswith('0') else: ubman.p.send(f'printenv {var_name}\n') - output = ubman.p.expect(['not defined']) + output = ubman.expect(['not defined']) assert output == 0 assert ret_code(ubman).endswith('1') -- 2.43.0