From 1f5861492f09a0e3f7cc8754463dd8584a6ff632 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 27 Sep 2023 17:48:53 +0200 Subject: [PATCH] feat(app_trace): migrate the tests from unit-test-app --- components/app_trace/test/CMakeLists.txt | 4 -- .../app_trace/test_apps/.build-test-rules.yml | 9 ++++ components/app_trace/test_apps/CMakeLists.txt | 9 ++++ components/app_trace/test_apps/README.md | 16 +++++++ components/app_trace/test_apps/app_trace | 1 + .../app_trace/test_apps/main/CMakeLists.txt | 4 ++ .../test_apps/main/test_app_trace_main.c | 48 +++++++++++++++++++ .../{test => test_apps/main}/test_trace.c | 19 ++++---- .../test_apps/sdkconfig.ci.app_trace | 1 + .../app_trace/test_apps/sdkconfig.ci.sysview | 1 + .../app_trace/test_apps/sdkconfig.defaults | 2 + components/app_trace/test_apps/sysview | 1 + 12 files changed, 101 insertions(+), 14 deletions(-) delete mode 100644 components/app_trace/test/CMakeLists.txt create mode 100644 components/app_trace/test_apps/.build-test-rules.yml create mode 100644 components/app_trace/test_apps/CMakeLists.txt create mode 100644 components/app_trace/test_apps/README.md create mode 100644 components/app_trace/test_apps/app_trace create mode 100644 components/app_trace/test_apps/main/CMakeLists.txt create mode 100644 components/app_trace/test_apps/main/test_app_trace_main.c rename components/app_trace/{test => test_apps/main}/test_trace.c (98%) create mode 100644 components/app_trace/test_apps/sdkconfig.ci.app_trace create mode 100644 components/app_trace/test_apps/sdkconfig.ci.sysview create mode 100644 components/app_trace/test_apps/sdkconfig.defaults create mode 100644 components/app_trace/test_apps/sysview diff --git a/components/app_trace/test/CMakeLists.txt b/components/app_trace/test/CMakeLists.txt deleted file mode 100644 index 0b2be0a790..0000000000 --- a/components/app_trace/test/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -idf_component_register(SRC_DIRS "." - PRIV_INCLUDE_DIRS "." - PRIV_REQUIRES cmock driver) -target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") diff --git a/components/app_trace/test_apps/.build-test-rules.yml b/components/app_trace/test_apps/.build-test-rules.yml new file mode 100644 index 0000000000..10e09636d0 --- /dev/null +++ b/components/app_trace/test_apps/.build-test-rules.yml @@ -0,0 +1,9 @@ +# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps + +components/app_trace/test_apps: + depends_components: + - app_trace + - esp_timer + - soc + - driver + - esp_hw_support diff --git a/components/app_trace/test_apps/CMakeLists.txt b/components/app_trace/test_apps/CMakeLists.txt new file mode 100644 index 0000000000..9ed7e331c5 --- /dev/null +++ b/components/app_trace/test_apps/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.16) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +set(COMPONENTS main) +list(PREPEND SDKCONFIG_DEFAULTS + "$ENV{IDF_PATH}/tools/test_apps/configs/sdkconfig.debug_helpers" + "sdkconfig.defaults") + +project(app_trace_test) diff --git a/components/app_trace/test_apps/README.md b/components/app_trace/test_apps/README.md new file mode 100644 index 0000000000..061305f61a --- /dev/null +++ b/components/app_trace/test_apps/README.md @@ -0,0 +1,16 @@ +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | + +# app_trace test + +To build and run this test app for app_trace related tests: +```bash +IDF_TARGET=esp32 idf.py @app_trace build flash monitor +``` + +To build and run this test app for SystemView related tests: +```bash +IDF_TARGET=esp32 idf.py @sysview build flash monitor +``` + +`@app_trace` and `@sysview` arguments apply additional `idf.py` options, from [app_trace](app_trace) and [sysview](sysview) files. diff --git a/components/app_trace/test_apps/app_trace b/components/app_trace/test_apps/app_trace new file mode 100644 index 0000000000..3659de0381 --- /dev/null +++ b/components/app_trace/test_apps/app_trace @@ -0,0 +1 @@ +-DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.ci.app_trace" -B build/app_trace -DSDKCONFIG=build/app_trace/sdkconfig diff --git a/components/app_trace/test_apps/main/CMakeLists.txt b/components/app_trace/test_apps/main/CMakeLists.txt new file mode 100644 index 0000000000..7661fbba76 --- /dev/null +++ b/components/app_trace/test_apps/main/CMakeLists.txt @@ -0,0 +1,4 @@ +idf_component_register(SRCS "test_app_trace_main.c" "test_trace.c" + INCLUDE_DIRS "." + PRIV_REQUIRES app_trace unity driver + WHOLE_ARCHIVE) diff --git a/components/app_trace/test_apps/main/test_app_trace_main.c b/components/app_trace/test_apps/main/test_app_trace_main.c new file mode 100644 index 0000000000..317b0358f3 --- /dev/null +++ b/components/app_trace/test_apps/main/test_app_trace_main.c @@ -0,0 +1,48 @@ +/* + * SPDX-FileCopyrightText: 2023 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_DEFAULT 0 +static int leak_threshold = TEST_MEMORY_LEAK_THRESHOLD_DEFAULT; +void set_leak_threshold(int threshold) +{ + leak_threshold = threshold; +} + +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 >= 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"); + + leak_threshold = TEST_MEMORY_LEAK_THRESHOLD_DEFAULT; +} + +void app_main(void) +{ + printf("Running app_trace component tests\n"); + unity_run_menu(); +} diff --git a/components/app_trace/test/test_trace.c b/components/app_trace/test_apps/main/test_trace.c similarity index 98% rename from components/app_trace/test/test_trace.c rename to components/app_trace/test_apps/main/test_trace.c index fc90d7ffe8..6d61ac9049 100644 --- a/components/app_trace/test/test_trace.c +++ b/components/app_trace/test_apps/main/test_trace.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -16,7 +16,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" #include "freertos/task.h" -#if CONFIG_APPTRACE_ENABLE == 1 + #include "esp_app_trace.h" #include "esp_app_trace_util.h" @@ -423,7 +423,6 @@ TEST_CASE("App trace test (1 task + 1 crashed timer ISR @ 1 core)", "[trace][ign esp_apptrace_test(&test_cfg); } - TEST_CASE("App trace test (1 crashed task)", "[trace][ignore]") { esp_apptrace_test_task_arg_t s_test_tasks[1]; @@ -717,6 +716,7 @@ typedef struct { static bool esp_sysview_test_timer_isr(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_ctx) { esp_sysviewtrace_timer_arg_t *tim_arg = (esp_sysviewtrace_timer_arg_t *)user_ctx; + (void) tim_arg; return false; } @@ -724,7 +724,7 @@ static void esp_sysviewtrace_test_task(void *p) { esp_sysviewtrace_task_arg_t *arg = (esp_sysviewtrace_task_arg_t *) p; volatile uint32_t tmp = 0; - printf("%x: run sysview task\n", (uint32_t)xTaskGetCurrentTaskHandle()); + printf("%p: run sysview task\n", xTaskGetCurrentTaskHandle()); if (arg->timer) { gptimer_alarm_config_t alarm_config = { @@ -744,7 +744,7 @@ static void esp_sysviewtrace_test_task(void *p) int i = 0; while (1) { static uint32_t count; - printf("%d", arg->id); + printf("%" PRIu32, arg->id); if ((++count % 80) == 0) { printf("\n"); } @@ -890,22 +890,22 @@ TEST_CASE("SysView trace test 2", "[trace][ignore]") TEST_ESP_OK(gptimer_new_timer(&timer_config, &tim_arg2.gptimer)); xTaskCreatePinnedToCore(esp_sysviewtrace_test_task, "svtrace0", 2048, &arg1, 3, &thnd, 0); - printf("Created task %x\n", (uint32_t)thnd); + printf("Created task %p\n", thnd); #if CONFIG_FREERTOS_UNICORE == 0 xTaskCreatePinnedToCore(esp_sysviewtrace_test_task, "svtrace1", 2048, &arg2, 4, &thnd, 1); #else xTaskCreatePinnedToCore(esp_sysviewtrace_test_task, "svtrace1", 2048, &arg2, 4, &thnd, 0); #endif - printf("Created task %x\n", (uint32_t)thnd); + printf("Created task %p\n", thnd); xTaskCreatePinnedToCore(esp_sysviewtrace_test_task, "svsync0", 2048, &arg3, 3, &thnd, 0); - printf("Created task %x\n", (uint32_t)thnd); + printf("Created task %p\n", thnd); #if CONFIG_FREERTOS_UNICORE == 0 xTaskCreatePinnedToCore(esp_sysviewtrace_test_task, "svsync1", 2048, &arg4, 5, &thnd, 1); #else xTaskCreatePinnedToCore(esp_sysviewtrace_test_task, "svsync1", 2048, &arg4, 5, &thnd, 0); #endif - printf("Created task %x\n", (uint32_t)thnd); + printf("Created task %p\n", thnd); xSemaphoreTake(arg1.done, portMAX_DELAY); vSemaphoreDelete(arg1.done); @@ -924,4 +924,3 @@ TEST_CASE("SysView trace test 2", "[trace][ignore]") TEST_ESP_OK(gptimer_del_timer(tim_arg2.gptimer)); } #endif // #if CONFIG_APPTRACE_SV_ENABLE == 0 -#endif // #if CONFIG_APPTRACE_ENABLE == 1 diff --git a/components/app_trace/test_apps/sdkconfig.ci.app_trace b/components/app_trace/test_apps/sdkconfig.ci.app_trace new file mode 100644 index 0000000000..ce6deb8676 --- /dev/null +++ b/components/app_trace/test_apps/sdkconfig.ci.app_trace @@ -0,0 +1 @@ +# app_trace is already enabled by sdkconfig.defaults, so no options are needed here diff --git a/components/app_trace/test_apps/sdkconfig.ci.sysview b/components/app_trace/test_apps/sdkconfig.ci.sysview new file mode 100644 index 0000000000..0308ac377b --- /dev/null +++ b/components/app_trace/test_apps/sdkconfig.ci.sysview @@ -0,0 +1 @@ +CONFIG_APPTRACE_SV_ENABLE=y diff --git a/components/app_trace/test_apps/sdkconfig.defaults b/components/app_trace/test_apps/sdkconfig.defaults new file mode 100644 index 0000000000..5e62fe2487 --- /dev/null +++ b/components/app_trace/test_apps/sdkconfig.defaults @@ -0,0 +1,2 @@ +CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n +CONFIG_APPTRACE_DEST_JTAG=y diff --git a/components/app_trace/test_apps/sysview b/components/app_trace/test_apps/sysview new file mode 100644 index 0000000000..88ca400769 --- /dev/null +++ b/components/app_trace/test_apps/sysview @@ -0,0 +1 @@ +-DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.ci.sysview" -B build/sysview -DSDKCONFIG=build/sysview/sdkconfig