1# SPDX-License-Identifier:      GPL-2.0+
2
3"""Fixture for UEFI bootmanager test."""
4
5import os
6import shutil
7from subprocess import check_call
8import pytest
9
10@pytest.fixture(scope='session')
11def efi_bootmgr_data(u_boot_config):
12    """Set up a file system to be used in UEFI bootmanager tests.
13
14    Args:
15        u_boot_config -- U-boot configuration.
16
17    Return:
18        A path to disk image to be used for testing
19    """
20    mnt_point = u_boot_config.persistent_data_dir + '/test_efi_bootmgr'
21    image_path = u_boot_config.persistent_data_dir + '/efi_bootmgr.img'
22
23    shutil.rmtree(mnt_point, ignore_errors=True)
24    os.mkdir(mnt_point, mode = 0o755)
25
26    with open(mnt_point + '/initrd-1.img', 'w', encoding = 'ascii') as file:
27        file.write("initrd 1")
28
29    with open(mnt_point + '/initrd-2.img', 'w', encoding = 'ascii') as file:
30        file.write("initrd 2")
31
32    shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/initrddump.efi',
33                    mnt_point + '/initrddump.efi')
34
35    check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}',
36               shell=True)
37
38    return image_path
39