9#ifndef ZEPHYR_TESTSUITE_INCLUDE_TC_UTIL_H_
10#define ZEPHYR_TESTSUITE_INCLUDE_TC_UTIL_H_
20#if defined CONFIG_ZTEST_TC_UTIL_USER_OVERRIDE
21#include <tc_util_user_override.h>
25#define PRINT_DATA(fmt, ...) printk(fmt, ##__VA_ARGS__)
28#if defined CONFIG_ARCH_POSIX
29#include "posix_board_if.h"
47#define TC_STR_HELPER(x) #x
48#define TC_STR(x) TC_STR_HELPER(x)
50#define TC_PRINT_RUNID PRINT_DATA("RunID: " TC_STR(TC_RUNID) "\n")
52#define TC_PRINT_RUNID do {} while (false)
58 "============================================================" \
63#define TASK_STACK_SIZE (1024 * 2)
65#define FMT_ERROR "%s - %s@%d. "
73#define TC_PASS_STR "PASS"
76#define TC_FAIL_STR "FAIL"
79#define TC_SKIP_STR "SKIP"
82#define TC_FLAKY_STR "FLAKY"
117#define TC_ERROR(fmt, ...) \
119 PRINT_DATA(FMT_ERROR, "FAIL", __func__, __LINE__); \
120 PRINT_DATA(fmt, ##__VA_ARGS__); \
130#if defined(CONFIG_ZTEST_VERBOSE_OUTPUT)
131#define TC_PRINT(fmt, ...) PRINT_DATA(fmt, ##__VA_ARGS__)
133#define TC_PRINT(fmt, ...) print_nothing(fmt, ##__VA_ARGS__)
137#ifndef TC_SUMMARY_PRINT
138#define TC_SUMMARY_PRINT(fmt, ...) PRINT_DATA(fmt, ##__VA_ARGS__)
141#ifndef TC_START_PRINT
142#if defined(CONFIG_ZTEST_VERBOSE_OUTPUT)
143#define TC_START_PRINT(name) PRINT_DATA("START - %s\n", name);
145#define TC_START_PRINT(name) print_nothing(name)
150#define TC_START(name) \
152 TC_START_PRINT(name); \
157#define TC_END(result, fmt, ...) PRINT_DATA(fmt, ##__VA_ARGS__)
161#if defined(CONFIG_ZTEST_VERBOSE_OUTPUT)
162#define TC_END_PRINT(result, fmt, ...) PRINT_DATA(fmt, ##__VA_ARGS__); PRINT_LINE
164#define TC_END_PRINT(result, fmt, ...) print_nothing(fmt)
169#ifndef Z_TC_END_RESULT
170#define Z_TC_END_RESULT(result, func) \
172 TC_END_PRINT(result, " %s - %s in %u.%03u seconds\n", \
173 TC_RESULT_TO_STR(result), func, tc_spend_time/1000, \
174 tc_spend_time%1000); \
179#define TC_END_RESULT(result) \
180 Z_TC_END_RESULT((result), __func__)
183#ifndef TC_END_RESULT_CUSTOM
184#define TC_END_RESULT_CUSTOM(result, func) \
185 Z_TC_END_RESULT((result), func)
188#ifndef TC_SUITE_PRINT
189#define TC_SUITE_PRINT(fmt, ...) PRINT_DATA(fmt, ##__VA_ARGS__)
192#ifndef TC_SUITE_START
193#define TC_SUITE_START(name) \
195 TC_SUITE_PRINT("Running TESTSUITE %s\n", name); \
201#define TC_SUITE_END(name, result) \
203 if (result != TC_FAIL) { \
204 TC_SUITE_PRINT("TESTSUITE %s succeeded\n", name); \
206 TC_SUITE_PRINT("TESTSUITE %s failed.\n", name); \
211#if defined(CONFIG_ARCH_POSIX)
213#define TC_END_POST(result) do { \
215 posix_exit(result); \
218#define TC_END_POST(result)
222#define TC_END_REPORT(result) \
227 "PROJECT EXECUTION %s\n", \
228 (result) == TC_PASS ? "SUCCESSFUL" : "FAILED"); \
229 TC_END_POST(result); \
233#if defined(CONFIG_SHELL)
234#define TC_CMD_DEFINE(name) \
235 static int cmd_##name(const struct shell *sh, size_t argc, \
238 TC_START(__func__); \
240 TC_END_RESULT(TC_PASS); \
243#define TC_CMD_ITEM(name) cmd_##name
245#define TC_CMD_DEFINE(name) \
246 int cmd_##name(int argc, char *argv[]) \
248 TC_START(__func__); \
250 TC_END_RESULT(TC_PASS); \
253#define TC_CMD_ITEM(name) {STRINGIFY(name), cmd_##name, "none"}
static uint32_t k_cycle_get_32(void)
Read the hardware clock.
Definition kernel.h:1906
#define k_cyc_to_ms_ceil32(t)
Convert hardware cycles to milliseconds.
Definition time_units.h:1285
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
#define TC_FAIL
Definition tc_util.h:68
static void print_nothing(const char *fmt,...)
Definition tc_util.h:124
static void get_start_time_cyc(void)
Definition tc_util.h:104
#define TC_FLAKY_STR
Definition tc_util.h:82
#define TC_SKIP_STR
Definition tc_util.h:79
#define TC_PASS_STR
Definition tc_util.h:73
static uint32_t tc_spend_time
Definition tc_util.h:102
static const char * TC_RESULT_TO_STR(int result)
Definition tc_util.h:85
static void get_test_duration_ms(void)
Definition tc_util.h:109
#define TC_SKIP
Definition tc_util.h:69
#define TC_FLAKY
Definition tc_util.h:70
#define TC_FAIL_STR
Definition tc_util.h:76
static uint32_t tc_start_time
Definition tc_util.h:101
#define TC_PASS
Definition tc_util.h:67