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>
diff --git a/test/py/tests/test_eficonfig/test_eficonfig.py b/test/py/tests/test_eficonfig.py
similarity index 88%
rename from test/py/tests/test_eficonfig/test_eficonfig.py
rename to test/py/tests/test_eficonfig.py
index 3ca8e27..ac1600e 100644
--- a/test/py/tests/test_eficonfig/test_eficonfig.py
+++ b/test/py/tests/test_eficonfig.py
@@ -3,12 +3,56 @@
"""
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 @@
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 @@
# 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
diff --git a/test/py/tests/test_eficonfig/conftest.py b/test/py/tests/test_eficonfig/conftest.py
deleted file mode 100644
index 0a82fbe..0000000
--- 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