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