diff --git a/subsys/testsuite/include/zephyr/tc_util.h b/subsys/testsuite/include/zephyr/tc_util.h index 95bec0becc5..edcf8c02d38 100644 --- a/subsys/testsuite/include/zephyr/tc_util.h +++ b/subsys/testsuite/include/zephyr/tc_util.h @@ -97,16 +97,10 @@ static uint32_t tc_spend_time; static inline void get_start_time_cyc(void) { - /* Besides the ztest framework, some testcase will also call - * TC_START() in their code. But the caller thread cannot be - * in userspace. - */ - if (!k_is_user_context()) { - tc_start_time = k_cycle_get_32(); - } + tc_start_time = k_cycle_get_32(); } -static inline void test_time_ms(void) +static inline void get_test_duration_ms(void) { uint32_t spend_cycle = k_cycle_get_32() - tc_start_time; @@ -161,7 +155,6 @@ static inline void print_nothing(const char *fmt, ...) #define TC_START(name) \ do { \ TC_START_PRINT(name); \ - get_start_time_cyc(); \ } while (0) #endif @@ -185,7 +178,6 @@ static inline void print_nothing(const char *fmt, ...) #ifndef Z_TC_END_RESULT #define Z_TC_END_RESULT(result, func) \ do { \ - test_time_ms(); \ TC_END_PRINT(result, " %s - %s in %u.%u seconds\n", \ TC_RESULT_TO_STR(result), func, tc_spend_time/1000, \ tc_spend_time%1000); \ diff --git a/subsys/testsuite/ztest/src/ztest.c b/subsys/testsuite/ztest/src/ztest.c index 15de1b7dd9a..b41cb5e6888 100644 --- a/subsys/testsuite/ztest/src/ztest.c +++ b/subsys/testsuite/ztest/src/ztest.c @@ -273,6 +273,7 @@ static int run_test(struct unit_test *test) int skip = 0; TC_START(test->name); + get_start_time_cyc(); if (setjmp(test_fail)) { ret = TC_FAIL; @@ -292,6 +293,7 @@ static int run_test(struct unit_test *test) run_test_functions(test); out: ret |= cleanup_test(test); + get_test_duration_ms(); if (skip) { Z_TC_END_RESULT(TC_SKIP, test->name); @@ -365,6 +367,7 @@ static int run_test(struct unit_test *test) int ret = TC_PASS; TC_START(test->name); + get_start_time_cyc(); if (IS_ENABLED(CONFIG_MULTITHREADING)) { k_thread_create(&ztest_thread, ztest_thread_stack, @@ -405,6 +408,7 @@ static int run_test(struct unit_test *test) if (!test_result || !FAIL_FAST) { ret |= cleanup_test(test); } + get_test_duration_ms(); if (test_result == -2) { Z_TC_END_RESULT(TC_SKIP, test->name);