blob: 058fe523521467fc9d7a6ba9393b9c7182c4a4e6 [file] [log] [blame]
Roger Knecht11827c42022-09-03 11:34:53 +00001# SPDX-License-Identifier: GPL-2.0+
2
3"""Fixture for cat command test
4"""
5
6import os
7import shutil
8from subprocess import check_call, CalledProcessError
9import pytest
10
11@pytest.fixture(scope='session')
12def cat_data(u_boot_config):
13 """Set up a file system to be used in cat tests
14
15 Args:
16 u_boot_config -- U-boot configuration.
17 """
18 mnt_point = u_boot_config.persistent_data_dir + '/test_cat'
19 image_path = u_boot_config.persistent_data_dir + '/cat.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')
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)