[PATCH v4 7/7] test/py: eficonfig: use direct menu entry access mode

Masahisa Kojima masahisa.kojima at linaro.org
Mon Oct 24 06:48:04 CEST 2022


To select the menu entry, use direct access mode instead of
UP/DOWN key operation.

Signed-off-by: Masahisa Kojima <masahisa.kojima at linaro.org>
---
Newly added in v4

 .../py/tests/test_eficonfig/test_eficonfig.py | 177 +++++++-----------
 1 file changed, 70 insertions(+), 107 deletions(-)

diff --git a/test/py/tests/test_eficonfig/test_eficonfig.py b/test/py/tests/test_eficonfig/test_eficonfig.py
index 102bfd7541..dc08a35216 100644
--- a/test/py/tests/test_eficonfig/test_eficonfig.py
+++ b/test/py/tests/test_eficonfig/test_eficonfig.py
@@ -11,7 +11,7 @@ import time
 def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
 
     def send_user_input_and_wait(user_str, expect_str):
-        time.sleep(0.1) # TODO: does not work correctly without sleep
+        time.sleep(0.3) # TODO: does not work correctly without sleep
         u_boot_console.run_command(cmd=user_str, wait_for_prompt=False,
                                    wait_for_echo=True, send_nl=False)
         u_boot_console.run_command(cmd='\x0d', wait_for_prompt=False,
@@ -20,20 +20,13 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
             for i in expect_str:
                 u_boot_console.p.expect([i])
 
-    def press_up_down_enter_and_wait(up_count, down_count, enter, expect_str):
-        # press UP key
-        for i in range(up_count):
-            u_boot_console.run_command(cmd='\x1b\x5b\x41', wait_for_prompt=False,
+    def select_entry_and_wait(name, expect_str):
+        u_boot_console.run_command(cmd='&', wait_for_prompt=False,
                                        wait_for_echo=False, send_nl=False)
-        # press DOWN key
-        for i in range(down_count):
-            u_boot_console.run_command(cmd='\x1b\x5b\x42', wait_for_prompt=False,
-                                       wait_for_echo=False, send_nl=False)
-        # press ENTER if requested
-        if enter:
-            u_boot_console.run_command(cmd='\x0d', wait_for_prompt=False,
+        u_boot_console.run_command(cmd=name, wait_for_prompt=False,
+                                       wait_for_echo=True, send_nl=False)
+        u_boot_console.run_command(cmd='\x0d', wait_for_prompt=False,
                                        wait_for_echo=False, send_nl=False)
-        # wait expected output
         if expect_str is not None:
             for i in expect_str:
                 u_boot_console.p.expect([i])
@@ -76,11 +69,12 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
         for i in ('UEFI Maintenance Menu', 'Add Boot Option', 'Edit Boot Option',
                   'Change Boot Order', 'Delete Boot Option', 'Quit'):
             u_boot_console.p.expect([i])
-        # Select "Add Boot Option"
-        press_enter_key(False)
+
+        select_entry_and_wait('Add Boot', None)
         for i in ('Add Boot Option', 'Description:', 'File', 'Initrd File', 'Optional Data',
                   'Save', 'Quit'):
             u_boot_console.p.expect([i])
+
         press_escape_key(False)
         check_current_is_maintenance_menu()
         # return to U-Boot console
@@ -95,55 +89,43 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
 
         u_boot_console.run_command('eficonfig', wait_for_prompt=False)
 
-        # Change the Boot Order
-        press_up_down_enter_and_wait(0, 2, True, 'Quit')
-        for i in ('host 0:1', 'Save', 'Quit'):
-            u_boot_console.p.expect([i])
+        select_entry_and_wait('Change Boot', 'Quit')
         # disable auto generated boot option for succeeding test
+        select_entry_and_wait('host 0:1', None)
         u_boot_console.run_command(cmd=' ', wait_for_prompt=False,
                                        wait_for_echo=False, send_nl=False)
-        # Save the BootOrder
-        press_up_down_enter_and_wait(0, 1, True, None)
+        select_entry_and_wait('Save', None)
         check_current_is_maintenance_menu()
 
         #
         # Test Case 3: Add first Boot Option and load it
         #
 
-        # Select 'Add Boot Option'
-        press_up_down_enter_and_wait(0, 0, True, 'Quit')
-
-        # Press the enter key to select 'Description:' entry, then enter Description
-        press_up_down_enter_and_wait(0, 0, True, 'enter description:')
-        # Send Description user input, press ENTER key to complete
+        # Set Description
+        select_entry_and_wait('Add Boot', 'Quit')
+        select_entry_and_wait('Description', 'enter description:')
         send_user_input_and_wait('test 1', 'Quit')
 
         # Set EFI image(initrddump.efi)
-        press_up_down_enter_and_wait(0, 1, True, 'Quit')
-        press_up_down_enter_and_wait(0, 0, True, 'host 0:1')
-        # Select 'host 0:1'
-        press_up_down_enter_and_wait(0, 0, True, 'Quit')
-        # Press down key to select "initrddump.efi" entry followed by the enter key
-        press_up_down_enter_and_wait(0, 2, True, 'Quit')
+        select_entry_and_wait('File:', 'Quit')
+        select_entry_and_wait('Select File', 'Quit')
+        select_entry_and_wait('host 0:1', 'Quit')
+        select_entry_and_wait('initrddump.efi', 'Quit')
 
         # Set Initrd file(initrd-1.img)
-        press_up_down_enter_and_wait(0, 2, True, 'Quit')
-        press_up_down_enter_and_wait(0, 0, True, 'host 0:1')
-        # Select 'host 0:1'
-        press_up_down_enter_and_wait(0, 0, True, 'Quit')
-        # Press down key to select "initrd-1.img" entry followed by the enter key
-        press_up_down_enter_and_wait(0, 0, True, 'Quit')
+        select_entry_and_wait('Initrd File:', 'Quit')
+        select_entry_and_wait('Select File', 'Quit')
+        select_entry_and_wait('host 0:1', 'Quit')
+        select_entry_and_wait('initrd-1.img', 'Quit')
 
         # Set optional_data
-        press_up_down_enter_and_wait(0, 3, True, 'Optional Data:')
-        # Send Description user input, press ENTER key to complete
+        select_entry_and_wait('Optional Data:', 'Optional Data:')
         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'):
             u_boot_console.p.expect([i])
 
-        # Save the Boot Option
-        press_up_down_enter_and_wait(0, 4, True, None)
+        select_entry_and_wait('Save', None)
         check_current_is_maintenance_menu()
 
         # Check the newly added Boot Option is handled correctly
@@ -159,51 +141,42 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
         #
         u_boot_console.run_command('eficonfig', wait_for_prompt=False)
 
-        # Select 'Add Boot Option'
-        press_up_down_enter_and_wait(0, 0, True, 'Quit')
-
-        # Press the enter key to select 'Description:' entry, then enter Description
-        press_up_down_enter_and_wait(0, 0, True, 'enter description:')
-        # Send Description user input, press ENTER key to complete
+        # Set Description
+        select_entry_and_wait('Add Boot', 'Quit')
+        select_entry_and_wait('Description', 'enter description:')
         send_user_input_and_wait('test 2', 'Quit')
 
         # Set EFI image(initrddump.efi)
-        press_up_down_enter_and_wait(0, 1, True, 'Quit')
-        press_up_down_enter_and_wait(0, 0, True, 'host 0:1')
-        # Select 'host 0:1'
-        press_up_down_enter_and_wait(0, 0, True, 'Quit')
-        # Press down key to select "initrddump.efi" entry followed by the enter key
-        press_up_down_enter_and_wait(0, 2, True, 'Quit')
+        select_entry_and_wait('File:', 'Quit')
+        select_entry_and_wait('Select File', 'Quit')
+        select_entry_and_wait('host 0:1', 'Quit')
+        select_entry_and_wait('initrddump.efi', 'Quit')
 
         # Set Initrd file(initrd-2.img)
-        press_up_down_enter_and_wait(0, 2, True, 'Quit')
-        press_up_down_enter_and_wait(0, 0, True, 'host 0:1')
-        # Select 'host 0:1'
-        press_up_down_enter_and_wait(0, 0, True, 'Quit')
-        # Press down key to select "initrd-2.img" entry followed by the enter key
-        press_up_down_enter_and_wait(0, 1, True, 'Quit')
+        select_entry_and_wait('Initrd File:', 'Quit')
+        select_entry_and_wait('Select File', 'Quit')
+        select_entry_and_wait('host 0:1', 'Quit')
+        select_entry_and_wait('initrd-2.img', 'Quit')
 
         # Set optional_data
-        press_up_down_enter_and_wait(0, 3, True, 'Optional Data:')
-        # Send Description user input, press ENTER key to complete
+        select_entry_and_wait('Optional Data:', 'Optional Data:')
         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'):
             u_boot_console.p.expect([i])
 
-        # Save the Boot Option
-        press_up_down_enter_and_wait(0, 4, True, 'Quit')
+        select_entry_and_wait('Save', None)
+        check_current_is_maintenance_menu()
 
-        # Change the Boot Order
-        press_up_down_enter_and_wait(0, 2, True, 'Quit')
-        press_up_down_enter_and_wait(0, 1, False, 'Quit')
-        # move 'test 1' to the second entry
+        select_entry_and_wait('Change Boot', 'Quit')
+        # move 'test 2' to the first entry
+        select_entry_and_wait('test 2', 'Quit')
         u_boot_console.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'):
             u_boot_console.p.expect([i])
-        # Save the BootOrder
-        press_up_down_enter_and_wait(0, 3, True, None)
+
+        select_entry_and_wait('Save', None)
         check_current_is_maintenance_menu()
 
         # Check the newly added Boot Option is handled correctly
@@ -219,18 +192,18 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
         #
         u_boot_console.run_command('eficonfig', wait_for_prompt=False)
 
-        # Change the Boot Order
-        press_up_down_enter_and_wait(0, 2, True, None)
+        select_entry_and_wait('Change Boot', 'Quit')
         # Check the curren BootOrder
         for i in ('test 2', 'test 1', 'host 0:1', 'Save', 'Quit'):
             u_boot_console.p.expect([i])
         # move 'test 2' to the second entry
+        select_entry_and_wait('test 2', 'Quit')
         u_boot_console.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'):
             u_boot_console.p.expect([i])
-        # Save the BootOrder
-        press_up_down_enter_and_wait(0, 2, True, None)
+
+        select_entry_and_wait('Save', 'Quit')
         check_current_is_maintenance_menu()
 
         # Return to U-Boot console
@@ -245,14 +218,13 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
         #
         u_boot_console.run_command('eficonfig', wait_for_prompt=False)
 
-        # Select 'Delete Boot Option'
-        press_up_down_enter_and_wait(0, 3, True, None)
+        select_entry_and_wait('Delete Boot', 'Quit')
         # Check the current BootOrder
         for i in ('test 1', 'test 2', 'Quit'):
             u_boot_console.p.expect([i])
 
         # Delete 'test 2'
-        press_up_down_enter_and_wait(0, 1, True, None)
+        select_entry_and_wait('test 2', 'Quit')
         for i in ('test 1', 'Quit'):
             u_boot_console.p.expect([i])
         press_escape_key(False)
@@ -264,47 +236,40 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
         # Test Case 7: Edit Boot Option
         #
         u_boot_console.run_command('eficonfig', wait_for_prompt=False)
-        # Select 'Edit Boot Option'
-        press_up_down_enter_and_wait(0, 1, True, None)
+
+        select_entry_and_wait('Edit Boot', 'Quit')
         # Check the curren BootOrder
         for i in ('test 1', 'Quit'):
             u_boot_console.p.expect([i])
-        press_up_down_enter_and_wait(0, 0, True, None)
+        select_entry_and_wait('test 1', 'Quit')
         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'):
             u_boot_console.p.expect([i])
 
-        # Press the enter key to select 'Description:' entry, then enter Description
-        press_up_down_enter_and_wait(0, 0, True, 'enter description:')
-        # Send Description user input, press ENTER key to complete
+        # Set Description
+        select_entry_and_wait('Description', 'enter description:')
         send_user_input_and_wait('test 3', 'Quit')
 
         # Set EFI image(initrddump.efi)
-        press_up_down_enter_and_wait(0, 1, True, 'Quit')
-        press_up_down_enter_and_wait(0, 0, True, 'host 0:1')
-        # Select 'host 0:1'
-        press_up_down_enter_and_wait(0, 0, True, 'Quit')
-        # Press down key to select "initrddump.efi" entry followed by the enter key
-        press_up_down_enter_and_wait(0, 2, True, 'Quit')
+        select_entry_and_wait('File:', 'Quit')
+        select_entry_and_wait('Select File', 'Quit')
+        select_entry_and_wait('host 0:1', 'Quit')
+        select_entry_and_wait('initrddump.efi', 'Quit')
 
         # Set Initrd file(initrd-2.img)
-        press_up_down_enter_and_wait(0, 2, True, 'Quit')
-        press_up_down_enter_and_wait(0, 0, True, 'host 0:1')
-        # Select 'host 0:1'
-        press_up_down_enter_and_wait(0, 0, True, 'Quit')
-        # Press down key to select "initrd-1.img" entry followed by the enter key
-        press_up_down_enter_and_wait(0, 1, True, 'Quit')
+        select_entry_and_wait('Initrd File:', 'Quit')
+        select_entry_and_wait('Select File', 'Quit')
+        select_entry_and_wait('host 0:1', 'Quit')
+        select_entry_and_wait('initrd-2.img', 'Quit')
 
         # Set optional_data
-        press_up_down_enter_and_wait(0, 3, True, 'Optional Data:')
-        # Send Description user input, press ENTER key to complete
+        select_entry_and_wait('Optional Data:', 'Optional Data:')
         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'):
             u_boot_console.p.expect([i])
 
-        # Save the Boot Option
-        press_up_down_enter_and_wait(0, 4, True, 'Quit')
+        select_entry_and_wait('Save', None)
         press_escape_key(False)
         check_current_is_maintenance_menu()
 
@@ -321,14 +286,13 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
         #
         u_boot_console.run_command('eficonfig', wait_for_prompt=False)
 
-        # Select 'Delete Boot Option'
-        press_up_down_enter_and_wait(0, 3, True, None)
+        select_entry_and_wait('Delete Boot', 'Quit')
         # Check the curren BootOrder
         for i in ('test 3', 'Quit'):
             u_boot_console.p.expect([i])
 
         # Delete 'test 3'
-        press_up_down_enter_and_wait(0, 0, True, 'Quit')
+        select_entry_and_wait('test 3', 'Quit')
         press_escape_key(False)
         check_current_is_maintenance_menu()
         # Return to U-Boot console
@@ -342,12 +306,11 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
         #
         u_boot_console.run_command('eficonfig', wait_for_prompt=False)
 
-        # Select 'Add Boot Option'
-        press_up_down_enter_and_wait(0, 0, True, 'Quit')
+        select_entry_and_wait('Add Boot', 'Quit')
 
         # Set EFI image
-        press_up_down_enter_and_wait(0, 1, True, 'Quit')
-        press_up_down_enter_and_wait(0, 0, True, 'No block device found!')
+        select_entry_and_wait('File:', 'Quit')
+        select_entry_and_wait('Select File', 'No block device found!')
         press_escape_key(False)
         press_escape_key(False)
         check_current_is_maintenance_menu()
-- 
2.17.1



More information about the U-Boot mailing list