Skip to content

Commit 42c5bd8

Browse files
committed
samples: console: use pytest for basic verification of sample
Use pytest to run the tests expected input on the console. Signed-off-by: Anas Nashif <[email protected]>
1 parent c99868a commit 42c5bd8

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 is great', 'line: Zephyr is great'),
14+
('This is a test', 'line: This is a test'),
15+
]
16+
@pytest.mark.parametrize('command,expected', TESTDATA)
17+
def test_getline(dut: DeviceAdapter, command, expected):
18+
command_ext = f'{command}\n\n'
19+
regex_expected = f'.*{re.escape(expected)}'
20+
dut.clear_buffer()
21+
dut.write(command_ext.encode())
22+
lines: list[str] = []
23+
lines.extend(dut.readlines_until(regex=regex_expected, timeout=10.0, print_output=True))
24+
assert expected in lines, 'expected response not found'

samples/subsys/console/getline/sample.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ tests:
66
- mps2/an385
77
filter: CONFIG_UART_CONSOLE and CONFIG_SERIAL_SUPPORT_INTERRUPT
88
tags: console
9-
harness: keyboard
9+
harness: pytest

0 commit comments

Comments
 (0)