mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
ci: twai runner setup
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
import os
|
||||
import os.path
|
||||
import subprocess
|
||||
|
||||
@@ -8,23 +9,23 @@ from can import Bus
|
||||
from can import Message
|
||||
from pytest_embedded_idf import IdfDut
|
||||
|
||||
can_env = os.getenv('CAN_PORT', 'can0')
|
||||
print(f'CAN_PORT={can_env}')
|
||||
|
||||
|
||||
# Socket CAN fixture
|
||||
@pytest.fixture(name='socket_can')
|
||||
def fixture_create_socket_can() -> Bus:
|
||||
start_command = 'sudo ip link set can0 up type can bitrate 1000000'
|
||||
stop_command = 'sudo ip link set can0 down'
|
||||
try:
|
||||
subprocess.run(start_command, shell=True, capture_output=True, text=True)
|
||||
except Exception as e:
|
||||
print(f'Open bus Error: {e}')
|
||||
bus = Bus(interface='socketcan', channel='can0', bitrate=1000000)
|
||||
start_command = f'sudo ip link set {can_env} up type can bitrate 1000000'
|
||||
stop_command = f'sudo ip link set {can_env} down'
|
||||
subprocess.run(start_command, shell=True, capture_output=True, text=True)
|
||||
bus = Bus(interface='socketcan', channel=f'{can_env}', bitrate=1000000)
|
||||
yield bus # test invoked here
|
||||
bus.shutdown()
|
||||
subprocess.run(stop_command, shell=True, capture_output=True, text=True)
|
||||
|
||||
|
||||
@pytest.mark.twai_std
|
||||
@pytest.mark.twai_adapter
|
||||
@pytest.mark.parametrize('count', [2], indirect=True)
|
||||
@pytest.mark.timeout(120)
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -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
|
||||
from collections.abc import Generator
|
||||
@@ -18,6 +18,9 @@ from pytest_embedded_idf.utils import soc_filtered_targets
|
||||
# Constants / Helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
can_env = os.getenv('CAN_PORT', 'can0')
|
||||
print(f'CAN_PORT={can_env}')
|
||||
|
||||
PROMPTS = ['twai>']
|
||||
|
||||
# Hardware configuration
|
||||
@@ -253,7 +256,7 @@ class TwaiTestHelper:
|
||||
class CanBusManager:
|
||||
"""CAN bus manager for external hardware tests"""
|
||||
|
||||
def __init__(self, interface: str = 'can0'):
|
||||
def __init__(self, interface: str = can_env):
|
||||
self.interface = interface
|
||||
self.bus: can.Bus | None = None
|
||||
|
||||
@@ -280,8 +283,6 @@ class CanBusManager:
|
||||
|
||||
self.bus = can.Bus(interface='socketcan', channel=self.interface)
|
||||
yield self.bus
|
||||
except Exception as e:
|
||||
pytest.skip(f'CAN interface not available: {str(e)}')
|
||||
finally:
|
||||
if self.bus:
|
||||
self.bus.shutdown()
|
||||
@@ -607,7 +608,7 @@ def test_twai_utils_range_filters(twai: TwaiTestHelper) -> None:
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.mark.twai_std
|
||||
@pytest.mark.twai_adapter
|
||||
@pytest.mark.temp_skip_ci(targets=['esp32h4'], reason='no runner') # TODO: IDFCI-11110
|
||||
@pytest.mark.temp_skip_ci(targets=['esp32s31'], reason='no runner')
|
||||
@idf_parametrize('target', soc_filtered_targets('SOC_TWAI_SUPPORTED == 1'), indirect=['target'])
|
||||
|
||||
Reference in New Issue
Block a user