blob: c457c54146cdc0a179f21d82b866de548a589b76 [file] [log] [blame]
Tom Rini288d8652025-03-20 07:59:23 -06001# SPDX-License-Identifier: GPL-2.0+
2
3""" Unit test for xxd 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_xxd')
12def test_xxd(ubman):
13 """ Unit test for xxd
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\x00\x01\x02\x03\x04\x05')
25
26 xxd_data = fs_helper.mk_fs(ubman.config, 'vfat', 0x100000,
27 'test_xxd', scratch_dir)
28 response = ubman.run_command_list([ f'host bind 0 {xxd_data}',
29 'xxd host 0 hello'])
30
31 assert '00000000: 68 65 6c 6c 6f 20 77 6f 72 6c 64 0a 00 01 02 03 hello world.....\r\r\n' + \
32 '00000010: 04 05 ..' \
33 in response
34 except CalledProcessError as err:
35 pytest.skip('Preparing test_xxd image failed')
36 call('rm -f %s' % xxd_data, shell=True)
37 return
38 finally:
39 call('rm -rf %s' % scratch_dir, shell=True)
40 call('rm -f %s' % xxd_data, shell=True)