RTEMS  5.0.0
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
24 extern "C" {
25 #endif /* __cplusplus */
26 
38 extern const char rtems_test_name[];
39 
44 
49  rtems_fatal_source source,
50  bool always_set_to_false,
51  rtems_fatal_code code
52 );
53 
57 #define RTEMS_TEST_INITIAL_EXTENSION \
58  { NULL, NULL, NULL, NULL, NULL, NULL, NULL, rtems_test_fatal_extension }
59 
63 typedef enum
64 {
65  RTEMS_TEST_STATE_PASS,
66  RTEMS_TEST_STATE_FAIL,
67  RTEMS_TEST_STATE_USER_INPUT,
68  RTEMS_TEST_STATE_INDETERMINATE,
69  RTEMS_TEST_STATE_BENCHMARK
71 
72 #if (TEST_STATE_EXPECTED_FAIL && TEST_STATE_USER_INPUT) || \
73  (TEST_STATE_EXPECTED_FAIL && TEST_STATE_INDETERMINATE) || \
74  (TEST_STATE_EXPECTED_FAIL && TEST_STATE_BENCHMARK) || \
75  (TEST_STATE_USER_INPUT && TEST_STATE_INDETERMINATE) || \
76  (TEST_STATE_USER_INPUT && TEST_STATE_BENCHMARK) || \
77  (TEST_STATE_INDETERMINATE && TEST_STATE_BENCHMARK)
78  #error Test states must be unique
79 #endif
80 
81 #if TEST_STATE_EXPECTED_FAIL
82  #define TEST_STATE RTEMS_TEST_STATE_FAIL
83 #elif TEST_STATE_USER_INPUT
84  #define TEST_STATE RTEMS_TEST_STATE_USER_INPUT
85 #elif TEST_STATE_INDETERMINATE
86  #define TEST_STATE RTEMS_TEST_STATE_INDETERMINATE
87 #elif TEST_STATE_BENCHMARK
88  #define TEST_STATE RTEMS_TEST_STATE_BENCHMARK
89 #else
90  #define TEST_STATE RTEMS_TEST_STATE_PASS
91 #endif
92 
98 int rtems_test_begin(const char* name, const RTEMS_TEST_STATE state);
99 
105 int rtems_test_end(const char* name);
106 
111 void rtems_test_exit(int status) RTEMS_NO_RETURN;
112 
118 int rtems_test_printf(const char* format, ...) RTEMS_PRINTFLIKE(1, 2);
119 
120 #define RTEMS_TEST_PARALLEL_PROCESSOR_MAX 32
121 
122 typedef struct rtems_test_parallel_job rtems_test_parallel_job;
123 
127 typedef struct {
128  Atomic_Ulong stop;
129  SMP_barrier_Control barrier;
130  size_t worker_count;
131  rtems_id worker_ids[RTEMS_TEST_PARALLEL_PROCESSOR_MAX];
132  rtems_id stop_worker_timer_id;
133  const struct rtems_test_parallel_job *jobs;
134  size_t job_count;
136 
149  size_t worker_index,
150  rtems_id worker_id
151 );
152 
156 struct rtems_test_parallel_job {
173  void *arg,
174  size_t active_workers
175  );
176 
187  void (*body)(
189  void *arg,
190  size_t active_workers,
191  size_t worker_index
192  );
193 
205  void (*fini)(
207  void *arg,
208  size_t active_workers
209  );
210 
214  void *arg;
215 
223  bool cascade;
224 };
225 
234 static inline bool rtems_test_parallel_stop_job(
235  const rtems_test_parallel_context *ctx
236 )
237 {
238  return _Atomic_Load_ulong(&ctx->stop, ATOMIC_ORDER_RELAXED) != 0;
239 }
240 
251 static inline bool rtems_test_parallel_is_master_worker(size_t worker_index)
252 {
253  return worker_index == 0;
254 }
255 
264 static inline rtems_id rtems_test_parallel_get_task_id(
265  const rtems_test_parallel_context *ctx,
266  size_t worker_index
267 )
268 {
269  return ctx->worker_ids[worker_index];
270 }
271 
288  const rtems_test_parallel_job *jobs,
289  size_t job_count
290 );
291 
303 void rtems_test_busy_cpu_usage(time_t seconds, long nanoseconds);
304 
313 void rtems_test_busy(uint_fast32_t count);
314 
319 uint_fast32_t rtems_test_get_one_tick_busy_count(void);
320 
323 #ifdef __cplusplus
324 }
325 #endif /* __cplusplus */
326 
327 #endif /* _RTEMS_TEST_H */
Watchdog_Interval rtems_interval
Used to manage and manipulate intervals specified by clock ticks.
Definition: types.h:127
rtems_interval(* init)(rtems_test_parallel_context *ctx, void *arg, size_t active_workers)
Job initialization handler.
Definition: test.h:171
const char rtems_test_name[]
Each test must define a test name string.
SMP barrier control.
Definition: smpbarrier.h:51
SMP Barrier API.
Definition: mknod-pack_dev.c:254
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:147
Basic parallel job description.
Definition: test.h:156
Definition: printer.h:55
Atomic Operations API.
RTEMS_TEST_STATE
Test states.
Definition: test.h:63
int rtems_test_begin(const char *name, const RTEMS_TEST_STATE state)
Prints a begin of test message using printf().
Definition: testbeginend.c:38
int rtems_test_printf(const char *format,...) RTEMS_PRINTFLIKE(1
Prints via the RTEMS printer.
int rtems_test_end(const char *name)
Prints an end of test message using printf().
Definition: testbeginend.c:75
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
Internal context for parallel job execution.
Definition: test.h:127
bool cascade
Job cascading flag.
Definition: test.h:223
void(* fini)(rtems_test_parallel_context *ctx, void *arg, size_t active_workers)
Job finalization handler.
Definition: test.h:205
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
#define RTEMS_NO_RETURN
Definition: basedefs.h:101
void rtems_test_busy(uint_fast32_t count)
Performs a busy loop with the specified iteration count.
Definition: testbusy.c:53
void * arg
Job specific argument.
Definition: test.h:214
Definition: inftrees.h:24
rtems_printer rtems_test_printer
Each test must define a printer.
Definition: testbeginend.c:25
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
#define RTEMS_PRINTFLIKE(_format_pos, _ap_pos)
Tells the compiler that this function expects printf()-like arguments.
Definition: basedefs.h:237
void(* body)(rtems_test_parallel_context *ctx, void *arg, size_t active_workers, size_t worker_index)
Job body handler.
Definition: test.h:187
Objects_Id rtems_id
Used to manage and manipulate RTEMS object identifiers.
Definition: types.h:83
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
User print interface to the bspIO print plug in.
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
Internal_errors_Source
This type lists the possible sources from which an error can be reported.
Definition: interr.h:42