13#ifndef TESTSUITE_ZTEST_INCLUDE_ZTRESS_H__
14#define TESTSUITE_ZTEST_INCLUDE_ZTRESS_H__
24#define ZTRESS_ID_THREAD 0
25#define ZTRESS_ID_K_TIMER 1
55#define ZTRESS_TIMER(handler, user_data, exec_cnt, init_timeout) \
56 (ZTRESS_ID_K_TIMER, handler, user_data, exec_cnt, 0, init_timeout)
80#define ZTRESS_THREAD(handler, user_data, exec_cnt, preempt_cnt, init_timeout) \
81 (ZTRESS_ID_THREAD, handler, user_data, exec_cnt, preempt_cnt, init_timeout)
130#define ZTRESS_CONTEXT_INITIALIZER(_handler, _user_data, _exec_cnt, _preempt_cnt, _t) \
132 .handler = (_handler), \
133 .user_data = (_user_data), \
134 .exec_cnt = (_exec_cnt), \
135 .preempt_cnt = (_preempt_cnt), \
140#define Z_ZTRESS_GET_HANDLER_DATA2(_, ...) \
141 ZTRESS_CONTEXT_INITIALIZER(__VA_ARGS__)
144#define Z_ZTRESS_GET_HANDLER_DATA(data) \
145 Z_ZTRESS_GET_HANDLER_DATA2 data
148#define Z_ZTRESS_HAS_TIMER(data, ...) \
149 GET_ARG_N(1, __DEBRACKET data)
154#define Z_ZTRESS_TIMER_IDX(idx, data) \
155 ((GET_ARG_N(1, __DEBRACKET data)) == ZTRESS_ID_K_TIMER ? idx : 0)
160#define Z_ZTRESS_TIMER_CONTEXT_VALIDATE(...) \
161 BUILD_ASSERT((FOR_EACH_IDX(Z_ZTRESS_TIMER_IDX, (+), __VA_ARGS__)) == 0, \
162 "There can only be up to one ZTRESS_TIMER context and it must " \
163 "be the first in the list")
176#define ZTRESS_EXECUTE(...) do { \
177 Z_ZTRESS_TIMER_CONTEXT_VALIDATE(__VA_ARGS__); \
178 int has_timer = Z_ZTRESS_HAS_TIMER(__VA_ARGS__); \
179 struct ztress_context_data _ctx_data1[] = { \
180 FOR_EACH(Z_ZTRESS_GET_HANDLER_DATA, (,), __VA_ARGS__) \
182 size_t cnt = ARRAY_SIZE(_ctx_data1) - has_timer; \
183 static struct ztress_context_data _ctx_data[ARRAY_SIZE(_ctx_data1)]; \
184 for (size_t i = 0; i < ARRAY_SIZE(_ctx_data1); i++) { \
185 _ctx_data[i] = _ctx_data1[i]; \
187 int exec_err = ztress_execute(has_timer ? &_ctx_data[0] : NULL, \
188 &_ctx_data[has_timer], cnt); \
190 zassert_equal(exec_err, 0, "ztress_execute failed (err: %d)", exec_err); \
int ztress_preempt_count(uint32_t id)
Get number of preemptions of a given context in the last test.
void ztress_abort(void)
Abort ongoing stress test.
void ztress_set_timeout(k_timeout_t t)
Set test timeout.
bool(* ztress_handler)(void *user_data, uint32_t cnt, bool last, int prio)
User handler called in one of the configured contexts.
Definition: ztress.h:97
int ztress_exec_count(uint32_t id)
Get number of executions of a given context in the last test.
uint32_t ztress_optimized_ticks(uint32_t id)
Get optimized timeout base of a given context in the last test.
void ztress_report(void)
Print last test report.
int ztress_execute(struct ztress_context_data *timer_data, struct ztress_context_data *thread_data, size_t cnt)
Execute contexts.
#define bool
Definition: stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
Kernel timeout type.
Definition: sys_clock.h:65
k_timeout_t t
Definition: ztress.h:116
uint32_t preempt_cnt
Definition: ztress.h:113
void * user_data
Definition: ztress.h:105
ztress_handler handler
Definition: ztress.h:102
uint32_t exec_cnt
Definition: ztress.h:108