diff mbox series

[v15,10/10] test: unit test for eficonfig

Message ID 20220902142349.16722-11-masahisa.kojima@linaro.org
State Superseded
Headers show
Series enable menu-driven UEFI variable maintenance | expand

Commit Message

Masahisa Kojima Sept. 2, 2022, 2:23 p.m. UTC
Provide a unit test for the eficonfig command.

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
No update since v15

Changes in v14:
- update to support media device enumeration in eficonfig startup
- move no block device test to the last test case

Changes in v12:
- update menu handling

Changes in v11:
- fix expected result when no BootOrder is defined

Newly added in v10

 configs/sandbox_defconfig                     |   1 +
 test/py/tests/test_eficonfig/conftest.py      |  40 ++
 .../py/tests/test_eficonfig/test_eficonfig.py | 350 ++++++++++++++++++
 3 files changed, 391 insertions(+)
 create mode 100644 test/py/tests/test_eficonfig/conftest.py
 create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py

Comments

Heinrich Schuchardt Sept. 4, 2022, 9:08 a.m. UTC | #1
On 9/2/22 16:23, Masahisa Kojima wrote:
> Provide a unit test for the eficonfig command.
>
> Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
> Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
> No update since v15
>
> Changes in v14:
> - update to support media device enumeration in eficonfig startup
> - move no block device test to the last test case
>
> Changes in v12:
> - update menu handling
>
> Changes in v11:
> - fix expected result when no BootOrder is defined
>
> Newly added in v10

Your code does not pass the test, see
https://source.denx.de/u-boot/custodians/u-boot-efi/-/jobs/491449

test/py/tests/test_eficonfig/test_eficonfig.py:103: in test_efi_eficonfig
     check_current_is_maintenance_menu()
test/py/tests/test_eficonfig/test_eficonfig.py:51: in
check_current_is_maintenance_menu
     u_boot_console.p.expect([i])
test/py/u_boot_spawn.py:193: in expect
     raise Timeout()
E   u_boot_spawn.Timeout

Best regards

Heinrich

