2022-03-03 11:31:18 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
|
|
|
|
2023-05-03 05:08:05 +00:00
|
|
|
"""Fixture for UEFI bootmanager test."""
|
2022-03-03 11:31:18 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import shutil
|
2022-03-27 08:03:33 +00:00
|
|
|
from subprocess import check_call
|
|
|
|
import pytest
|
2022-03-03 11:31:18 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope='session')
|
|
|
|
def efi_bootmgr_data(u_boot_config):
|
2023-05-03 05:08:05 +00:00
|
|
|
"""Set up a file system to be used in UEFI bootmanager tests.
|
2022-03-03 11:31:18 +00:00
|
|
|
|
|
|
|
Args:
|
2023-05-17 07:17:16 +00:00
|
|
|
u_boot_config -- U-Boot configuration.
|
2022-03-03 11:31:18 +00:00
|
|
|
|
|
|
|
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')
|
|
|
|
|
2022-03-27 08:03:33 +00:00
|
|
|
check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}',
|
|
|
|
shell=True)
|
2022-03-03 11:31:18 +00:00
|
|
|
|
2022-03-27 08:03:33 +00:00
|
|
|
return image_path
|