Zephyr API Documentation 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
ztress.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
13#ifndef TESTSUITE_ZTEST_INCLUDE_ZTRESS_H__
14#define TESTSUITE_ZTEST_INCLUDE_ZTRESS_H__
15
16#include <zephyr/sys/util.h>
17#include <zephyr/kernel.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
24#define ZTRESS_ID_THREAD 0
25#define ZTRESS_ID_K_TIMER 1
26
55#define ZTRESS_TIMER(handler, user_data, exec_cnt, init_timeout) \
56 (ZTRESS_ID_K_TIMER, handler, user_data, exec_cnt, 0, init_timeout)
57
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)
82
97typedef bool (*ztress_handler)(void *user_data, uint32_t cnt, bool last, int prio);
98
101 /* Handler. */
103
104 /* User data */
106
107 /* Minimum number of executions to complete the test. */
109
110 /* Minimum number of preemptions to complete the test. Valid only for
111 * thread context.
112 */
114
115 /* Initial timeout. */
117};
118
130#define ZTRESS_CONTEXT_INITIALIZER(_handler, _user_data, _exec_cnt, _preempt_cnt, _t) \
131 { \
132 .handler = (_handler), \
133 .user_data = (_user_data), \
134 .exec_cnt = (_exec_cnt), \
135 .preempt_cnt = (_preempt_cnt), \
136 .t = (_t) \
137 }
138
140#define Z_ZTRESS_GET_HANDLER_DATA2(_, ...) \
141 ZTRESS_CONTEXT_INITIALIZER(__VA_ARGS__)
142
144#define Z_ZTRESS_GET_HANDLER_DATA(data) \
145 Z_ZTRESS_GET_HANDLER_DATA2 data
146
148#define Z_ZTRESS_HAS_TIMER(data, ...) \
149 GET_ARG_N(1, __DEBRACKET data)
150
154#define Z_ZTRESS_TIMER_IDX(idx, data) \
155 ((GET_ARG_N(1, __DEBRACKET data)) == ZTRESS_ID_K_TIMER ? idx : 0)
156
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")
164
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__) \
181 }; \
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]; \
186 } \
187 int exec_err = ztress_execute(has_timer ? &_ctx_data[0] : NULL, \
188 &_ctx_data[has_timer], cnt); \
189 \
190 zassert_equal(exec_err, 0, "ztress_execute failed (err: %d)", exec_err); \
191} while (0)
192
208int ztress_execute(struct ztress_context_data *timer_data,
209 struct ztress_context_data *thread_data,
210 size_t cnt);
211
213void ztress_abort(void);
214
223
229void ztress_report(void);
230
238
246
257
262#ifdef __cplusplus
263}
264#endif
265
266#endif /* TESTSUITE_ZTEST_INCLUDE_ZTRESS_H__ */
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.
Public kernel APIs.
#define bool
Definition stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Kernel timeout type.
Definition sys_clock.h:65
Definition ztress.h:100
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
Misc utilities.