Skip to content

Commit

Permalink
Added esp_timer to get time for unit tests run
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherkinyua committed Oct 31, 2024
1 parent 8877af6 commit 00cb224
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion firmware/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ file(GLOB SRC_FILES "${SRC_DIR}/*.c" "${SRC_DIR}/unit_tests/*.c")
# Register the component with ESP-IDF
idf_component_register(SRCS ${SRC_FILES}
INCLUDE_DIRS ${INCLUDE_DIRS}
REQUIRES driver)
REQUIRES driver esp_timer)
6 changes: 3 additions & 3 deletions firmware/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ void app_main(void)

if (unit_tests_result)
{
printf("\nall tests passed\n");
printf("\nAll tests passed!\n");
}
else
{
printf("\nsome tests failed\n");
printf("\nSome tests failed!\n");
}

ESP_LOGI("Main", "Hello, ESP32-C3!");
ESP_LOGI("Main", "Hello, ESP32-C3!");

// For demonstration, create a simple task
while (true)
Expand Down
11 changes: 6 additions & 5 deletions firmware/Core/Src/unit_tests/unit_test_executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

#include "string.h"
#include "stdio.h"
#include "esp_timer.h"

uint8_t TEST_run_all_unit_tests_and_log(char log_buffer[], uint16_t log_buffer_size)
{
uint16_t total_exec_count = 0;
uint16_t total_pass_count = 0;
uint16_t total_fail_count = 0;
// const uint32_t start_time_ms = HAL_GetTick();
const uint32_t start_time_ms = esp_timer_get_time() / 1000;

log_buffer[0] = '\0';

Expand Down Expand Up @@ -41,16 +42,16 @@ uint8_t TEST_run_all_unit_tests_and_log(char log_buffer[], uint16_t log_buffer_s
total_fail_count++;
}
}
// const uint32_t end_time_ms = HAL_GetTick();
const uint32_t end_time_ms = esp_timer_get_time() / 1000;

snprintf(
log_buffer,
log_buffer_size,
"Total tests: %d - Pass: %d, Fail: %d",
"Total tests: %d - Pass: %d, Fail: %d, Duration: %lums",
total_exec_count,
total_pass_count,
total_fail_count);
// end_time_ms - start_time_ms);
total_fail_count,
end_time_ms - start_time_ms);

return total_fail_count == 0;
}

0 comments on commit 00cb224

Please sign in to comment.