conftest.py 1.1 KB

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