jemalloc_test.h.in revision 0f4f1efd94d33a4bbf766d3d4e7e349fa7c0d3b9
1#include <stdlib.h>
2#include <stdarg.h>
3#include <stdbool.h>
4#include <errno.h>
5#include <inttypes.h>
6#include <math.h>
7#include <string.h>
8
9#ifdef _WIN32
10#  include <windows.h>
11#else
12#  include <pthread.h>
13#endif
14
15/******************************************************************************/
16/*
17 * Define always-enabled assertion macros, so that test assertions execute even
18 * if assertions are disabled in the library code.  These definitions must
19 * exist prior to including "jemalloc/internal/util.h".
20 */
21#define	assert(e) do {							\
22	if (!(e)) {							\
23		malloc_printf(						\
24		    "<jemalloc>: %s:%d: Failed assertion: \"%s\"\n",	\
25		    __FILE__, __LINE__, #e);				\
26		abort();						\
27	}								\
28} while (0)
29
30#define	not_reached() do {						\
31	malloc_printf(							\
32	    "<jemalloc>: %s:%d: Unreachable code reached\n",		\
33	    __FILE__, __LINE__);					\
34	abort();							\
35} while (0)
36
37#define	not_implemented() do {						\
38	malloc_printf("<jemalloc>: %s:%d: Not implemented\n",		\
39	    __FILE__, __LINE__);					\
40	abort();							\
41} while (0)
42
43#define	assert_not_implemented(e) do {					\
44	if (!(e))							\
45		not_implemented();					\
46} while (0)
47
48#include "test/jemalloc_test_defs.h"
49
50#ifdef JEMALLOC_OSSPIN
51#  include <libkern/OSAtomic.h>
52#endif
53
54#if defined(HAVE_ALTIVEC) && !defined(__APPLE__)
55#  include <altivec.h>
56#endif
57#ifdef HAVE_SSE2
58#  include <emmintrin.h>
59#endif
60
61/******************************************************************************/
62/*
63 * For unit tests, expose all public and private interfaces.
64 */
65#ifdef JEMALLOC_UNIT_TEST
66#  define JEMALLOC_JET
67#  include "jemalloc/internal/jemalloc_internal.h"
68
69/******************************************************************************/
70/*
71 * For integration tests, expose the public jemalloc interfaces, but only
72 * expose the minimum necessary internal utility code (to avoid re-implementing
73 * essentially identical code within the test infrastructure).
74 */
75#elif defined(JEMALLOC_INTEGRATION_TEST)
76#  define JEMALLOC_MANGLE
77#  include "jemalloc/jemalloc@install_suffix@.h"
78#  include "jemalloc/internal/jemalloc_internal_defs.h"
79#  include "jemalloc/internal/jemalloc_internal_macros.h"
80
81#  define JEMALLOC_N(n) @private_namespace@##n
82#  include "jemalloc/internal/private_namespace.h"
83
84#  define JEMALLOC_H_TYPES
85#  define JEMALLOC_H_STRUCTS
86#  define JEMALLOC_H_EXTERNS
87#  define JEMALLOC_H_INLINES
88#  include "jemalloc/internal/util.h"
89#  include "jemalloc/internal/qr.h"
90#  include "jemalloc/internal/ql.h"
91#  undef JEMALLOC_H_TYPES
92#  undef JEMALLOC_H_STRUCTS
93#  undef JEMALLOC_H_EXTERNS
94#  undef JEMALLOC_H_INLINES
95
96/******************************************************************************/
97/*
98 * For stress tests, expose the public jemalloc interfaces with name mangling
99 * so that they can be tested as e.g. malloc() and free().  Also expose the
100 * public jemalloc interfaces with jet_ prefixes, so that stress tests can use
101 * a separate allocator for their internal data structures.
102 */
103#elif defined(JEMALLOC_STRESS_TEST)
104#  define JEMALLOC_NO_DEMANGLE
105#  include "jemalloc/jemalloc@install_suffix@.h"
106#  include "jemalloc/internal/public_unnamespace.h"
107#  undef JEMALLOC_NO_DEMANGLE
108
109#  include "jemalloc/jemalloc_protos_jet.h"
110
111#  define JEMALLOC_JET
112#  include "jemalloc/internal/jemalloc_internal.h"
113#  include "jemalloc/internal/public_unnamespace.h"
114#  undef JEMALLOC_JET
115
116#  define JEMALLOC_MANGLE
117#  include "jemalloc/jemalloc_mangle@install_suffix@.h"
118
119/******************************************************************************/
120/*
121 * This header does dangerous things, the effects of which only test code
122 * should be subject to.
123 */
124#else
125#  error "This header cannot be included outside a testing context"
126#endif
127
128/******************************************************************************/
129/*
130 * Common test utilities.
131 */
132#include "test/math.h"
133#include "test/mtx.h"
134#include "test/mq.h"
135#include "test/test.h"
136#include "test/thd.h"
137#define	MEXP 19937
138#include "test/SFMT.h"
139