PipeWire  0.3.33
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 
153 struct pwtest_context;
155 struct pwtest_suite;
157 struct pwtest_test;
158 
159 #include "pwtest-implementation.h"
160 
165  PWTEST_PASS = 75,
166  PWTEST_FAIL = 76,
168  PWTEST_SKIP = 77,
171 };
172 
179 
185 
187 
189 #define pwtest_fail() \
190  _pwtest_fail_condition(PWTEST_FAIL, __FILE__, __LINE__, __func__, "aborting", "")
191 
193 #define pwtest_fail_if_reached() \
194  _pwtest_fail_condition(PWTEST_FAIL, __FILE__, __LINE__, __func__, "This line is supposed to be unreachable", "")
195 
197 #define pwtest_fail_with_msg(...) \
198  _pwtest_fail_condition(PWTEST_FAIL, __FILE__, __LINE__, __func__, \
199  "aborting", __VA_ARGS__)
200 
202 #define pwtest_error_with_msg(...) \
203  _pwtest_fail_condition(PWTEST_SYSTEM_ERROR, __FILE__, __LINE__, __func__, \
204  "error", __VA_ARGS__)
205 
207 #define pwtest_errno_ok(r_) \
208  pwtest_errno_check(r_, 0);
209 
211 #define pwtest_errno(r_, errno_) \
212  pwtest_errno_check(r_, errno_);
213 
215 #define pwtest_neg_errno_ok(r_) \
216  pwtest_neg_errno_check(r_, 0);
217 
219 #define pwtest_neg_errno(r_, errno_) \
220  pwtest_neg_errno_check(r_, errno_);
221 
223 #define pwtest_bool_eq(a_, b_) \
224  pwtest_comparison_bool_(a_, ==, b_)
225 
227 #define pwtest_bool_ne(a_, b_) \
228  pwtest_comparison_bool_(a_, !=, b_)
229 
231 #define pwtest_bool_true(cond_) \
232  pwtest_comparison_bool_(cond_, ==, true)
233 
235 #define pwtest_bool_false(cond_) \
236  pwtest_comparison_bool_(cond_, ==, false)
237 
239 #define pwtest_int_eq(a_, b_) \
240  pwtest_comparison_int_(a_, ==, b_)
241 
243 #define pwtest_int_ne(a_, b_) \
244  pwtest_comparison_int_(a_, !=, b_)
245 
247 #define pwtest_int_lt(a_, b_) \
248  pwtest_comparison_int_(a_, <, b_)
249 
251 #define pwtest_int_le(a_, b_) \
252  pwtest_comparison_int_(a_, <=, b_)
253 
255 #define pwtest_int_ge(a_, b_) \
256  pwtest_comparison_int_(a_, >=, b_)
257 
259 #define pwtest_int_gt(a_, b_) \
260  pwtest_comparison_int_(a_, >, b_)
261 
263 #define pwtest_ptr_eq(a_, b_) \
264  pwtest_comparison_ptr_(a_, ==, b_)
265 
267 #define pwtest_ptr_ne(a_, b_) \
268  pwtest_comparison_ptr_(a_, !=, b_)
269 
271 #define pwtest_ptr_null(a_) \
272  pwtest_comparison_ptr_(a_, ==, NULL)
273 
275 #define pwtest_ptr_notnull(a_) \
276  pwtest_comparison_ptr_(a_, !=, NULL)
277 
279 #define pwtest_double_eq(a_, b_)\
280  pwtest_comparison_double_((a_), ==, (b_))
281 
283 #define pwtest_double_ne(a_, b_)\
284  pwtest_comparison_double_((a_), !=, (b_))
285 
287 #define pwtest_double_lt(a_, b_)\
288  pwtest_comparison_double_((a_), <, (b_))
289 
291 #define pwtest_double_le(a_, b_)\
292  pwtest_comparison_double_((a_), <=, (b_))
293 
295 #define pwtest_double_ge(a_, b_)\
296  pwtest_comparison_double_((a_), >=, (b_))
297 
299 #define pwtest_double_gt(a_, b_)\
300  pwtest_comparison_double_((a_), >, (b_))
301 
302 #define pwtest_int(a_, op_, b_) \
303  pwtest_comparison_int_(a_, op_, b_)
304 
305 
307 #define pwtest_str_eq(a_, b_) \
308  do { \
309  const char *_a = a_; \
310  const char *_b = b_; \
311  if (!spa_streq(_a, _b)) \
312  _pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
313  #a_ " equals " #b_, _a, _b); \
314  } while(0)
315 
317 #define pwtest_str_eq_n(a_, b_, l_) \
318  do { \
319  const char *_a = a_; \
320  const char *_b = b_; \
321  if (!spa_strneq(_a, _b, l_)) \
322  _pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
323  #a_ " equals " #b_ ", len: " #l_, _a, _b); \
324  } while(0)
325 
327 #define pwtest_str_ne(a_, b_) \
328  do { \
329  const char *_a = a_; \
330  const char *_b = b_; \
331  if (spa_streq(_a, _b)) \
332  _pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
333  #a_ " not equal to " #b_, _a, _b); \
334  } while(0)
335 
337 #define pwtest_str_ne_n(a_, b_, l_) \
338  do { \
339  __typeof__(a_) _a = a_; \
340  __typeof__(b_) _b = b_; \
341  if (spa_strneq(_a, _b, l_)) \
342  _pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
343  #a_ " not equal to " #b_ ", len: " #l_, _a, _b); \
344  } while(0)
345 
346 
347 /* Needs to be a #define NULL for SPA_SENTINEL */
422 };
444 #define pwtest_add(func_, ...) \
445  _pwtest_add(ctx, suite, #func_, func_, __VA_ARGS__, NULL)
446 
447 
472 #define PWTEST(tname) \
473  static enum pwtest_result tname(struct pwtest_test *current_test)
474 
481 #define PWTEST_SUITE(cname) \
482  static enum pwtest_result (cname##__setup)(struct pwtest_context *ctx, struct pwtest_suite *suite); \
483  static const struct pwtest_suite_decl _test_suite \
484  __attribute__((used)) \
485  __attribute((section("pwtest_suite_section"))) = { \
486  .name = #cname, \
487  .setup = cname##__setup, \
488  }; \
489  static enum pwtest_result (cname##__setup)(struct pwtest_context *ctx, struct pwtest_suite *suite)
490 
492 #define PWTEST_PLUGIN_MAX 32
493  size_t nsupport;
495 
496  size_t ndlls;
498 
499  size_t nhandles;
501 };
502 
505 
510 void*
512  const char *libname,
513  const char *factory_name,
514  const char *interface_name,
515  const struct spa_dict *info);
516 
528 int
530  void **iface_return,
531  const char *libname,
532  const char *factory_name,
533  const char *interface_name,
534  const struct spa_dict *info);
535 
536 
537 
545 void pwtest_mkstemp(char path[PATH_MAX]);
546 
547 
552 #ifdef __cplusplus
553 }
554 #endif
555 
556 #endif /* PWTEST_H */
PWTEST_ARG_PROP
@ PWTEST_ARG_PROP
The next two const char * arguments are the key and value for a property entry.
Definition: pwtest.h:386
PWTEST_FAIL
@ PWTEST_FAIL
test failed.
Definition: pwtest.h:166
pwtest_context
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:371
pwtest_spa_plugin::ndlls
size_t ndlls
Definition: pwtest.h:496
pwtest_mkstemp
void pwtest_mkstemp(char path[PATH_MAX])
Create a temporary file and copy its full path to path.
string.h
pwtest_spa_plugin::nsupport
size_t nsupport
Definition: pwtest.h:493
pwtest_test
Definition: pwtest.h:155
PWTEST_NOARG
@ PWTEST_NOARG
Definition: pwtest.h:349
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_PLUGIN_MAX
#define PWTEST_PLUGIN_MAX
Definition: pwtest.h:492
plugin.h
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 Key-Value pairs.
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_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_SYSTEM_ERROR
@ PWTEST_SYSTEM_ERROR
unrelated error occured
Definition: pwtest.h:170
pwtest_suite
Definition: pwtest.h:153
pwtest_spa_plugin
Definition: pwtest.h:491
PWTEST_ARG_SIGNAL
@ PWTEST_ARG_SIGNAL
The next argument is an int specifying the numerical signal number.
Definition: pwtest.h:360
PWTEST_PASS
@ PWTEST_PASS
test successful
Definition: pwtest.h:165
plugin
Definition: pipewire.c:59
pwtest_result
pwtest_result
Result returned from tests or suites.
Definition: pwtest.h:164
pwtest_spa_plugin_new
struct pwtest_spa_plugin * pwtest_spa_plugin_new(void)
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:405
spa_handle
Definition: plugin.h:44
pwtest_spa_plugin::handles
struct spa_handle * handles[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:500
spa_dict
Definition: utils/dict.h:48
PWTEST_TIMEOUT
@ PWTEST_TIMEOUT
test aborted after timeout
Definition: pwtest.h:169
PWTEST_ARG_DAEMON
@ PWTEST_ARG_DAEMON
Takes no extra arguments.
Definition: pwtest.h:421
pwtest_spa_plugin::nhandles
size_t nhandles
Definition: pwtest.h:499
pwtest_spa_plugin_destroy
void pwtest_spa_plugin_destroy(struct pwtest_spa_plugin *plugin)
PWTEST_SKIP
@ PWTEST_SKIP
test was skipped
Definition: pwtest.h:168
pwtest_spa_plugin::dlls
void * dlls[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:497
pwtest_arg
pwtest_arg
Definition: pwtest.h:348
spa_support
Extra supporting infrastructure passed to the init() function of a factory.
Definition: plugin.h:89
pwtest_get_context
struct pwtest_context * pwtest_get_context(struct pwtest_test *t)
support
Definition: pipewire.c:80
pw_properties
Definition: properties.h:49
dict.h