Part 1
요약·해설
Twister, pytest-twister-harness와 두 shell test의 전체 output을 설명합니다.
Twister
pytest
shell
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
3729155D1EDF1982EAF428343827E92CD90EC72A2D187BA8995D124D70715392
.. zephyr:code-sample:: pytest_shell
:name: Pytest shell application testing
Execute pytest tests against the Zephyr shell.
Overview
********
The sample project illustrates usage of pytest framework integrated with
Twister test runner.
A simple application provides basic Zephyr shell interface. Twister builds it
and then calls pytest in subprocess which runs tests from
``pytest/test_shell.py`` file. The first test verifies valid response for
``help`` command, second one verifies if application is able to return
information about used kernel version. Both tests use ``shell`` fixture, which
is defined in ``pytest-twister-harness`` plugin. More information about plugin
can be found :ref:`here <integration_with_pytest>`.
Requirements
************
Board (hardware, ``native_sim`` or ``QEMU``) with UART console.
Building and Running
********************
Build and run sample by Twister:
.. code-block:: console
$ ./scripts/twister -vv --platform native_sim -T samples/subsys/testsuite/pytest/shell
Sample Output
=============
.. code-block:: console
...
samples/subsys/testsuite/pytest/shell/pytest/test_shell.py::test_shell_print_help
INFO: send "help" command
DEBUG: #: uart:~$ help
DEBUG: #: Please press the <Tab> button to see all available commands.
DEBUG: #: You can also use the <Tab> button to prompt or auto-complete all commands or its subcommands.
DEBUG: #: You can try to call commands with <-h> or <--help> parameter for more information.
DEBUG: #: Shell supports following meta-keys:
DEBUG: #: Ctrl + (a key from: abcdefklnpuw)
DEBUG: #: Alt + (a key from: bf)
DEBUG: #: Please refer to shell documentation for more details.
DEBUG: #: Available commands:
DEBUG: #: clear :Clear screen.
DEBUG: #: device :Device commands
DEBUG: #: devmem :Read/write physical memory
DEBUG: #: Usage:
DEBUG: #: Read memory at address with optional width:
DEBUG: #: devmem address [width]
DEBUG: #: Write memory at address with mandatory width and value:
DEBUG: #: devmem address <width> <value>
DEBUG: #: help :Prints the help message.
DEBUG: #: history :Command history.
DEBUG: #: kernel :Kernel commands
DEBUG: #: rem :Ignore lines beginning with 'rem '
DEBUG: #: resize :Console gets terminal screen size or assumes default in case the
DEBUG: #: readout fails. It must be executed after each terminal width change
DEBUG: #: to ensure correct text display.
DEBUG: #: retval :Print return value of most recent command
DEBUG: #: shell :Useful, not Unix-like shell commands.
DEBUG: #: uart:~$
INFO: response is valid
PASSED
samples/subsys/testsuite/pytest/shell/pytest/test_shell.py::test_shell_print_version
INFO: send "kernel version" command
DEBUG: #: uart:~$ kernel version
DEBUG: #: Zephyr version 3.5.99
DEBUG: #: uart:~$
INFO: response is valid
PASSED
...
Part 3
한국어 전문 번역
개요
Twister test runner와 통합된 pytest framework 사용법을 보여 주는 sample project입니다.
간단한 application이 기본 Zephyr shell interface를 제공합니다. Twister가 application을 build한 뒤 subprocess로 pytest를 호출하고 pytest/test_shell.py의 test를 실행합니다.
첫 test는 help command가 올바른 response를 반환하는지 확인하고, 두 번째 test는 application이 사용 중인 kernel version 정보를 반환할 수 있는지 확인합니다. 두 test 모두 pytest-twister-harness plugin이 정의한 shell fixture를 사용합니다.
요구 사항
UART console이 있는 hardware board, native_sim 또는 QEMU target이 필요합니다.
빌드 및 실행
다음 command로 Twister를 verbose mode에서 실행해 native_sim용 sample을 build하고 test합니다.
$ ./scripts/twister -vv --platform native_sim -T samples/subsys/testsuite/pytest/shell
샘플 출력
test_shell_print_help는 shell에 help를 보내 usage, Tab completion, meta-key와 available command 목록이 포함된 response를 확인합니다. test_shell_print_version은 kernel version을 보내 Zephyr version 문자열을 확인합니다. 두 test는 각각 response is valid와 PASSED로 끝납니다.
...
samples/subsys/testsuite/pytest/shell/pytest/test_shell.py::test_shell_print_help
INFO: send "help" command
DEBUG: #: uart:~$ help
DEBUG: #: Please press the <Tab> button to see all available commands.
DEBUG: #: You can also use the <Tab> button to prompt or auto-complete all commands or its subcommands.
DEBUG: #: You can try to call commands with <-h> or <--help> parameter for more information.
DEBUG: #: Shell supports following meta-keys:
DEBUG: #: Ctrl + (a key from: abcdefklnpuw)
DEBUG: #: Alt + (a key from: bf)
DEBUG: #: Please refer to shell documentation for more details.
DEBUG: #: Available commands:
DEBUG: #: clear :Clear screen.
DEBUG: #: device :Device commands
DEBUG: #: devmem :Read/write physical memory
DEBUG: #: Usage:
DEBUG: #: Read memory at address with optional width:
DEBUG: #: devmem address [width]
DEBUG: #: Write memory at address with mandatory width and value:
DEBUG: #: devmem address <width> <value>
DEBUG: #: help :Prints the help message.
DEBUG: #: history :Command history.
DEBUG: #: kernel :Kernel commands
DEBUG: #: rem :Ignore lines beginning with 'rem '
DEBUG: #: resize :Console gets terminal screen size or assumes default in case the
DEBUG: #: readout fails. It must be executed after each terminal width change
DEBUG: #: to ensure correct text display.
DEBUG: #: retval :Print return value of most recent command
DEBUG: #: shell :Useful, not Unix-like shell commands.
DEBUG: #: uart:~$
INFO: response is valid
PASSED
samples/subsys/testsuite/pytest/shell/pytest/test_shell.py::test_shell_print_version
INFO: send "kernel version" command
DEBUG: #: uart:~$ kernel version
DEBUG: #: Zephyr version 3.5.99
DEBUG: #: uart:~$
INFO: response is valid
PASSED
...
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.