ztest: Refine when to collect unit test duration
Previously, unit test duration is collected within the TC_START and Z_TC_END_RESULT macros. With existing tests, the TC_START macro can be invoked by both the ztest fx and the tests themselves. And the TC_START macro definition went lengths to avoid the interference when it is invoked within a unit test. This commit decouple the time collection and the TC_STRAT/Z_TC_END_RESULT macros to fix this issue. Now only the (old) ztest framework is responsible for the test duration measure. The test duration stats of new ztest fx is different from this btw. Signed-off-by: Ming Shao <ming.shao@intel.com>
This commit is contained in:
parent
77e1e39cff
commit
cce1ec6f42
2 changed files with 6 additions and 10 deletions
|
@ -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); \
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue