From c2d011f366583ea27bdba5d9f09f01be28cbc919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=BCnther?= Date: Wed, 4 Dec 2024 22:18:31 +0100 Subject: [PATCH] twister: fix shell prompt detection with VT100 colors disabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Device adapter strips all whitespace from output lines causing test failures when matching default shell prompt "uart:~$ " with trailing space. Update _handle_device_output to only strip line endings (\r\n) while preserving whitespace required for prompt detection. A testcase sample.pytest.shell.no_vt100 was added to verify prompt matching works with CONFIG_SHELL_VT100_COLORS disabled. Signed-off-by: Thomas Günther --- .../subsys/testsuite/pytest/shell/testcase.yaml | 14 ++++++++++++++ .../src/twister_harness/device/device_adapter.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/samples/subsys/testsuite/pytest/shell/testcase.yaml b/samples/subsys/testsuite/pytest/shell/testcase.yaml index 86b9314f4444..f256cd9df8f5 100644 --- a/samples/subsys/testsuite/pytest/shell/testcase.yaml +++ b/samples/subsys/testsuite/pytest/shell/testcase.yaml @@ -12,3 +12,17 @@ tests: - test_framework - pytest - shell + sample.pytest.shell.vt100_colors_off: + filter: CONFIG_SERIAL and dt_chosen_enabled("zephyr,shell-uart") + min_ram: 40 + harness: pytest + extra_configs: + - arch:posix:CONFIG_NATIVE_UART_0_ON_STDINOUT=y + - CONFIG_SHELL_VT100_COLORS=n + integration_platforms: + - native_sim + - qemu_cortex_m3 + tags: + - test_framework + - pytest + - shell diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/device/device_adapter.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/device/device_adapter.py index fd97972c74af..87ecac0f75a9 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/device/device_adapter.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/device/device_adapter.py @@ -240,7 +240,7 @@ def _handle_device_output(self) -> None: with open(self.handler_log_path, 'a+') as log_file: while self.is_device_running(): if self.is_device_connected(): - output = self._read_device_output().decode(errors='replace').strip() + output = self._read_device_output().decode(errors='replace').rstrip("\r\n") if output: self._device_read_queue.put(output) log_file.write(f'{output}\n')