From 8536ffb490d92d32e1256787c8c01f9518e25af2 Mon Sep 17 00:00:00 2001 From: wanlei Date: Tue, 26 Dec 2023 10:38:06 +0800 Subject: [PATCH] fix(twai): enable twai interactive test for all targets on new std runner --- .gitlab/ci/target-test.yml | 54 +++++++++++++++++++ .../driver/test_apps/.build-test-rules.yml | 4 ++ .../twai/main/test_twai_interactive.c | 8 +-- .../driver/test_apps/twai/pytest_twai.py | 15 ++++-- tools/ci/idf_pytest/constants.py | 3 +- 5 files changed, 76 insertions(+), 8 deletions(-) diff --git a/.gitlab/ci/target-test.yml b/.gitlab/ci/target-test.yml index 78360181d4..2d067bdac8 100644 --- a/.gitlab/ci/target-test.yml +++ b/.gitlab/ci/target-test.yml @@ -926,6 +926,60 @@ pytest_components_esp32_psramv0: artifacts: false tags: [ esp32, psramv0 ] +pytest_components_esp32_twai_std: + extends: + - .pytest_components_dir_template + - .rules:test:component_ut-esp32 + needs: + - job: build_pytest_components_esp32 + artifacts: false + tags: [ esp32, twai_std ] + +pytest_components_esp32s2_twai_std: + extends: + - .pytest_components_dir_template + - .rules:test:component_ut-esp32s2 + needs: + - job: build_pytest_components_esp32s2 + artifacts: false + tags: [ esp32s2, twai_std ] + +pytest_components_esp32s3_twai_std: + extends: + - .pytest_components_dir_template + - .rules:test:component_ut-esp32s3 + needs: + - job: build_pytest_components_esp32s3 + artifacts: false + tags: [ esp32s3, twai_std ] + +pytest_components_esp32c3_twai_std: + extends: + - .pytest_components_dir_template + - .rules:test:component_ut-esp32c3 + needs: + - job: build_pytest_components_esp32c3 + artifacts: false + tags: [ esp32c3, twai_std ] + +pytest_components_esp32c6_twai_std: + extends: + - .pytest_components_dir_template + - .rules:test:component_ut-esp32c6 + needs: + - job: build_pytest_components_esp32c6 + artifacts: false + tags: [ esp32c6, twai_std ] + +pytest_components_esp32h2_twai_std: + extends: + - .pytest_components_dir_template + - .rules:test:component_ut-esp32h2 + needs: + - job: build_pytest_components_esp32h2 + artifacts: false + tags: [ esp32h2, twai_std ] + pytest_components_esp32s2_generic: extends: - .pytest_components_dir_template diff --git a/components/driver/test_apps/.build-test-rules.yml b/components/driver/test_apps/.build-test-rules.yml index 7fa7eca8b3..6c6d60a7d1 100644 --- a/components/driver/test_apps/.build-test-rules.yml +++ b/components/driver/test_apps/.build-test-rules.yml @@ -93,6 +93,10 @@ components/driver/test_apps/twai: - if: IDF_TARGET == "esp32p4" temporary: true reason: test not pass, should be re-enable # TODO: IDF-8966 + depends_filepatterns: + - components/driver/twai/**/* + depends_components: + - esp_driver_gpio components/driver/test_apps/usb_serial_jtag: disable: diff --git a/components/driver/test_apps/twai/main/test_twai_interactive.c b/components/driver/test_apps/twai/main/test_twai_interactive.c index 88b74af55b..78ee660555 100644 --- a/components/driver/test_apps/twai/main/test_twai_interactive.c +++ b/components/driver/test_apps/twai/main/test_twai_interactive.c @@ -27,7 +27,7 @@ TEST_CASE("twai_listen_only", "[twai]") { twai_timing_config_t t_config = TWAI_TIMING_CONFIG_250KBITS(); twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL(); - twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(0, 2, TWAI_MODE_LISTEN_ONLY); + twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(4, 5, TWAI_MODE_LISTEN_ONLY); #if CONFIG_TWAI_ISR_IN_IRAM g_config.intr_flags |= ESP_INTR_FLAG_IRAM; #endif @@ -60,8 +60,10 @@ TEST_CASE("twai_remote_request", "[twai]") twai_handle_t bus_handle; twai_timing_config_t t_config = TWAI_TIMING_CONFIG_250KBITS(); twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL(); - twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(0, 2, TWAI_MODE_NORMAL); - g_config.controller_id = 2; + twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(4, 5, TWAI_MODE_NORMAL); +#if CONFIG_IDF_TARGET_ESP32C6 + g_config.controller_id = 1; +#endif TEST_ESP_OK(twai_driver_install_v2(&g_config, &t_config, &f_config, &bus_handle)); TEST_ESP_OK(twai_start_v2(bus_handle)); diff --git a/components/driver/test_apps/twai/pytest_twai.py b/components/driver/test_apps/twai/pytest_twai.py index 95595646e5..5b05e08fb3 100644 --- a/components/driver/test_apps/twai/pytest_twai.py +++ b/components/driver/test_apps/twai/pytest_twai.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: CC0-1.0 import logging +import subprocess from time import sleep import pytest @@ -29,10 +30,14 @@ def test_twai_self(dut: Dut) -> None: @pytest.fixture(name='socket_can', scope='module') def fixture_create_socket_can() -> Bus: - # See README.md for instructions on how to set up the socket CAN with the bitrate + # Set up the socket CAN with the bitrate + start_command = 'sudo ip link set can0 up type can bitrate 250000 restart-ms 100' + stop_command = 'sudo ip link set can0 down' + subprocess.run(start_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) bus = Bus(interface='socketcan', channel='can0', bitrate=250000) - yield bus + yield bus # test invoked here bus.shutdown() + subprocess.run(stop_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) @pytest.mark.esp32 @@ -41,7 +46,7 @@ def fixture_create_socket_can() -> Bus: @pytest.mark.esp32h2 @pytest.mark.esp32s2 @pytest.mark.esp32s3 -@pytest.mark.skip(reason='Runner not set up yet') +@pytest.mark.twai_std @pytest.mark.parametrize( 'config', [ @@ -50,6 +55,7 @@ def fixture_create_socket_can() -> Bus: indirect=True, ) def test_twai_listen_only(dut: Dut, socket_can: Bus) -> None: + dut.serial.hard_reset() dut.expect_exact('Press ENTER to see the list of tests') # TEST_CASE("twai_listen_only", "[twai]") @@ -73,7 +79,7 @@ def test_twai_listen_only(dut: Dut, socket_can: Bus) -> None: @pytest.mark.esp32h2 @pytest.mark.esp32s2 @pytest.mark.esp32s3 -@pytest.mark.skip(reason='Runner not set up yet') +@pytest.mark.twai_std @pytest.mark.parametrize( 'config', [ @@ -82,6 +88,7 @@ def test_twai_listen_only(dut: Dut, socket_can: Bus) -> None: indirect=True, ) def test_twai_remote_request(dut: Dut, socket_can: Bus) -> None: + dut.serial.hard_reset() dut.expect_exact('Press ENTER to see the list of tests') # TEST_CASE("twai_remote_request", "[twai]") diff --git a/tools/ci/idf_pytest/constants.py b/tools/ci/idf_pytest/constants.py index a56cedc2dd..f5bb8743ae 100644 --- a/tools/ci/idf_pytest/constants.py +++ b/tools/ci/idf_pytest/constants.py @@ -108,7 +108,8 @@ ENV_MARKERS = { 'twai_network': 'multiple runners form a TWAI network.', '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)' + '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' }