diff --git a/.gitlab/ci/target-test.yml b/.gitlab/ci/target-test.yml index b8224a96f0..c0bea8d035 100644 --- a/.gitlab/ci/target-test.yml +++ b/.gitlab/ci/target-test.yml @@ -346,6 +346,14 @@ component_ut_pytest_esp32_flash_multi: - build_pytest_components_esp32 tags: [ esp32, flash_mutli ] +component_ut_pytest_esp32_rs485_multi: + extends: + - .pytest_components_dir_template + - .rules:test:component_ut-esp32 + needs: + - build_pytest_components_esp32 + tags: [ esp32, multi_dut_modbus_rs485 ] + component_ut_pytest_esp32s2_generic: extends: - .pytest_components_dir_template @@ -962,13 +970,6 @@ UT_006: - UT_T1_SPIMODE - psram -UT_014: - extends: .unit_test_esp32_template - tags: - - ESP32_IDF - - UT_T2_RS485 - - psram - UT_017: extends: .unit_test_esp32_template tags: diff --git a/components/driver/.build-test-rules.yml b/components/driver/.build-test-rules.yml index 74646d5a0a..378949d94f 100644 --- a/components/driver/.build-test-rules.yml +++ b/components/driver/.build-test-rules.yml @@ -57,6 +57,12 @@ components/driver/test_apps/rmt: disable: - if: SOC_RMT_SUPPORTED != 1 +components/driver/test_apps/rs485: + disable_test: + - if: IDF_TARGET != "esp32" + temporary: true + reason: lack of runners + components/driver/test_apps/sdm: disable: - if: SOC_SDM_SUPPORTED != 1 diff --git a/components/driver/test_apps/rs485/CMakeLists.txt b/components/driver/test_apps/rs485/CMakeLists.txt new file mode 100644 index 0000000000..2efdce99f1 --- /dev/null +++ b/components/driver/test_apps/rs485/CMakeLists.txt @@ -0,0 +1,7 @@ +# This is the project CMakeLists.txt file for the test subproject +cmake_minimum_required(VERSION 3.16) + +set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components") + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(rs485_test) diff --git a/components/driver/test_apps/rs485/README.md b/components/driver/test_apps/rs485/README.md new file mode 100644 index 0000000000..7e7523ec85 --- /dev/null +++ b/components/driver/test_apps/rs485/README.md @@ -0,0 +1,2 @@ +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | diff --git a/components/driver/test_apps/rs485/main/CMakeLists.txt b/components/driver/test_apps/rs485/main/CMakeLists.txt new file mode 100644 index 0000000000..48d86f05ec --- /dev/null +++ b/components/driver/test_apps/rs485/main/CMakeLists.txt @@ -0,0 +1,7 @@ +# In order for the cases defined by `TEST_CASE` to be linked into the final elf, +# the component can be registered as WHOLE_ARCHIVE +idf_component_register( + SRCS "test_app_main.c" "test_rs485.c" + REQUIRES driver unity test_utils + WHOLE_ARCHIVE +) diff --git a/components/driver/test_apps/rs485/main/test_app_main.c b/components/driver/test_apps/rs485/main/test_app_main.c new file mode 100644 index 0000000000..8d94794888 --- /dev/null +++ b/components/driver/test_apps/rs485/main/test_app_main.c @@ -0,0 +1,49 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "unity.h" +#include "unity_test_utils.h" +#include "esp_heap_caps.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + +#define TEST_MEMORY_LEAK_THRESHOLD (200) + +static size_t before_free_8bit; +static size_t before_free_32bit; + + +void setUp(void) +{ + before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); + before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); +} + +void tearDown(void) +{ + size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); + size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); + printf("\n"); + unity_utils_check_leak(before_free_8bit, after_free_8bit, "8BIT", TEST_MEMORY_LEAK_THRESHOLD); + unity_utils_check_leak(before_free_32bit, after_free_32bit, "32BIT", TEST_MEMORY_LEAK_THRESHOLD); +} + +void app_main(void) +{ + // _____ _ ____ ____ _ _ ___ ____ + // |_ _|__ ___| |_ | _ \/ ___|| || | ( o ) ___| + // | |/ _ \/ __| __| | |_) \___ \| || |_ / _ \__ `. + // | | __/\__ \ |_ | _ < ___) |__ _| (_) |__) | + // |_|\___||___/\__| |_| \_\____/ |_| \___/____/ + printf("\n"); + printf(" _____ _ ____ ____ _ _ ___ ____\n"); + printf(" |_ _|__ ___| |_ | _ \\/ ___|| || | ( o ) ___|\n"); + printf(" | |/ _ \\/ __| __| | |_) \\___ \\| || |_ / _ \\__ `.\n"); + printf(" | | __/\\__ \\ |_ | _ < ___) |__ _| (_) |__) |\n"); + printf(" |_|\\___||___/\\__| |_| \\_\\____/ |_| \\___/____/\n"); + + unity_run_menu(); +} diff --git a/components/driver/test/test_rs485.c b/components/driver/test_apps/rs485/main/test_rs485.c similarity index 98% rename from components/driver/test/test_rs485.c rename to components/driver/test_apps/rs485/main/test_rs485.c index 40edeb9a14..774adc641f 100644 --- a/components/driver/test/test_rs485.c +++ b/components/driver/test_apps/rs485/main/test_rs485.c @@ -32,9 +32,6 @@ #define TEST_ALLOW_PROC_FAIL (10) #define TEST_CHECK_PROC_FAIL(fails, threshold) TEST_ASSERT((fails * 100 / PACKETS_NUMBER) <= threshold) -#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32S3, ESP32C3, ESP32C2, ESP32H4) -//No runners - static const char *TAG = "rs485_test"; // The table for fast CRC16 calculation @@ -291,6 +288,4 @@ static void rs485_master(void) * correctness of RS485 interface channel communication. It requires * RS485 bus driver hardware to be connected to boards. */ -TEST_CASE_MULTIPLE_DEVICES("RS485 half duplex uart multiple devices test.", "[driver_RS485][test_env=UT_T2_RS485]", rs485_master, rs485_slave); - -#endif //!TEMPORARY_DISABLED_FOR_TARGETS(..) +TEST_CASE_MULTIPLE_DEVICES("RS485 half duplex uart multiple devices test.", "[RS485][test_env=UT_T2_RS485]", rs485_master, rs485_slave); diff --git a/components/driver/test_apps/rs485/pytest_rs485.py b/components/driver/test_apps/rs485/pytest_rs485.py new file mode 100644 index 0000000000..d539b0c151 --- /dev/null +++ b/components/driver/test_apps/rs485/pytest_rs485.py @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 + +import pytest + + +@pytest.mark.esp32 +@pytest.mark.multi_dut_modbus_rs485 +@pytest.mark.parametrize('count, config', [(2, 'release',)], indirect=True) +def test_rs485_multi_dev(case_tester) -> None: # type: ignore + case_tester.run_all_multi_dev_cases(reset=True) diff --git a/components/driver/test_apps/rs485/sdkconfig.ci.release b/components/driver/test_apps/rs485/sdkconfig.ci.release new file mode 100644 index 0000000000..91d93f163e --- /dev/null +++ b/components/driver/test_apps/rs485/sdkconfig.ci.release @@ -0,0 +1,5 @@ +CONFIG_PM_ENABLE=y +CONFIG_FREERTOS_USE_TICKLESS_IDLE=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y diff --git a/components/driver/test_apps/rs485/sdkconfig.defaults b/components/driver/test_apps/rs485/sdkconfig.defaults new file mode 100644 index 0000000000..b308cb2ddd --- /dev/null +++ b/components/driver/test_apps/rs485/sdkconfig.defaults @@ -0,0 +1,2 @@ +CONFIG_FREERTOS_HZ=1000 +CONFIG_ESP_TASK_WDT=n diff --git a/pytest.ini b/pytest.ini index 5952f504dd..bab928e9fb 100644 --- a/pytest.ini +++ b/pytest.ini @@ -67,6 +67,7 @@ markers = MSPI_F4R4: runner with Quad Flash and Quad PSRAM test_jtag_arm: runner where the chip is accessible through JTAG as well adc: ADC related tests should run on adc runners + multi_dut_modbus_rs485: a pair of runners connectd by RS485 bus # multi-dut markers ieee802154: ieee802154 related tests should run on ieee802154 runners.