1# SPDX-License-Identifier: GPL-2.0+ 2 3""" Unit test for cat command 4""" 5 6import pytest 7from subprocess import call, check_call, CalledProcessError 8from tests import fs_helper 9 10@pytest.mark.boardspec('sandbox') 11@pytest.mark.buildconfigspec('cmd_cat') 12def test_cat(ubman): 13 """ Unit test for cat 14 15 Args: 16 ubman -- U-Boot console 17 """ 18 try: 19 scratch_dir = ubman.config.persistent_data_dir + '/scratch' 20 21 check_call('mkdir -p %s' % scratch_dir, shell=True) 22 23 with open(scratch_dir + '/hello', 'w', encoding = 'ascii') as file: 24 file.write('hello world\n') 25 26 cat_data = fs_helper.mk_fs(ubman.config, 'vfat', 0x100000, 27 'test_cat', scratch_dir) 28 response = ubman.run_command_list([ f'host bind 0 {cat_data}', 29 'cat host 0 hello']) 30 assert 'hello world' in response 31 except CalledProcessError as err: 32 pytest.skip('Preparing test_cat image failed') 33 call('rm -f %s' % cat_data, shell=True) 34 return 35 finally: 36 call('rm -rf %s' % scratch_dir, shell=True) 37 call('rm -f %s' % cat_data, shell=True) 38