Skip to content

Commit 27c0cfd

Browse files
henrikbrixandersenanangl
authored andcommitted
[nrf fromtree] tests: drivers: can: host: allow specifying context along with fixture
Allow specifying the python-can configuration context to use along with the "can" fixture. This opens up for specifying board-specific contexts in the twister hardware map file. Signed-off-by: Henrik Brix Andersen <[email protected]> (cherry picked from commit afb2791)
1 parent c53780b commit 27c0cfd

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

tests/drivers/can/host/README.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,17 @@ The Zephyr end of the CAN fixture can be configured as follows:
2828

2929
The host end of the CAN fixture can be configured through python-can. Available configuration
3030
options depend on the type of host CAN adapter used. The python-can library provides a lot of
31-
flexibility for configuration as decribed in the `python-can configuration`_ page. By default, the
32-
python-can configuration context is not specified, causing python-can to use the default
33-
configuration context. The context can be overridden using the ``--can-context`` test suite argument
34-
(see examples below).
31+
flexibility for configuration as decribed in the `python-can configuration`_ page, all centered
32+
around the concept of a configuration "context. The configuration context for this test suite can be
33+
configured as follows:
34+
35+
* By default, the python-can configuration context is not specified, causing python-can to use the
36+
default configuration context.
37+
* A specific configuration context can be provided along with the ``can`` fixture separated by a
38+
``:`` (i.e. specify fixture ``can:zcan0`` to use the ``zcan0`` python-can configuration context).
39+
* The configuration context can be overridden using the ``--can-context`` test suite argument
40+
(i.e. run ``twister`` with the ``--pytest-args=--can-context=zcan0`` argument to use the ``zcan0``
41+
python-can configuration context).
3542

3643
Building and Running
3744
********************
@@ -65,7 +72,7 @@ be launched using Twister:
6572

6673
.. code-block:: shell
6774
68-
west twister -v -p native_sim/native/64 -X can -T tests/drivers/can/host/ --pytest-args=--can-context=zcan0
75+
west twister -v -p native_sim/native/64 -X can:zcan0 -T tests/drivers/can/host/
6976
7077
After the test suite has completed, the virtual SocketCAN interface can be removed again:
7178

@@ -107,7 +114,7 @@ Twister. Below is an example for running on the :ref:`lpcxpresso55s36`:
107114

108115
.. code-block:: shell
109116
110-
west twister -v -p lpcxpresso55s36/lpc55s36 --device-testing --device-serial /dev/ttyACM0 -X can -T tests/drivers/can/host/ --pytest-args=--can-context=can0
117+
west twister -v -p lpcxpresso55s36/lpc55s36 --device-testing --device-serial /dev/ttyACM0 -X can:can0 -T tests/drivers/can/host/
111118
112119
After the test suite has completed, the SocketCAN interface can be brought down again:
113120

tests/drivers/can/host/pytest/conftest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ def pytest_addoption(parser) -> None:
2323
help='Configuration context to use for python-can (default: None)')
2424

2525
@pytest.fixture(name='context', scope='session')
26-
def fixture_context(request) -> str:
26+
def fixture_context(request, dut: DeviceAdapter) -> str:
2727
"""Return the name of the python-can configuration context to use."""
2828
ctx = request.config.getoption('--can-context')
29+
30+
if ctx is None:
31+
for fixture in dut.device_config.fixtures:
32+
if fixture.startswith('can:'):
33+
ctx = fixture.split(sep=':', maxsplit=1)[1]
34+
break
35+
2936
logger.info('using python-can configuration context "%s"', ctx)
3037
return ctx
3138

0 commit comments

Comments
 (0)