Heinrich Schuchardt | 76d0c87 | 2022-03-03 12:31:18 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
Heinrich Schuchardt | 14dee8b | 2023-05-03 07:08:05 +0200 | [diff] [blame] | 3 | """Fixture for UEFI bootmanager test.""" |
Heinrich Schuchardt | 76d0c87 | 2022-03-03 12:31:18 +0100 | [diff] [blame] | 4 | |
| 5 | import os |
Heinrich Schuchardt | 76d0c87 | 2022-03-03 12:31:18 +0100 | [diff] [blame] | 6 | import shutil |
Heinrich Schuchardt | 8bb75c9 | 2022-03-27 10:03:33 +0200 | [diff] [blame] | 7 | from subprocess import check_call |
| 8 | import pytest |
Heinrich Schuchardt | 76d0c87 | 2022-03-03 12:31:18 +0100 | [diff] [blame] | 9 | |
| 10 | @pytest.fixture(scope='session') |
| 11 | def efi_bootmgr_data(u_boot_config): |
Heinrich Schuchardt | 14dee8b | 2023-05-03 07:08:05 +0200 | [diff] [blame] | 12 | """Set up a file system to be used in UEFI bootmanager tests. |
Heinrich Schuchardt | 76d0c87 | 2022-03-03 12:31:18 +0100 | [diff] [blame] | 13 | |
| 14 | Args: |
Michal Simek | 50fa118 | 2023-05-17 09:17:16 +0200 | [diff] [blame] | 15 | u_boot_config -- U-Boot configuration. |
Heinrich Schuchardt | 76d0c87 | 2022-03-03 12:31:18 +0100 | [diff] [blame] | 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 | |
Heinrich Schuchardt | 8bb75c9 | 2022-03-27 10:03:33 +0200 | [diff] [blame] | 35 | check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}', |
| 36 | shell=True) |
Heinrich Schuchardt | 76d0c87 | 2022-03-03 12:31:18 +0100 | [diff] [blame] | 37 | |
Heinrich Schuchardt | 8bb75c9 | 2022-03-27 10:03:33 +0200 | [diff] [blame] | 38 | return image_path |