From: AKASHI Takahiro <takahiro.akashi@linaro.org>
To: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Cc: u-boot@lists.denx.de, Ilias Apalodimas <ilias.apalodimas@linaro.org>
Subject: Re: [PATCH v3 3/3] test: test UEFI boot manager
Date: Wed, 23 Mar 2022 15:32:56 +0900 [thread overview]
Message-ID: <20220323063256.GA49108@laputa> (raw)
In-Reply-To: <20220322205807.7584-4-heinrich.schuchardt@canonical.com>
On Tue, Mar 22, 2022 at 09:58:07PM +0100, Heinrich Schuchardt wrote:
> Provide a unit test for
>
> * efidebug boot add
and other boot sub-commands as well?
See below.
> * efidebug bootmgr
-> bootefi bootmgr
> * initrd via EFI_LOAD_FILE2_PROTOCOL
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
> v3:
> pass u"nocolor" as optional data to initrddump.efi
> v2:
> new patch
> ---
> test/py/tests/test_efi_bootmgr/conftest.py | 42 +++++++++++++++++++
> .../test_efi_bootmgr/test_efi_bootmgr.py | 31 ++++++++++++++
> 2 files changed, 73 insertions(+)
> create mode 100644 test/py/tests/test_efi_bootmgr/conftest.py
> create mode 100644 test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
>
> diff --git a/test/py/tests/test_efi_bootmgr/conftest.py b/test/py/tests/test_efi_bootmgr/conftest.py
> new file mode 100644
> index 0000000000..69008fddce
> --- /dev/null
> +++ b/test/py/tests/test_efi_bootmgr/conftest.py
> @@ -0,0 +1,42 @@
> +# SPDX-License-Identifier: GPL-2.0+
> +
> +"""Fixture for UEFI bootmanager test
> +"""
> +
> +import os
> +import pytest
> +import shutil
> +from subprocess import call, check_call
> +
> +@pytest.fixture(scope='session')
> +def efi_bootmgr_data(u_boot_config):
> + """Set up a file system to be used in UEFI bootmanager
> + 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_bootmgr'
> + image_path = u_boot_config.persistent_data_dir + '/efi_bootmgr.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('virt-make-fs --partition=gpt --size=+1M --type=vfat {} {}'
> + .format(mnt_point, image_path), shell=True)
> +
> + print(image_path)
> +
> + yield image_path
> diff --git a/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py b/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
> new file mode 100644
> index 0000000000..feba306580
> --- /dev/null
> +++ b/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
> @@ -0,0 +1,31 @@
> +# SPDX-License-Identifier: GPL-2.0+
> +
> +import pytest
> +
> +@pytest.mark.boardspec('sandbox')
> +@pytest.mark.buildconfigspec('efi_loader')
Obviously, this test depends on 'cmd_efidebug' and 'cmd_bootefi'.
> +def test_efi_bootmgr(u_boot_console, efi_bootmgr_data):
> + u_boot_console.run_command(cmd = 'host bind 0 {}'.format(efi_bootmgr_data))
> +
> + u_boot_console.run_command(cmd = 'efidebug boot add ' \
> + '-b 0001 label-1 host 0:1 initrddump.efi ' \
> + '-i host 0:1 initrd-1.img -s nocolor')
> + u_boot_console.run_command(cmd = 'efidebug boot dump')
Why do you call "boot dump" here?
If you intend to test this sub-command, you should check the output.
Or do you think it's enough to simply exercise the code for testing?
> + u_boot_console.run_command(cmd = 'efidebug boot order 0001')
> + 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)
> +
> + u_boot_console.run_command(cmd = 'efidebug boot add ' \
> + '-B 0002 label-2 host 0:1 initrddump.efi ' \
> + '-I host 0:1 initrd-2.img -s nocolor')
> + u_boot_console.run_command(cmd = 'efidebug boot dump')
> + u_boot_console.run_command(cmd = 'efidebug boot order 0002')
> + 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)
If you like, please add a test for "boot next" (or BootNext variable)
as well.
Thanks,
-Takahiro Akashi
> +
> + u_boot_console.run_command(cmd = 'efidebug boot rm 0001')
> + u_boot_console.run_command(cmd = 'efidebug boot rm 0002')
> --
> 2.34.1
>
next prev parent reply other threads:[~2022-03-23 6:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-22 20:58 [PATCH v3 0/3] test: test UEFI boot manager Heinrich Schuchardt
2022-03-22 20:58 ` [PATCH v3 1/3] efi_loader: nocolor command line attr for initrddump.efi Heinrich Schuchardt
2022-03-25 14:58 ` Ilias Apalodimas
2022-03-26 6:36 ` Heinrich Schuchardt
2022-03-22 20:58 ` [PATCH v3 2/3] efi_loader: initrddump: drain input before prompt Heinrich Schuchardt
2022-03-25 14:59 ` Ilias Apalodimas
2022-03-22 20:58 ` [PATCH v3 3/3] test: test UEFI boot manager Heinrich Schuchardt
2022-03-23 6:32 ` AKASHI Takahiro [this message]
2022-03-26 6:40 ` Heinrich Schuchardt
2022-03-26 6:53 ` Heinrich Schuchardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220323063256.GA49108@laputa \
--to=takahiro.akashi@linaro.org \
--cc=heinrich.schuchardt@canonical.com \
--cc=ilias.apalodimas@linaro.org \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox