Hi Tom, I've never really looked at our fs helper functions but this looks reasonable
On Fri, 7 Mar 2025 at 01:23, Tom Rini <tr...@konsulko.com> wrote: > > The problem with using "virt-make-fs" to make a filesystem image is that > it is extremely slow. Switch to using the fs_helper functions we have > instead from the filesystem tests as these can add files to images and > are significantly faster and still do not require root access. > > As this test already had a number of internal functions, add a > prepare_image function to do this part of the test. > > Signed-off-by: Tom Rini <tr...@konsulko.com> > --- > I noted to Heinrich in private that this test is currently disabled. I > re-enabled it locally to verify that the disk image is created correctly > still. > > Cc: Ilias Apalodimas <ilias.apalodi...@linaro.org> > Cc: Heinrich Schuchardt <xypron.g...@gmx.de> > --- > .../{test_eficonfig => }/test_eficonfig.py | 53 ++++++++++++++++--- > test/py/tests/test_eficonfig/conftest.py | 40 -------------- > 2 files changed, 46 insertions(+), 47 deletions(-) > rename test/py/tests/{test_eficonfig => }/test_eficonfig.py (89%) > delete mode 100644 test/py/tests/test_eficonfig/conftest.py > > diff --git a/test/py/tests/test_eficonfig/test_eficonfig.py > b/test/py/tests/test_eficonfig.py > similarity index 89% > rename from test/py/tests/test_eficonfig/test_eficonfig.py > rename to test/py/tests/test_eficonfig.py > index d98de5249dfd..caccd1f42190 100644 > --- a/test/py/tests/test_eficonfig/test_eficonfig.py > +++ b/test/py/tests/test_eficonfig.py > @@ -2,13 +2,57 @@ > """ Unit test for UEFI menu-driven configuration > """ > > +import pytest > +import shutil > import pytest > import time > +from subprocess import call, check_call, CalledProcessError > +from tests import fs_helper > > @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 test_efi_eficonfig(u_boot_console): > + > + def prepare_image(u_boot_config): > + """Set up a file system to be used in UEFI "eficonfig" command > + tests. This creates a disk image with the following files: > + initrd-1.img > + initrd-2.img > + initrddump.efi > + > + Args: > + u_boot_config -- U-Boot configuration. > + > + Return: > + A path to disk image to be used for testing > + > + """ > + try: > + image_path, mnt_point = fs_helper.setup_image(u_boot_config, 0, > + 0xc, > + > basename='test_eficonfig') > + > + 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') > + > + fsfile = fs_helper.mk_fs(u_boot_console.config, 'vfat', 0x100000, > + 'test_eficonfig', mnt_point) > + check_call(f'dd if={fsfile} of={image_path} bs=1M seek=1', > shell=True) > + > + yield image_path > + except CalledProcessError as err: > + pytest.skip('Preparing test_eficonfig image failed') > + call('rm -f %s' % image_path, shell=True) > + finally: > + call('rm -rf %s' % mnt_point, shell=True) > + call('rm -f %s' % image_path, shell=True) > > def send_user_input_and_wait(user_str, expect_str): > time.sleep(0.1) # TODO: does not work correctly without sleep > @@ -57,12 +101,6 @@ def test_efi_eficonfig(u_boot_console, > efi_eficonfig_data): > > 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 > - initrd-2.img > - initrddump.efi > - > """ > # This test passes for unknown reasons in the bowels of U-Boot. It needs > to > # be replaced with a unit test. > @@ -71,6 +109,7 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): > # Restart the system to clean the previous state > u_boot_console.restart_uboot() > > + efi_eficonfig_data = prepare_image(u_boot_console.config) > with u_boot_console.temporary_timeout(500): > # > # Test Case 1: Check the menu is displayed > diff --git a/test/py/tests/test_eficonfig/conftest.py > b/test/py/tests/test_eficonfig/conftest.py > deleted file mode 100644 > index 0a82fbefd752..000000000000 > --- a/test/py/tests/test_eficonfig/conftest.py > +++ /dev/null > @@ -1,40 +0,0 @@ > -# 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 > -- > 2.43.0 > Acked-by: Ilias Apalodimas <ilias.apalodi...@linaro.org>