2023-02-08 18:12:00 +01:00
|
|
|
/* PipeWire */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2021 Red Hat, Inc. */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2021-05-27 10:05:19 +10:00
|
|
|
|
|
|
|
|
#ifndef PWTEST_IMPLEMENTATION_H
|
|
|
|
|
#define PWTEST_IMPLEMENTATION_H
|
|
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
/* This header should never be included on its own, it merely exists to make
|
|
|
|
|
* the user-visible pwtest.h header more readable */
|
|
|
|
|
|
test: move SPA_NORETURN attributes to header
Otherwise, when building with fortify-headers, I get an error because
the compiler doesn't know pwtest_ptr_notnull will not return if the
passed pointer is null, so it doesn't know the pointer subsequently
passed to memmove via pw_array_remove will be non-null.
In file included from ../spa/include/spa/utils/defs.h:11,
from ../spa/include/spa/utils/string.h:15,
from ../test/pwtest.h:15,
from ../test/test-array.c:7:
In function ‘memmove’,
inlined from ‘array_test’ at ../test/test-array.c:66:2:
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:77:16: error: argument 1 is null but the corresponding size argument 3 value is [8, 18446744073709551615] [-Werror=nonnull]
77 | return __orig_memmove(__d, __s, __n);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:77:16: warning: ‘__orig_memmove’ reading 8 or more bytes from a region of size 0 [-Wstringop-overread]
In function ‘array_test’:
cc1: note: source object is likely at address zero
In file included from /nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/stdlib.h:33,
from ../spa/include/spa/utils/string.h:11:
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:69:1: note: in a call to function ‘__orig_memmove’ declared with attribute ‘access (read_only, 2, 3)’
69 | _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
| ^~~~~~~~~~~
2026-05-04 17:43:44 +02:00
|
|
|
SPA_NORETURN
|
2021-05-27 10:05:19 +10:00
|
|
|
void
|
|
|
|
|
_pwtest_fail_condition(int exitstatus, const char *file, int line, const char *func,
|
|
|
|
|
const char *condition, const char *message, ...);
|
test: move SPA_NORETURN attributes to header
Otherwise, when building with fortify-headers, I get an error because
the compiler doesn't know pwtest_ptr_notnull will not return if the
passed pointer is null, so it doesn't know the pointer subsequently
passed to memmove via pw_array_remove will be non-null.
In file included from ../spa/include/spa/utils/defs.h:11,
from ../spa/include/spa/utils/string.h:15,
from ../test/pwtest.h:15,
from ../test/test-array.c:7:
In function ‘memmove’,
inlined from ‘array_test’ at ../test/test-array.c:66:2:
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:77:16: error: argument 1 is null but the corresponding size argument 3 value is [8, 18446744073709551615] [-Werror=nonnull]
77 | return __orig_memmove(__d, __s, __n);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:77:16: warning: ‘__orig_memmove’ reading 8 or more bytes from a region of size 0 [-Wstringop-overread]
In function ‘array_test’:
cc1: note: source object is likely at address zero
In file included from /nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/stdlib.h:33,
from ../spa/include/spa/utils/string.h:11:
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:69:1: note: in a call to function ‘__orig_memmove’ declared with attribute ‘access (read_only, 2, 3)’
69 | _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
| ^~~~~~~~~~~
2026-05-04 17:43:44 +02:00
|
|
|
SPA_NORETURN
|
2021-05-27 10:05:19 +10:00
|
|
|
void
|
|
|
|
|
_pwtest_fail_comparison_int(const char *file, int line, const char *func,
|
|
|
|
|
const char *operator, int a, int b,
|
|
|
|
|
const char *astr, const char *bstr);
|
test: move SPA_NORETURN attributes to header
Otherwise, when building with fortify-headers, I get an error because
the compiler doesn't know pwtest_ptr_notnull will not return if the
passed pointer is null, so it doesn't know the pointer subsequently
passed to memmove via pw_array_remove will be non-null.
In file included from ../spa/include/spa/utils/defs.h:11,
from ../spa/include/spa/utils/string.h:15,
from ../test/pwtest.h:15,
from ../test/test-array.c:7:
In function ‘memmove’,
inlined from ‘array_test’ at ../test/test-array.c:66:2:
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:77:16: error: argument 1 is null but the corresponding size argument 3 value is [8, 18446744073709551615] [-Werror=nonnull]
77 | return __orig_memmove(__d, __s, __n);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:77:16: warning: ‘__orig_memmove’ reading 8 or more bytes from a region of size 0 [-Wstringop-overread]
In function ‘array_test’:
cc1: note: source object is likely at address zero
In file included from /nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/stdlib.h:33,
from ../spa/include/spa/utils/string.h:11:
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:69:1: note: in a call to function ‘__orig_memmove’ declared with attribute ‘access (read_only, 2, 3)’
69 | _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
| ^~~~~~~~~~~
2026-05-04 17:43:44 +02:00
|
|
|
SPA_NORETURN
|
2021-05-27 10:05:19 +10:00
|
|
|
void
|
|
|
|
|
_pwtest_fail_comparison_double(const char *file, int line, const char *func,
|
|
|
|
|
const char *operator, double a, double b,
|
|
|
|
|
const char *astr, const char *bstr);
|
test: move SPA_NORETURN attributes to header
Otherwise, when building with fortify-headers, I get an error because
the compiler doesn't know pwtest_ptr_notnull will not return if the
passed pointer is null, so it doesn't know the pointer subsequently
passed to memmove via pw_array_remove will be non-null.
In file included from ../spa/include/spa/utils/defs.h:11,
from ../spa/include/spa/utils/string.h:15,
from ../test/pwtest.h:15,
from ../test/test-array.c:7:
In function ‘memmove’,
inlined from ‘array_test’ at ../test/test-array.c:66:2:
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:77:16: error: argument 1 is null but the corresponding size argument 3 value is [8, 18446744073709551615] [-Werror=nonnull]
77 | return __orig_memmove(__d, __s, __n);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:77:16: warning: ‘__orig_memmove’ reading 8 or more bytes from a region of size 0 [-Wstringop-overread]
In function ‘array_test’:
cc1: note: source object is likely at address zero
In file included from /nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/stdlib.h:33,
from ../spa/include/spa/utils/string.h:11:
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:69:1: note: in a call to function ‘__orig_memmove’ declared with attribute ‘access (read_only, 2, 3)’
69 | _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
| ^~~~~~~~~~~
2026-05-04 17:43:44 +02:00
|
|
|
SPA_NORETURN
|
2021-05-27 10:05:19 +10:00
|
|
|
void
|
|
|
|
|
_pwtest_fail_comparison_ptr(const char *file, int line, const char *func,
|
|
|
|
|
const char *comparison);
|
|
|
|
|
|
test: move SPA_NORETURN attributes to header
Otherwise, when building with fortify-headers, I get an error because
the compiler doesn't know pwtest_ptr_notnull will not return if the
passed pointer is null, so it doesn't know the pointer subsequently
passed to memmove via pw_array_remove will be non-null.
In file included from ../spa/include/spa/utils/defs.h:11,
from ../spa/include/spa/utils/string.h:15,
from ../test/pwtest.h:15,
from ../test/test-array.c:7:
In function ‘memmove’,
inlined from ‘array_test’ at ../test/test-array.c:66:2:
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:77:16: error: argument 1 is null but the corresponding size argument 3 value is [8, 18446744073709551615] [-Werror=nonnull]
77 | return __orig_memmove(__d, __s, __n);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:77:16: warning: ‘__orig_memmove’ reading 8 or more bytes from a region of size 0 [-Wstringop-overread]
In function ‘array_test’:
cc1: note: source object is likely at address zero
In file included from /nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/stdlib.h:33,
from ../spa/include/spa/utils/string.h:11:
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:69:1: note: in a call to function ‘__orig_memmove’ declared with attribute ‘access (read_only, 2, 3)’
69 | _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
| ^~~~~~~~~~~
2026-05-04 17:43:44 +02:00
|
|
|
SPA_NORETURN
|
2021-05-27 10:05:19 +10:00
|
|
|
void
|
|
|
|
|
_pwtest_fail_comparison_str(const char *file, int line, const char *func,
|
|
|
|
|
const char *comparison, const char *a, const char *b);
|
|
|
|
|
|
test: move SPA_NORETURN attributes to header
Otherwise, when building with fortify-headers, I get an error because
the compiler doesn't know pwtest_ptr_notnull will not return if the
passed pointer is null, so it doesn't know the pointer subsequently
passed to memmove via pw_array_remove will be non-null.
In file included from ../spa/include/spa/utils/defs.h:11,
from ../spa/include/spa/utils/string.h:15,
from ../test/pwtest.h:15,
from ../test/test-array.c:7:
In function ‘memmove’,
inlined from ‘array_test’ at ../test/test-array.c:66:2:
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:77:16: error: argument 1 is null but the corresponding size argument 3 value is [8, 18446744073709551615] [-Werror=nonnull]
77 | return __orig_memmove(__d, __s, __n);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:77:16: warning: ‘__orig_memmove’ reading 8 or more bytes from a region of size 0 [-Wstringop-overread]
In function ‘array_test’:
cc1: note: source object is likely at address zero
In file included from /nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/stdlib.h:33,
from ../spa/include/spa/utils/string.h:11:
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:69:1: note: in a call to function ‘__orig_memmove’ declared with attribute ‘access (read_only, 2, 3)’
69 | _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
| ^~~~~~~~~~~
2026-05-04 17:43:44 +02:00
|
|
|
SPA_NORETURN
|
2021-05-27 10:05:19 +10:00
|
|
|
void
|
|
|
|
|
_pwtest_fail_comparison_bool(const char *file, int line, const char *func,
|
|
|
|
|
const char *operator, bool a, bool b,
|
|
|
|
|
const char *astr, const char *bstr);
|
|
|
|
|
|
test: move SPA_NORETURN attributes to header
Otherwise, when building with fortify-headers, I get an error because
the compiler doesn't know pwtest_ptr_notnull will not return if the
passed pointer is null, so it doesn't know the pointer subsequently
passed to memmove via pw_array_remove will be non-null.
In file included from ../spa/include/spa/utils/defs.h:11,
from ../spa/include/spa/utils/string.h:15,
from ../test/pwtest.h:15,
from ../test/test-array.c:7:
In function ‘memmove’,
inlined from ‘array_test’ at ../test/test-array.c:66:2:
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:77:16: error: argument 1 is null but the corresponding size argument 3 value is [8, 18446744073709551615] [-Werror=nonnull]
77 | return __orig_memmove(__d, __s, __n);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:77:16: warning: ‘__orig_memmove’ reading 8 or more bytes from a region of size 0 [-Wstringop-overread]
In function ‘array_test’:
cc1: note: source object is likely at address zero
In file included from /nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/stdlib.h:33,
from ../spa/include/spa/utils/string.h:11:
/nix/store/9031y56lsf4mq177s68ql1axsf241r7j-fortify-headers-3.0.1/include/string.h:69:1: note: in a call to function ‘__orig_memmove’ declared with attribute ‘access (read_only, 2, 3)’
69 | _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
| ^~~~~~~~~~~
2026-05-04 17:43:44 +02:00
|
|
|
SPA_NORETURN
|
2021-06-04 15:23:51 +10:00
|
|
|
void
|
|
|
|
|
_pwtest_fail_errno(const char *file, int line, const char *func,
|
|
|
|
|
int expected, int err_no);
|
|
|
|
|
|
|
|
|
|
#define pwtest_errno_check(r_, errno_) \
|
|
|
|
|
do { \
|
|
|
|
|
int _r = r_; \
|
|
|
|
|
int _e = errno_; \
|
|
|
|
|
if (_e == 0) { \
|
|
|
|
|
if (_r == -1) \
|
|
|
|
|
_pwtest_fail_errno(__FILE__, __LINE__, __func__, _e, errno); \
|
|
|
|
|
} else { \
|
|
|
|
|
if (_r != -1 || errno != _e) \
|
|
|
|
|
_pwtest_fail_errno(__FILE__, __LINE__, __func__, _e, errno); \
|
|
|
|
|
} \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define pwtest_neg_errno_check(r_, errno_) \
|
|
|
|
|
do { \
|
|
|
|
|
int _r = r_; \
|
|
|
|
|
int _e = errno_; \
|
|
|
|
|
if (_e == 0) { \
|
|
|
|
|
if (_r < 0) \
|
|
|
|
|
_pwtest_fail_errno(__FILE__, __LINE__, __func__, _e, -_r); \
|
|
|
|
|
} else { \
|
|
|
|
|
if (_r >= 0 || _r != _e) \
|
|
|
|
|
_pwtest_fail_errno(__FILE__, __LINE__, __func__, -_e, _r >= 0 ? 0 : -_r); \
|
|
|
|
|
} \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
2021-05-27 10:05:19 +10:00
|
|
|
#define pwtest_comparison_bool_(a_, op_, b_) \
|
|
|
|
|
do { \
|
|
|
|
|
bool _a = !!(a_); \
|
|
|
|
|
bool _b = !!(b_); \
|
|
|
|
|
if (!(_a op_ _b)) \
|
|
|
|
|
_pwtest_fail_comparison_bool(__FILE__, __LINE__, __func__,\
|
|
|
|
|
#op_, _a, _b, #a_, #b_); \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define pwtest_comparison_int_(a_, op_, b_) \
|
|
|
|
|
do { \
|
|
|
|
|
__typeof__(a_) _a = a_; \
|
|
|
|
|
__typeof__(b_) _b = b_; \
|
|
|
|
|
if (trunc(_a) != _a || trunc(_b) != _b) \
|
|
|
|
|
pwtest_error_with_msg("pwtest_int_* used for non-integer value\n"); \
|
|
|
|
|
if (!((_a) op_ (_b))) \
|
|
|
|
|
_pwtest_fail_comparison_int(__FILE__, __LINE__, __func__,\
|
|
|
|
|
#op_, _a, _b, #a_, #b_); \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define pwtest_comparison_ptr_(a_, op_, b_) \
|
|
|
|
|
do { \
|
|
|
|
|
__typeof__(a_) _a = a_; \
|
|
|
|
|
__typeof__(b_) _b = b_; \
|
|
|
|
|
if (!((_a) op_ (_b))) \
|
|
|
|
|
_pwtest_fail_comparison_ptr(__FILE__, __LINE__, __func__,\
|
|
|
|
|
#a_ " " #op_ " " #b_); \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
#define pwtest_comparison_double_(a_, op_, b_) \
|
|
|
|
|
do { \
|
|
|
|
|
const double EPSILON = 1.0/256; \
|
|
|
|
|
__typeof__(a_) _a = a_; \
|
|
|
|
|
__typeof__(b_) _b = b_; \
|
|
|
|
|
if (!((_a) op_ (_b)) && fabs((_a) - (_b)) > EPSILON) \
|
|
|
|
|
_pwtest_fail_comparison_double(__FILE__, __LINE__, __func__,\
|
|
|
|
|
#op_, _a, _b, #a_, #b_); \
|
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
void _pwtest_add(struct pwtest_context *ctx,
|
|
|
|
|
struct pwtest_suite *suite,
|
|
|
|
|
const char *funcname, const void *func,
|
|
|
|
|
...) SPA_SENTINEL;
|
|
|
|
|
|
|
|
|
|
struct pwtest_suite_decl {
|
|
|
|
|
const char *name;
|
|
|
|
|
enum pwtest_result (*setup)(struct pwtest_context *, struct pwtest_suite *);
|
2022-04-13 18:13:12 +02:00
|
|
|
};
|
2021-05-27 10:05:19 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* PWTEST_IMPLEMENTATION_H */
|