blob: 0eca025058ee4ece628f66570aa3ec1cdbd2cdde [file] [log] [blame]
Heinrich Schuchardt76d0c872022-03-03 12:31:18 +01001# SPDX-License-Identifier: GPL-2.0+
2
Heinrich Schuchardt14dee8b2023-05-03 07:08:05 +02003"""Fixture for UEFI bootmanager test."""
Heinrich Schuchardt76d0c872022-03-03 12:31:18 +01004
5import os
Heinrich Schuchardt76d0c872022-03-03 12:31:18 +01006import shutil
Heinrich Schuchardt8bb75c92022-03-27 10:03:33 +02007from subprocess import check_call
8import pytest
Heinrich Schuchardt76d0c872022-03-03 12:31:18 +01009
10@pytest.fixture(scope='session')
11def efi_bootmgr_data(u_boot_config):
Heinrich Schuchardt14dee8b2023-05-03 07:08:05 +020012 """Set up a file system to be used in UEFI bootmanager tests.
Heinrich Schuchardt76d0c872022-03-03 12:31:18 +010013
14 Args:
Michal Simek50fa1182023-05-17 09:17:16 +020015 u_boot_config -- U-Boot configuration.
Heinrich Schuchardt76d0c872022-03-03 12:31:18 +010016
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
Heinrich Schuchardt8bb75c92022-03-27 10:03:33 +020035 check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}',
36 shell=True)
Heinrich Schuchardt76d0c872022-03-03 12:31:18 +010037
Heinrich Schuchardt8bb75c92022-03-27 10:03:33 +020038 return image_path