ci: twai runner setup

This commit is contained in:
igor.udot
2026-06-15 14:28:26 +08:00
committed by wanckl
parent d757b5d2b7
commit b94ebf6d97
7 changed files with 25 additions and 21 deletions

View File

@@ -1,8 +1,9 @@
# SPDX-FileCopyrightText: 2021-2026 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: CC0-1.0
import logging
import os
import subprocess
from time import sleep
import time
import pytest
from can import Bus
@@ -26,19 +27,23 @@ def test_twai_self(dut: Dut) -> None:
dut.run_all_single_board_cases(group='twai-loop-back')
can_env = os.getenv('CAN_PORT', 'can0')
print(f'CAN_PORT={can_env}')
@pytest.fixture(name='socket_can')
def fixture_create_socket_can() -> Bus:
# Set up the socket CAN with the bitrate
start_command = 'sudo ip link set can0 up type can bitrate 250000'
stop_command = 'sudo ip link set can0 down'
start_command = f'sudo ip link set {can_env} up type can bitrate 250000'
stop_command = f'sudo ip link set {can_env} down'
subprocess.run(start_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
bus = Bus(interface='socketcan', channel='can0', bitrate=250000)
bus = Bus(interface='socketcan', channel=f'{can_env}', bitrate=250000)
yield bus # test invoked here
bus.shutdown()
subprocess.run(stop_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
@pytest.mark.twai_std
@pytest.mark.twai_adapter
@pytest.mark.parametrize(
'config',
[
@@ -56,7 +61,7 @@ def test_twai_listen_only(dut: Dut, socket_can: Bus) -> None:
dut.write('"twai_listen_only"')
# wait the DUT to block at the receive API
sleep(0.03)
time.sleep(0.03)
message = Message(
arbitration_id=0x123,
@@ -67,7 +72,7 @@ def test_twai_listen_only(dut: Dut, socket_can: Bus) -> None:
dut.expect_unity_test_output()
@pytest.mark.twai_std
@pytest.mark.twai_adapter
@pytest.mark.parametrize(
'config',
[
@@ -84,11 +89,15 @@ def test_twai_remote_request(dut: Dut, socket_can: Bus) -> None:
# TEST_CASE("twai_remote_request", "[twai]")
dut.write('"twai_remote_request"')
while True:
deadline = time.time() + 2.0
req = None
while time.time() < deadline:
req = socket_can.recv(timeout=0.2)
# wait for the remote request frame
if req is not None and req.is_remote_frame:
break
if req is None:
raise Exception('Remote frame not received')
logging.info(f'Received message: {req}')

View File

@@ -5,8 +5,7 @@ menu "Example Configuration"
config EXAMPLE_TX_GPIO_NUM
int "TX GPIO number"
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
default 21 if IDF_TARGET_ESP32
default 0
default 4
help
This option selects the GPIO pin used for the TX signal. Connect the
TX signal to your transceiver.
@@ -14,8 +13,7 @@ menu "Example Configuration"
config EXAMPLE_RX_GPIO_NUM
int "RX GPIO number"
range ENV_GPIO_RANGE_MIN ENV_GPIO_IN_RANGE_MAX
default 22 if IDF_TARGET_ESP32
default 2
default 5
help
This option selects the GPIO pin used for the RX signal. Connect the
RX signal to your transceiver.

View File

@@ -5,7 +5,7 @@ from pytest_embedded import Dut
from pytest_embedded_idf.utils import idf_parametrize
@pytest.mark.twai_transceiver
@pytest.mark.twai_adapter
@idf_parametrize('target', ['esp32'], indirect=['target'])
def test_twai_alert_recovery_example(dut: Dut) -> None:
dut.expect_exact('TWAI Alert and Recovery: Driver installed')

View File

@@ -5,8 +5,7 @@ menu "Example Configuration"
config EXAMPLE_TX_GPIO_NUM
int "TX GPIO number"
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
default 21 if IDF_TARGET_ESP32
default 0
default 4
help
This option selects the GPIO pin used for the TX signal. Connect the
TX signal to your transceiver.
@@ -14,8 +13,7 @@ menu "Example Configuration"
config EXAMPLE_RX_GPIO_NUM
int "RX GPIO number"
range ENV_GPIO_RANGE_MIN ENV_GPIO_IN_RANGE_MAX
default 22 if IDF_TARGET_ESP32
default 2
default 5
help
This option selects the GPIO pin used for the RX signal. Connect the
RX signal to your transceiver.

View File

@@ -5,7 +5,7 @@ from pytest_embedded import Dut
from pytest_embedded_idf.utils import idf_parametrize
@pytest.mark.twai_transceiver
@pytest.mark.twai_adapter
@idf_parametrize('target', ['esp32'], indirect=['target'])
def test_twai_self_test_example(dut: Dut) -> None:
dut.expect_exact('TWAI Self Test: Driver installed')

View File

@@ -34,7 +34,7 @@ no_runner_tags:
- esp32p4,esp32p4_eco4,ram_app
- esp32p4,esp32p4_eco4,sdcard
- esp32p4,esp32p4_eco4,sdcard_spimode
- esp32p4,esp32p4_eco4,twai_std
- esp32p4,esp32p4_eco4,twai_adapter
- esp32p4,esp32p4_eco4,usb_device
- esp32p4,esp32p4_eco4,usb_host_flash_disk
- esp32p4,jtag

View File

@@ -72,7 +72,6 @@ ENV_MARKERS = {
'flash_multi': 'Multiple flash chips tests',
'psram': 'Chip has 4-line psram',
'ir_transceiver': 'runners with a pair of IR transmitter and receiver',
'twai_transceiver': 'runners with a TWAI PHY transceiver',
'flash_encryption_wifi_high_traffic': 'Flash Encryption runners with wifi high traffic support',
'ethernet': 'ethernet runner',
'ethernet_flash_8m': 'ethernet runner with 8mb flash',
@@ -122,7 +121,7 @@ ENV_MARKERS = {
'sdio_master_slave': 'Test sdio multi board, esp32+esp32',
'sdio_multidev_32_c6': 'Test sdio multi board, esp32+esp32c6',
'usj_device': 'Test usb_serial_jtag and usb_serial_jtag is used as serial only (not console)',
'twai_std': 'twai runner with all twai supported targets connect to usb-can adapter',
'twai_adapter': 'runner with multiple twai_std',
'lp_i2s': 'lp_i2s runner tested with hp_i2s',
'ram_app': 'ram_app runners',
'esp32c3eco7': 'esp32c3 major version(v1.1) chips',