1# SPDX-License-Identifier: GPL-2.0+ 2 3"""Fixture for xxd command test 4""" 5 6import os 7import shutil 8from subprocess import check_call, CalledProcessError 9import pytest 10 11@pytest.fixture(scope='session') 12def xxd_data(u_boot_config): 13 """Set up a file system to be used in xxd tests 14 15 Args: 16 u_boot_config -- U-boot configuration. 17 """ 18 mnt_point = u_boot_config.persistent_data_dir + '/test_xxd' 19 image_path = u_boot_config.persistent_data_dir + '/xxd.img' 20 21 try: 22 os.mkdir(mnt_point, mode = 0o755) 23 24 with open(mnt_point + '/hello', 'w', encoding = 'ascii') as file: 25 file.write('hello world\n\x00\x01\x02\x03\x04\x05') 26 27 check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}', 28 shell=True) 29 30 yield image_path 31 except CalledProcessError: 32 pytest.skip('Setup failed') 33 finally: 34 shutil.rmtree(mnt_point) 35 os.remove(image_path) 36