test/py: Rework test_eficonfig to not use virt-make-fs

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.

Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Tom Rini <trini@konsulko.com>
This commit is contained in:
Tom Rini 2025-03-20 07:59:27 -06:00
parent 4b33810511
commit 397fc80b9f
2 changed files with 46 additions and 47 deletions

View file

@ -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(ubman, efi_eficonfig_data):
def test_efi_eficonfig(ubman):
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(ubman.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(ubman, efi_eficonfig_data):
Args:
ubman -- 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(ubman, efi_eficonfig_data):
# Restart the system to clean the previous state
ubman.restart_uboot()
efi_eficonfig_data = prepare_image(ubman.config)
with ubman.temporary_timeout(500):
#
# Test Case 1: Check the menu is displayed

View file

@ -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