1#ifdef __cplusplus 2extern "C" { 3#endif 4 5#include <limits.h> 6#ifndef SIZE_T_MAX 7# define SIZE_T_MAX SIZE_MAX 8#endif 9#include <stdlib.h> 10#include <stdarg.h> 11#include <stdbool.h> 12#include <errno.h> 13#include <math.h> 14#include <string.h> 15#ifdef _WIN32 16# include "msvc_compat/strings.h" 17#endif 18 19#ifdef _WIN32 20# include <windows.h> 21# include "msvc_compat/windows_extra.h" 22#else 23# include <pthread.h> 24#endif 25 26#include "test/jemalloc_test_defs.h" 27 28#ifdef JEMALLOC_OSSPIN 29# include <libkern/OSAtomic.h> 30#endif 31 32#if defined(HAVE_ALTIVEC) && !defined(__APPLE__) 33# include <altivec.h> 34#endif 35#ifdef HAVE_SSE2 36# include <emmintrin.h> 37#endif 38 39/******************************************************************************/ 40/* 41 * For unit tests, expose all public and private interfaces. 42 */ 43#ifdef JEMALLOC_UNIT_TEST 44# define JEMALLOC_JET 45# define JEMALLOC_MANGLE 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 defined(JEMALLOC_INTEGRATION_CPP_TEST) 56# define JEMALLOC_MANGLE 57# include "jemalloc/jemalloc@install_suffix@.h" 58# include "jemalloc/internal/jemalloc_internal_defs.h" 59# include "jemalloc/internal/jemalloc_internal_macros.h" 60 61static const bool config_debug = 62#ifdef JEMALLOC_DEBUG 63 true 64#else 65 false 66#endif 67 ; 68 69# define JEMALLOC_N(n) @private_namespace@##n 70# include "jemalloc/internal/private_namespace.h" 71 72# include "jemalloc/internal/nstime_types.h" 73# include "jemalloc/internal/nstime_structs.h" 74# include "jemalloc/internal/nstime_externs.h" 75# include "jemalloc/internal/util_types.h" 76# include "jemalloc/internal/util_externs.h" 77# include "jemalloc/internal/util_inlines.h" 78# include "jemalloc/internal/qr.h" 79# include "jemalloc/internal/ql.h" 80 81/******************************************************************************/ 82/* 83 * For stress tests, expose the public jemalloc interfaces with name mangling 84 * so that they can be tested as e.g. malloc() and free(). Also expose the 85 * public jemalloc interfaces with jet_ prefixes, so that stress tests can use 86 * a separate allocator for their internal data structures. 87 */ 88#elif defined(JEMALLOC_STRESS_TEST) 89# include "jemalloc/jemalloc@install_suffix@.h" 90 91# include "jemalloc/jemalloc_protos_jet.h" 92 93# define JEMALLOC_JET 94# include "jemalloc/internal/jemalloc_internal.h" 95# include "jemalloc/internal/public_unnamespace.h" 96# undef JEMALLOC_JET 97 98# include "jemalloc/jemalloc_rename.h" 99# define JEMALLOC_MANGLE 100# ifdef JEMALLOC_STRESS_TESTLIB 101# include "jemalloc/jemalloc_mangle_jet.h" 102# else 103# include "jemalloc/jemalloc_mangle.h" 104# endif 105 106/******************************************************************************/ 107/* 108 * This header does dangerous things, the effects of which only test code 109 * should be subject to. 110 */ 111#else 112# error "This header cannot be included outside a testing context" 113#endif 114 115/******************************************************************************/ 116/* 117 * Common test utilities. 118 */ 119#include "test/btalloc.h" 120#include "test/math.h" 121#include "test/mtx.h" 122#include "test/mq.h" 123#include "test/test.h" 124#include "test/timer.h" 125#include "test/thd.h" 126#define MEXP 19937 127#include "test/SFMT.h" 128 129/******************************************************************************/ 130/* 131 * Define always-enabled assertion macros, so that test assertions execute even 132 * if assertions are disabled in the library code. 133 */ 134#undef assert 135#undef not_reached 136#undef not_implemented 137#undef assert_not_implemented 138 139#define assert(e) do { \ 140 if (!(e)) { \ 141 malloc_printf( \ 142 "<jemalloc>: %s:%d: Failed assertion: \"%s\"\n", \ 143 __FILE__, __LINE__, #e); \ 144 abort(); \ 145 } \ 146} while (0) 147 148#define not_reached() do { \ 149 malloc_printf( \ 150 "<jemalloc>: %s:%d: Unreachable code reached\n", \ 151 __FILE__, __LINE__); \ 152 abort(); \ 153} while (0) 154 155#define not_implemented() do { \ 156 malloc_printf("<jemalloc>: %s:%d: Not implemented\n", \ 157 __FILE__, __LINE__); \ 158 abort(); \ 159} while (0) 160 161#define assert_not_implemented(e) do { \ 162 if (!(e)) \ 163 not_implemented(); \ 164} while (0) 165 166#ifdef __cplusplus 167} 168#endif 169