twister: pytest: Fix shell fixture

On the hardware, after booting up the device, on the
console might appear additional logs after receiving first
prompt. Wait and clear the buffer to avoid unexpected
messages when verifying output.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
This commit is contained in:
Grzegorz Chwierut 2024-01-31 17:05:00 +01:00 committed by David Leach
parent 34cb22e919
commit 8f18094c62
2 changed files with 8 additions and 3 deletions

View file

@ -6,6 +6,7 @@ import logging
from typing import Generator, Type
import pytest
import time
from twister_harness.device.device_adapter import DeviceAdapter
from twister_harness.device.factory import DeviceFactory
@ -58,7 +59,13 @@ def shell(dut: DeviceAdapter) -> Shell:
"""Return ready to use shell interface"""
shell = Shell(dut, timeout=20.0)
logger.info('Wait for prompt')
assert shell.wait_for_prompt()
if not shell.wait_for_prompt():
pytest.fail('Prompt not found')
if dut.device_config.type == 'hardware':
# after booting up the device, there might appear additional logs
# after first prompt, so we need to wait and clear the buffer
time.sleep(0.5)
dut.clear_buffer()
return shell

View file

@ -45,8 +45,6 @@ class Shell:
continue
if self.prompt in line:
logger.debug('Got prompt')
time.sleep(0.05)
self._device.clear_buffer()
return True
return False