Xenomai 3.3.2
Loading...
Searching...
No Matches
smokey.h
1/*
2 * Copyright (C) 2014 Philippe Gerum <rpm@xenomai.org>.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 */
18#ifndef _XENOMAI_SMOKEY_SMOKEY_H
19#define _XENOMAI_SMOKEY_SMOKEY_H
20
21#include <stdarg.h>
22#include <stdbool.h>
23#include <pthread.h>
24#include <boilerplate/list.h>
25#include <boilerplate/libc.h>
26#include <copperplate/clockobj.h>
27#include <xenomai/init.h>
28
29#ifdef HAVE_FORK
30#define do_fork fork
31#else
32#define do_fork vfork
33#endif
34
35#define SMOKEY_INT(__name) { \
36 .name = # __name, \
37 .parser = smokey_int, \
38 .matched = 0, \
39 }
40
41#define SMOKEY_BOOL(__name) { \
42 .name = # __name, \
43 .parser = smokey_bool, \
44 .matched = 0, \
45 }
46
47#define SMOKEY_STRING(__name) { \
48 .name = # __name, \
49 .parser = smokey_string, \
50 .matched = 0, \
51 }
52
53#define SMOKEY_SIZE(__name) { \
54 .name = # __name, \
55 .parser = smokey_size, \
56 .matched = 0, \
57 }
58
59#define SMOKEY_ARGLIST(__args...) ((struct smokey_arg[]){ __args })
60
61#define SMOKEY_NOARGS (((struct smokey_arg[]){ { .name = NULL } }))
62
63struct smokey_arg {
64 const char *name;
65 int (*parser)(const char *s,
66 struct smokey_arg *arg);
67 union {
68 int n_val;
69 char *s_val;
70 size_t l_val;
71 } u;
72 int matched;
73};
74
75struct smokey_test {
76 const char *name;
77 struct smokey_arg *args;
78 int nargs;
79 const char *description;
80 int (*run)(struct smokey_test *t,
81 int argc, char *const argv[]);
82 struct {
83 int id;
84 struct pvholder next;
85 } __reserved;
86};
87
88#define for_each_smokey_test(__pos) \
89 pvlist_for_each_entry((__pos), &smokey_test_list, __reserved.next)
90
91#define __smokey_arg_count(__args) \
92 ARRAY_SIZE(__args)
93
94#define smokey_test_plugin(__plugin, __args, __desc) \
95 static int run_ ## __plugin(struct smokey_test *t, \
96 int argc, char *const argv[]); \
97 static struct smokey_test __plugin = { \
98 .name = #__plugin, \
99 .args = (__args), \
100 .nargs = __smokey_arg_count(__args), \
101 .description = (__desc), \
102 .run = run_ ## __plugin, \
103 }; \
104 __early_ctor void smokey_plugin_ ## __plugin(void); \
105 void smokey_plugin_ ## __plugin(void) \
106 { \
107 smokey_register_plugin(&(__plugin)); \
108 }
109
110#define SMOKEY_ARG(__plugin, __arg) (smokey_lookup_arg(&(__plugin), # __arg))
111#define SMOKEY_ARG_ISSET(__plugin, __arg) (SMOKEY_ARG(__plugin, __arg)->matched)
112#define SMOKEY_ARG_INT(__plugin, __arg) (SMOKEY_ARG(__plugin, __arg)->u.n_val)
113#define SMOKEY_ARG_BOOL(__plugin, __arg) (!!SMOKEY_ARG_INT(__plugin, __arg))
114#define SMOKEY_ARG_STRING(__plugin, __arg) (SMOKEY_ARG(__plugin, __arg)->u.s_val)
115#define SMOKEY_ARG_SIZE(__plugin, __arg) (SMOKEY_ARG(__plugin, __arg)->u.l_val)
116
117#define smokey_arg_isset(__t, __name) (smokey_lookup_arg(__t, __name)->matched)
118#define smokey_arg_int(__t, __name) (smokey_lookup_arg(__t, __name)->u.n_val)
119#define smokey_arg_bool(__t, __name) (!!smokey_arg_int(__t, __name))
120#define smokey_arg_string(__t, __name) (smokey_lookup_arg(__t, __name)->u.s_val)
121#define smokey_arg_size(__t, __name) (smokey_lookup_arg(__t, __name)->u.l_val)
122
123#define smokey_check_errno(__expr) \
124 ({ \
125 int __ret = (__expr); \
126 if (__ret < 0) { \
127 __ret = -errno; \
128 __smokey_warning(__FILE__, __LINE__, "%s: %s", \
129 #__expr, strerror(errno)); \
130 } \
131 __ret; \
132 })
133
134#define smokey_check_status(__expr) \
135 ({ \
136 int __ret = (__expr); \
137 if (__ret) { \
138 __smokey_warning(__FILE__, __LINE__, "%s: %s", \
139 #__expr, strerror(__ret)); \
140 __ret = -__ret; \
141 } \
142 __ret; \
143 })
144
145#define smokey_assert(__expr) \
146 ({ \
147 int __ret = (__expr); \
148 if (!__ret) \
149 __smokey_warning(__FILE__, __LINE__, \
150 "assertion failed: %s", #__expr); \
151 __ret; \
152 })
153
154#define smokey_warning(__fmt, __args...) \
155 __smokey_warning(__FILE__, __LINE__, __fmt, ##__args)
156
157#define __T(__ret, __action) \
158 ({ \
159 (__ret) = (__action); \
160 if (__ret) { \
161 if ((__ret) > 0) \
162 (__ret) = -(__ret); \
163 smokey_warning("FAILED: %s (=%s)", \
164 __stringify(__action), \
165 symerror(__ret)); \
166 } \
167 (__ret) == 0; \
168 })
169
170#define __F(__ret, __action) \
171 ({ \
172 (__ret) = (__action); \
173 if ((__ret) == 0) \
174 smokey_warning("FAILED: %s (=0)", \
175 __stringify(__action)); \
176 else if ((__ret) > 0) \
177 (__ret) = -(__ret); \
178 (__ret) != 0; \
179 })
180
181#define __Terrno(__ret, __action) \
182 ({ \
183 (__ret) = (__action); \
184 if (__ret) { \
185 (__ret) = -errno; \
186 smokey_warning("FAILED: %s (=%s)", \
187 __stringify(__action), \
188 symerror(__ret)); \
189 } \
190 (__ret) == 0; \
191 })
192
193#define __Tassert(__expr) \
194 ({ \
195 int __ret = !!(__expr); \
196 if (!__ret) \
197 smokey_warning("FAILED: %s (=false)", \
198 __stringify(__expr)); \
199 __ret; \
200 })
201
202#define __Fassert(__expr) \
203 ({ \
204 int __ret = (__expr); \
205 if (__ret) \
206 smokey_warning("FAILED: %s (=true)", \
207 __stringify(__expr)); \
208 !__ret; \
209 })
210
211struct smokey_barrier {
212 pthread_mutex_t lock;
213 pthread_cond_t barrier;
214 int signaled;
215};
216
217#ifdef __cplusplus
218extern "C" {
219#endif
220
221void smokey_register_plugin(struct smokey_test *t);
222
223int smokey_int(const char *s, struct smokey_arg *arg);
224
225int smokey_bool(const char *s, struct smokey_arg *arg);
226
227int smokey_string(const char *s, struct smokey_arg *arg);
228
229int smokey_size(const char *s, struct smokey_arg *arg);
230
231struct smokey_arg *smokey_lookup_arg(struct smokey_test *t,
232 const char *arg);
233
234int smokey_parse_args(struct smokey_test *t,
235 int argc, char *const argv[]);
236
237void smokey_vatrace(const char *fmt, va_list ap);
238
239void smokey_trace(const char *fmt, ...);
240
241void smokey_note(const char *fmt, ...);
242
243void __smokey_warning(const char *file, int lineno,
244 const char *fmt, ...);
245
246int smokey_barrier_init(struct smokey_barrier *b);
247
248void smokey_barrier_destroy(struct smokey_barrier *b);
249
250int smokey_barrier_wait(struct smokey_barrier *b);
251
252int smokey_barrier_timedwait(struct smokey_barrier *b,
253 struct timespec *ts);
254
255void smokey_barrier_release(struct smokey_barrier *b);
256
257int smokey_fork_exec(const char *path, const char *arg);
258
259int smokey_modprobe(const char *name, bool silent);
260
261int smokey_rmmod(const char *name);
262
263int smokey_run_extprog(const char *dir, const char *name, const char *args,
264 int *test_ret);
265
266#ifdef __cplusplus
267}
268#endif
269
270extern struct pvlistobj smokey_test_list;
271
272extern int smokey_keep_going;
273
274extern int smokey_verbose_mode;
275
276extern int smokey_on_vm;
277
278#endif /* _XENOMAI_SMOKEY_SMOKEY_H */