>
>   configs/sandbox_defconfig                     |   1 +
>   test/py/tests/test_eficonfig/conftest.py      |  40 ++
>   .../py/tests/test_eficonfig/test_eficonfig.py | 350 ++++++++++++++++++
>   3 files changed, 391 insertions(+)
>   create mode 100644 test/py/tests/test_eficonfig/conftest.py
>   create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py
>
> diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
> index eba7bcbb48..48c60c606d 100644
> --- a/configs/sandbox_defconfig
> +++ b/configs/sandbox_defconfig
> @@ -93,6 +93,7 @@ CONFIG_CMD_LINK_LOCAL=y
>   CONFIG_CMD_ETHSW=y
>   CONFIG_CMD_BMP=y
>   CONFIG_CMD_BOOTCOUNT=y
> +CONFIG_CMD_EFICONFIG=y
>   CONFIG_CMD_EFIDEBUG=y
>   CONFIG_CMD_RTC=y
>   CONFIG_CMD_TIME=y
> diff --git a/test/py/tests/test_eficonfig/conftest.py b/test/py/tests/test_eficonfig/conftest.py
> new file mode 100644
> index 0000000000..f289df0362
> --- /dev/null
> +++ b/test/py/tests/test_eficonfig/conftest.py
> @@ -0,0 +1,40 @@
> +# SPDX-License-Identifier:      GPL-2.0+
> +
> +"""Fixture for UEFI eficonfig test
> +"""
> +
> +import os
> +import shutil
> +from subprocess import check_call
> +import pytest
> +
> +@pytest.fixture(scope='session')
> +def efi_eficonfig_data(u_boot_config):
> +    """Set up a file system to be used in UEFI "eficonfig" command
> +       tests
> +
> +    Args:
> +        u_boot_config -- U-boot configuration.
> +
> +    Return:
> +        A path to disk image to be used for testing
> +    """
> +    mnt_point = u_boot_config.persistent_data_dir + '/test_efi_eficonfig'
> +    image_path = u_boot_config.persistent_data_dir + '/efi_eficonfig.img'
> +
> +    shutil.rmtree(mnt_point, ignore_errors=True)
> +    os.mkdir(mnt_point, mode = 0o755)
> +
> +    with open(mnt_point + '/initrd-1.img', 'w', encoding = 'ascii') as file:
> +        file.write("initrd 1")
> +
> +    with open(mnt_point + '/initrd-2.img', 'w', encoding = 'ascii') as file:
> +        file.write("initrd 2")
> +
> +    shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/initrddump.efi',
> +                    mnt_point + '/initrddump.efi')
> +
> +    check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}',
> +               shell=True)
> +
> +    return image_path
> diff --git a/test/py/tests/test_eficonfig/test_eficonfig.py b/test/py/tests/test_eficonfig/test_eficonfig.py
> new file mode 100644
> index 0000000000..1c501deb1f
> --- /dev/null
> +++ b/test/py/tests/test_eficonfig/test_eficonfig.py
> @@ -0,0 +1,350 @@
> +# SPDX-License-Identifier:      GPL-2.0+
> +""" Unit test for UEFI menu-driven configuration
> +"""
> +
> +import pytest
> +import time
> +
> +@pytest.mark.boardspec('sandbox')
> +@pytest.mark.buildconfigspec('cmd_eficonfig')
> +@pytest.mark.buildconfigspec('cmd_bootefi_bootmgr')
> +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
> +        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,
> +                                   wait_for_echo=False, send_nl=False)
> +        if expect_str is not None:
> +            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,
> +                                       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,
> +                                       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])
> +
> +    def press_escape_key(wait_prompt):
> +        u_boot_console.run_command(cmd='\x1b', wait_for_prompt=wait_prompt, wait_for_echo=False, send_nl=False)
> +
> +    def press_enter_key(wait_prompt):
> +        u_boot_console.run_command(cmd='\x0d', wait_for_prompt=wait_prompt,
> +                                   wait_for_echo=False, send_nl=False)
> +
> +    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'):
> +            u_boot_console.p.expect([i])
> +
> +    """ Unit test for "eficonfig" command
> +    The menu-driven interface is used to set up UEFI load options.
> +    The bootefi bootmgr loads initrddump.efi as a payload.
> +    The crc32 of the loaded initrd.img is checked
> +
> +    Args:
> +        u_boot_console -- U-Boot console
> +        efi__data -- Path to the disk image used for testing.
> +                     Test disk image has following files.
> +                         initrd-1.img
> +                         initrddump.efi
> +                         initrd-2.img
> +
> +    """
> +    with u_boot_console.temporary_timeout(500):
> +        #
> +        # Test Case 1: Check the menu is displayed
> +        #
> +        u_boot_console.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'):
> +            u_boot_console.p.expect([i])
> +        # Select "Add Boot Option"
> +        press_enter_key(False)
> +        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
> +        press_escape_key(True)
> +
> +        #
> +        # Test Case 2: check auto generated media device entry
> +        #
> +
> +        # bind the test disk image for succeeding tests
> +        u_boot_console.run_command(cmd = f'host bind 0 {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])
> +        # disable auto generated boot option for succeeding test
> +        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)
> +        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
> +        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, 1, True, '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')
> +
> +        # Set optional_data
> +        press_up_down_enter_and_wait(0, 3, True, 'Optional Data:')
> +        # Send Description user input, press ENTER key to complete
> +        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)
> +        check_current_is_maintenance_menu()
> +
> +        # Check the newly added Boot Option is handled correctly
> +        # Return to U-Boot console
> +        press_escape_key(True)
> +        u_boot_console.run_command(cmd = 'bootefi bootmgr')
> +        response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
> +        assert 'crc32: 0x181464af' in response
> +        u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
> +
> +        #
> +        # Test Case 4: Add second Boot Option and load it
> +        #
> +        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
> +        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, 1, True, '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, 2, True, 'Quit')
> +
> +        # Set optional_data
> +        press_up_down_enter_and_wait(0, 3, True, 'Optional Data:')
> +        # Send Description user input, press ENTER key to complete
> +        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')
> +
> +        # 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
> +        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)
> +        check_current_is_maintenance_menu()
> +
> +        # Check the newly added Boot Option is handled correctly
> +        # Return to U-Boot console
> +        press_escape_key(True)
> +        u_boot_console.run_command(cmd = 'bootefi bootmgr')
> +        response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
> +        assert 'crc32: 0x811d3515' in response
> +        u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
> +
> +        #
> +        # Test Case 5: Change BootOrder and load it
> +        #
> +        u_boot_console.run_command('eficonfig', wait_for_prompt=False)
> +
> +        # Change the Boot Order
> +        press_up_down_enter_and_wait(0, 2, True, None)
> +        # 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
> +        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)
> +        check_current_is_maintenance_menu()
> +
> +        # Return to U-Boot console
> +        press_escape_key(True)
> +        u_boot_console.run_command(cmd = 'bootefi bootmgr')
> +        response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
> +        assert 'crc32: 0x181464af' in response
> +        u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
> +
> +        #
> +        # Test Case 6: Delete Boot Option(label:test 2)
> +        #
> +        u_boot_console.run_command('eficonfig', wait_for_prompt=False)
> +
> +        # Select 'Delete Boot Option'
> +        press_up_down_enter_and_wait(0, 3, True, None)
> +        # 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)
> +        for i in ('test 1', 'Quit'):
> +            u_boot_console.p.expect([i])
> +        press_escape_key(False)
> +        check_current_is_maintenance_menu()
> +        # Return to U-Boot console
> +        press_escape_key(True)
> +
> +        #
> +        # 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)
> +        # 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)
> +        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
> +        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, 1, True, '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, 2, True, 'Quit')
> +
> +        # Set optional_data
> +        press_up_down_enter_and_wait(0, 3, True, 'Optional Data:')
> +        # Send Description user input, press ENTER key to complete
> +        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')
> +        press_escape_key(False)
> +        check_current_is_maintenance_menu()
> +
> +        # Check the updated Boot Option is handled correctly
> +        # Return to U-Boot console
> +        press_escape_key(True)
> +        u_boot_console.run_command(cmd = 'bootefi bootmgr')
> +        response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
> +        assert 'crc32: 0x811d3515' in response
> +        u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
> +
> +        #
> +        # Test Case 8: Delete Boot Option(label:test 3)
> +        #
> +        u_boot_console.run_command('eficonfig', wait_for_prompt=False)
> +
> +        # Select 'Delete Boot Option'
> +        press_up_down_enter_and_wait(0, 3, True, None)
> +        # 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')
> +        press_escape_key(False)
> +        check_current_is_maintenance_menu()
> +        # Return to U-Boot console
> +        press_escape_key(True)
> +
> +        # remove the host device
> +        u_boot_console.run_command(cmd = f'host bind -r 0')
> +
> +        #
> +        # Test Case 9: No block device found
> +        #
> +        u_boot_console.run_command('eficonfig', wait_for_prompt=False)
> +
> +        # Select 'Add Boot Option'
> +        press_up_down_enter_and_wait(0, 0, True, '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!')
> +        press_escape_key(False)
> +        check_current_is_maintenance_menu()
> +        # Return to U-Boot console
> +        press_escape_key(True)
Masahisa Kojima Sept. 5, 2022, 11:51 a.m. UTC | #2
On Sun, 4 Sept 2022 at 18:08, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> On 9/2/22 16:23, Masahisa Kojima wrote:
> > Provide a unit test for the eficonfig command.
> >
> > Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
> > Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> > ---
> > No update since v15
> >
> > Changes in v14:
> > - update to support media device enumeration in eficonfig startup
> > - move no block device test to the last test case
> >
> > Changes in v12:
> > - update menu handling
> >
> > Changes in v11:
> > - fix expected result when no BootOrder is defined
> >
> > Newly added in v10
>
> Your code does not pass the test, see
> https://source.denx.de/u-boot/custodians/u-boot-efi/-/jobs/491449
>
> test/py/tests/test_eficonfig/test_eficonfig.py:103: in test_efi_eficonfig
>      check_current_is_maintenance_menu()
> test/py/tests/test_eficonfig/test_eficonfig.py:51: in
> check_current_is_maintenance_menu
>      u_boot_console.p.expect([i])
> test/py/u_boot_spawn.py:193: in expect
>      raise Timeout()
> E   u_boot_spawn.Timeout

