summaryrefslogtreecommitdiff
path: root/test/include/test/jemalloc_test.h.in
blob: 3f8c0da7fc50c668eb03b3ea36a68fbfea97bbae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#ifdef __cplusplus
extern "C" {
#endif

#include <limits.h>
#ifndef SIZE_T_MAX
#  define SIZE_T_MAX	SIZE_MAX
#endif
#include <stdlib.h>
#include <stdarg.h>
#include <stdbool.h>
#include <errno.h>
#include <math.h>
#include <string.h>
#ifdef _WIN32
#  include "msvc_compat/strings.h"
#endif

#ifdef _WIN32
#  include <windows.h>
#  include "msvc_compat/windows_extra.h"
#else
#  include <pthread.h>
#endif

#include "test/jemalloc_test_defs.h"

#if defined(JEMALLOC_OSATOMIC)
#  include <libkern/OSAtomic.h>
#endif

#if defined(HAVE_ALTIVEC) && !defined(__APPLE__)
#  include <altivec.h>
#endif
#ifdef HAVE_SSE2
#  include <emmintrin.h>
#endif

/******************************************************************************/
/*
 * For unit tests and analytics tests, expose all public and private interfaces.
 */
#if defined(JEMALLOC_UNIT_TEST) || defined (JEMALLOC_ANALYZE_TEST)
#  define JEMALLOC_JET
#  define JEMALLOC_MANGLE
#  include "jemalloc/internal/jemalloc_preamble.h"
#  include "jemalloc/internal/jemalloc_internal_includes.h"

/******************************************************************************/
/*
 * For integration tests, expose the public jemalloc interfaces, but only
 * expose the minimum necessary internal utility code (to avoid re-implementing
 * essentially identical code within the test infrastructure).
 */
#elif defined(JEMALLOC_INTEGRATION_TEST) || \
    defined(JEMALLOC_INTEGRATION_CPP_TEST)
#  define JEMALLOC_MANGLE
#  include "jemalloc/jemalloc@install_suffix@.h"
#  include "jemalloc/internal/jemalloc_internal_defs.h"
#  include "jemalloc/internal/jemalloc_internal_macros.h"

static const bool config_debug =
#ifdef JEMALLOC_DEBUG
    true
#else
    false
#endif
    ;

#  define JEMALLOC_N(n) @private_namespace@##n
#  include "jemalloc/internal/private_namespace.h"
#  include "jemalloc/internal/test_hooks.h"

/* Hermetic headers. */
#  include "jemalloc/internal/assert.h"
#  include "jemalloc/internal/malloc_io.h"
#  include "jemalloc/internal/nstime.h"
#  include "jemalloc/internal/util.h"

/* Non-hermetic headers. */
#  include "jemalloc/internal/qr.h"
#  include "jemalloc/internal/ql.h"

/******************************************************************************/
/*
 * For stress tests, expose the public jemalloc interfaces with name mangling
 * so that they can be tested as e.g. malloc() and free().  Also expose the
 * public jemalloc interfaces with jet_ prefixes, so that stress tests can use
 * a separate allocator for their internal data structures.
 */
#elif defined(JEMALLOC_STRESS_TEST)
#  include "jemalloc/jemalloc@install_suffix@.h"

#  include "jemalloc/jemalloc_protos_jet.h"

#  define JEMALLOC_JET
#  include "jemalloc/internal/jemalloc_preamble.h"
#  include "jemalloc/internal/jemalloc_internal_includes.h"
#  include "jemalloc/internal/public_unnamespace.h"
#  undef JEMALLOC_JET

#  include "jemalloc/jemalloc_rename.h"
#  define JEMALLOC_MANGLE
#  ifdef JEMALLOC_STRESS_TESTLIB
#    include "jemalloc/jemalloc_mangle_jet.h"
#  else
#    include "jemalloc/jemalloc_mangle.h"
#  endif

/******************************************************************************/
/*
 * This header does dangerous things, the effects of which only test code
 * should be subject to.
 */
#else
#  error "This header cannot be included outside a testing context"
#endif

/******************************************************************************/
/*
 * Common test utilities.
 */
#include "test/btalloc.h"
#include "test/math.h"
#include "test/mtx.h"
#include "test/mq.h"
#include "test/sleep.h"
#include "test/test.h"
#include "test/timer.h"
#include "test/thd.h"
#include "test/bgthd.h"
#define MEXP 19937
#include "test/SFMT.h"

#ifndef JEMALLOC_HAVE_MALLOC_SIZE
#define TEST_MALLOC_SIZE malloc_usable_size
#else
#define TEST_MALLOC_SIZE malloc_size
#endif
/******************************************************************************/
/*
 * Define always-enabled assertion macros, so that test assertions execute even
 * if assertions are disabled in the library code.
 */
#undef assert
#undef not_reached
#undef not_implemented
#undef expect_not_implemented

#define assert(e) do {							\
	if (!(e)) {							\
		malloc_printf(						\
		    "<jemalloc>: %s:%d: Failed assertion: \"%s\"\n",	\
		    __FILE__, __LINE__, #e);				\
		abort();						\
	}								\
} while (0)

#define not_reached() do {						\
	malloc_printf(							\
	    "<jemalloc>: %s:%d: Unreachable code reached\n",		\
	    __FILE__, __LINE__);					\
	abort();							\
} while (0)

#define not_implemented() do {						\
	malloc_printf("<jemalloc>: %s:%d: Not implemented\n",		\
	    __FILE__, __LINE__);					\
	abort();							\
} while (0)

#define expect_not_implemented(e) do {					\
	if (!(e)) {							\
		not_implemented();					\
	}								\
} while (0)

#ifdef __cplusplus
}
#endif