23#include "freertos/FreeRTOS.h"
24#include "freertos/task.h"
25#include "freertos/semphr.h"
26#include "driver/gpio.h"
44 gpio_config_t io_conf = {};
46 io_conf.mode = GPIO_MODE_OUTPUT;
47 io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
48 io_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
49 io_conf.intr_type = GPIO_INTR_DISABLE;
51 if (gpio_config(&io_conf) != ESP_OK) {
72 vTaskDelay(pdMS_TO_TICKS(50));
83 for (uint8_t i = 0; i < blink_count; ++i) {
85 vTaskDelay(pdMS_TO_TICKS(50));
87 vTaskDelay(pdMS_TO_TICKS(50));
127 void add_result(
bool passed, uint64_t execution_time)
noexcept {
147 ESP_LOGI(tag,
"╔══════════════════════════════════════════════════════════════════════════════╗");
148 ESP_LOGI(tag,
"║ TEST RESULTS SUMMARY ║");
149 ESP_LOGI(tag,
"╠══════════════════════════════════════════════════════════════════════════════╣");
150 ESP_LOGI(tag,
"║ Total Tests: %-56d ║",
total_tests);
155 ESP_LOGI(tag,
"╚══════════════════════════════════════════════════════════════════════════════╝");
170#define RUN_TEST(test_func) \
172 ensure_gpio14_initialized(); \
174 ESP_LOGI(TAG, "╔══════════════════════════════════════════════════════════════════════════════╗"); \
175 ESP_LOGI(TAG, "║ Running: " #test_func " "); \
176 ESP_LOGI(TAG, "╚══════════════════════════════════════════════════════════════════════════════╝"); \
177 uint64_t start_time = esp_timer_get_time(); \
178 bool result = test_func(); \
179 uint64_t end_time = esp_timer_get_time(); \
180 uint64_t execution_time = end_time - start_time; \
181 g_test_results.add_result(result, execution_time); \
183 ESP_LOGI(TAG, "[SUCCESS] PASSED: " #test_func " (%.2f ms)", execution_time / 1000.0); \
185 ESP_LOGE(TAG, "[FAILED] FAILED: " #test_func " (%.2f ms)", execution_time / 1000.0); \
187 flip_test_progress_indicator(); \
188 vTaskDelay(pdMS_TO_TICKS(100)); \
207 ESP_LOGI(ctx->
tag,
"");
208 ESP_LOGI(ctx->
tag,
"╔══════════════════════════════════════════════════════════════════════════════╗");
209 ESP_LOGI(ctx->
tag,
"║ Running (task): %-62s║", ctx->
test_name);
210 ESP_LOGI(ctx->
tag,
"╚══════════════════════════════════════════════════════════════════════════════╝");
212 uint64_t start_time = esp_timer_get_time();
214 uint64_t end_time = esp_timer_get_time();
215 uint64_t execution_time = end_time - start_time;
220 ESP_LOGI(ctx->
tag,
"[SUCCESS] PASSED (task): %s (%.2f ms)",
221 ctx->
test_name, execution_time / 1000.0);
223 ESP_LOGE(ctx->
tag,
"[FAILED] FAILED (task): %s (%.2f ms)",
224 ctx->
test_name, execution_time / 1000.0);
228 vTaskDelete(
nullptr);
234#define RUN_TEST_IN_TASK(name, func, stack_size_bytes, priority) \
236 ensure_gpio14_initialized(); \
237 static TestTaskContext ctx; \
238 ctx.test_name = name; \
239 ctx.test_func = func; \
240 ctx.results = &g_test_results; \
242 ctx.completion_semaphore = xSemaphoreCreateBinary(); \
243 if (ctx.completion_semaphore == nullptr) { \
244 ESP_LOGE(TAG, "Failed to create semaphore for test: %s", name); \
247 BaseType_t created = xTaskCreate(test_task_trampoline, name, \
248 (stack_size_bytes) / sizeof(StackType_t), \
249 &ctx, (priority), nullptr); \
250 if (created != pdPASS) { \
251 ESP_LOGE(TAG, "Failed to create test task: %s", name); \
252 vSemaphoreDelete(ctx.completion_semaphore); \
255 if (xSemaphoreTake(ctx.completion_semaphore, pdMS_TO_TICKS(30000)) == pdTRUE) { \
256 ESP_LOGI(TAG, "Test task completed: %s", name); \
258 ESP_LOGW(TAG, "Test task timeout: %s", name); \
260 vSemaphoreDelete(ctx.completion_semaphore); \
261 flip_test_progress_indicator(); \
262 vTaskDelay(pdMS_TO_TICKS(100)); \
270#define RUN_TEST_SECTION_IF_ENABLED(enabled, section_name, ...) \
274 ESP_LOGI(TAG, "╔══════════════════════════════════════════════════════════════════════════════╗"); \
275 ESP_LOGI(TAG, "║ SECTION: %-69s║", section_name); \
276 ESP_LOGI(TAG, "╚══════════════════════════════════════════════════════════════════════════════╝"); \
277 output_section_indicator(5); \
285#define RUN_TEST_SECTION_IF_ENABLED_WITH_PATTERN(enabled, section_name, blink_count, ...) \
289 ESP_LOGI(TAG, "╔══════════════════════════════════════════════════════════════════════════════╗"); \
290 ESP_LOGI(TAG, "║ SECTION: %-69s║", section_name); \
291 ESP_LOGI(TAG, "╚══════════════════════════════════════════════════════════════════════════════╝"); \
292 output_section_indicator(blink_count); \
306 ESP_LOGI(tag,
"╔══════════════════════════════════════════════════════════════════════════════╗");
307 ESP_LOGI(tag,
"║ %s TEST CONFIGURATION ", module_name);
308 ESP_LOGI(tag,
"╠══════════════════════════════════════════════════════════════════════════════╣");
309 ESP_LOGI(tag,
"║ Test sections will execute based on compile-time configuration ║");
310 ESP_LOGI(tag,
"║ GPIO14 test progression indicator: ENABLED ║");
311 ESP_LOGI(tag,
"╚══════════════════════════════════════════════════════════════════════════════╝");
static constexpr gpio_num_t TEST_PROGRESS_PIN
Definition TLE92466ED_TestFramework.hpp:32
void output_section_indicator(uint8_t blink_count=5) noexcept
Blink GPIO14 to indicate section start/end.
Definition TLE92466ED_TestFramework.hpp:78
static bool g_gpio14_state
Definition TLE92466ED_TestFramework.hpp:34
bool init_test_progress_indicator() noexcept
Initialize GPIO14 as test progression indicator.
Definition TLE92466ED_TestFramework.hpp:39
void ensure_gpio14_initialized() noexcept
Ensure GPIO14 is initialized.
Definition TLE92466ED_TestFramework.hpp:108
void cleanup_test_progress_indicator() noexcept
Cleanup GPIO14 indicator.
Definition TLE92466ED_TestFramework.hpp:96
void flip_test_progress_indicator() noexcept
Toggle GPIO14 to indicate test progression.
Definition TLE92466ED_TestFramework.hpp:65
void print_test_section_status(const char *tag, const char *module_name)
Print section configuration status.
Definition TLE92466ED_TestFramework.hpp:304
static TestResults g_test_results
Definition TLE92466ED_TestFramework.hpp:161
void test_task_trampoline(void *param)
FreeRTOS task trampoline for test execution.
Definition TLE92466ED_TestFramework.hpp:205
static bool g_gpio14_initialized
Definition TLE92466ED_TestFramework.hpp:33
Test execution tracking and results accumulation.
Definition TLE92466ED_TestFramework.hpp:121
int failed_tests
Definition TLE92466ED_TestFramework.hpp:124
void add_result(bool passed, uint64_t execution_time) noexcept
Definition TLE92466ED_TestFramework.hpp:127
int passed_tests
Definition TLE92466ED_TestFramework.hpp:123
void print_summary(const char *tag) const noexcept
Definition TLE92466ED_TestFramework.hpp:145
double get_total_time_ms() const noexcept
Definition TLE92466ED_TestFramework.hpp:141
uint64_t total_execution_time_us
Definition TLE92466ED_TestFramework.hpp:125
double get_success_percentage() const noexcept
Definition TLE92466ED_TestFramework.hpp:137
int total_tests
Definition TLE92466ED_TestFramework.hpp:122
Context for test task.
Definition TLE92466ED_TestFramework.hpp:194
TestResults * results
Definition TLE92466ED_TestFramework.hpp:197
bool(* test_func)() noexcept
Definition TLE92466ED_TestFramework.hpp:196
SemaphoreHandle_t completion_semaphore
Definition TLE92466ED_TestFramework.hpp:199
const char * test_name
Definition TLE92466ED_TestFramework.hpp:195
const char * tag
Definition TLE92466ED_TestFramework.hpp:198