The reason for failure is an unexpected boot option from the previous test case.
u_boot_console.restart_uboot() must be called at the beginning of
eficonfig test.

Thanks,
Masahisa Kojima

>
> Best regards
>
> Heinrich
>
> >
> >   configs/sandbox_defconfig                     |   1 +
> >   test/py/tests/test_eficonfig/conftest.py      |  40 ++
> >   .../py/tests/test_eficonfig/test_eficonfig.py | 350 ++++++++++++++++++
> >   3 files changed, 391 insertions(+)
> >   create mode 100644 test/py/tests/test_eficonfig/conftest.py
> >   create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py
> >
> > diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
> > index eba7bcbb48..48c60c606d 100644
> > --- a/configs/sandbox_defconfig
> > +++ b/configs/sandbox_defconfig
> > @@ -93,6 +93,7 @@ CONFIG_CMD_LINK_LOCAL=y
> >   CONFIG_CMD_ETHSW=y
> >   CONFIG_CMD_BMP=y
> >   CONFIG_CMD_BOOTCOUNT=y
> > +CONFIG_CMD_EFICONFIG=y
> >   CONFIG_CMD_EFIDEBUG=y
> >   CONFIG_CMD_RTC=y
> >   CONFIG_CMD_TIME=y
> > diff --git a/test/py/tests/test_eficonfig/conftest.py b/test/py/tests/test_eficonfig/conftest.py
> > new file mode 100644
> > index 0000000000..f289df0362
> > --- /dev/null
> > +++ b/test/py/tests/test_eficonfig/conftest.py
> > @@ -0,0 +1,40 @@
> > +# SPDX-License-Identifier:      GPL-2.0+
> > +
> > +"""Fixture for UEFI eficonfig test
> > +"""
> > +
> > +import os
> > +import shutil
> > +from subprocess import check_call
> > +import pytest
> > +
> > +@pytest.fixture(scope='session')
> > +def efi_eficonfig_data(u_boot_config):
> > +    """Set up a file system to be used in UEFI "eficonfig" command
> > +       tests
> > +
> > +    Args:
> > +        u_boot_config -- U-boot configuration.
> > +
> > +    Return:
> > +        A path to disk image to be used for testing
> > +    """
> > +    mnt_point = u_boot_config.persistent_data_dir + '/test_efi_eficonfig'
> > +    image_path = u_boot_config.persistent_data_dir + '/efi_eficonfig.img'
> > +
> > +    shutil.rmtree(mnt_point, ignore_errors=True)
> > +    os.mkdir(mnt_point, mode = 0o755)
> > +
> > +    with open(mnt_point + '/initrd-1.img', 'w', encoding = 'ascii') as file:
> > +        file.write("initrd 1")
> > +
> > +    with open(mnt_point + '/initrd-2.img', 'w', encoding = 'ascii') as file:
> > +        file.write("initrd 2")
> > +
> > +    shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/initrddump.efi',
> > +                    mnt_point + '/initrddump.efi')
> > +
> > +    check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}',
> > +               shell=True)
> > +
> > +    return image_path
> > diff --git a/test/py/tests/test_eficonfig/test_eficonfig.py b/test/py/tests/test_eficonfig/test_eficonfig.py
> > new file mode 100644
> > index 0000000000..1c501deb1f
> > --- /dev/null
> > +++ b/test/py/tests/test_eficonfig/test_eficonfig.py
> > @@ -0,0 +1,350 @@
> > +# SPDX-License-Identifier:      GPL-2.0+
> > +""" Unit test for UEFI menu-driven configuration
> > +"""
> > +
> > +import pytest
> > +import time
> > +
> > +@pytest.mark.boardspec('sandbox')
> > +@pytest.mark.buildconfigspec('cmd_eficonfig')
> > +@pytest.mark.buildconfigspec('cmd_bootefi_bootmgr')
> > +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
> > +        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,
> > +                                   wait_for_echo=False, send_nl=False)
> > +        if expect_str is not None:
> > +            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,
> > +                                       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,
> > +                                       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])
> > +
> > +    def press_escape_key(wait_prompt):
> > +        u_boot_console.run_command(cmd='\x1b', wait_for_prompt=wait_prompt, wait_for_echo=False, send_nl=False)
> > +
> > +    def press_enter_key(wait_prompt):
> > +        u_boot_console.run_command(cmd='\x0d', wait_for_prompt=wait_prompt,
> > +                                   wait_for_echo=False, send_nl=False)
> > +
> > +    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'):
> > +            u_boot_console.p.expect([i])
> > +
> > +    """ Unit test for "eficonfig" command
> > +    The menu-driven interface is used to set up UEFI load options.
> > +    The bootefi bootmgr loads initrddump.efi as a payload.
> > +    The crc32 of the loaded initrd.img is checked
> > +
> > +    Args:
> > +        u_boot_console -- U-Boot console
> > +        efi__data -- Path to the disk image used for testing.
> > +                     Test disk image has following files.
> > +                         initrd-1.img
> > +                         initrddump.efi
> > +                         initrd-2.img
> > +
> > +    """
> > +    with u_boot_console.temporary_timeout(500):
> > +        #
> > +        # Test Case 1: Check the menu is displayed
> > +        #
> > +        u_boot_console.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'):
> > +            u_boot_console.p.expect([i])
> > +        # Select "Add Boot Option"
> > +        press_enter_key(False)
> > +        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
> > +        press_escape_key(True)
> > +
> > +        #
> > +        # Test Case 2: check auto generated media device entry
> > +        #
> > +
> > +        # bind the test disk image for succeeding tests
> > +        u_boot_console.run_command(cmd = f'host bind 0 {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])
> > +        # disable auto generated boot option for succeeding test
> > +        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)
> > +        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
> > +        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, 1, True, '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')
> > +
> > +        # Set optional_data
> > +        press_up_down_enter_and_wait(0, 3, True, 'Optional Data:')
> > +        # Send Description user input, press ENTER key to complete
> > +        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)
> > +        check_current_is_maintenance_menu()
> > +
> > +        # Check the newly added Boot Option is handled correctly
> > +        # Return to U-Boot console
> > +        press_escape_key(True)
> > +        u_boot_console.run_command(cmd = 'bootefi bootmgr')
> > +        response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
> > +        assert 'crc32: 0x181464af' in response
> > +        u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
> > +
> > +        #
> > +        # Test Case 4: Add second Boot Option and load it
> > +        #
> > +        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
> > +        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, 1, True, '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, 2, True, 'Quit')
> > +
> > +        # Set optional_data
> > +        press_up_down_enter_and_wait(0, 3, True, 'Optional Data:')
> > +        # Send Description user input, press ENTER key to complete
> > +        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')
> > +
> > +        # 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
> > +        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)
> > +        check_current_is_maintenance_menu()
> > +
> > +        # Check the newly added Boot Option is handled correctly
> > +        # Return to U-Boot console
> > +        press_escape_key(True)
> > +        u_boot_console.run_command(cmd = 'bootefi bootmgr')
> > +        response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
> > +        assert 'crc32: 0x811d3515' in response
> > +        u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
> > +
> > +        #
> > +        # Test Case 5: Change BootOrder and load it
> > +        #
> > +        u_boot_console.run_command('eficonfig', wait_for_prompt=False)
> > +
> > +        # Change the Boot Order
> > +        press_up_down_enter_and_wait(0, 2, True, None)
> > +        # 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
> > +        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)
> > +        check_current_is_maintenance_menu()
> > +
> > +        # Return to U-Boot console
> > +        press_escape_key(True)
> > +        u_boot_console.run_command(cmd = 'bootefi bootmgr')
> > +        response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
> > +        assert 'crc32: 0x181464af' in response
> > +        u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
> > +
> > +        #
> > +        # Test Case 6: Delete Boot Option(label:test 2)
> > +        #
> > +        u_boot_console.run_command('eficonfig', wait_for_prompt=False)
> > +
> > +        # Select 'Delete Boot Option'
> > +        press_up_down_enter_and_wait(0, 3, True, None)
> > +        # 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)
> > +        for i in ('test 1', 'Quit'):
> > +            u_boot_console.p.expect([i])
> > +        press_escape_key(False)
> > +        check_current_is_maintenance_menu()
> > +        # Return to U-Boot console
> > +        press_escape_key(True)
> > +
> > +        #
> > +        # 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)
> > +        # 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)
> > +        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
> > +        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, 1, True, '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, 2, True, 'Quit')
> > +
> > +        # Set optional_data
> > +        press_up_down_enter_and_wait(0, 3, True, 'Optional Data:')
> > +        # Send Description user input, press ENTER key to complete
> > +        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')
> > +        press_escape_key(False)
> > +        check_current_is_maintenance_menu()
> > +
> > +        # Check the updated Boot Option is handled correctly
> > +        # Return to U-Boot console
> > +        press_escape_key(True)
> > +        u_boot_console.run_command(cmd = 'bootefi bootmgr')
> > +        response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
> > +        assert 'crc32: 0x811d3515' in response
> > +        u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
> > +
> > +        #
> > +        # Test Case 8: Delete Boot Option(label:test 3)
> > +        #
> > +        u_boot_console.run_command('eficonfig', wait_for_prompt=False)
> > +
> > +        # Select 'Delete Boot Option'
> > +        press_up_down_enter_and_wait(0, 3, True, None)
> > +        # 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')
> > +        press_escape_key(False)
> > +        check_current_is_maintenance_menu()
> > +        # Return to U-Boot console
> > +        press_escape_key(True)
> > +
> > +        # remove the host device
> > +        u_boot_console.run_command(cmd = f'host bind -r 0')
> > +
> > +        #
> > +        # Test Case 9: No block device found
> > +        #
> > +        u_boot_console.run_command('eficonfig', wait_for_prompt=False)
> > +
> > +        # Select 'Add Boot Option'
> > +        press_up_down_enter_and_wait(0, 0, True, '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!')
> > +        press_escape_key(False)
> > +        check_current_is_maintenance_menu()
> > +        # Return to U-Boot console
> > +        press_escape_key(True)
>
Simon Glass Sept. 6, 2022, 9:18 p.m. UTC | #3
Hi,

