twister: pytest: Fix problems with no prompt in tests with shell

Only impacts on twister-pytest scenarios. Exec command is waiting for
the prompt message, but in some cases, e.g. after reseting the DUT, prompt
can be followed by another strings. Solution is to clear internal serial
buffer and to not request the prompt string before executing a command.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
This commit is contained in:
Grzegorz Chwierut 2023-09-19 15:07:21 +02:00 committed by Fabio Baltieri
commit 6c86af0331
2 changed files with 2 additions and 1 deletions

View file

@ -250,6 +250,7 @@ class HardwareAdapter(DeviceAdapter):
super()._clear_internal_resources()
self._serial_connection = None
self._serial_pty_proc = None
self._serial_buffer.clear()
@staticmethod
def _run_custom_script(script_path: str | Path, timeout: float) -> None:

View file

@ -57,7 +57,7 @@ class Shell:
timeout = timeout or self.base_timeout
command_ext = f'{command}\n\n'
regex_prompt = re.escape(self.prompt)
regex_command = f'{regex_prompt}.*{command}'
regex_command = f'.*{command}'
self._device.clear_buffer()
self._device.write(command_ext.encode())
lines: list[str] = []