blob: 47c7cce1aa9f8688e3597abb6a1ed80ee1282a41 [file] [log] [blame]
Roger Knechtf841bb82022-09-03 13:15:04 +00001# 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:
Michal Simek50fa1182023-05-17 09:17:16 +020016 u_boot_config -- U-Boot configuration.
Roger Knechtf841bb82022-09-03 13:15:04 +000017 """
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)
Joshua Watt8e6e2de2023-07-03 08:35:09 -050035 if os.path.exists(image_path):
36 os.remove(image_path)