Skip to content

Commit 6a6512f

Browse files
committed
samples: echo_bot: use pytest to run test
Use pytest to verify sample. Signed-off-by: Anas Nashif <[email protected]>
1 parent 42c5bd8 commit 6a6512f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) 2023 Nordic Semiconductor ASA
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
import logging
6+
import pytest
7+
from twister_harness import DeviceAdapter
8+
import re
9+
10+
logger = logging.getLogger(__name__)
11+
12+
TESTDATA = [
13+
('zephyr', 'Echo: zephyr'),
14+
('console', 'Echo: console'),
15+
]
16+
@pytest.mark.parametrize('command,expected', TESTDATA)
17+
def test_echo_bot(dut: DeviceAdapter, command, expected):
18+
timeout = 10.0
19+
command_ext = f'{command}\n\n'
20+
regex_expected = f'.*{re.escape(expected)}'
21+
dut.clear_buffer()
22+
dut.write(command_ext.encode())
23+
lines: list[str] = []
24+
lines.extend(dut.readlines_until(regex=regex_expected, timeout=timeout, print_output=True))
25+
assert expected in lines, 'expected response not found'

samples/drivers/uart/echo_bot/sample.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ tests:
1010
filter: CONFIG_SERIAL and
1111
CONFIG_UART_INTERRUPT_DRIVEN and
1212
dt_chosen_enabled("zephyr,shell-uart")
13-
harness: keyboard
13+
harness: pytest

0 commit comments

Comments
 (0)