Zephyr Project API
3.7.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
20
extern
"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
97
typedef
bool
(*
ztress_handler
)(
void
*
user_data
,
uint32_t
cnt,
bool
last,
int
prio);
98
100
struct
ztress_context_data
{
101
/* Handler. */
102
ztress_handler
handler
;
103
104
/* User data */
105
void
*
user_data
;
106
107
/* Minimum number of executions to complete the test. */
108
uint32_t
exec_cnt
;
109
110
/* Minimum number of preemptions to complete the test. Valid only for
111
* thread context.
112
*/
113
uint32_t
preempt_cnt
;
114
115
/* Initial timeout. */
116
k_timeout_t
t
;
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
208
int
ztress_execute
(
struct
ztress_context_data
*
timer_data
,
209
struct
ztress_context_data
*
thread_data
,
210
size_t
cnt);
211
213
void
ztress_abort
(
void
);
214
222
void
ztress_set_timeout
(
k_timeout_t
t
);
223
229
void
ztress_report
(
void
);
230
237
int
ztress_exec_count
(
uint32_t
id
);
238
245
int
ztress_preempt_count
(
uint32_t
id
);
246
256
uint32_t
ztress_optimized_ticks
(
uint32_t
id
);
257
262
#ifdef __cplusplus
263
}
264
#endif
265
266
#endif
/* TESTSUITE_ZTEST_INCLUDE_ZTRESS_H__ */
ztress_preempt_count
int ztress_preempt_count(uint32_t id)
Get number of preemptions of a given context in the last test.
ztress_abort
void ztress_abort(void)
Abort ongoing stress test.
ztress_set_timeout
void ztress_set_timeout(k_timeout_t t)
Set test timeout.
ztress_handler
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
ztress_exec_count
int ztress_exec_count(uint32_t id)
Get number of executions of a given context in the last test.
ztress_optimized_ticks
uint32_t ztress_optimized_ticks(uint32_t id)
Get optimized timeout base of a given context in the last test.
ztress_report
void ztress_report(void)
Print last test report.
ztress_execute
int ztress_execute(struct ztress_context_data *timer_data, struct ztress_context_data *thread_data, size_t cnt)
Execute contexts.
kernel.h
Public kernel APIs.
t
struct k_thread t
Definition
kobject.c:1324
bool
#define bool
Definition
stdbool.h:13
uint32_t
__UINT32_TYPE__ uint32_t
Definition
stdint.h:90
k_timeout_t
Kernel timeout type.
Definition
sys_clock.h:65
thread_data
Definition
test_sched.h:21
timer_data
Definition
clock.c:16
ztress_context_data
Definition
ztress.h:100
ztress_context_data::t
k_timeout_t t
Definition
ztress.h:116
ztress_context_data::preempt_cnt
uint32_t preempt_cnt
Definition
ztress.h:113
ztress_context_data::user_data
void * user_data
Definition
ztress.h:105
ztress_context_data::handler
ztress_handler handler
Definition
ztress.h:102
ztress_context_data::exec_cnt
uint32_t exec_cnt
Definition
ztress.h:108
user_data
static const intptr_t user_data[5]
Definition
main.c:588
util.h
Misc utilities.
subsys
testsuite
ztest
include
zephyr
ztress.h
Generated on Sun Sep 15 2024 17:01:30 for Zephyr Project API by
1.9.8