From b94ebf6d97ac65a2c3e738056a3fcac7ffdcc322 Mon Sep 17 00:00:00 2001 From: "igor.udot" Date: Mon, 15 Jun 2026 14:28:26 +0800 Subject: [PATCH] ci: twai runner setup --- .../driver/test_apps/twai/pytest_twai.py | 25 +++++++++++++------ .../main/Kconfig.projbuild | 6 ++--- .../pytest_twai_alert_recovery_example.py | 2 +- .../twai_self_test/main/Kconfig.projbuild | 6 ++--- .../pytest_twai_self_test_example.py | 2 +- ..._generate_test_child_pipeline_warnings.yml | 2 +- tools/ci/idf_pytest/constants.py | 3 +-- 7 files changed, 25 insertions(+), 21 deletions(-) diff --git a/components/driver/test_apps/twai/pytest_twai.py b/components/driver/test_apps/twai/pytest_twai.py index 688ba267e72..540ea0f5dda 100644 --- a/components/driver/test_apps/twai/pytest_twai.py +++ b/components/driver/test_apps/twai/pytest_twai.py @@ -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}') diff --git a/examples/peripherals/twai/twai_alert_and_recovery/main/Kconfig.projbuild b/examples/peripherals/twai/twai_alert_and_recovery/main/Kconfig.projbuild index 1688672cec3..6468f064425 100644 --- a/examples/peripherals/twai/twai_alert_and_recovery/main/Kconfig.projbuild +++ b/examples/peripherals/twai/twai_alert_and_recovery/main/Kconfig.projbuild @@ -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. diff --git a/examples/peripherals/twai/twai_alert_and_recovery/pytest_twai_alert_recovery_example.py b/examples/peripherals/twai/twai_alert_and_recovery/pytest_twai_alert_recovery_example.py index d2f915df17a..8d41cd0350f 100644 --- a/examples/peripherals/twai/twai_alert_and_recovery/pytest_twai_alert_recovery_example.py +++ b/examples/peripherals/twai/twai_alert_and_recovery/pytest_twai_alert_recovery_example.py @@ -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') diff --git a/examples/peripherals/twai/twai_self_test/main/Kconfig.projbuild b/examples/peripherals/twai/twai_self_test/main/Kconfig.projbuild index 1688672cec3..6468f064425 100644 --- a/examples/peripherals/twai/twai_self_test/main/Kconfig.projbuild +++ b/examples/peripherals/twai/twai_self_test/main/Kconfig.projbuild @@ -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. diff --git a/examples/peripherals/twai/twai_self_test/pytest_twai_self_test_example.py b/examples/peripherals/twai/twai_self_test/pytest_twai_self_test_example.py index 85981e80f34..76df978ec4a 100644 --- a/examples/peripherals/twai/twai_self_test/pytest_twai_self_test_example.py +++ b/examples/peripherals/twai/twai_self_test/pytest_twai_self_test_example.py @@ -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') diff --git a/tools/ci/dynamic_pipelines/templates/known_generate_test_child_pipeline_warnings.yml b/tools/ci/dynamic_pipelines/templates/known_generate_test_child_pipeline_warnings.yml index 2beed67c7b9..9bc4e9cc445 100644 --- a/tools/ci/dynamic_pipelines/templates/known_generate_test_child_pipeline_warnings.yml +++ b/tools/ci/dynamic_pipelines/templates/known_generate_test_child_pipeline_warnings.yml @@ -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 diff --git a/tools/ci/idf_pytest/constants.py b/tools/ci/idf_pytest/constants.py index 683428bf939..35bf1eb20cb 100644 --- a/tools/ci/idf_pytest/constants.py +++ b/tools/ci/idf_pytest/constants.py @@ -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',