PipeWire: test/pwtest.h Source File

PipeWire 0.3.64

Loading...
Searching...
No Matches
pwtest.h
Go to the documentation of this file.
1/* PipeWire
2 *
3 * Copyright © 2021 Red Hat, Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include "config.h"
26
27#ifndef PWTEST_H
28#define PWTEST_H
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#include <limits.h>
35#include <stddef.h>
36#include <stdbool.h>
37#include <math.h>
38
39#include <spa/utils/string.h>
40#include <spa/utils/dict.h>
41#include "spa/support/plugin.h"
42
156struct pwtest_context;
158struct pwtest_suite;
160struct pwtest_test;
161
162#include "pwtest-implementation.h"
163
167enum pwtest_result {
168 PWTEST_PASS = 75,
169 PWTEST_FAIL = 76,
171 PWTEST_SKIP = 77,
172 PWTEST_TIMEOUT = 78,
173 PWTEST_SYSTEM_ERROR = 79,
174};
175
181int pwtest_get_iteration(struct pwtest_test *t);
182
187struct pw_properties *pwtest_get_props(struct pwtest_test *t);
188
189struct pwtest_context *pwtest_get_context(struct pwtest_test *t);
190
192#define pwtest_fail() \
193 _pwtest_fail_condition(PWTEST_FAIL, __FILE__, __LINE__, __func__, "aborting", "")
194
196#define pwtest_fail_if_reached() \
197 _pwtest_fail_condition(PWTEST_FAIL, __FILE__, __LINE__, __func__, "This line is supposed to be unreachable", "")
198
200#define pwtest_fail_with_msg(...) \
201 _pwtest_fail_condition(PWTEST_FAIL, __FILE__, __LINE__, __func__, \
202 "aborting", __VA_ARGS__)
203
205#define pwtest_error_with_msg(...) \
206 _pwtest_fail_condition(PWTEST_SYSTEM_ERROR, __FILE__, __LINE__, __func__, \
207 "error", __VA_ARGS__)
208
210#define pwtest_errno_ok(r_) \
211 pwtest_errno_check(r_, 0);
212
214#define pwtest_errno(r_, errno_) \
215 pwtest_errno_check(r_, errno_);
216
218#define pwtest_neg_errno_ok(r_) \
219 pwtest_neg_errno_check(r_, 0);
220
222#define pwtest_neg_errno(r_, errno_) \
223 pwtest_neg_errno_check(r_, errno_);
224
226#define pwtest_bool_eq(a_, b_) \
227 pwtest_comparison_bool_(a_, ==, b_)
228
230#define pwtest_bool_ne(a_, b_) \
231 pwtest_comparison_bool_(a_, !=, b_)
232
234#define pwtest_bool_true(cond_) \
235 pwtest_comparison_bool_(cond_, ==, true)
236
238#define pwtest_bool_false(cond_) \
239 pwtest_comparison_bool_(cond_, ==, false)
240
242#define pwtest_int_eq(a_, b_) \
243 pwtest_comparison_int_(a_, ==, b_)
244
246#define pwtest_int_ne(a_, b_) \
247 pwtest_comparison_int_(a_, !=, b_)
248
250#define pwtest_int_lt(a_, b_) \
251 pwtest_comparison_int_(a_, <, b_)
252
254#define pwtest_int_le(a_, b_) \
255 pwtest_comparison_int_(a_, <=, b_)
256
258#define pwtest_int_ge(a_, b_) \
259 pwtest_comparison_int_(a_, >=, b_)
260
262#define pwtest_int_gt(a_, b_) \
263 pwtest_comparison_int_(a_, >, b_)
264
266#define pwtest_ptr_eq(a_, b_) \
267 pwtest_comparison_ptr_(a_, ==, b_)
268
270#define pwtest_ptr_ne(a_, b_) \
271 pwtest_comparison_ptr_(a_, !=, b_)
272
274#define pwtest_ptr_null(a_) \
275 pwtest_comparison_ptr_(a_, ==, NULL)
276
278#define pwtest_ptr_notnull(a_) \
279 pwtest_comparison_ptr_(a_, !=, NULL)
280
282#define pwtest_double_eq(a_, b_)\
283 pwtest_comparison_double_((a_), ==, (b_))
284
286#define pwtest_double_ne(a_, b_)\
287 pwtest_comparison_double_((a_), !=, (b_))
288
290#define pwtest_double_lt(a_, b_)\
291 pwtest_comparison_double_((a_), <, (b_))
292
294#define pwtest_double_le(a_, b_)\
295 pwtest_comparison_double_((a_), <=, (b_))
296
298#define pwtest_double_ge(a_, b_)\
299 pwtest_comparison_double_((a_), >=, (b_))
300
302#define pwtest_double_gt(a_, b_)\
303 pwtest_comparison_double_((a_), >, (b_))
304
305#define pwtest_int(a_, op_, b_) \
306 pwtest_comparison_int_(a_, op_, b_)
307
308
310#define pwtest_str_eq(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_ " equals " #b_, _a, _b); \
317 } while(0)
318
320#define pwtest_str_eq_n(a_, b_, l_) \
321 do { \
322 const char *_a = a_; \
323 const char *_b = b_; \
324 if (!spa_strneq(_a, _b, l_)) \
325 _pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
326 #a_ " equals " #b_ ", len: " #l_, _a, _b); \
327 } while(0)
328
330#define pwtest_str_ne(a_, b_) \
331 do { \
332 const char *_a = a_; \
333 const char *_b = b_; \
334 if (spa_streq(_a, _b)) \
335 _pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
336 #a_ " not equal to " #b_, _a, _b); \
337 } while(0)
338
340#define pwtest_str_ne_n(a_, b_, l_) \
341 do { \
342 __typeof__(a_) _a = a_; \
343 __typeof__(b_) _b = b_; \
344 if (spa_strneq(_a, _b, l_)) \
345 _pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
346 #a_ " not equal to " #b_ ", len: " #l_, _a, _b); \
347 } while(0)
348
349
351#define pwtest_str_contains(haystack_, needle_) \
352 do { \
353 const char *_h = haystack_; \
354 const char *_n = needle_; \
355 if (!strstr(_h, _n)) \
356 _pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
357 #haystack_ " contains " #needle_, _h, _n); \
358 } while(0)
359
360
361/* Needs to be a #define NULL for SPA_SENTINEL */
362enum pwtest_arg {
363 PWTEST_NOARG = 0,
374 PWTEST_ARG_SIGNAL,
385 PWTEST_ARG_RANGE,
400 PWTEST_ARG_PROP,
419 PWTEST_ARG_ENV,
435 PWTEST_ARG_DAEMON,
436};
458#define pwtest_add(func_, ...) \
459 _pwtest_add(ctx, suite, #func_, func_, __VA_ARGS__, NULL)
460
461
486#define PWTEST(tname) \
487 static enum pwtest_result tname(struct pwtest_test *current_test)
488
495#define PWTEST_SUITE(cname) \
496 static enum pwtest_result (cname##__setup)(struct pwtest_context *ctx, struct pwtest_suite *suite); \
497 __attribute__((used)) \
498 __attribute__((retain)) \
499 __attribute__((section("pwtest_suite_section"))) \
500 __attribute__((aligned(__alignof__(struct pwtest_suite_decl)))) \
501 static const struct pwtest_suite_decl _test_suite = { \
502 .name = #cname, \
503 .setup = cname##__setup, \
504 }; \
505 static enum pwtest_result (cname##__setup)(struct pwtest_context *ctx, struct pwtest_suite *suite)
506
507struct pwtest_spa_plugin {
508#define PWTEST_PLUGIN_MAX 32
509 size_t nsupport;
510 struct spa_support support[PWTEST_PLUGIN_MAX];
511
512 size_t ndlls;
513 void *dlls[PWTEST_PLUGIN_MAX];
514
515 size_t nhandles;
516 struct spa_handle *handles[PWTEST_PLUGIN_MAX];
517};
518
519 struct pwtest_spa_plugin* pwtest_spa_plugin_new(void);
520 void pwtest_spa_plugin_destroy(struct pwtest_spa_plugin *plugin);
521
526 void*
527 pwtest_spa_plugin_load_interface(struct pwtest_spa_plugin *plugin,
528 const char *libname,
529 const char *factory_name,
530 const char *interface_name,
531 const struct spa_dict *info);
532
544int
545 pwtest_spa_plugin_try_load_interface(struct pwtest_spa_plugin *plugin,
546 void **iface_return,
547 const char *libname,
548 const char *factory_name,
549 const char *interface_name,
550 const struct spa_dict *info);
551
552
553
561void pwtest_mkstemp(char path[PATH_MAX]);
562
566int pwtest_spawn(const char *file, char *const argv[]);
567
568
573#ifdef __cplusplus
574}
575#endif
576
577#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:174
pwtest_arg
pwtest_arg
Definition: pwtest.h:369
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:175
PWTEST_TIMEOUT
@ PWTEST_TIMEOUT
test aborted after timeout
Definition: pwtest.h:179
PWTEST_SKIP
@ PWTEST_SKIP
test was skipped
Definition: pwtest.h:178
PWTEST_SYSTEM_ERROR
@ PWTEST_SYSTEM_ERROR
unrelated error occurred
Definition: pwtest.h:180
PWTEST_FAIL
@ PWTEST_FAIL
test failed.
Definition: pwtest.h:176
PWTEST_ARG_PROP
@ PWTEST_ARG_PROP
The next two const char * arguments are the key and value for a property entry.
Definition: pwtest.h:407
PWTEST_ARG_SIGNAL
@ PWTEST_ARG_SIGNAL
The next argument is an int specifying the numerical signal number.
Definition: pwtest.h:381
PWTEST_ARG_DAEMON
@ PWTEST_ARG_DAEMON
Takes no extra arguments.
Definition: pwtest.h:442
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:426
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:392
PWTEST_NOARG
@ PWTEST_NOARG
Definition: pwtest.h:370
plugin.h
spa/support/plugin.h
PWTEST_PLUGIN_MAX
#define PWTEST_PLUGIN_MAX
Definition: pwtest.h:515
string.h
spa/utils/string.h
pw_properties
Definition: properties.h:53
pwtest_context
pwtest_spa_plugin
Definition: pwtest.h:514
pwtest_spa_plugin::ndlls
size_t ndlls
Definition: pwtest.h:519
pwtest_spa_plugin::handles
struct spa_handle * handles[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:523
pwtest_spa_plugin::nsupport
size_t nsupport
Definition: pwtest.h:516
pwtest_spa_plugin::dlls
void * dlls[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:520
pwtest_spa_plugin::support
struct spa_support support[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:517
pwtest_spa_plugin::nhandles
size_t nhandles
Definition: pwtest.h:522
pwtest_suite
pwtest_test
spa_dict
Definition: dict.h:59
spa_handle
Definition: plugin.h:50
spa_support
Extra supporting infrastructure passed to the init() function of a factory.
Definition: plugin.h:96
dict.h
spa/utils/dict.h