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