Skip to content

Commit ff63dca

Browse files
committed
Avoid blindly enabling assertions for header code when testing.
Restructure the test program master header to avoid blindly enabling assertions. Prior to this change, assertion code in e.g. arena.h was always enabled for tests, which could skew performance-related testing.
1 parent 61a6dfc commit ff63dca

File tree

1 file changed

+45
-33
lines changed

1 file changed

+45
-33
lines changed

test/include/test/jemalloc_test.h.in

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,6 @@
1919
# include <pthread.h>
2020
#endif
2121

22-
/******************************************************************************/
23-
/*
24-
* Define always-enabled assertion macros, so that test assertions execute even
25-
* if assertions are disabled in the library code. These definitions must
26-
* exist prior to including "jemalloc/internal/util.h".
27-
*/
28-
#define assert(e) do { \
29-
if (!(e)) { \
30-
malloc_printf( \
31-
"<jemalloc>: %s:%d: Failed assertion: \"%s\"\n", \
32-
__FILE__, __LINE__, #e); \
33-
abort(); \
34-
} \
35-
} while (0)
36-
37-
#define not_reached() do { \
38-
malloc_printf( \
39-
"<jemalloc>: %s:%d: Unreachable code reached\n", \
40-
__FILE__, __LINE__); \
41-
abort(); \
42-
} while (0)
43-
44-
#define not_implemented() do { \
45-
malloc_printf("<jemalloc>: %s:%d: Not implemented\n", \
46-
__FILE__, __LINE__); \
47-
abort(); \
48-
} while (0)
49-
50-
#define assert_not_implemented(e) do { \
51-
if (!(e)) \
52-
not_implemented(); \
53-
} while (0)
54-
5522
#include "test/jemalloc_test_defs.h"
5623

5724
#ifdef JEMALLOC_OSSPIN
@@ -86,6 +53,14 @@
8653
# include "jemalloc/internal/jemalloc_internal_defs.h"
8754
# include "jemalloc/internal/jemalloc_internal_macros.h"
8855

56+
static const bool config_debug =
57+
#ifdef JEMALLOC_DEBUG
58+
true
59+
#else
60+
false
61+
#endif
62+
;
63+
8964
# define JEMALLOC_N(n) @private_namespace@##n
9065
# include "jemalloc/internal/private_namespace.h"
9166

@@ -149,3 +124,40 @@
149124
#include "test/thd.h"
150125
#define MEXP 19937
151126
#include "test/SFMT.h"
127+
128+
/******************************************************************************/
129+
/*
130+
* Define always-enabled assertion macros, so that test assertions execute even
131+
* if assertions are disabled in the library code.
132+
*/
133+
#undef assert
134+
#undef not_reached
135+
#undef not_implemented
136+
#undef assert_not_implemented
137+
138+
#define assert(e) do { \
139+
if (!(e)) { \
140+
malloc_printf( \
141+
"<jemalloc>: %s:%d: Failed assertion: \"%s\"\n", \
142+
__FILE__, __LINE__, #e); \
143+
abort(); \
144+
} \
145+
} while (0)
146+
147+
#define not_reached() do { \
148+
malloc_printf( \
149+
"<jemalloc>: %s:%d: Unreachable code reached\n", \
150+
__FILE__, __LINE__); \
151+
abort(); \
152+
} while (0)
153+
154+
#define not_implemented() do { \
155+
malloc_printf("<jemalloc>: %s:%d: Not implemented\n", \
156+
__FILE__, __LINE__); \
157+
abort(); \
158+
} while (0)
159+
160+
#define assert_not_implemented(e) do { \
161+
if (!(e)) \
162+
not_implemented(); \
163+
} while (0)

0 commit comments

Comments
 (0)