diff --git a/components/freertos/test/CMakeLists.txt b/components/freertos/test/CMakeLists.txt deleted file mode 100644 index ac4364d633..0000000000 --- a/components/freertos/test/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# For refactored FreeRTOS unit tests, we need to support #include "xxx.h" of FreeRTOS headers -idf_component_get_property(FREERTOS_ORIG_INCLUDE_PATH freertos ORIG_INCLUDE_PATH) - -idf_component_register(SRC_DIRS integration # For freertos_test_utils.c - integration/event_groups - integration/queue - integration/stream_buffer - integration/tasks - integration/timers - miscellaneous - performance - port - PRIV_INCLUDE_DIRS . ./integration "${FREERTOS_ORIG_INCLUDE_PATH}" - PRIV_REQUIRES cmock test_utils esp_system driver esp_timer) -target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") diff --git a/components/freertos/test_apps/freertos/CMakeLists.txt b/components/freertos/test_apps/freertos/CMakeLists.txt new file mode 100644 index 0000000000..ff3d5d9774 --- /dev/null +++ b/components/freertos/test_apps/freertos/CMakeLists.txt @@ -0,0 +1,16 @@ +# This is the project CMakeLists.txt file for the test subproject +cmake_minimum_required(VERSION 3.16) + +# FreeRTOS tests of different types (e.g., kernel, port, performance etc.)are +# split into different directores in the test app's root directory. Each test +# type is treated as separate component +set(test_types) + +list(APPEND EXTRA_COMPONENT_DIRS + ${test_types}) # Add each test type as a component + +# "Trim" the build. Include the minimal set of components, main, and anything it depends on. +set(COMPONENTS main) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(freertos_test) diff --git a/components/freertos/test_apps/freertos/README.md b/components/freertos/test_apps/freertos/README.md new file mode 100644 index 0000000000..b5be4985c5 --- /dev/null +++ b/components/freertos/test_apps/freertos/README.md @@ -0,0 +1,2 @@ +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | diff --git a/components/freertos/test_apps/freertos/main/CMakeLists.txt b/components/freertos/test_apps/freertos/main/CMakeLists.txt new file mode 100644 index 0000000000..0d8828ca14 --- /dev/null +++ b/components/freertos/test_apps/freertos/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "test_freertos_main.c" + PRIV_REQUIRES unity test_utils driver) diff --git a/components/freertos/test_apps/freertos/main/test_freertos_main.c b/components/freertos/test_apps/freertos/main/test_freertos_main.c new file mode 100644 index 0000000000..e8247d9657 --- /dev/null +++ b/components/freertos/test_apps/freertos/main/test_freertos_main.c @@ -0,0 +1,40 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "unity.h" +#include "unity_test_runner.h" +#include "esp_heap_caps.h" + +#define TEST_MEMORY_LEAK_THRESHOLD (-256) + +static size_t before_free_8bit; +static size_t before_free_32bit; + +static void check_leak(size_t before_free, size_t after_free, const char *type) +{ + ssize_t delta = after_free - before_free; + printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta); + TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak"); +} + +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); + check_leak(before_free_8bit, after_free_8bit, "8BIT"); + check_leak(before_free_32bit, after_free_32bit, "32BIT"); +} + +void app_main(void) +{ + unity_run_menu(); +} diff --git a/components/freertos/test_apps/freertos/pytest_freertos.py b/components/freertos/test_apps/freertos/pytest_freertos.py new file mode 100644 index 0000000000..464d842724 --- /dev/null +++ b/components/freertos/test_apps/freertos/pytest_freertos.py @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 + +import pytest +from pytest_embedded import Dut + + +@pytest.mark.supported_targets +@pytest.mark.generic +def test_freertos(dut: Dut) -> None: + dut.expect_exact('Press ENTER to see the list of tests') + dut.write('*') + dut.expect_unity_test_output()