On Fri, 2 Sept 2022 at 08:22, Masahisa Kojima
<masahisa.kojima@linaro.org> wrote:
>
> Provide a unit test for the eficonfig command.
>
> Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
> Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
> No update since v15
>
> Changes in v14:
> - update to support media device enumeration in eficonfig startup
> - move no block device test to the last test case
>
> Changes in v12:
> - update menu handling
>
> Changes in v11:
> - fix expected result when no BootOrder is defined
>
> Newly added in v10
>
>  configs/sandbox_defconfig                     |   1 +
>  test/py/tests/test_eficonfig/conftest.py      |  40 ++
>  .../py/tests/test_eficonfig/test_eficonfig.py | 350 ++++++++++++++++++
>  3 files changed, 391 insertions(+)
>  create mode 100644 test/py/tests/test_eficonfig/conftest.py
>  create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py

How come this is written in Python? Shouldn't it be in C?

Regards,
Simon
Masahisa Kojima Sept. 7, 2022, 6:13 a.m. UTC | #4
Hi Simon,

On Wed, 7 Sept 2022 at 06:18, Simon Glass <sjg@chromium.org> wrote:
>
> Hi,
>
> On Fri, 2 Sept 2022 at 08:22, Masahisa Kojima
> <masahisa.kojima@linaro.org> wrote:
> >
> > Provide a unit test for the eficonfig command.
> >
> > Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
> > Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> > ---
> > No update since v15
> >
> > Changes in v14:
> > - update to support media device enumeration in eficonfig startup
> > - move no block device test to the last test case
> >
> > Changes in v12:
> > - update menu handling
> >
> > Changes in v11:
> > - fix expected result when no BootOrder is defined
> >
> > Newly added in v10
> >
> >  configs/sandbox_defconfig                     |   1 +
> >  test/py/tests/test_eficonfig/conftest.py      |  40 ++
> >  .../py/tests/test_eficonfig/test_eficonfig.py | 350 ++++++++++++++++++
> >  3 files changed, 391 insertions(+)
> >  create mode 100644 test/py/tests/test_eficonfig/conftest.py
> >  create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py
>
> How come this is written in Python? Shouldn't it be in C?

