[PATCH 0/2] test: unit test for semihosting

* Provide a unit test for semihosting testing, reading and writing a file.
* Enable semihosting on qemu_arm64_defconfig. Semihosting is already enabled for the board in u-boot-testhooks.
Heinrich Schuchardt (2): configs: enable SEMIHOSTING on qemu_arm64_defconfig test: unit test for semihosting
configs/qemu_arm64_defconfig | 1 + test/py/tests/test_semihosting/conftest.py | 23 +++++++++++++ test/py/tests/test_semihosting/test_hostfs.py | 33 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 test/py/tests/test_semihosting/conftest.py create mode 100644 test/py/tests/test_semihosting/test_hostfs.py

We need a platform on which we can test our semihosting code.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- configs/qemu_arm64_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/qemu_arm64_defconfig b/configs/qemu_arm64_defconfig index 94bd966784..2080f5ee9a 100644 --- a/configs/qemu_arm64_defconfig +++ b/configs/qemu_arm64_defconfig @@ -71,4 +71,5 @@ CONFIG_TPM2_MMIO=y CONFIG_USB=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_PCI=y +CONFIG_SEMIHOSTING=y CONFIG_TPM=y

On 7/31/23 16:01, Heinrich Schuchardt wrote:
We need a platform on which we can test our semihosting code.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
configs/qemu_arm64_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/qemu_arm64_defconfig b/configs/qemu_arm64_defconfig index 94bd966784..2080f5ee9a 100644 --- a/configs/qemu_arm64_defconfig +++ b/configs/qemu_arm64_defconfig @@ -71,4 +71,5 @@ CONFIG_TPM2_MMIO=y CONFIG_USB=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_PCI=y +CONFIG_SEMIHOSTING=y CONFIG_TPM=y
Reviewed-by: Sean Anderson sean.anderson@seco.com

On Mon, Jul 31, 2023 at 10:01:20PM +0200, Heinrich Schuchardt wrote:
We need a platform on which we can test our semihosting code.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com Reviewed-by: Sean Anderson sean.anderson@seco.com
Applied to u-boot/next, thanks!

Provide a unit test for semihosting testing reading and writing a file.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- test/py/tests/test_semihosting/conftest.py | 23 +++++++++++++ test/py/tests/test_semihosting/test_hostfs.py | 33 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 test/py/tests/test_semihosting/conftest.py create mode 100644 test/py/tests/test_semihosting/test_hostfs.py
diff --git a/test/py/tests/test_semihosting/conftest.py b/test/py/tests/test_semihosting/conftest.py new file mode 100644 index 0000000000..b00d8f4ea9 --- /dev/null +++ b/test/py/tests/test_semihosting/conftest.py @@ -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) diff --git a/test/py/tests/test_semihosting/test_hostfs.py b/test/py/tests/test_semihosting/test_hostfs.py new file mode 100644 index 0000000000..9c5ad0dc9f --- /dev/null +++ b/test/py/tests/test_semihosting/test_hostfs.py @@ -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

On 7/31/23 16:01, Heinrich Schuchardt wrote:
Provide a unit test for semihosting testing reading and writing a file.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
test/py/tests/test_semihosting/conftest.py | 23 +++++++++++++ test/py/tests/test_semihosting/test_hostfs.py | 33 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 test/py/tests/test_semihosting/conftest.py create mode 100644 test/py/tests/test_semihosting/test_hostfs.py
diff --git a/test/py/tests/test_semihosting/conftest.py b/test/py/tests/test_semihosting/conftest.py new file mode 100644 index 0000000000..b00d8f4ea9 --- /dev/null +++ b/test/py/tests/test_semihosting/conftest.py @@ -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)
diff --git a/test/py/tests/test_semihosting/test_hostfs.py b/test/py/tests/test_semihosting/test_hostfs.py new file mode 100644 index 0000000000..9c5ad0dc9f --- /dev/null +++ b/test/py/tests/test_semihosting/test_hostfs.py @@ -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
Reviewed-by: Sean Anderson sean.anderson@seco.com

On Mon, Jul 31, 2023 at 10:01:21PM +0200, Heinrich Schuchardt wrote:
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
Applied to u-boot/next, thanks!
participants (3)
-
Heinrich Schuchardt
-
Sean Anderson
-
Tom Rini