142 #include "pwtest-implementation.h"
172 #define pwtest_fail() \
173 _pwtest_fail_condition(PWTEST_FAIL, __FILE__, __LINE__, __func__, "aborting", "")
176 #define pwtest_fail_if_reached() \
177 _pwtest_fail_condition(PWTEST_FAIL, __FILE__, __LINE__, __func__, "This line is supposed to be unreachable", "")
180 #define pwtest_fail_with_msg(...) \
181 _pwtest_fail_condition(PWTEST_FAIL, __FILE__, __LINE__, __func__, \
182 "aborting", __VA_ARGS__)
185 #define pwtest_error_with_msg(...) \
186 _pwtest_fail_condition(PWTEST_SYSTEM_ERROR, __FILE__, __LINE__, __func__, \
187 "error", __VA_ARGS__)
190 #define pwtest_errno_ok(r_) \
191 pwtest_errno_check(r_, 0);
194 #define pwtest_errno(r_, errno_) \
195 pwtest_errno_check(r_, errno_);
198 #define pwtest_neg_errno_ok(r_) \
199 pwtest_neg_errno_check(r_, 0);
202 #define pwtest_neg_errno(r_, errno_) \
203 pwtest_neg_errno_check(r_, errno_);
206 #define pwtest_bool_eq(a_, b_) \
207 pwtest_comparison_bool_(a_, ==, b_)
210 #define pwtest_bool_ne(a_, b_) \
211 pwtest_comparison_bool_(a_, !=, b_)
214 #define pwtest_bool_true(cond_) \
215 pwtest_comparison_bool_(cond_, ==, true)
218 #define pwtest_bool_false(cond_) \
219 pwtest_comparison_bool_(cond_, ==, false)
222 #define pwtest_int_eq(a_, b_) \
223 pwtest_comparison_int_(a_, ==, b_)
226 #define pwtest_int_ne(a_, b_) \
227 pwtest_comparison_int_(a_, !=, b_)
230 #define pwtest_int_lt(a_, b_) \
231 pwtest_comparison_int_(a_, <, b_)
234 #define pwtest_int_le(a_, b_) \
235 pwtest_comparison_int_(a_, <=, b_)
238 #define pwtest_int_ge(a_, b_) \
239 pwtest_comparison_int_(a_, >=, b_)
242 #define pwtest_int_gt(a_, b_) \
243 pwtest_comparison_int_(a_, >, b_)
246 #define pwtest_ptr_eq(a_, b_) \
247 pwtest_comparison_ptr_(a_, ==, b_)
250 #define pwtest_ptr_ne(a_, b_) \
251 pwtest_comparison_ptr_(a_, !=, b_)
254 #define pwtest_ptr_null(a_) \
255 pwtest_comparison_ptr_(a_, ==, NULL)
258 #define pwtest_ptr_notnull(a_) \
259 pwtest_comparison_ptr_(a_, !=, NULL)
262 #define pwtest_double_eq(a_, b_)\
263 pwtest_comparison_double_((a_), ==, (b_))
266 #define pwtest_double_ne(a_, b_)\
267 pwtest_comparison_double_((a_), !=, (b_))
270 #define pwtest_double_lt(a_, b_)\
271 pwtest_comparison_double_((a_), <, (b_))
274 #define pwtest_double_le(a_, b_)\
275 pwtest_comparison_double_((a_), <=, (b_))
278 #define pwtest_double_ge(a_, b_)\
279 pwtest_comparison_double_((a_), >=, (b_))
282 #define pwtest_double_gt(a_, b_)\
283 pwtest_comparison_double_((a_), >, (b_))
285 #define pwtest_int(a_, op_, b_) \
286 pwtest_comparison_int_(a_, op_, b_)
290 #define pwtest_str_eq(a_, b_) \
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); \
300 #define pwtest_str_eq_n(a_, b_, l_) \
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); \
310 #define pwtest_str_ne(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_ " not equal to " #b_, _a, _b); \
320 #define pwtest_str_ne_n(a_, b_, l_) \
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); \
331 #define pwtest_str_contains(haystack_, needle_) \
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); \
438 #define pwtest_add(func_, ...) \
439 _pwtest_add(ctx, suite, #func_, func_, __VA_ARGS__, NULL)
466 #define PWTEST(tname) \
467 static enum pwtest_result tname(struct pwtest_test *current_test)
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 = { \
483 .setup = cname##__setup, \
485 static enum pwtest_result (cname##__setup)(struct pwtest_context *ctx, struct pwtest_suite *suite)
488 #define PWTEST_PLUGIN_MAX 32
509 const char *factory_name,
510 const char *interface_name,
528 const char *factory_name,
529 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:154
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:349
@ PWTEST_PASS
test successful
Definition: pwtest.h:155
@ PWTEST_TIMEOUT
test aborted after timeout
Definition: pwtest.h:159
@ PWTEST_SKIP
test was skipped
Definition: pwtest.h:158
@ PWTEST_SYSTEM_ERROR
unrelated error occurred
Definition: pwtest.h:160
@ PWTEST_FAIL
test failed.
Definition: pwtest.h:156
@ 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
The next argument is an int specifying the numerical signal number.
Definition: pwtest.h:361
@ PWTEST_ARG_DAEMON
Takes no extra arguments.
Definition: pwtest.h:422
@ 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
The next two int arguments are the minimum (inclusive) and maximum (exclusive) range for this test.
Definition: pwtest.h:372
@ PWTEST_NOARG
Definition: pwtest.h:350
#define PWTEST_PLUGIN_MAX
Definition: pwtest.h:495
Definition: properties.h:33
size_t ndlls
Definition: pwtest.h:499
struct spa_handle * handles[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:503
size_t nsupport
Definition: pwtest.h:496
void * dlls[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:500
struct spa_support support[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:497
size_t nhandles
Definition: pwtest.h:502
Definition: utils/dict.h:39
Extra supporting infrastructure passed to the init() function of a factory.
Definition: plugin.h:76