Would you give more information why you prefer C to Python?

Thanks,
Masahisa Kojima

>
> Regards,
> Simon
Simon Glass Sept. 7, 2022, 9:10 p.m. UTC | #5
Hi Masahisa,

On Wed, 7 Sept 2022 at 00:13, Masahisa Kojima
<masahisa.kojima@linaro.org> wrote:
>
> Hi Simon,
>
> On Wed, 7 Sept 2022 at 06:18, Simon Glass <sjg@chromium.org> wrote:
> >
> > Hi,
> >
> > On Fri, 2 Sept 2022 at 08:22, Masahisa Kojima
> > <masahisa.kojima@linaro.org> wrote:
> > >
> > > Provide a unit test for the eficonfig command.
> > >
> > > Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
> > > Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> > > ---
> > > No update since v15
> > >
> > > Changes in v14:
> > > - update to support media device enumeration in eficonfig startup
> > > - move no block device test to the last test case
> > >
> > > Changes in v12:
> > > - update menu handling
> > >
> > > Changes in v11:
> > > - fix expected result when no BootOrder is defined
> > >
> > > Newly added in v10
> > >
> > >  configs/sandbox_defconfig                     |   1 +
> > >  test/py/tests/test_eficonfig/conftest.py      |  40 ++
> > >  .../py/tests/test_eficonfig/test_eficonfig.py | 350 ++++++++++++++++++
> > >  3 files changed, 391 insertions(+)
> > >  create mode 100644 test/py/tests/test_eficonfig/conftest.py
> > >  create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py
> >
> > How come this is written in Python? Shouldn't it be in C?
>
> Would you give more information why you prefer C to Python?

Please see here:

https://u-boot.readthedocs.io/en/latest/develop/tests_writing.html

Regards,
Simon
Ilias Apalodimas Sept. 8, 2022, 10:21 a.m. UTC | #6
Hi all,

On Thu, 8 Sept 2022 at 00:11, Simon Glass <sjg@chromium.org> wrote:
>
> Hi Masahisa,
>
> On Wed, 7 Sept 2022 at 00:13, Masahisa Kojima
> <masahisa.kojima@linaro.org> wrote:
> >
> > Hi Simon,
> >
> > On Wed, 7 Sept 2022 at 06:18, Simon Glass <sjg@chromium.org> wrote:
> > >
> > > Hi,
> > >
> > > On Fri, 2 Sept 2022 at 08:22, Masahisa Kojima
> > > <masahisa.kojima@linaro.org> wrote:
> > > >
> > > > Provide a unit test for the eficonfig command.
> > > >
> > > > Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
> > > > Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> > > > ---
> > > > No update since v15
> > > >
> > > > Changes in v14:
> > > > - update to support media device enumeration in eficonfig startup
> > > > - move no block device test to the last test case
> > > >
> > > > Changes in v12:
> > > > - update menu handling
> > > >
> > > > Changes in v11:
> > > > - fix expected result when no BootOrder is defined
> > > >
> > > > Newly added in v10
> > > >
> > > >  configs/sandbox_defconfig                     |   1 +
> > > >  test/py/tests/test_eficonfig/conftest.py      |  40 ++
> > > >  .../py/tests/test_eficonfig/test_eficonfig.py | 350 ++++++++++++++++++
> > > >  3 files changed, 391 insertions(+)
> > > >  create mode 100644 test/py/tests/test_eficonfig/conftest.py
> > > >  create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py
> > >
> > > How come this is written in Python? Shouldn't it be in C?
> >
> > Would you give more information why you prefer C to Python?
>
> Please see here:
>
> https://u-boot.readthedocs.io/en/latest/develop/tests_writing.html

I am not too familiar with all the testing facilities, but isn't
selecting menu items (which is what this is testing) easier to do in
python?
I assumed so since the bootmenu tests, which is what this command
using under the hood, are written in python

Regards
/Ilias
>
> Regards,
> Simon
Heinrich Schuchardt Sept. 8, 2022, 3:48 p.m. UTC | #7
On 9/6/22 23:18, Simon Glass wrote:
> Hi,
>
> On Fri, 2 Sept 2022 at 08:22, Masahisa Kojima
> <masahisa.kojima@linaro.org> wrote:
>>
>> Provide a unit test for the eficonfig command.
>>
>> Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
>> Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
>> ---
>> No update since v15
>>
>> Changes in v14:
>> - update to support media device enumeration in eficonfig startup
>> - move no block device test to the last test case
>>
>> Changes in v12:
>> - update menu handling
>>
>> Changes in v11:
>> - fix expected result when no BootOrder is defined
>>
>> Newly added in v10
>>
>>   configs/sandbox_defconfig                     |   1 +
>>   test/py/tests/test_eficonfig/conftest.py      |  40 ++
>>   .../py/tests/test_eficonfig/test_eficonfig.py | 350 ++++++++++++++++++
>>   3 files changed, 391 insertions(+)
>>   create mode 100644 test/py/tests/test_eficonfig/conftest.py
>>   create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py
>
> How come this is written in Python? Shouldn't it be in C?

We need to prepare an image for testing and provide it to U-Boot.

This cannot be done with C.

Best regards

Heinrich
Simon Glass Sept. 8, 2022, 6:18 p.m. UTC | #8
Hi Heinrich,

On Thu, 8 Sept 2022 at 09:53, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> On 9/6/22 23:18, Simon Glass wrote:
> > Hi,
> >
> > On Fri, 2 Sept 2022 at 08:22, Masahisa Kojima
> > <masahisa.kojima@linaro.org> wrote:
> >>
> >> Provide a unit test for the eficonfig command.
> >>
> >> Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
> >> Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> >> ---
> >> No update since v15
> >>
> >> Changes in v14:
> >> - update to support media device enumeration in eficonfig startup
> >> - move no block device test to the last test case
> >>
> >> Changes in v12:
> >> - update menu handling
> >>
> >> Changes in v11:
> >> - fix expected result when no BootOrder is defined
> >>
> >> Newly added in v10
> >>
> >>   configs/sandbox_defconfig                     |   1 +
> >>   test/py/tests/test_eficonfig/conftest.py      |  40 ++
> >>   .../py/tests/test_eficonfig/test_eficonfig.py | 350 ++++++++++++++++++
> >>   3 files changed, 391 insertions(+)
> >>   create mode 100644 test/py/tests/test_eficonfig/conftest.py
> >>   create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py
> >
> > How come this is written in Python? Shouldn't it be in C?
>
> We need to prepare an image for testing and provide it to U-Boot.
>
> This cannot be done with C.

