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