PipeWire  0.3.49
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
31 extern "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 
156 struct pwtest_context;
158 struct pwtest_suite;
160 struct pwtest_test;
162 #include "pwtest-implementation.h"
163 
167 enum pwtest_result {
168  PWTEST_PASS = 75,
169  PWTEST_FAIL = 76,
171  PWTEST_SKIP = 77,
172  PWTEST_TIMEOUT = 78,
173  PWTEST_SYSTEM_ERROR = 79,
174 };
181 int pwtest_get_iteration(struct pwtest_test *t);
182 
187 struct pw_properties *pwtest_get_props(struct pwtest_test *t);
188 
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__)
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);
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 */
362 enum pwtest_arg {
363  PWTEST_NOARG = 0,
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  static const struct pwtest_suite_decl _test_suite \
498  __attribute__((used)) \
499  __attribute((section("pwtest_suite_section"))) = { \
500  .name = #cname, \
501  .setup = cname##__setup, \
502  }; \
503  static enum pwtest_result (cname##__setup)(struct pwtest_context *ctx, struct pwtest_suite *suite)
504 
505 struct pwtest_spa_plugin {
506 #define PWTEST_PLUGIN_MAX 32
507  size_t nsupport;
509 
510  size_t ndlls;
511  void *dlls[PWTEST_PLUGIN_MAX];
513  size_t nhandles;
515 };
516 
519 
524 void*
526  const char *libname,
527  const char *factory_name,
528  const char *interface_name,
529  const struct spa_dict *info);
530 
542 int
544  void **iface_return,
545  const char *libname,
546  const char *factory_name,
547  const char *interface_name,
548  const struct spa_dict *info);
549 
550 
551 
559 void pwtest_mkstemp(char path[PATH_MAX]);
560 
564 int pwtest_spawn(const char *file, char *const argv[]);
565 
566 
571 #ifdef __cplusplus
572 }
573 #endif
574 
575 #endif /* PWTEST_H */
Definition: properties.h:53
Definition: pwtest.h:370
size_t nsupport
Definition: pwtest.h:514
#define PWTEST_PLUGIN_MAX
Definition: pwtest.h:513
The next two int arguments are the minimum (inclusive) and maximum (exclusive) range for this test...
Definition: pwtest.h:392
spa/utils/string.h
The next two const char * arguments are the key and value for a property entry.
Definition: pwtest.h:407
struct spa_handle * handles[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:521
void pwtest_mkstemp(char path[PATH_MAX])
Create a temporary file and copy its full path to path.
test was skipped
Definition: pwtest.h:178
struct spa_support support[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:515
spa/support/plugin.h
The next two const char * arguments are the key and value for the environment variable to be set in t...
Definition: pwtest.h:426
Definition: pwtest.h:164
Definition: pwtest.h:161
Definition: dict.h:59
test successful
Definition: pwtest.h:175
Definition: pwtest.h:512
void * dlls[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:518
test failed.
Definition: pwtest.h:176
unrelated error occurred
Definition: pwtest.h:180
pwtest_arg
Definition: pwtest.h:369
Definition: plugin.h:50
test aborted after timeout
Definition: pwtest.h:179
The next argument is an int specifying the numerical signal number.
Definition: pwtest.h:381
pwtest_result
Result returned from tests or suites.
Definition: pwtest.h:174
Takes no extra arguments.
Definition: pwtest.h:442
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...
int pwtest_spawn(const char *file, char *const argv[])
Run a command and wait for it to return.
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.
struct pwtest_spa_plugin * pwtest_spa_plugin_new(void)
size_t nhandles
Definition: pwtest.h:520
Extra supporting infrastructure passed to the init() function of a factory.
Definition: plugin.h:96
size_t ndlls
Definition: pwtest.h:517
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...
spa/utils/dict.h
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.
struct pwtest_context * pwtest_get_context(struct pwtest_test *t)
void pwtest_spa_plugin_destroy(struct pwtest_spa_plugin *plugin)