We do that now with the bootstd tests. Please see setup_bootflow_image().

It is also pretty easy to do it in a Python test but do the actual
checking in C. I'll send a patch showing that if you like.

Regards,
Simon
Heinrich Schuchardt Sept. 8, 2022, 7:51 p.m. UTC | #9
On 9/8/22 20:18, Simon Glass wrote:
> Hi Heinrich,
>
> On Thu, 8 Sept 2022 at 09:53, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>>
>> On 9/6/22 23:18, Simon Glass wrote:
>>> Hi,
>>>
>>> On Fri, 2 Sept 2022 at 08:22, Masahisa Kojima
>>> <masahisa.kojima@linaro.org> wrote:
>>>>
>>>> Provide a unit test for the eficonfig command.
>>>>
>>>> Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
>>>> Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
>>>> ---
>>>> No update since v15
>>>>
>>>> Changes in v14:
>>>> - update to support media device enumeration in eficonfig startup
>>>> - move no block device test to the last test case
>>>>
>>>> Changes in v12:
>>>> - update menu handling
>>>>
>>>> Changes in v11:
>>>> - fix expected result when no BootOrder is defined
>>>>
>>>> Newly added in v10
>>>>
>>>>    configs/sandbox_defconfig                     |   1 +
>>>>    test/py/tests/test_eficonfig/conftest.py      |  40 ++
>>>>    .../py/tests/test_eficonfig/test_eficonfig.py | 350 ++++++++++++++++++
>>>>    3 files changed, 391 insertions(+)
>>>>    create mode 100644 test/py/tests/test_eficonfig/conftest.py
>>>>    create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py
>>>
>>> How come this is written in Python? Shouldn't it be in C?
>>
>> We need to prepare an image for testing and provide it to U-Boot.
>>
>> This cannot be done with C.
>
> We do that now with the bootstd tests. Please see setup_bootflow_image().

setup_bootflow_image() uses sudo. For security reasons I don't like to
provide root privileges to other people's code. Distributions don't like
their builders to run with root privileges. Please, use virt-make-fs
instead.

Best regards

Heinrich

>
> It is also pretty easy to do it in a Python test but do the actual
> checking in C. I'll send a patch showing that if you like.
>
> Regards,
> Simon
Simon Glass Sept. 8, 2022, 10:12 p.m. UTC | #10
Hi Heinrich,

On Thu, 8 Sept 2022 at 13:56, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> On 9/8/22 20:18, Simon Glass wrote:
> > Hi Heinrich,
> >
> > On Thu, 8 Sept 2022 at 09:53, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> >>
> >> On 9/6/22 23:18, Simon Glass wrote:
> >>> Hi,
> >>>
> >>> On Fri, 2 Sept 2022 at 08:22, Masahisa Kojima
> >>> <masahisa.kojima@linaro.org> wrote:
> >>>>
> >>>> Provide a unit test for the eficonfig command.
> >>>>
> >>>> Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
> >>>> Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> >>>> ---
> >>>> No update since v15
> >>>>
> >>>> Changes in v14:
> >>>> - update to support media device enumeration in eficonfig startup
> >>>> - move no block device test to the last test case
> >>>>
> >>>> Changes in v12:
> >>>> - update menu handling
> >>>>
> >>>> Changes in v11:
> >>>> - fix expected result when no BootOrder is defined
> >>>>
> >>>> Newly added in v10
> >>>>
> >>>>    configs/sandbox_defconfig                     |   1 +
> >>>>    test/py/tests/test_eficonfig/conftest.py      |  40 ++
> >>>>    .../py/tests/test_eficonfig/test_eficonfig.py | 350 ++++++++++++++++++
> >>>>    3 files changed, 391 insertions(+)
> >>>>    create mode 100644 test/py/tests/test_eficonfig/conftest.py
> >>>>    create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py
> >>>
> >>> How come this is written in Python? Shouldn't it be in C?
> >>
> >> We need to prepare an image for testing and provide it to U-Boot.
> >>
> >> This cannot be done with C.
> >
> > We do that now with the bootstd tests. Please see setup_bootflow_image().
>
> setup_bootflow_image() uses sudo. For security reasons I don't like to
> provide root privileges to other people's code. Distributions don't like
> their builders to run with root privileges. Please, use virt-make-fs
> instead.

I do agree, but then don't we need to chmod a+r the current kernel? Is
there a way around that?

Regards,
Simon
Heinrich Schuchardt Sept. 9, 2022, 9:39 a.m. UTC | #11
On 9/9/22 00:12, Simon Glass wrote:
> Hi Heinrich,
>
> On Thu, 8 Sept 2022 at 13:56, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>>
>> On 9/8/22 20:18, Simon Glass wrote:
>>> Hi Heinrich,
>>>
>>> On Thu, 8 Sept 2022 at 09:53, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>>>>
>>>> On 9/6/22 23:18, Simon Glass wrote:
>>>>> Hi,
>>>>>
>>>>> On Fri, 2 Sept 2022 at 08:22, Masahisa Kojima
>>>>> <masahisa.kojima@linaro.org> wrote:
>>>>>>
>>>>>> Provide a unit test for the eficonfig command.
>>>>>>
>>>>>> Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
>>>>>> Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
>>>>>> ---
>>>>>> No update since v15
>>>>>>
>>>>>> Changes in v14:
>>>>>> - update to support media device enumeration in eficonfig startup
>>>>>> - move no block device test to the last test case
>>>>>>
>>>>>> Changes in v12:
>>>>>> - update menu handling
>>>>>>
>>>>>> Changes in v11:
>>>>>> - fix expected result when no BootOrder is defined
>>>>>>
>>>>>> Newly added in v10
>>>>>>
>>>>>>     configs/sandbox_defconfig                     |   1 +
>>>>>>     test/py/tests/test_eficonfig/conftest.py      |  40 ++
>>>>>>     .../py/tests/test_eficonfig/test_eficonfig.py | 350 ++++++++++++++++++
>>>>>>     3 files changed, 391 insertions(+)
>>>>>>     create mode 100644 test/py/tests/test_eficonfig/conftest.py
>>>>>>     create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py
>>>>>
>>>>> How come this is written in Python? Shouldn't it be in C?
>>>>
>>>> We need to prepare an image for testing and provide it to U-Boot.
>>>>
>>>> This cannot be done with C.
>>>
>>> We do that now with the bootstd tests. Please see setup_bootflow_image().
>>
>> setup_bootflow_image() uses sudo. For security reasons I don't like to
>> provide root privileges to other people's code. Distributions don't like
>> their builders to run with root privileges. Please, use virt-make-fs
>> instead.
>
> I do agree, but then don't we need to chmod a+r the current kernel? Is
> there a way around that?

