Skip to content

Commit 5040028

Browse files
nordic-baminordic-piks
authored andcommitted
tests: drivers: uart: Do not use 'readlines' in test execution
Remove usage of the biuld in 'readlines' DeviceAdapter method. Signed-off-by: Bartosz Miller <[email protected]>
1 parent ed8ceb2 commit 5040028

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

tests/drivers/uart/uart_passtrough/pytest/serial_port.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SerialPort:
1919
8 data bits, 1 stop bit, no parity
2020
"""
2121

22-
def __init__(self, serial_port: str, baudrate: int, timeout: int = 15):
22+
def __init__(self, serial_port: str, baudrate: int, timeout: int = 5):
2323
"""
2424
:param serial_port: full name of the serial device port
2525
:param baudrate: buadrate [bps]
@@ -75,20 +75,21 @@ def send(
7575
raise OSError("Serial port is closed")
7676

7777
try:
78-
time.sleep(0.25)
7978
self.serial_port.write_timeout = self._timeout
8079
logger.info(f"[{self.serial_port.port}] Serial --> {message}")
8180
line_termination: str = "\n" if add_line_termination else ""
8281
self.serial_port.write((message + line_termination).encode())
82+
time.sleep(0.25)
8383
if get_response:
84-
start = time.time()
85-
while (self.serial_port.in_waiting == 0) and (time.time() - start < self._timeout):
86-
# no data in buffer yet
87-
time.sleep(0.1)
88-
while (self.serial_port.in_waiting > 0) and (time.time() - start < self._timeout):
89-
time.sleep(0.1)
90-
response += self.serial_port.read_all().decode()
91-
logger.info(f"Serial <-- {response}")
84+
start = time.perf_counter()
85+
while time.perf_counter() - start < self._timeout:
86+
if self.serial_port.in_waiting == 0:
87+
time.sleep(0.1)
88+
else:
89+
response += self.serial_port.read_all().decode()
90+
logger.info(f"Serial <-- {response}")
91+
if response:
92+
break
9293
return response
9394

9495
except serial.SerialTimeoutException as exc:

tests/drivers/uart/uart_passtrough/pytest/test_passtrough.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def test_uart_passtrough(dut: DeviceAdapter):
4242
then send message from 'passtrough' UART to 'console 'UART' and verify it.
4343
"""
4444

45-
dut.readlines_until(regex="Ready", print_output=True, timeout=2)
4645
dut.disconnect()
46+
time.sleep(1)
4747
console_serial_port: SerialPort = SerialPort(
4848
serial_port=dut.device_config.serial, baudrate=dut.device_config.baud
4949
)

0 commit comments

Comments
 (0)