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