This is a Ubuntu specific "feature". Debian does not have that problem.

Just create a file

/etc/initramfs-tools/hooks/vmlinuz (chmod 755) with content

#!/bin/sh
echo "chmod a+r vmlinuz-*"
chmod a+r /boot/vmlinuz-*

And run

    update-initramfs -u

The next time a kernel update is installed the script will be executed
automatically.

Best regards

Heinrich
Simon Glass Sept. 9, 2022, 6:21 p.m. UTC | #12
Hi Heinrich,

On Fri, 9 Sept 2022 at 03:45, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> On 9/9/22 00:12, Simon Glass wrote:
> > Hi Heinrich,
> >
> > On Thu, 8 Sept 2022 at 13:56, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> >>
> >> On 9/8/22 20:18, Simon Glass wrote:
> >>> Hi Heinrich,
> >>>
> >>> On Thu, 8 Sept 2022 at 09:53, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> >>>>
> >>>> On 9/6/22 23:18, Simon Glass wrote:
> >>>>> Hi,
> >>>>>
> >>>>> On Fri, 2 Sept 2022 at 08:22, Masahisa Kojima
> >>>>> <masahisa.kojima@linaro.org> wrote:
> >>>>>>
> >>>>>> Provide a unit test for the eficonfig command.
> >>>>>>
> >>>>>> Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
> >>>>>> Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> >>>>>> ---
> >>>>>> No update since v15
> >>>>>>
> >>>>>> Changes in v14:
> >>>>>> - update to support media device enumeration in eficonfig startup
> >>>>>> - move no block device test to the last test case
> >>>>>>
> >>>>>> Changes in v12:
> >>>>>> - update menu handling
> >>>>>>
> >>>>>> Changes in v11:
> >>>>>> - fix expected result when no BootOrder is defined
> >>>>>>
> >>>>>> Newly added in v10
> >>>>>>
> >>>>>>     configs/sandbox_defconfig                     |   1 +
> >>>>>>     test/py/tests/test_eficonfig/conftest.py      |  40 ++
> >>>>>>     .../py/tests/test_eficonfig/test_eficonfig.py | 350 ++++++++++++++++++
> >>>>>>     3 files changed, 391 insertions(+)
> >>>>>>     create mode 100644 test/py/tests/test_eficonfig/conftest.py
> >>>>>>     create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py
> >>>>>
> >>>>> How come this is written in Python? Shouldn't it be in C?
> >>>>
> >>>> We need to prepare an image for testing and provide it to U-Boot.
> >>>>
> >>>> This cannot be done with C.
> >>>
> >>> We do that now with the bootstd tests. Please see setup_bootflow_image().
> >>
> >> setup_bootflow_image() uses sudo. For security reasons I don't like to
> >> provide root privileges to other people's code. Distributions don't like
> >> their builders to run with root privileges. Please, use virt-make-fs
> >> instead.
> >
> > I do agree, but then don't we need to chmod a+r the current kernel? Is
> > there a way around that?
>
> This is a Ubuntu specific "feature". Debian does not have that problem.
>
> Just create a file
>
> /etc/initramfs-tools/hooks/vmlinuz (chmod 755) with content
>
> #!/bin/sh
> echo "chmod a+r vmlinuz-*"
> chmod a+r /boot/vmlinuz-*
>
> And run
>
>     update-initramfs -u
>
> The next time a kernel update is installed the script will be executed
> automatically.

Thanks for the info.

Can we add this to the docs and print out a message in the test
pointing people to this fix?

Regards,
Simon
diff mbox series

Patch

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index eba7bcbb48..48c60c606d 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -93,6 +93,7 @@  CONFIG_CMD_LINK_LOCAL=y
 CONFIG_CMD_ETHSW=y
 CONFIG_CMD_BMP=y
 CONFIG_CMD_BOOTCOUNT=y
+CONFIG_CMD_EFICONFIG=y
 CONFIG_CMD_EFIDEBUG=y
 CONFIG_CMD_RTC=y
 CONFIG_CMD_TIME=y
