Roger Knecht | 11827c4 | 2022-09-03 11:34:53 +0000 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
| 3 | """Fixture for cat command test |
| 4 | """ |
| 5 | |
| 6 | import os |
| 7 | import shutil |
| 8 | from subprocess import check_call, CalledProcessError |
| 9 | import pytest |
| 10 | |
| 11 | @pytest.fixture(scope='session') |
| 12 | def cat_data(u_boot_config): |
| 13 | """Set up a file system to be used in cat tests |
| 14 | |
| 15 | Args: |
Michal Simek | 50fa118 | 2023-05-17 09:17:16 +0200 | [diff] [blame] | 16 | u_boot_config -- U-Boot configuration. |
Roger Knecht | 11827c4 | 2022-09-03 11:34:53 +0000 | [diff] [blame] | 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) |
Joshua Watt | 8e6e2de | 2023-07-03 08:35:09 -0500 | [diff] [blame^] | 35 | if os.path.exists(image_path): |
| 36 | os.remove(image_path) |