PipeWire: pwtest.h Source File

PipeWire 0.3.69

Loading...
Searching...
No Matches
pwtest.h
Go to the documentation of this file.
1/* PipeWire */
2/* SPDX-FileCopyrightText: Copyright © 2021 Red Hat, Inc. */
3/* SPDX-License-Identifier: MIT */
4
5#include "config.h"
6
7#ifndef PWTEST_H
8#define PWTEST_H
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14#include <limits.h>
15#include <stddef.h>
16#include <stdbool.h>
17#include <math.h>
18
19#include <spa/utils/string.h>
20#include <spa/utils/dict.h>
21#include "spa/support/plugin.h"
22
136struct pwtest_context;
138struct pwtest_suite;
140struct pwtest_test;
141
142#include "pwtest-implementation.h"
143
147enum pwtest_result {
148 PWTEST_PASS = 75,
149 PWTEST_FAIL = 76,
151 PWTEST_SKIP = 77,
152 PWTEST_TIMEOUT = 78,
153 PWTEST_SYSTEM_ERROR = 79,
154};
155
161int pwtest_get_iteration(struct pwtest_test *t);
162
167struct pw_properties *pwtest_get_props(struct pwtest_test *t);
168
169struct pwtest_context *pwtest_get_context(struct pwtest_test *t);
170
172#define pwtest_fail() \
173 _pwtest_fail_condition(PWTEST_FAIL, __FILE__, __LINE__, __func__, "aborting", "")
174
176#define pwtest_fail_if_reached() \
177 _pwtest_fail_condition(PWTEST_FAIL, __FILE__, __LINE__, __func__, "This line is supposed to be unreachable", "")
178
180#define pwtest_fail_with_msg(...) \
181 _pwtest_fail_condition(PWTEST_FAIL, __FILE__, __LINE__, __func__, \
182 "aborting", __VA_ARGS__)
183
185#define pwtest_error_with_msg(...) \
186 _pwtest_fail_condition(PWTEST_SYSTEM_ERROR, __FILE__, __LINE__, __func__, \
187 "error", __VA_ARGS__)
188
190#define pwtest_errno_ok(r_) \
191 pwtest_errno_check(r_, 0);
192
194#define pwtest_errno(r_, errno_) \
195 pwtest_errno_check(r_, errno_);
196
198#define pwtest_neg_errno_ok(r_) \
199 pwtest_neg_errno_check(r_, 0);
200
202#define pwtest_neg_errno(r_, errno_) \
203 pwtest_neg_errno_check(r_, errno_);
204
206#define pwtest_bool_eq(a_, b_) \
207 pwtest_comparison_bool_(a_, ==, b_)
208
210#define pwtest_bool_ne(a_, b_) \
211 pwtest_comparison_bool_(a_, !=, b_)
212
214#define pwtest_bool_true(cond_) \
215 pwtest_comparison_bool_(cond_, ==, true)
216
218#define pwtest_bool_false(cond_) \
219 pwtest_comparison_bool_(cond_, ==, false)
220
222#define pwtest_int_eq(a_, b_) \
223 pwtest_comparison_int_(a_, ==, b_)
224
226#define pwtest_int_ne(a_, b_) \
227 pwtest_comparison_int_(a_, !=, b_)
228
230#define pwtest_int_lt(a_, b_) \
231 pwtest_comparison_int_(a_, <, b_)
232
234#define pwtest_int_le(a_, b_) \
235 pwtest_comparison_int_(a_, <=, b_)
236
238#define pwtest_int_ge(a_, b_) \
239 pwtest_comparison_int_(a_, >=, b_)
240
242#define pwtest_int_gt(a_, b_) \
243 pwtest_comparison_int_(a_, >, b_)
244
246#define pwtest_ptr_eq(a_, b_) \
247 pwtest_comparison_ptr_(a_, ==, b_)
248
250#define pwtest_ptr_ne(a_, b_) \
251 pwtest_comparison_ptr_(a_, !=, b_)
252
254#define pwtest_ptr_null(a_) \
255 pwtest_comparison_ptr_(a_, ==, NULL)
256
258#define pwtest_ptr_notnull(a_) \
259 pwtest_comparison_ptr_(a_, !=, NULL)
260
262#define pwtest_double_eq(a_, b_)\
263 pwtest_comparison_double_((a_), ==, (b_))
264
266#define pwtest_double_ne(a_, b_)\
267 pwtest_comparison_double_((a_), !=, (b_))
268
270#define pwtest_double_lt(a_, b_)\
271 pwtest_comparison_double_((a_), <, (b_))
272
274#define pwtest_double_le(a_, b_)\
275 pwtest_comparison_double_((a_), <=, (b_))
276
278#define pwtest_double_ge(a_, b_)\
279 pwtest_comparison_double_((a_), >=, (b_))
280
282#define pwtest_double_gt(a_, b_)\
283 pwtest_comparison_double_((a_), >, (b_))
284
285#define pwtest_int(a_, op_, b_) \
286 pwtest_comparison_int_(a_, op_, b_)
287
288
290#define pwtest_str_eq(a_, b_) \
291 do { \
292 const char *_a = a_; \
293 const char *_b = b_; \
294 if (!spa_streq(_a, _b)) \
295 _pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
296 #a_ " equals " #b_, _a, _b); \
297 } while(0)
298
300#define pwtest_str_eq_n(a_, b_, l_) \
301 do { \
302 const char *_a = a_; \
303 const char *_b = b_; \
304 if (!spa_strneq(_a, _b, l_)) \
305 _pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
306 #a_ " equals " #b_ ", len: " #l_, _a, _b); \
307 } while(0)
308
310#define pwtest_str_ne(a_, b_) \
311 do { \
312 const char *_a = a_; \
313 const char *_b = b_; \
314 if (spa_streq(_a, _b)) \
315 _pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
316 #a_ " not equal to " #b_, _a, _b); \
317 } while(0)
318
320#define pwtest_str_ne_n(a_, b_, l_) \
321 do { \
322 __typeof__(a_) _a = a_; \
323 __typeof__(b_) _b = b_; \
324 if (spa_strneq(_a, _b, l_)) \
325 _pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
326 #a_ " not equal to " #b_ ", len: " #l_, _a, _b); \
327 } while(0)
328
329
331#define pwtest_str_contains(haystack_, needle_) \
332 do { \
333 const char *_h = haystack_; \
334 const char *_n = needle_; \
335 if (!strstr(_h, _n)) \
336 _pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
337 #haystack_ " contains " #needle_, _h, _n); \
338 } while(0)
339
340
341/* Needs to be a #define NULL for SPA_SENTINEL */
342enum pwtest_arg {
343 PWTEST_NOARG = 0,
354 PWTEST_ARG_SIGNAL,
365 PWTEST_ARG_RANGE,
380 PWTEST_ARG_PROP,
399 PWTEST_ARG_ENV,
415 PWTEST_ARG_DAEMON,
416};
438#define pwtest_add(func_, ...) \
439 _pwtest_add(ctx, suite, #func_, func_, __VA_ARGS__, NULL)
440
441
466#define PWTEST(tname) \
467 static enum pwtest_result tname(struct pwtest_test *current_test)
468
475#define PWTEST_SUITE(cname) \
476 static enum pwtest_result (cname##__setup)(struct pwtest_context *ctx, struct pwtest_suite *suite); \
477 __attribute__((used)) \
478 __attribute__((retain)) \
479 __attribute__((section("pwtest_suite_section"))) \
480 __attribute__((aligned(__alignof__(struct pwtest_suite_decl)))) \
481 static const struct pwtest_suite_decl _test_suite = { \
482 .name = #cname, \
483 .setup = cname##__setup, \
484 }; \
485 static enum pwtest_result (cname##__setup)(struct pwtest_context *ctx, struct pwtest_suite *suite)
486
487struct pwtest_spa_plugin {
488#define PWTEST_PLUGIN_MAX 32
489 size_t nsupport;
490 struct spa_support support[PWTEST_PLUGIN_MAX];
491
492 size_t ndlls;
493 void *dlls[PWTEST_PLUGIN_MAX];
494
495 size_t nhandles;
496 struct spa_handle *handles[PWTEST_PLUGIN_MAX];
497};
498
499 struct pwtest_spa_plugin* pwtest_spa_plugin_new(void);
500 void pwtest_spa_plugin_destroy(struct pwtest_spa_plugin *plugin);
501
506 void*
507 pwtest_spa_plugin_load_interface(struct pwtest_spa_plugin *plugin,
508 const char *libname,
509 const char *factory_name,
510 const char *interface_name,
511 const struct spa_dict *info);
512
524int
525 pwtest_spa_plugin_try_load_interface(struct pwtest_spa_plugin *plugin,
526 void **iface_return,
527 const char *libname,
528 const char *factory_name,
529 const char *interface_name,
530 const struct spa_dict *info);
531
532
533
541void pwtest_mkstemp(char path[PATH_MAX]);
542
546int pwtest_spawn(const char *file, char *const argv[]);
547
548
553#ifdef __cplusplus
554}
555#endif
556
557#endif /* PWTEST_H */
pwtest_spa_plugin_load_interface
void * pwtest_spa_plugin_load_interface(struct pwtest_spa_plugin *plugin, const char *libname, const char *factory_name, const char *interface_name, const struct spa_dict *info)
Identical to pwtest_spa_plugin_try_load_interface() but returns the interface and fails if the interf...
pwtest_spa_plugin_new
struct pwtest_spa_plugin * pwtest_spa_plugin_new(void)
pwtest_get_iteration
int pwtest_get_iteration(struct pwtest_test *t)
If the test was added with a range (see PWTEST_ARG_RANGE), this function returns the current iteratio...
pwtest_spa_plugin_destroy
void pwtest_spa_plugin_destroy(struct pwtest_spa_plugin *plugin)
pwtest_mkstemp
void pwtest_mkstemp(char path[PATH_MAX])
Create a temporary file and copy its full path to path.
pwtest_spawn
int pwtest_spawn(const char *file, char *const argv[])
Run a command and wait for it to return.
pwtest_spa_plugin_try_load_interface
int pwtest_spa_plugin_try_load_interface(struct pwtest_spa_plugin *plugin, void **iface_return, const char *libname, const char *factory_name, const char *interface_name, const struct spa_dict *info)
Load interface_name from the factory in libname.
pwtest_get_context
struct pwtest_context * pwtest_get_context(struct pwtest_test *t)
pwtest_result
pwtest_result
Result returned from tests or suites.
Definition: pwtest.h:154
pwtest_arg
pwtest_arg
Definition: pwtest.h:349
pwtest_get_props
struct pw_properties * pwtest_get_props(struct pwtest_test *t)
If the test had properties set (see PWTEST_ARG_PROP), this function returns the Properties.
PWTEST_PASS
@ PWTEST_PASS
test successful
Definition: pwtest.h:155
PWTEST_TIMEOUT
@ PWTEST_TIMEOUT
test aborted after timeout
Definition: pwtest.h:159
PWTEST_SKIP
@ PWTEST_SKIP
test was skipped
Definition: pwtest.h:158
PWTEST_SYSTEM_ERROR
@ PWTEST_SYSTEM_ERROR
unrelated error occurred
Definition: pwtest.h:160
PWTEST_FAIL
@ PWTEST_FAIL
test failed.
Definition: pwtest.h:156
PWTEST_ARG_PROP
@ PWTEST_ARG_PROP
The next two const char * arguments are the key and value for a property entry.
Definition: pwtest.h:387
PWTEST_ARG_SIGNAL
@ PWTEST_ARG_SIGNAL
The next argument is an int specifying the numerical signal number.
Definition: pwtest.h:361
PWTEST_ARG_DAEMON
@ PWTEST_ARG_DAEMON
Takes no extra arguments.
Definition: pwtest.h:422
PWTEST_ARG_ENV
@ PWTEST_ARG_ENV
The next two const char * arguments are the key and value for the environment variable to be set in t...
Definition: pwtest.h:406
PWTEST_ARG_RANGE
@ PWTEST_ARG_RANGE
The next two int arguments are the minimum (inclusive) and maximum (exclusive) range for this test.
Definition: pwtest.h:372
PWTEST_NOARG
@ PWTEST_NOARG
Definition: pwtest.h:350
plugin.h
spa/support/plugin.h
PWTEST_PLUGIN_MAX
#define PWTEST_PLUGIN_MAX
Definition: pwtest.h:495
string.h
spa/utils/string.h
pw_properties
Definition: properties.h:33
pwtest_context
pwtest_spa_plugin
Definition: pwtest.h:494
pwtest_spa_plugin::ndlls
size_t ndlls
Definition: pwtest.h:499
pwtest_spa_plugin::handles
struct spa_handle * handles[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:503
pwtest_spa_plugin::nsupport
size_t nsupport
Definition: pwtest.h:496
pwtest_spa_plugin::dlls
void * dlls[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:500
pwtest_spa_plugin::support
struct spa_support support[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:497
pwtest_spa_plugin::nhandles
size_t nhandles
Definition: pwtest.h:502
pwtest_suite
pwtest_test
spa_dict
Definition: utils/dict.h:39
spa_handle
Definition: plugin.h:30
spa_support
Extra supporting infrastructure passed to the init() function of a factory.
Definition: plugin.h:76
dict.h
spa/utils/dict.h