Refactor to support more varied testing.
Refactor the test harness to support three types of tests:
- unit: White box unit tests. These tests have full access to all
internal jemalloc library symbols. Though in actuality all symbols
are prefixed by jet_, macro-based name mangling abstracts this away
from test code.
- integration: Black box integration tests. These tests link with
the installable shared jemalloc library, and with the exception of
some utility code and configure-generated macro definitions, they have
no access to jemalloc internals.
- stress: Black box stress tests. These tests link with the installable
shared jemalloc library, as well as with an internal allocator with
symbols prefixed by jet_ (same as for unit tests) that can be used to
allocate data structures that are internal to the test code.
Move existing tests into test/{unit,integration}/ as appropriate.
Split out internal parts of jemalloc_defs.h.in and put them in
jemalloc_internal_defs.h.in. This reduces internals exposure to
applications that #include <jemalloc/jemalloc.h>.
Refactor jemalloc.h header generation so that a single header file
results, and the prototypes can be used to generate jet_ prototypes for
tests. Split jemalloc.h.in into multiple parts (jemalloc_defs.h.in,
jemalloc_macros.h.in, jemalloc_protos.h.in, jemalloc_mangle.h.in) and
use a shell script to generate a unified jemalloc.h at configure time.
Change the default private namespace prefix from "" to "je_".
Add missing private namespace mangling.
Remove hard-coded private_namespace.h. Instead generate it and
private_unnamespace.h from private_symbols.txt. Use similar logic for
public symbols, which aids in name mangling for jet_ symbols.
Add test_warn() and test_fail(). Replace existing exit(1) calls with
test_fail() calls.
2013-12-01 07:25:42 +08:00
|
|
|
#include "test/jemalloc_test.h"
|
|
|
|
|
2017-03-29 08:30:54 +08:00
|
|
|
/* Test status state. */
|
|
|
|
|
2013-12-09 12:52:21 +08:00
|
|
|
static unsigned test_count = 0;
|
|
|
|
static test_status_t test_counts[test_status_count] = {0, 0, 0};
|
|
|
|
static test_status_t test_status = test_status_pass;
|
|
|
|
static const char * test_name = "";
|
Refactor to support more varied testing.
Refactor the test harness to support three types of tests:
- unit: White box unit tests. These tests have full access to all
internal jemalloc library symbols. Though in actuality all symbols
are prefixed by jet_, macro-based name mangling abstracts this away
from test code.
- integration: Black box integration tests. These tests link with
the installable shared jemalloc library, and with the exception of
some utility code and configure-generated macro definitions, they have
no access to jemalloc internals.
- stress: Black box stress tests. These tests link with the installable
shared jemalloc library, as well as with an internal allocator with
symbols prefixed by jet_ (same as for unit tests) that can be used to
allocate data structures that are internal to the test code.
Move existing tests into test/{unit,integration}/ as appropriate.
Split out internal parts of jemalloc_defs.h.in and put them in
jemalloc_internal_defs.h.in. This reduces internals exposure to
applications that #include <jemalloc/jemalloc.h>.
Refactor jemalloc.h header generation so that a single header file
results, and the prototypes can be used to generate jet_ prototypes for
tests. Split jemalloc.h.in into multiple parts (jemalloc_defs.h.in,
jemalloc_macros.h.in, jemalloc_protos.h.in, jemalloc_mangle.h.in) and
use a shell script to generate a unified jemalloc.h at configure time.
Change the default private namespace prefix from "" to "je_".
Add missing private namespace mangling.
Remove hard-coded private_namespace.h. Instead generate it and
private_unnamespace.h from private_symbols.txt. Use similar logic for
public symbols, which aids in name mangling for jet_ symbols.
Add test_warn() and test_fail(). Replace existing exit(1) calls with
test_fail() calls.
2013-12-01 07:25:42 +08:00
|
|
|
|
2017-03-29 08:30:54 +08:00
|
|
|
/* Reentrancy testing helpers. */
|
|
|
|
|
|
|
|
#define NUM_REENTRANT_ALLOCS 20
|
2017-04-01 10:59:45 +08:00
|
|
|
typedef enum {
|
|
|
|
non_reentrant = 0,
|
|
|
|
libc_reentrant = 1,
|
|
|
|
arena_new_reentrant = 2
|
|
|
|
} reentrancy_t;
|
|
|
|
static reentrancy_t reentrancy;
|
|
|
|
|
|
|
|
static bool libc_hook_ran = false;
|
|
|
|
static bool arena_new_hook_ran = false;
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
reentrancy_t_str(reentrancy_t r) {
|
|
|
|
switch (r) {
|
|
|
|
case non_reentrant:
|
|
|
|
return "non-reentrant";
|
|
|
|
case libc_reentrant:
|
|
|
|
return "libc-reentrant";
|
|
|
|
case arena_new_reentrant:
|
|
|
|
return "arena_new-reentrant";
|
|
|
|
default:
|
|
|
|
unreachable();
|
|
|
|
}
|
|
|
|
}
|
2017-03-29 08:30:54 +08:00
|
|
|
|
|
|
|
static void
|
2017-04-01 10:59:45 +08:00
|
|
|
do_hook(bool *hook_ran, void (**hook)()) {
|
|
|
|
*hook_ran = true;
|
|
|
|
*hook = NULL;
|
2017-03-29 08:30:54 +08:00
|
|
|
|
|
|
|
size_t alloc_size = 1;
|
|
|
|
for (int i = 0; i < NUM_REENTRANT_ALLOCS; i++) {
|
2017-04-01 10:59:45 +08:00
|
|
|
free(malloc(alloc_size));
|
2017-03-29 08:30:54 +08:00
|
|
|
alloc_size *= 2;
|
|
|
|
}
|
2017-04-01 10:59:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
libc_reentrancy_hook() {
|
2018-04-10 09:09:34 +08:00
|
|
|
do_hook(&libc_hook_ran, &test_hooks_libc_hook);
|
2017-04-01 10:59:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
arena_new_reentrancy_hook() {
|
2018-04-10 09:09:34 +08:00
|
|
|
do_hook(&arena_new_hook_ran, &test_hooks_arena_new_hook);
|
2017-03-29 08:30:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Actual test infrastructure. */
|
|
|
|
bool
|
|
|
|
test_is_reentrant() {
|
2017-04-01 10:59:45 +08:00
|
|
|
return reentrancy != non_reentrant;
|
2017-03-29 08:30:54 +08:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:44:47 +08:00
|
|
|
JEMALLOC_FORMAT_PRINTF(1, 2)
|
Refactor to support more varied testing.
Refactor the test harness to support three types of tests:
- unit: White box unit tests. These tests have full access to all
internal jemalloc library symbols. Though in actuality all symbols
are prefixed by jet_, macro-based name mangling abstracts this away
from test code.
- integration: Black box integration tests. These tests link with
the installable shared jemalloc library, and with the exception of
some utility code and configure-generated macro definitions, they have
no access to jemalloc internals.
- stress: Black box stress tests. These tests link with the installable
shared jemalloc library, as well as with an internal allocator with
symbols prefixed by jet_ (same as for unit tests) that can be used to
allocate data structures that are internal to the test code.
Move existing tests into test/{unit,integration}/ as appropriate.
Split out internal parts of jemalloc_defs.h.in and put them in
jemalloc_internal_defs.h.in. This reduces internals exposure to
applications that #include <jemalloc/jemalloc.h>.
Refactor jemalloc.h header generation so that a single header file
results, and the prototypes can be used to generate jet_ prototypes for
tests. Split jemalloc.h.in into multiple parts (jemalloc_defs.h.in,
jemalloc_macros.h.in, jemalloc_protos.h.in, jemalloc_mangle.h.in) and
use a shell script to generate a unified jemalloc.h at configure time.
Change the default private namespace prefix from "" to "je_".
Add missing private namespace mangling.
Remove hard-coded private_namespace.h. Instead generate it and
private_unnamespace.h from private_symbols.txt. Use similar logic for
public symbols, which aids in name mangling for jet_ symbols.
Add test_warn() and test_fail(). Replace existing exit(1) calls with
test_fail() calls.
2013-12-01 07:25:42 +08:00
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
test_skip(const char *format, ...) {
|
Refactor to support more varied testing.
Refactor the test harness to support three types of tests:
- unit: White box unit tests. These tests have full access to all
internal jemalloc library symbols. Though in actuality all symbols
are prefixed by jet_, macro-based name mangling abstracts this away
from test code.
- integration: Black box integration tests. These tests link with
the installable shared jemalloc library, and with the exception of
some utility code and configure-generated macro definitions, they have
no access to jemalloc internals.
- stress: Black box stress tests. These tests link with the installable
shared jemalloc library, as well as with an internal allocator with
symbols prefixed by jet_ (same as for unit tests) that can be used to
allocate data structures that are internal to the test code.
Move existing tests into test/{unit,integration}/ as appropriate.
Split out internal parts of jemalloc_defs.h.in and put them in
jemalloc_internal_defs.h.in. This reduces internals exposure to
applications that #include <jemalloc/jemalloc.h>.
Refactor jemalloc.h header generation so that a single header file
results, and the prototypes can be used to generate jet_ prototypes for
tests. Split jemalloc.h.in into multiple parts (jemalloc_defs.h.in,
jemalloc_macros.h.in, jemalloc_protos.h.in, jemalloc_mangle.h.in) and
use a shell script to generate a unified jemalloc.h at configure time.
Change the default private namespace prefix from "" to "je_".
Add missing private namespace mangling.
Remove hard-coded private_namespace.h. Instead generate it and
private_unnamespace.h from private_symbols.txt. Use similar logic for
public symbols, which aids in name mangling for jet_ symbols.
Add test_warn() and test_fail(). Replace existing exit(1) calls with
test_fail() calls.
2013-12-01 07:25:42 +08:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
malloc_vcprintf(NULL, NULL, format, ap);
|
|
|
|
va_end(ap);
|
2013-12-16 07:54:18 +08:00
|
|
|
malloc_printf("\n");
|
2013-12-09 12:52:21 +08:00
|
|
|
test_status = test_status_skip;
|
Refactor to support more varied testing.
Refactor the test harness to support three types of tests:
- unit: White box unit tests. These tests have full access to all
internal jemalloc library symbols. Though in actuality all symbols
are prefixed by jet_, macro-based name mangling abstracts this away
from test code.
- integration: Black box integration tests. These tests link with
the installable shared jemalloc library, and with the exception of
some utility code and configure-generated macro definitions, they have
no access to jemalloc internals.
- stress: Black box stress tests. These tests link with the installable
shared jemalloc library, as well as with an internal allocator with
symbols prefixed by jet_ (same as for unit tests) that can be used to
allocate data structures that are internal to the test code.
Move existing tests into test/{unit,integration}/ as appropriate.
Split out internal parts of jemalloc_defs.h.in and put them in
jemalloc_internal_defs.h.in. This reduces internals exposure to
applications that #include <jemalloc/jemalloc.h>.
Refactor jemalloc.h header generation so that a single header file
results, and the prototypes can be used to generate jet_ prototypes for
tests. Split jemalloc.h.in into multiple parts (jemalloc_defs.h.in,
jemalloc_macros.h.in, jemalloc_protos.h.in, jemalloc_mangle.h.in) and
use a shell script to generate a unified jemalloc.h at configure time.
Change the default private namespace prefix from "" to "je_".
Add missing private namespace mangling.
Remove hard-coded private_namespace.h. Instead generate it and
private_unnamespace.h from private_symbols.txt. Use similar logic for
public symbols, which aids in name mangling for jet_ symbols.
Add test_warn() and test_fail(). Replace existing exit(1) calls with
test_fail() calls.
2013-12-01 07:25:42 +08:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:44:47 +08:00
|
|
|
JEMALLOC_FORMAT_PRINTF(1, 2)
|
Refactor to support more varied testing.
Refactor the test harness to support three types of tests:
- unit: White box unit tests. These tests have full access to all
internal jemalloc library symbols. Though in actuality all symbols
are prefixed by jet_, macro-based name mangling abstracts this away
from test code.
- integration: Black box integration tests. These tests link with
the installable shared jemalloc library, and with the exception of
some utility code and configure-generated macro definitions, they have
no access to jemalloc internals.
- stress: Black box stress tests. These tests link with the installable
shared jemalloc library, as well as with an internal allocator with
symbols prefixed by jet_ (same as for unit tests) that can be used to
allocate data structures that are internal to the test code.
Move existing tests into test/{unit,integration}/ as appropriate.
Split out internal parts of jemalloc_defs.h.in and put them in
jemalloc_internal_defs.h.in. This reduces internals exposure to
applications that #include <jemalloc/jemalloc.h>.
Refactor jemalloc.h header generation so that a single header file
results, and the prototypes can be used to generate jet_ prototypes for
tests. Split jemalloc.h.in into multiple parts (jemalloc_defs.h.in,
jemalloc_macros.h.in, jemalloc_protos.h.in, jemalloc_mangle.h.in) and
use a shell script to generate a unified jemalloc.h at configure time.
Change the default private namespace prefix from "" to "je_".
Add missing private namespace mangling.
Remove hard-coded private_namespace.h. Instead generate it and
private_unnamespace.h from private_symbols.txt. Use similar logic for
public symbols, which aids in name mangling for jet_ symbols.
Add test_warn() and test_fail(). Replace existing exit(1) calls with
test_fail() calls.
2013-12-01 07:25:42 +08:00
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
test_fail(const char *format, ...) {
|
2013-12-09 12:52:21 +08:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
malloc_vcprintf(NULL, NULL, format, ap);
|
|
|
|
va_end(ap);
|
2013-12-16 07:54:18 +08:00
|
|
|
malloc_printf("\n");
|
2013-12-09 12:52:21 +08:00
|
|
|
test_status = test_status_fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2017-01-16 08:56:30 +08:00
|
|
|
test_status_string(test_status_t test_status) {
|
2013-12-09 12:52:21 +08:00
|
|
|
switch (test_status) {
|
|
|
|
case test_status_pass: return "pass";
|
|
|
|
case test_status_skip: return "skip";
|
|
|
|
case test_status_fail: return "fail";
|
|
|
|
default: not_reached();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
p_test_init(const char *name) {
|
2013-12-09 12:52:21 +08:00
|
|
|
test_count++;
|
|
|
|
test_status = test_status_pass;
|
|
|
|
test_name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
p_test_fini(void) {
|
2013-12-09 12:52:21 +08:00
|
|
|
test_counts[test_status]++;
|
2017-04-01 10:59:45 +08:00
|
|
|
malloc_printf("%s (%s): %s\n", test_name, reentrancy_t_str(reentrancy),
|
|
|
|
test_status_string(test_status));
|
2013-12-09 12:52:21 +08:00
|
|
|
}
|
|
|
|
|
2018-05-12 07:43:43 +08:00
|
|
|
static void
|
|
|
|
check_global_slow(test_status_t *status) {
|
|
|
|
#ifdef JEMALLOC_UNIT_TEST
|
|
|
|
/*
|
|
|
|
* This check needs to peek into tsd internals, which is why it's only
|
|
|
|
* exposed in unit tests.
|
|
|
|
*/
|
|
|
|
if (tsd_global_slow()) {
|
|
|
|
malloc_printf("Testing increased global slow count\n");
|
|
|
|
*status = test_status_fail;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-05-08 03:42:31 +08:00
|
|
|
static test_status_t
|
2017-03-29 08:30:54 +08:00
|
|
|
p_test_impl(bool do_malloc_init, bool do_reentrant, test_t *t, va_list ap) {
|
2014-05-29 02:08:17 +08:00
|
|
|
test_status_t ret;
|
2013-12-09 12:52:21 +08:00
|
|
|
|
2016-05-08 03:42:31 +08:00
|
|
|
if (do_malloc_init) {
|
|
|
|
/*
|
|
|
|
* Make sure initialization occurs prior to running tests.
|
|
|
|
* Tests are special because they may use internal facilities
|
|
|
|
* prior to triggering initialization as a side effect of
|
|
|
|
* calling into the public API.
|
|
|
|
*/
|
|
|
|
if (nallocx(1, 0) == 0) {
|
|
|
|
malloc_printf("Initialization error");
|
2017-01-20 10:15:45 +08:00
|
|
|
return test_status_fail;
|
2016-05-08 03:42:31 +08:00
|
|
|
}
|
2014-05-29 02:08:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = test_status_pass;
|
2014-05-02 06:51:30 +08:00
|
|
|
for (; t != NULL; t = va_arg(ap, test_t *)) {
|
2017-03-29 08:30:54 +08:00
|
|
|
/* Non-reentrant run. */
|
2017-04-01 10:59:45 +08:00
|
|
|
reentrancy = non_reentrant;
|
2018-04-10 09:09:34 +08:00
|
|
|
test_hooks_arena_new_hook = test_hooks_libc_hook = NULL;
|
2013-12-09 12:52:21 +08:00
|
|
|
t();
|
2017-01-16 08:56:30 +08:00
|
|
|
if (test_status > ret) {
|
2013-12-09 12:52:21 +08:00
|
|
|
ret = test_status;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2018-05-12 07:43:43 +08:00
|
|
|
check_global_slow(&ret);
|
2017-03-29 08:30:54 +08:00
|
|
|
/* Reentrant run. */
|
|
|
|
if (do_reentrant) {
|
2017-04-01 10:59:45 +08:00
|
|
|
reentrancy = libc_reentrant;
|
2018-04-10 09:09:34 +08:00
|
|
|
test_hooks_arena_new_hook = NULL;
|
|
|
|
test_hooks_libc_hook = &libc_reentrancy_hook;
|
2017-03-29 08:30:54 +08:00
|
|
|
t();
|
|
|
|
if (test_status > ret) {
|
|
|
|
ret = test_status;
|
|
|
|
}
|
2018-05-12 07:43:43 +08:00
|
|
|
check_global_slow(&ret);
|
2017-04-01 10:59:45 +08:00
|
|
|
|
|
|
|
reentrancy = arena_new_reentrant;
|
2018-04-10 09:09:34 +08:00
|
|
|
test_hooks_libc_hook = NULL;
|
|
|
|
test_hooks_arena_new_hook = &arena_new_reentrancy_hook;
|
2017-04-01 10:59:45 +08:00
|
|
|
t();
|
|
|
|
if (test_status > ret) {
|
|
|
|
ret = test_status;
|
2017-03-29 08:30:54 +08:00
|
|
|
}
|
2018-05-12 07:43:43 +08:00
|
|
|
check_global_slow(&ret);
|
2017-03-29 08:30:54 +08:00
|
|
|
}
|
2013-12-09 12:52:21 +08:00
|
|
|
}
|
|
|
|
|
2013-12-13 06:58:26 +08:00
|
|
|
malloc_printf("--- %s: %u/%u, %s: %u/%u, %s: %u/%u ---\n",
|
|
|
|
test_status_string(test_status_pass),
|
|
|
|
test_counts[test_status_pass], test_count,
|
|
|
|
test_status_string(test_status_skip),
|
|
|
|
test_counts[test_status_skip], test_count,
|
|
|
|
test_status_string(test_status_fail),
|
|
|
|
test_counts[test_status_fail], test_count);
|
2013-12-09 12:52:21 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return ret;
|
2013-12-09 12:52:21 +08:00
|
|
|
}
|
|
|
|
|
2016-05-08 03:42:31 +08:00
|
|
|
test_status_t
|
2017-01-16 08:56:30 +08:00
|
|
|
p_test(test_t *t, ...) {
|
2016-05-08 03:42:31 +08:00
|
|
|
test_status_t ret;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
ret = test_status_pass;
|
|
|
|
va_start(ap, t);
|
2017-03-29 08:30:54 +08:00
|
|
|
ret = p_test_impl(true, true, t, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
test_status_t
|
|
|
|
p_test_no_reentrancy(test_t *t, ...) {
|
|
|
|
test_status_t ret;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
ret = test_status_pass;
|
|
|
|
va_start(ap, t);
|
|
|
|
ret = p_test_impl(true, false, t, ap);
|
2016-05-08 03:42:31 +08:00
|
|
|
va_end(ap);
|
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return ret;
|
2016-05-08 03:42:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
test_status_t
|
2017-01-16 08:56:30 +08:00
|
|
|
p_test_no_malloc_init(test_t *t, ...) {
|
2016-05-08 03:42:31 +08:00
|
|
|
test_status_t ret;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
ret = test_status_pass;
|
|
|
|
va_start(ap, t);
|
2017-03-29 08:30:54 +08:00
|
|
|
/*
|
|
|
|
* We also omit reentrancy from bootstrapping tests, since we don't
|
|
|
|
* (yet) care about general reentrancy during bootstrapping.
|
|
|
|
*/
|
|
|
|
ret = p_test_impl(false, false, t, ap);
|
2016-05-08 03:42:31 +08:00
|
|
|
va_end(ap);
|
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return ret;
|
2016-05-08 03:42:31 +08:00
|
|
|
}
|
|
|
|
|
2013-12-09 12:52:21 +08:00
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
p_test_fail(const char *prefix, const char *message) {
|
2014-03-30 14:14:32 +08:00
|
|
|
malloc_cprintf(NULL, NULL, "%s%s\n", prefix, message);
|
2013-12-09 12:52:21 +08:00
|
|
|
test_status = test_status_fail;
|
Refactor to support more varied testing.
Refactor the test harness to support three types of tests:
- unit: White box unit tests. These tests have full access to all
internal jemalloc library symbols. Though in actuality all symbols
are prefixed by jet_, macro-based name mangling abstracts this away
from test code.
- integration: Black box integration tests. These tests link with
the installable shared jemalloc library, and with the exception of
some utility code and configure-generated macro definitions, they have
no access to jemalloc internals.
- stress: Black box stress tests. These tests link with the installable
shared jemalloc library, as well as with an internal allocator with
symbols prefixed by jet_ (same as for unit tests) that can be used to
allocate data structures that are internal to the test code.
Move existing tests into test/{unit,integration}/ as appropriate.
Split out internal parts of jemalloc_defs.h.in and put them in
jemalloc_internal_defs.h.in. This reduces internals exposure to
applications that #include <jemalloc/jemalloc.h>.
Refactor jemalloc.h header generation so that a single header file
results, and the prototypes can be used to generate jet_ prototypes for
tests. Split jemalloc.h.in into multiple parts (jemalloc_defs.h.in,
jemalloc_macros.h.in, jemalloc_protos.h.in, jemalloc_mangle.h.in) and
use a shell script to generate a unified jemalloc.h at configure time.
Change the default private namespace prefix from "" to "je_".
Add missing private namespace mangling.
Remove hard-coded private_namespace.h. Instead generate it and
private_unnamespace.h from private_symbols.txt. Use similar logic for
public symbols, which aids in name mangling for jet_ symbols.
Add test_warn() and test_fail(). Replace existing exit(1) calls with
test_fail() calls.
2013-12-01 07:25:42 +08:00
|
|
|
}
|
2019-08-28 04:44:41 +08:00
|
|
|
|
2020-02-07 02:10:10 +08:00
|
|
|
bool
|
|
|
|
p_test_failed() {
|
|
|
|
return test_status == test_status_fail;
|
|
|
|
}
|
|
|
|
|
2019-08-28 04:44:41 +08:00
|
|
|
void
|
|
|
|
strncpy_cond(void *dst, const char *src, bool cond) {
|
|
|
|
if (cond) {
|
|
|
|
/*
|
|
|
|
* Avoid strcpy and explicitly set length to 0 because the
|
|
|
|
* `stringop-overflow` check may warn even if the specific test
|
|
|
|
* is unreachable.
|
|
|
|
*/
|
|
|
|
size_t n = cond ? strlen(src) + 1 : 0;
|
|
|
|
strncpy(dst, src, n);
|
|
|
|
}
|
|
|
|
}
|