RTEMS: cpukit/include/rtems/test.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
test.h
1/*
2 * Copyright (c) 2014, 2018 embedded brains GmbH. All rights reserved.
3 *
4 * embedded brains GmbH
5 * Dornierstr. 4
6 * 82178 Puchheim
7 * Germany
8 * <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifndef _RTEMS_TEST_H
16#define _RTEMS_TEST_H
17
18#include <rtems.h>
19#include <rtems/printer.h>
20#include <rtems/score/atomic.h>
21#include <rtems/score/smpbarrier.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif /* __cplusplus */
26
40extern const char rtems_test_name[];
41
45extern rtems_printer rtems_test_printer;
46
50void rtems_test_fatal_extension(
51 rtems_fatal_source source,
52 bool always_set_to_false,
53 rtems_fatal_code code
54);
55
59#define RTEMS_TEST_INITIAL_EXTENSION \
60 { NULL, NULL, NULL, NULL, NULL, NULL, NULL, rtems_test_fatal_extension }
61
65 typedef enum
66{
67 RTEMS_TEST_STATE_PASS,
68 RTEMS_TEST_STATE_FAIL,
69 RTEMS_TEST_STATE_USER_INPUT,
70 RTEMS_TEST_STATE_INDETERMINATE,
71 RTEMS_TEST_STATE_BENCHMARK
72} RTEMS_TEST_STATE;
73
74#if (TEST_STATE_EXPECTED_FAIL && TEST_STATE_USER_INPUT) || \
75 (TEST_STATE_EXPECTED_FAIL && TEST_STATE_INDETERMINATE) || \
76 (TEST_STATE_EXPECTED_FAIL && TEST_STATE_BENCHMARK) || \
77 (TEST_STATE_USER_INPUT && TEST_STATE_INDETERMINATE) || \
78 (TEST_STATE_USER_INPUT && TEST_STATE_BENCHMARK) || \
79 (TEST_STATE_INDETERMINATE && TEST_STATE_BENCHMARK)
80 #error Test states must be unique
81#endif
82
83#if TEST_STATE_EXPECTED_FAIL
84 #define TEST_STATE RTEMS_TEST_STATE_FAIL
85#elif TEST_STATE_USER_INPUT
86 #define TEST_STATE RTEMS_TEST_STATE_USER_INPUT
87#elif TEST_STATE_INDETERMINATE
88 #define TEST_STATE RTEMS_TEST_STATE_INDETERMINATE
89#elif TEST_STATE_BENCHMARK
90 #define TEST_STATE RTEMS_TEST_STATE_BENCHMARK
91#else
92 #define TEST_STATE RTEMS_TEST_STATE_PASS
93#endif
94
100int rtems_test_begin(const char* name, const RTEMS_TEST_STATE state);
101
107int rtems_test_end(const char* name);
108
113void rtems_test_exit(int status) RTEMS_NO_RETURN;
114
120 int rtems_test_printf(const char* format, ...) RTEMS_PRINTFLIKE(1, 2);
121
122#define RTEMS_TEST_PARALLEL_PROCESSOR_MAX 32
123
124typedef struct rtems_test_parallel_job rtems_test_parallel_job;
125
129 typedef struct {
130 Atomic_Ulong stop;
131 SMP_barrier_Control barrier;
132 size_t worker_count;
133 rtems_id worker_ids[RTEMS_TEST_PARALLEL_PROCESSOR_MAX];
134 rtems_id stop_worker_timer_id;
135 const struct rtems_test_parallel_job *jobs;
136 size_t job_count;
137} rtems_test_parallel_context;
138
149 typedef void (*rtems_test_parallel_worker_setup)(
150 rtems_test_parallel_context *ctx,
151 size_t worker_index,
152 rtems_id worker_id
153);
154
158 struct rtems_test_parallel_job {
173 rtems_interval (*init)(
174 rtems_test_parallel_context *ctx,
175 void *arg,
176 size_t active_workers
177 );
178
189 void (*body)(
190 rtems_test_parallel_context *ctx,
191 void *arg,
192 size_t active_workers,
193 size_t worker_index
194 );
195
207 void (*fini)(
208 rtems_test_parallel_context *ctx,
209 void *arg,
210 size_t active_workers
211 );
212
216 void *arg;
217
225 bool cascade;
226};
227
236static inline bool rtems_test_parallel_stop_job(
237 const rtems_test_parallel_context *ctx
238)
239{
240 return _Atomic_Load_ulong(&ctx->stop, ATOMIC_ORDER_RELAXED) != 0;
241}
242
253static inline bool rtems_test_parallel_is_master_worker(size_t worker_index)
254{
255 return worker_index == 0;
256}
257
266static inline rtems_id rtems_test_parallel_get_task_id(
267 const rtems_test_parallel_context *ctx,
268 size_t worker_index
269)
270{
271 return ctx->worker_ids[worker_index];
272}
273
287void rtems_test_parallel(
288 rtems_test_parallel_context *ctx,
289 rtems_test_parallel_worker_setup worker_setup,
290 const rtems_test_parallel_job *jobs,
291 size_t job_count
292);
293
305void rtems_test_busy_cpu_usage(time_t seconds, long nanoseconds);
306
315void rtems_test_busy(uint_fast32_t count);
316
321uint_fast32_t rtems_test_get_one_tick_busy_count(void);
322
325#ifdef __cplusplus
326}
327#endif /* __cplusplus */
328
329#endif /* _RTEMS_TEST_H */
rtems_id
Objects_Id rtems_id
Used to manage and manipulate RTEMS object identifiers.
Definition: types.h:83
rtems_interval
Watchdog_Interval rtems_interval
Used to manage and manipulate intervals specified by clock ticks.
Definition: types.h:127
RTEMS_NO_RETURN
#define RTEMS_NO_RETURN
Definition: basedefs.h:102
RTEMS_PRINTFLIKE
#define RTEMS_PRINTFLIKE(_format_pos, _ap_pos)
Tells the compiler that this function expects printf()-like arguments.
Definition: basedefs.h:249
Internal_errors_Source
Internal_errors_Source
This type lists the possible sources from which an error can be reported.
Definition: interr.h:47
rtems_test_get_one_tick_busy_count
uint_fast32_t rtems_test_get_one_tick_busy_count(void)
Returns a count value for rtems_test_busy() which yields roughly a duration of one clock tick.
Definition: testbusy.c:63
rtems_test_busy_cpu_usage
void rtems_test_busy_cpu_usage(time_t seconds, long nanoseconds)
Performs a busy loop for the specified seconds and nanoseconds based on the CPU usage of the executin...
Definition: testbusy.c:110
rtems_test_busy
void rtems_test_busy(uint_fast32_t count)
Performs a busy loop with the specified iteration count.
Definition: testbusy.c:53
rtems_test_printer
rtems_printer rtems_test_printer
Each test must define a printer.
Definition: testbeginend.c:25
rtems_test_name
const char rtems_test_name[]
Each test must define a test name string.
rtems_test_printf
int rtems_test_printf(const char *format,...) RTEMS_PRINTFLIKE(1
Prints via the RTEMS printer.
rtems_test_fatal_extension
void rtems_test_fatal_extension(rtems_fatal_source source, bool always_set_to_false, rtems_fatal_code code)
Fatal extension for tests.
Definition: testextension.c:29
rtems_test_parallel_worker_setup
void(* rtems_test_parallel_worker_setup)(rtems_test_parallel_context *ctx, size_t worker_index, rtems_id worker_id)
Worker task setup handler.
Definition: test.h:149
rtems_test_exit
void rtems_test_exit(int status) RTEMS_NO_RETURN
Exit the test without calling exit() since it closes stdin, etc and pulls in stdio code.
Definition: testbeginend.c:83
RTEMS_TEST_STATE
RTEMS_TEST_STATE
Test states.
Definition: test.h:66
rtems_test_parallel
void rtems_test_parallel(rtems_test_parallel_context *ctx, rtems_test_parallel_worker_setup worker_setup, const rtems_test_parallel_job *jobs, size_t job_count)
Runs a bunch of jobs in parallel on all processors of the system.
Definition: testparallel.c:123
rtems_test_begin
int rtems_test_begin(const char *name, const RTEMS_TEST_STATE state)
Prints a begin of test message using printf().
Definition: testbeginend.c:38
rtems_test_end
int rtems_test_end(const char *name)
Prints an end of test message using printf().
Definition: testbeginend.c:75
atomic.h
Atomic Operations API.
printer.h
User print interface to the bspIO print plug in.
rtems.h
smpbarrier.h
SMP Barrier API.
SMP_barrier_Control
SMP barrier control.
Definition: smpbarrier.h:51
code
Definition: inftrees.h:24
format
Definition: mknod-pack_dev.c:254
rtems_printer
Definition: printer.h:55
rtems_test_parallel_context
Internal context for parallel job execution.
Definition: test.h:129
rtems_test_parallel_job
Basic parallel job description.
Definition: test.h:158
rtems_test_parallel_job::init
rtems_interval(* init)(rtems_test_parallel_context *ctx, void *arg, size_t active_workers)
Job initialization handler.
Definition: test.h:173
rtems_test_parallel_job::arg
void * arg
Job specific argument.
Definition: test.h:216
rtems_test_parallel_job::body
void(* body)(rtems_test_parallel_context *ctx, void *arg, size_t active_workers, size_t worker_index)
Job body handler.
Definition: test.h:189
rtems_test_parallel_job::fini
void(* fini)(rtems_test_parallel_context *ctx, void *arg, size_t active_workers)
Job finalization handler.
Definition: test.h:207
rtems_test_parallel_job::cascade
bool cascade
Job cascading flag.
Definition: test.h:225