diff --git a/test/py/tests/test_eficonfig/conftest.py b/test/py/tests/test_eficonfig/conftest.py
new file mode 100644
index 0000000000..f289df0362
--- /dev/null
+++ b/test/py/tests/test_eficonfig/conftest.py
@@ -0,0 +1,40 @@ 
+# SPDX-License-Identifier:      GPL-2.0+
+
+"""Fixture for UEFI eficonfig test
+"""
+
+import os
+import shutil
+from subprocess import check_call
+import pytest
+
+@pytest.fixture(scope='session')
+def efi_eficonfig_data(u_boot_config):
+    """Set up a file system to be used in UEFI "eficonfig" command
+       tests
+
+    Args:
+        u_boot_config -- U-boot configuration.
+
+    Return:
+        A path to disk image to be used for testing
+    """
+    mnt_point = u_boot_config.persistent_data_dir + '/test_efi_eficonfig'
+    image_path = u_boot_config.persistent_data_dir + '/efi_eficonfig.img'
+
+    shutil.rmtree(mnt_point, ignore_errors=True)
+    os.mkdir(mnt_point, mode = 0o755)
+
+    with open(mnt_point + '/initrd-1.img', 'w', encoding = 'ascii') as file:
+        file.write("initrd 1")
+
+    with open(mnt_point + '/initrd-2.img', 'w', encoding = 'ascii') as file:
+        file.write("initrd 2")
+
+    shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/initrddump.efi',
+                    mnt_point + '/initrddump.efi')
+
+    check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}',
+               shell=True)
+
+    return image_path
diff --git a/test/py/tests/test_eficonfig/test_eficonfig.py b/test/py/tests/test_eficonfig/test_eficonfig.py
new file mode 100644
index 0000000000..1c501deb1f
--- /dev/null
+++ b/test/py/tests/test_eficonfig/test_eficonfig.py
@@ -0,0 +1,350 @@ 
+# SPDX-License-Identifier:      GPL-2.0+
+""" Unit test for UEFI menu-driven configuration
+"""
+
+import pytest
+import time
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_eficonfig')
+@pytest.mark.buildconfigspec('cmd_bootefi_bootmgr')
+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
+        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,
+                                   wait_for_echo=False, send_nl=False)
+        if expect_str is not None:
+            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,
+                                       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,
+                                       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])
+
+    def press_escape_key(wait_prompt):
+        u_boot_console.run_command(cmd='\x1b', wait_for_prompt=wait_prompt, wait_for_echo=False, send_nl=False)
+
+    def press_enter_key(wait_prompt):
+        u_boot_console.run_command(cmd='\x0d', wait_for_prompt=wait_prompt,
+                                   wait_for_echo=False, send_nl=False)
+
+    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'):
+            u_boot_console.p.expect([i])
+
+    """ Unit test for "eficonfig" command
+    The menu-driven interface is used to set up UEFI load options.
+    The bootefi bootmgr loads initrddump.efi as a payload.
+    The crc32 of the loaded initrd.img is checked
+
+    Args:
+        u_boot_console -- U-Boot console
+        efi__data -- Path to the disk image used for testing.
+                     Test disk image has following files.
+                         initrd-1.img
+                         initrddump.efi
+                         initrd-2.img
+
+    """
+    with u_boot_console.temporary_timeout(500):
+        #
+        # Test Case 1: Check the menu is displayed
+        #
+        u_boot_console.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'):
+            u_boot_console.p.expect([i])
+        # Select "Add Boot Option"
+        press_enter_key(False)
+        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
+        press_escape_key(True)
+
+        #
+        # Test Case 2: check auto generated media device entry
+        #
+
+        # bind the test disk image for succeeding tests
+        u_boot_console.run_command(cmd = f'host bind 0 {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])
+        # disable auto generated boot option for succeeding test
+        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)
+        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
+        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, 1, True, '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')
+
+        # Set optional_data
+        press_up_down_enter_and_wait(0, 3, True, 'Optional Data:')
+        # Send Description user input, press ENTER key to complete
+        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)
+        check_current_is_maintenance_menu()
+
+        # Check the newly added Boot Option is handled correctly
+        # Return to U-Boot console
+        press_escape_key(True)
+        u_boot_console.run_command(cmd = 'bootefi bootmgr')
+        response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
+        assert 'crc32: 0x181464af' in response
+        u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
+
+        #
+        # Test Case 4: Add second Boot Option and load it
+        #
+        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
+        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, 1, True, '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, 2, True, 'Quit')
+
+        # Set optional_data
+        press_up_down_enter_and_wait(0, 3, True, 'Optional Data:')
+        # Send Description user input, press ENTER key to complete
+        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')
+
+        # 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
+        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)
+        check_current_is_maintenance_menu()
+
+        # Check the newly added Boot Option is handled correctly
+        # Return to U-Boot console
+        press_escape_key(True)
+        u_boot_console.run_command(cmd = 'bootefi bootmgr')
+        response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
+        assert 'crc32: 0x811d3515' in response
+        u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
+
+        #
+        # Test Case 5: Change BootOrder and load it
+        #
+        u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+
+        # Change the Boot Order
+        press_up_down_enter_and_wait(0, 2, True, None)
+        # 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
+        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)
+        check_current_is_maintenance_menu()
+
+        # Return to U-Boot console
+        press_escape_key(True)
+        u_boot_console.run_command(cmd = 'bootefi bootmgr')
+        response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
+        assert 'crc32: 0x181464af' in response
+        u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
+
+        #
+        # Test Case 6: Delete Boot Option(label:test 2)
+        #
+        u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+
+        # Select 'Delete Boot Option'
+        press_up_down_enter_and_wait(0, 3, True, None)
+        # 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)
+        for i in ('test 1', 'Quit'):
+            u_boot_console.p.expect([i])
+        press_escape_key(False)
+        check_current_is_maintenance_menu()
+        # Return to U-Boot console
+        press_escape_key(True)
+
+        #
+        # 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)
+        # 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)
+        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
+        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, 1, True, '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, 2, True, 'Quit')
+
+        # Set optional_data
+        press_up_down_enter_and_wait(0, 3, True, 'Optional Data:')
+        # Send Description user input, press ENTER key to complete
+        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')
+        press_escape_key(False)
+        check_current_is_maintenance_menu()
+
+        # Check the updated Boot Option is handled correctly
+        # Return to U-Boot console
+        press_escape_key(True)
+        u_boot_console.run_command(cmd = 'bootefi bootmgr')
+        response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
+        assert 'crc32: 0x811d3515' in response
+        u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
+
+        #
+        # Test Case 8: Delete Boot Option(label:test 3)
+        #
+        u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+
+        # Select 'Delete Boot Option'
+        press_up_down_enter_and_wait(0, 3, True, None)
+        # 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')
+        press_escape_key(False)
+        check_current_is_maintenance_menu()
+        # Return to U-Boot console
+        press_escape_key(True)
+
+        # remove the host device
+        u_boot_console.run_command(cmd = f'host bind -r 0')
+
+        #
+        # Test Case 9: No block device found
+        #
+        u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+
+        # Select 'Add Boot Option'
+        press_up_down_enter_and_wait(0, 0, True, '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!')
+        press_escape_key(False)
+        check_current_is_maintenance_menu()
+        # Return to U-Boot console
+        press_escape_key(True)