pwtest.h
Go to the documentation of this file.
/* PipeWire
*
* Copyright © 2021 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#ifndef PWTEST_H
#define PWTEST_H
#ifdef __cplusplus
extern "C" {
#endif
#include <limits.h>
#include <stddef.h>
#include <stdbool.h>
#include <math.h>
#include <spa/utils/string.h>
#include <spa/utils/dict.h>
#include "spa/support/plugin.h"
struct pwtest_context;
struct pwtest_suite;
struct pwtest_test;
#include "pwtest-implementation.h"
enum pwtest_result {
PWTEST_PASS = 75,
PWTEST_FAIL = 76,
PWTEST_SKIP = 77,
PWTEST_TIMEOUT = 78,
PWTEST_SYSTEM_ERROR = 79,
};
int pwtest_get_iteration(struct pwtest_test *t);
struct pw_properties *pwtest_get_props(struct pwtest_test *t);
struct pwtest_context *pwtest_get_context(struct pwtest_test *t);
#define pwtest_fail() \
_pwtest_fail_condition(PWTEST_FAIL, __FILE__, __LINE__, __func__, "aborting", "")
#define pwtest_fail_if_reached() \
_pwtest_fail_condition(PWTEST_FAIL, __FILE__, __LINE__, __func__, "This line is supposed to be unreachable", "")
#define pwtest_fail_with_msg(...) \
_pwtest_fail_condition(PWTEST_FAIL, __FILE__, __LINE__, __func__, \
"aborting", __VA_ARGS__)
#define pwtest_error_with_msg(...) \
_pwtest_fail_condition(PWTEST_SYSTEM_ERROR, __FILE__, __LINE__, __func__, \
"error", __VA_ARGS__)
#define pwtest_errno_ok(r_) \
pwtest_errno_check(r_, 0);
#define pwtest_errno(r_, errno_) \
pwtest_errno_check(r_, errno_);
#define pwtest_neg_errno_ok(r_) \
pwtest_neg_errno_check(r_, 0);
#define pwtest_neg_errno(r_, errno_) \
pwtest_neg_errno_check(r_, errno_);
#define pwtest_bool_eq(a_, b_) \
pwtest_comparison_bool_(a_, ==, b_)
#define pwtest_bool_ne(a_, b_) \
pwtest_comparison_bool_(a_, !=, b_)
#define pwtest_bool_true(cond_) \
pwtest_comparison_bool_(cond_, ==, true)
#define pwtest_bool_false(cond_) \
pwtest_comparison_bool_(cond_, ==, false)
#define pwtest_int_eq(a_, b_) \
pwtest_comparison_int_(a_, ==, b_)
#define pwtest_int_ne(a_, b_) \
pwtest_comparison_int_(a_, !=, b_)
#define pwtest_int_lt(a_, b_) \
pwtest_comparison_int_(a_, <, b_)
#define pwtest_int_le(a_, b_) \
pwtest_comparison_int_(a_, <=, b_)
#define pwtest_int_ge(a_, b_) \
pwtest_comparison_int_(a_, >=, b_)
#define pwtest_int_gt(a_, b_) \
pwtest_comparison_int_(a_, >, b_)
#define pwtest_ptr_eq(a_, b_) \
pwtest_comparison_ptr_(a_, ==, b_)
#define pwtest_ptr_ne(a_, b_) \
pwtest_comparison_ptr_(a_, !=, b_)
#define pwtest_ptr_null(a_) \
pwtest_comparison_ptr_(a_, ==, NULL)
#define pwtest_ptr_notnull(a_) \
pwtest_comparison_ptr_(a_, !=, NULL)
#define pwtest_double_eq(a_, b_)\
pwtest_comparison_double_((a_), ==, (b_))
#define pwtest_double_ne(a_, b_)\
pwtest_comparison_double_((a_), !=, (b_))
#define pwtest_double_lt(a_, b_)\
pwtest_comparison_double_((a_), <, (b_))
#define pwtest_double_le(a_, b_)\
pwtest_comparison_double_((a_), <=, (b_))
#define pwtest_double_ge(a_, b_)\
pwtest_comparison_double_((a_), >=, (b_))
#define pwtest_double_gt(a_, b_)\
pwtest_comparison_double_((a_), >, (b_))
#define pwtest_int(a_, op_, b_) \
pwtest_comparison_int_(a_, op_, b_)
#define pwtest_str_eq(a_, b_) \
do { \
const char *_a = a_; \
const char *_b = b_; \
if (!spa_streq(_a, _b)) \
_pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
#a_ " equals " #b_, _a, _b); \
} while(0)
#define pwtest_str_eq_n(a_, b_, l_) \
do { \
const char *_a = a_; \
const char *_b = b_; \
if (!spa_strneq(_a, _b, l_)) \
_pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
#a_ " equals " #b_ ", len: " #l_, _a, _b); \
} while(0)
#define pwtest_str_ne(a_, b_) \
do { \
const char *_a = a_; \
const char *_b = b_; \
if (spa_streq(_a, _b)) \
_pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
#a_ " not equal to " #b_, _a, _b); \
} while(0)
#define pwtest_str_ne_n(a_, b_, l_) \
do { \
__typeof__(a_) _a = a_; \
__typeof__(b_) _b = b_; \
if (spa_strneq(_a, _b, l_)) \
_pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
#a_ " not equal to " #b_ ", len: " #l_, _a, _b); \
} while(0)
#define pwtest_str_contains(haystack_, needle_) \
do { \
const char *_h = haystack_; \
const char *_n = needle_; \
if (!strstr(_h, _n)) \
_pwtest_fail_comparison_str(__FILE__, __LINE__, __func__, \
#haystack_ " contains " #needle_, _h, _n); \
} while(0)
/* Needs to be a #define NULL for SPA_SENTINEL */
enum pwtest_arg {
PWTEST_NOARG = 0,
PWTEST_ARG_SIGNAL,
PWTEST_ARG_RANGE,
PWTEST_ARG_PROP,
PWTEST_ARG_ENV,
PWTEST_ARG_DAEMON,
};
#define pwtest_add(func_, ...) \
_pwtest_add(ctx, suite, #func_, func_, __VA_ARGS__, NULL)
#define PWTEST(tname) \
static enum pwtest_result tname(struct pwtest_test *current_test)
#define PWTEST_SUITE(cname) \
static enum pwtest_result (cname##__setup)(struct pwtest_context *ctx, struct pwtest_suite *suite); \
static const struct pwtest_suite_decl _test_suite \
__attribute__((used)) \
__attribute((section("pwtest_suite_section"))) = { \
.name = #cname, \
.setup = cname##__setup, \
}; \
static enum pwtest_result (cname##__setup)(struct pwtest_context *ctx, struct pwtest_suite *suite)
struct pwtest_spa_plugin {
#define PWTEST_PLUGIN_MAX 32
size_t nsupport;
struct spa_support support[PWTEST_PLUGIN_MAX];
size_t ndlls;
void *dlls[PWTEST_PLUGIN_MAX];
size_t nhandles;
struct spa_handle *handles[PWTEST_PLUGIN_MAX];
};
struct pwtest_spa_plugin* pwtest_spa_plugin_new(void);
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);
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);
void pwtest_mkstemp(char path[PATH_MAX]);
#ifdef __cplusplus
}
#endif
#endif /* PWTEST_H */
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_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_mkstemp
void pwtest_mkstemp(char path[PATH_MAX])
Create a temporary file and copy its full path to path.
pwtest_spa_plugin_new
struct pwtest_spa_plugin * pwtest_spa_plugin_new(void)
pwtest_get_context
struct pwtest_context * pwtest_get_context(struct pwtest_test *t)
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_result
pwtest_result
Result returned from tests or suites.
Definition: pwtest.h:174
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_arg
pwtest_arg
Definition: pwtest.h:369
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:513
string.h
spa/utils/string.h
pw_properties
Definition: properties.h:53
pwtest_context
pwtest_spa_plugin
Definition: pwtest.h:512
pwtest_spa_plugin::ndlls
size_t ndlls
Definition: pwtest.h:517
pwtest_spa_plugin::handles
struct spa_handle * handles[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:521
pwtest_spa_plugin::nsupport
size_t nsupport
Definition: pwtest.h:514
pwtest_spa_plugin::dlls
void * dlls[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:518
pwtest_spa_plugin::support
struct spa_support support[PWTEST_PLUGIN_MAX]
Definition: pwtest.h:515
pwtest_spa_plugin::nhandles
size_t nhandles
Definition: pwtest.h:520
pwtest_suite
Definition: pwtest.h:161
pwtest_test
Definition: pwtest.h:164
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