162 #include "pwtest-implementation.h"
192 #define pwtest_fail() \
193 _pwtest_fail_condition(PWTEST_FAIL, __FILE__, __LINE__, __func__, "aborting", "")
196 #define pwtest_fail_if_reached() \
197 _pwtest_fail_condition(PWTEST_FAIL, __FILE__, __LINE__, __func__, "This line is supposed to be unreachable", "")
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__)
210 #define pwtest_errno_ok(r_) \
211 pwtest_errno_check(r_, 0);
214 #define pwtest_errno(r_, errno_) \
215 pwtest_errno_check(r_, errno_);
218 #define pwtest_neg_errno_ok(r_) \
219 pwtest_neg_errno_check(r_, 0);
222 #define pwtest_neg_errno(r_, errno_) \
223 pwtest_neg_errno_check(r_, errno_);
226 #define pwtest_bool_eq(a_, b_) \
227 pwtest_comparison_bool_(a_, ==, b_)
230 #define pwtest_bool_ne(a_, b_) \
231 pwtest_comparison_bool_(a_, !=, b_)
234 #define pwtest_bool_true(cond_) \
235 pwtest_comparison_bool_(cond_, ==, true)
238 #define pwtest_bool_false(cond_) \
239 pwtest_comparison_bool_(cond_, ==, false)
242 #define pwtest_int_eq(a_, b_) \
243 pwtest_comparison_int_(a_, ==, b_)
246 #define pwtest_int_ne(a_, b_) \
247 pwtest_comparison_int_(a_, !=, b_)
250 #define pwtest_int_lt(a_, b_) \
251 pwtest_comparison_int_(a_, <, b_)
254 #define pwtest_int_le(a_, b_) \
255 pwtest_comparison_int_(a_, <=, b_)
258 #define pwtest_int_ge(a_, b_) \
259 pwtest_comparison_int_(a_, >=, b_)
262 #define pwtest_int_gt(a_, b_) \
263 pwtest_comparison_int_(a_, >, b_)
266 #define pwtest_ptr_eq(a_, b_) \
267 pwtest_comparison_ptr_(a_, ==, b_)
270 #define pwtest_ptr_ne(a_, b_) \
271 pwtest_comparison_ptr_(a_, !=, b_)
274 #define pwtest_ptr_null(a_) \
275 pwtest_comparison_ptr_(a_, ==, NULL)
278 #define pwtest_ptr_notnull(a_) \
279 pwtest_comparison_ptr_(a_, !=, NULL)
282 #define pwtest_double_eq(a_, b_)\
283 pwtest_comparison_double_((a_), ==, (b_))
286 #define pwtest_double_ne(a_, b_)\
287 pwtest_comparison_double_((a_), !=, (b_))
290 #define pwtest_double_lt(a_, b_)\
291 pwtest_comparison_double_((a_), <, (b_))
294 #define pwtest_double_le(a_, b_)\
295 pwtest_comparison_double_((a_), <=, (b_))
298 #define pwtest_double_ge(a_, b_)\
299 pwtest_comparison_double_((a_), >=, (b_))
302 #define pwtest_double_gt(a_, b_)\
303 pwtest_comparison_double_((a_), >, (b_))
305 #define pwtest_int(a_, op_, b_) \
306 pwtest_comparison_int_(a_, op_, b_)
310 #define pwtest_str_eq(a_, b_) \
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); \
320 #define pwtest_str_eq_n(a_, b_, l_) \
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); \
330 #define pwtest_str_ne(a_, b_) \
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); \
340 #define pwtest_str_ne_n(a_, b_, l_) \
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); \
351 #define pwtest_str_contains(haystack_, needle_) \
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); \
458 #define pwtest_add(func_, ...) \
459 _pwtest_add(ctx, suite, #func_, func_, __VA_ARGS__, NULL)
486 #define PWTEST(tname) \
487 static enum pwtest_result tname(struct pwtest_test *current_test)
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"))) = { \
501 .setup = cname##__setup, \
503 static enum pwtest_result (cname##__setup)(struct pwtest_context *ctx, struct pwtest_suite *suite)
506 #define PWTEST_PLUGIN_MAX 32
527 const char *factory_name,
528 const char *interface_name,
546 const char *factory_name,
547 const char *interface_name,
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...
void pwtest_spa_plugin_destroy(struct pwtest_spa_plugin *plugin)
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...
void pwtest_mkstemp(char path[PATH_MAX])
Create a temporary file and copy its full path to path.
struct pwtest_spa_plugin * pwtest_spa_plugin_new(void)
struct pwtest_context * pwtest_get_context(struct pwtest_test *t)
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.
pwtest_result
Result returned from tests or suites.
Definition: pwtest.h:174
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_arg
Definition: pwtest.h:369
@ PWTEST_PASS
test successful
Definition: pwtest.h:175
@ PWTEST_TIMEOUT
test aborted after timeout
Definition: pwtest.h:179
@ PWTEST_SKIP
test was skipped
Definition: pwtest.h:178
@ PWTEST_SYSTEM_ERROR
unrelated error occurred
Definition: pwtest.h:180
@ PWTEST_FAIL
test failed.
Definition: pwtest.h:176
@ 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
The next argument is an int specifying the numerical signal number.
Definition: pwtest.h:381
@ PWTEST_ARG_DAEMON
Takes no extra arguments.
Definition: pwtest.h:442
@ 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
The next two int arguments are the minimum (inclusive) and maximum (exclusive) range for this test.
Definition: pwtest.h:392
@ PWTEST_NOARG
Definition: pwtest.h:370
#define PWTEST_PLUGIN_MAX
Definition: pwtest.h:513
Definition: properties.h:53
size_t ndlls
Definition: pwtest.h:517
struct spa_handle * handles[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:521
size_t nsupport
Definition: pwtest.h:514
void * dlls[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:518
struct spa_support support[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:515
size_t nhandles
Definition: pwtest.h:520
Extra supporting infrastructure passed to the init() function of a factory.
Definition: plugin.h:96