zephyr/scripts/pylib/pytest-twister-harness
Mike Szczys 7eaca455fa twister: fix serial connection for flash_before
The --flash-before flag allows devices to be flashed before the serial
connection is established. However, the implementation was incomplete and
only worked if the port address already existed at the start of the run.
This is incompatible with devices that implement the USB in software
(eg: USB-CDC).

This commit fixes the implementation to delay setting up the connection
until after the device is flashed, and to retry the connection for two
seconds after flashing to give the device time to enumerate as a USB
device.

Signed-off-by: Mike Szczys <mike@golioth.io>
2024-05-22 21:39:13 -04:00
..
src/twister_harness twister: fix serial connection for flash_before 2024-05-22 21:39:13 -04:00
tests twister: pytest: use runner_params from hardware map YAML file 2024-04-20 13:45:44 -04:00
.gitignore scripts: add pytest plugin 2023-05-26 13:52:15 -04:00
pyproject.toml scripts: add pytest plugin 2023-05-26 13:52:15 -04:00
README.rst hwmv2: Introduce Hardware model version 2 and convert devices 2024-03-02 16:56:33 -05:00
setup.cfg scripts: add pytest plugin 2023-05-26 13:52:15 -04:00
setup.py scripts: add pytest plugin 2023-05-26 13:52:15 -04:00

==============
Pytest Twister harness
==============

Installation
------------

If you plan to use this plugin with Twister, then you don't need to install it
separately by pip. When Twister uses this plugin for pytest tests, it updates
`PYTHONPATH` variable, and then extends pytest command by
`-p twister_harness.plugin` argument.


Usage
-----

Run exemplary test shell application by Twister:

.. code-block:: sh

  cd ${ZEPHYR_BASE}

  # native_sim & QEMU
  ./scripts/twister -p native_sim -p qemu_x86 -T samples/subsys/testsuite/pytest/shell

  # hardware
  ./scripts/twister -p nrf52840dk/nrf52840 --device-testing --device-serial /dev/ttyACM0 -T samples/subsys/testsuite/pytest/shell

or build shell application by west and call pytest directly:

.. code-block:: sh

  export PYTHONPATH=${ZEPHYR_BASE}/scripts/pylib/pytest-twister-harness/src:${PYTHONPATH}

  cd ${ZEPHYR_BASE}/samples/subsys/testsuite/pytest/shell

  # native_sim
  west build -p -b native_sim -- -DCONFIG_NATIVE_UART_0_ON_STDINOUT=y
  pytest --twister-harness --device-type=native --build-dir=build -p twister_harness.plugin

  # QEMU
  west build -p -b qemu_x86 -- -DQEMU_PIPE=qemu-fifo
  pytest --twister-harness --device-type=qemu --build-dir=build -p twister_harness.plugin

  # hardware
  west build -p -b nrf52840dk/nrf52840
  pytest --twister-harness --device-type=hardware --device-serial=/dev/ttyACM0 --build-dir=build -p twister_harness.plugin