mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-19 11:24:42 +00:00
test: unit test for semihosting
Provide a unit test for semihosting testing reading and writing a file. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Sean Anderson <sean.anderson@seco.com>
This commit is contained in:
parent
cf159fe0b6
commit
f7ee9f3d36
2 changed files with 56 additions and 0 deletions
23
test/py/tests/test_semihosting/conftest.py
Normal file
23
test/py/tests/test_semihosting/conftest.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
"""Fixture for semihosting command test
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
@pytest.fixture(scope='session')
|
||||||
|
def semihosting_data(u_boot_config):
|
||||||
|
"""Set up a file system to be used in semihosting tests
|
||||||
|
|
||||||
|
Args:
|
||||||
|
u_boot_config -- U-Boot configuration.
|
||||||
|
"""
|
||||||
|
image_path = u_boot_config.persistent_data_dir + '/semihosting.txt'
|
||||||
|
|
||||||
|
with open(image_path, 'w', encoding = 'utf-8') as file:
|
||||||
|
file.write('Das U-Boot\n')
|
||||||
|
|
||||||
|
yield image_path
|
||||||
|
|
||||||
|
os.remove(image_path)
|
33
test/py/tests/test_semihosting/test_hostfs.py
Normal file
33
test/py/tests/test_semihosting/test_hostfs.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
# SPDX-License-Identifier: GPL-2.0+
|
||||||
|
|
||||||
|
""" Unit test for semihosting
|
||||||
|
"""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
@pytest.mark.buildconfigspec('semihosting')
|
||||||
|
def test_semihosting_hostfs(u_boot_console, semihosting_data):
|
||||||
|
""" Unit test for semihosting
|
||||||
|
|
||||||
|
Args:
|
||||||
|
u_boot_console -- U-Boot console
|
||||||
|
semihosting_data -- Path to the disk image used for testing.
|
||||||
|
"""
|
||||||
|
response = u_boot_console.run_command(
|
||||||
|
f'load hostfs - $loadaddr {semihosting_data}')
|
||||||
|
assert '11 bytes read' in response
|
||||||
|
|
||||||
|
response = u_boot_console.run_command(
|
||||||
|
'crc32 $loadaddr $filesize')
|
||||||
|
assert '==> 60cfccfc' in response
|
||||||
|
|
||||||
|
u_boot_console.run_command(
|
||||||
|
f'save hostfs - $loadaddr {semihosting_data} 11 11')
|
||||||
|
|
||||||
|
response = u_boot_console.run_command(
|
||||||
|
f'load hostfs - $loadaddr {semihosting_data} 4 13')
|
||||||
|
assert '4 bytes read' in response
|
||||||
|
|
||||||
|
response = u_boot_console.run_command(
|
||||||
|
'crc32 $loadaddr $filesize')
|
||||||
|
assert '==> e29063ea' in response
|
Loading…
Add table
Reference in a new issue