Chore/unit-test-cmake-and-ztest-time-duration (#1240)

* Fixed cmake for unit test so that indivisual build and test works from vscode

* Fixed the time duration in the ztest used for unit testing.
This commit is contained in:
Steve Karg
2026-02-20 09:15:55 -06:00
committed by GitHub
parent 8209673c43
commit 7d78889aa9
2 changed files with 10 additions and 16 deletions
+2 -2
View File
@@ -268,8 +268,8 @@ foreach(testdir IN ITEMS ${testdirs})
--target test_${basename} --target test_${basename}
) )
add_test(test_${basename} ${testdir}/test_${basename}) add_test(test_${basename} ${testdir}/test_${basename})
set_tests_properties(test_${basename} PROPERTIES FIXTURES_REQUIRED test_fixture) set_tests_properties(test_${basename} PROPERTIES FIXTURES_REQUIRED fixture_${basename})
set_tests_properties(build_${basename} PROPERTIES FIXTURES_SETUP test_fixture) set_tests_properties(build_${basename} PROPERTIES FIXTURES_SETUP fixture_${basename})
endforeach() endforeach()
message(STATUS "BACNET: using cmake:....................\"${CMAKE_VERSION}\"") message(STATUS "BACNET: using cmake:....................\"${CMAKE_VERSION}\"")
+8 -14
View File
@@ -12,6 +12,7 @@
#include <zephyr/kernel.h> #include <zephyr/kernel.h>
#include <string.h> #include <string.h>
#include <time.h>
#ifdef CONFIG_SHELL #ifdef CONFIG_SHELL
#include <zephyr/shell/shell.h> #include <zephyr/shell/shell.h>
#endif #endif
@@ -92,9 +93,7 @@ static inline const char *TC_RESULT_TO_STR(int result)
} }
} }
#if 0
static uint32_t tc_start_time; static uint32_t tc_start_time;
#endif
static uint32_t tc_spend_time; static uint32_t tc_spend_time;
static inline void get_start_time_cyc(void) static inline void get_start_time_cyc(void)
@@ -103,22 +102,17 @@ static inline void get_start_time_cyc(void)
* TC_START() in their code. But the caller thread cannot be * TC_START() in their code. But the caller thread cannot be
* in userspace. * in userspace.
*/ */
#if 0 struct timespec ts;
if (!k_is_user_context()) { clock_gettime(CLOCK_MONOTONIC, &ts);
tc_start_time = k_cycle_get_32(); tc_start_time = (uint32_t)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
}
#endif
} }
static inline void test_time_ms(void) static inline void test_time_ms(void)
{ {
#if 0 struct timespec ts;
uint32_t spend_cycle = k_cycle_get_32() - tc_start_time; clock_gettime(CLOCK_MONOTONIC, &ts);
uint32_t now = (uint32_t)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
tc_spend_time = k_cyc_to_ms_ceil32(spend_cycle); tc_spend_time = now - tc_start_time;
#else
tc_spend_time = 0;
#endif
} }
#ifndef TC_ERROR #ifndef TC_ERROR