Zephyr API Documentation
3.0.0
A Scalable Open Source RTOS
3.0.0
Toggle main menu visibility
Main Page
Related Pages
Modules
Data Structures
Data Structures
Data Structure Index
Data Fields
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
Variables
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Enumerator
Files
File List
Globals
All
$
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Variables
$
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Typedefs
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Enumerations
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
Enumerator
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Macros
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
•
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Modules
Pages
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
#ifndef TESTSUITE_ZTEST_INCLUDE_ZTRESS_H__
7
#define TESTSUITE_ZTEST_INCLUDE_ZTRESS_H__
8
9
#include <
sys/util.h
>
10
#include <kernel.h>
11
13
#define ZTRESS_ID_THREAD 0
14
#define ZTRESS_ID_K_TIMER 1
15
35
#define ZTRESS_TIMER(handler, user_data, exec_cnt, init_timeout) \
36
(ZTRESS_ID_K_TIMER, handler, user_data, exec_cnt, 0, init_timeout)
37
60
#define ZTRESS_THREAD(handler, user_data, exec_cnt, preempt_cnt, init_timeout) \
61
(ZTRESS_ID_THREAD, handler, user_data, exec_cnt, preempt_cnt, init_timeout)
62
77
typedef
bool
(*
ztress_handler
)(
void
*
user_data
,
uint32_t
cnt,
bool
last,
int
prio);
78
80
struct
ztress_context_data
{
81
/* Handler. */
82
ztress_handler
handler
;
83
84
/* User data */
85
void
*
user_data
;
86
87
/* Minimum number of executions to complete the test. */
88
uint32_t
exec_cnt
;
89
90
/* Minimum number of preemptions to complete the test. Valid only for
91
* thread context.
92
*/
93
uint32_t
preempt_cnt
;
94
95
/* Initial timeout. */
96
k_timeout_t
t
;
97
};
98
110
#define ZTRESS_CONTEXT_INITIALIZER(_handler, _user_data, _exec_cnt, _preempt_cnt, _t) \
111
{ \
112
.handler = (_handler), \
113
.user_data = (_user_data), \
114
.exec_cnt = (_exec_cnt), \
115
.preempt_cnt = (_preempt_cnt), \
116
.t = (_t) \
117
}
118
120
#define Z_ZTRESS_GET_HANDLER_DATA2(_, ...) \
121
ZTRESS_CONTEXT_INITIALIZER(__VA_ARGS__)
122
124
#define Z_ZTRESS_GET_HANDLER_DATA(data) \
125
Z_ZTRESS_GET_HANDLER_DATA2 data
126
128
#define Z_ZTRESS_HAS_TIMER(data, ...) \
129
GET_ARG_N(1, __DEBRACKET data)
130
134
#define Z_ZTRESS_TIMER_IDX(idx, data) \
135
((GET_ARG_N(1, __DEBRACKET data)) == ZTRESS_ID_K_TIMER ? idx : 0)
136
140
#define Z_ZTRESS_TIMER_CONTEXT_VALIDATE(...) \
141
BUILD_ASSERT((FOR_EACH_IDX(Z_ZTRESS_TIMER_IDX, (+), __VA_ARGS__)) == 0, \
142
"There can only be up to one ZTRESS_TIMER context and it must "
\
143
"be the first in the list")
144
155
#define ZTRESS_EXECUTE(...) do { \
156
Z_ZTRESS_TIMER_CONTEXT_VALIDATE(__VA_ARGS__); \
157
int has_timer = Z_ZTRESS_HAS_TIMER(__VA_ARGS__); \
158
struct ztress_context_data data[] = { \
159
FOR_EACH(Z_ZTRESS_GET_HANDLER_DATA, (,), __VA_ARGS__) \
160
}; \
161
size_t cnt = ARRAY_SIZE(data) - has_timer; \
162
int err = ztress_execute(has_timer ? &data[0] : NULL, &data[has_timer], cnt); \
163
\
164
zassert_equal(err, 0, "ztress_execute failed (err: %d)"
, err); \
165
} while (0)
166
182
int
ztress_execute
(
struct
ztress_context_data
*
timer_data
,
183
struct
ztress_context_data
*
thread_data
,
184
size_t
cnt);
185
187
void
ztress_abort
(
void
);
188
196
void
ztress_set_timeout
(
k_timeout_t
t
);
197
203
void
ztress_report
(
void
);
204
211
int
ztress_exec_count
(
uint32_t
id
);
212
219
int
ztress_preempt_count
(
uint32_t
id
);
220
230
uint32_t
ztress_optimized_ticks
(
uint32_t
id
);
231
232
#endif
/* TESTSUITE_ZTEST_INCLUDE_ZTRESS_H__ */
t
struct k_thread t
Definition:
kobject.c:1321
bool
#define bool
Definition:
stdbool.h:13
uint32_t
__UINT32_TYPE__ uint32_t
Definition:
stdint.h:60
k_timeout_t
Kernel timeout type.
Definition:
sys_clock.h:65
thread_data
Definition:
test_sched.h:21
timer_data
Definition:
clock.c:25
ztress_context_data
Definition:
ztress.h:80
ztress_context_data::t
k_timeout_t t
Definition:
ztress.h:96
ztress_context_data::preempt_cnt
uint32_t preempt_cnt
Definition:
ztress.h:93
ztress_context_data::user_data
void * user_data
Definition:
ztress.h:85
ztress_context_data::handler
ztress_handler handler
Definition:
ztress.h:82
ztress_context_data::exec_cnt
uint32_t exec_cnt
Definition:
ztress.h:88
user_data
static const intptr_t user_data[5]
Definition:
main.c:590
util.h
Misc utilities.
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:77
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)
subsys
testsuite
ztest
include
ztress.h
Generated on Mon Feb 21 2022 22:43:02 for Zephyr API Documentation by
1.9.2