Merge branch 'ci/twai-runner-migration' into 'master'

ci: twai runner setup

See merge request espressif/esp-idf!49651
This commit is contained in:
Fu Hanxi
2026-06-17 10:11:57 +02:00
5 changed files with 56 additions and 40 deletions
@@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import os
import subprocess
import time
@@ -11,6 +11,9 @@ from pytest_embedded import Dut
from pytest_embedded_idf.utils import idf_parametrize
from pytest_embedded_idf.utils import soc_filtered_targets
can_env = os.getenv('CAN_PORT', 'can0')
print(f'CAN_PORT={can_env}')
# ---------------------------------------------------------------------------
# Loop Back Tests
@@ -50,26 +53,24 @@ def esp_enter_flash_mode(dut: Dut) -> None:
@pytest.fixture(name='socket_can')
def fixture_create_socket_can() -> Bus:
# Set up the socket CAN with the bitrate
start_command = 'sudo -n ip link set can0 up type can bitrate 250000'
stop_command = 'sudo -n ip link set can0 down'
status_command = 'sudo -n ip -details link show can0'
start_command = f'sudo -n ip link set {can_env} up type can bitrate 250000'
stop_command = f'sudo -n ip link set {can_env} down'
status_command = f'sudo -n ip -details link show {can_env}'
try:
result = subprocess.run(status_command, shell=True, capture_output=True, text=True)
if result.returncode != 0:
raise Exception('CAN interface "can0" not found')
raise Exception(f'CAN interface "{can_env}" not found')
if 'UP' in result.stdout: # Close the bus anyway if it is already up
subprocess.run(stop_command, shell=True, capture_output=True, text=True)
subprocess.run(start_command, shell=True, capture_output=True, text=True)
time.sleep(0.5)
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()
except Exception as e:
pytest.skip(f'Open usb-can bus Error: {str(e)}')
finally:
subprocess.run(stop_command, shell=True, capture_output=True, text=True)
@@ -77,7 +78,7 @@ def fixture_create_socket_can() -> Bus:
# ---------------------------------------------------------------------------
# Interactive Tests
# ---------------------------------------------------------------------------
@pytest.mark.twai_std
@pytest.mark.twai_adapter
@pytest.mark.temp_skip_ci(targets=['esp32s31'], reason='no runner')
@pytest.mark.parametrize('config', ['release'], indirect=True)
@idf_parametrize('target', soc_filtered_targets('SOC_TWAI_SUPPORTED == 1'), indirect=['target'])
@@ -99,7 +100,7 @@ def test_driver_twai_listen_only(dut: Dut, socket_can: Bus) -> None:
esp_enter_flash_mode(dut)
@pytest.mark.twai_std
@pytest.mark.twai_adapter
@pytest.mark.temp_skip_ci(targets=['esp32s31'], reason='no runner')
@pytest.mark.parametrize('config', ['release'], indirect=True)
@idf_parametrize('target', soc_filtered_targets('SOC_TWAI_SUPPORTED == 1'), indirect=['target'])
@@ -109,10 +110,16 @@ def test_driver_twai_remote_request(dut: Dut, socket_can: Bus) -> None:
dut.write('"twai_remote_request"')
print('Waiting remote frame ...')
while True:
deadline = time.time() + 5.0
req = None
while time.time() < deadline:
req = socket_can.recv(timeout=0.2)
if req is not None and req.is_remote_frame:
break
if req is None:
raise Exception('Remote frame not received')
print(f'USB Socket CAN Received: {req}')
reply = Message(