Zephyr API Documentation  3.0.0
A Scalable Open Source RTOS
3.0.0
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
77typedef bool (*ztress_handler)(void *user_data, uint32_t cnt, bool last, int prio);
78
81 /* Handler. */
83
84 /* User data */
85 void *user_data;
86
87 /* Minimum number of executions to complete the test. */
89
90 /* Minimum number of preemptions to complete the test. Valid only for
91 * thread context.
92 */
94
95 /* Initial timeout. */
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
184 size_t cnt);
185
187void ztress_abort(void);
188
197
203void ztress_report(void);
204
212
220
231
232#endif /* TESTSUITE_ZTEST_INCLUDE_ZTRESS_H__ */
struct k_thread t
Definition: kobject.c:1321
#define bool
Definition: stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
Kernel timeout type.
Definition: sys_clock.h:65
Definition: test_sched.h:21
Definition: clock.c:25
Definition: ztress.h:80
k_timeout_t t
Definition: ztress.h:96
uint32_t preempt_cnt
Definition: ztress.h:93
void * user_data
Definition: ztress.h:85
ztress_handler handler
Definition: ztress.h:82
uint32_t exec_cnt
Definition: ztress.h:88
static const intptr_t user_data[5]
Definition: main.c:590
Misc utilities.
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:77
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)