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_preamble.h" 47# include "jemalloc/internal/jemalloc_internal_includes.h" 48 49/******************************************************************************/ 50/* 51 * For integration tests, expose the public jemalloc interfaces, but only 52 * expose the minimum necessary internal utility code (to avoid re-implementing 53 * essentially identical code within the test infrastructure). 54 */ 55#elif defined(JEMALLOC_INTEGRATION_TEST) || \ 56 defined(JEMALLOC_INTEGRATION_CPP_TEST) 57# define JEMALLOC_MANGLE 58# include "jemalloc/jemalloc@install_suffix@.h" 59# include "jemalloc/internal/jemalloc_internal_defs.h" 60# include "jemalloc/internal/jemalloc_internal_macros.h" 61 62static const bool config_debug = 63#ifdef JEMALLOC_DEBUG 64 true 65#else 66 false 67#endif 68 ; 69 70# define JEMALLOC_N(n) @private_namespace@##n 71# include "jemalloc/internal/private_namespace.h" 72# include "jemalloc/internal/hooks.h" 73 74/* Hermetic headers. */ 75# include "jemalloc/internal/assert.h" 76# include "jemalloc/internal/malloc_io.h" 77# include "jemalloc/internal/nstime.h" 78# include "jemalloc/internal/util.h" 79 80/* Non-hermetic headers. */ 81# include "jemalloc/internal/qr.h" 82# include "jemalloc/internal/ql.h" 83 84/******************************************************************************/ 85/* 86 * For stress tests, expose the public jemalloc interfaces with name mangling 87 * so that they can be tested as e.g. malloc() and free(). Also expose the 88 * public jemalloc interfaces with jet_ prefixes, so that stress tests can use 89 * a separate allocator for their internal data structures. 90 */ 91#elif defined(JEMALLOC_STRESS_TEST) 92# include "jemalloc/jemalloc@install_suffix@.h" 93 94# include "jemalloc/jemalloc_protos_jet.h" 95 96# define JEMALLOC_JET 97# include "jemalloc/internal/jemalloc_preamble.h" 98# include "jemalloc/internal/jemalloc_internal_includes.h" 99# include "jemalloc/internal/public_unnamespace.h" 100# undef JEMALLOC_JET 101 102# include "jemalloc/jemalloc_rename.h" 103# define JEMALLOC_MANGLE 104# ifdef JEMALLOC_STRESS_TESTLIB 105# include "jemalloc/jemalloc_mangle_jet.h" 106# else 107# include "jemalloc/jemalloc_mangle.h" 108# endif 109 110/******************************************************************************/ 111/* 112 * This header does dangerous things, the effects of which only test code 113 * should be subject to. 114 */ 115#else 116# error "This header cannot be included outside a testing context" 117#endif 118 119/******************************************************************************/ 120/* 121 * Common test utilities. 122 */ 123#include "test/btalloc.h" 124#include "test/math.h" 125#include "test/mtx.h" 126#include "test/mq.h" 127#include "test/test.h" 128#include "test/timer.h" 129#include "test/thd.h" 130#define MEXP 19937 131#include "test/SFMT.h" 132 133/******************************************************************************/ 134/* 135 * Define always-enabled assertion macros, so that test assertions execute even 136 * if assertions are disabled in the library code. 137 */ 138#undef assert 139#undef not_reached 140#undef not_implemented 141#undef assert_not_implemented 142 143#define assert(e) do { \ 144 if (!(e)) { \ 145 malloc_printf( \ 146 "<jemalloc>: %s:%d: Failed assertion: \"%s\"\n", \ 147 __FILE__, __LINE__, #e); \ 148 abort(); \ 149 } \ 150} while (0) 151 152#define not_reached() do { \ 153 malloc_printf( \ 154 "<jemalloc>: %s:%d: Unreachable code reached\n", \ 155 __FILE__, __LINE__); \ 156 abort(); \ 157} while (0) 158 159#define not_implemented() do { \ 160 malloc_printf("<jemalloc>: %s:%d: Not implemented\n", \ 161 __FILE__, __LINE__); \ 162 abort(); \ 163} while (0) 164 165#define assert_not_implemented(e) do { \ 166 if (!(e)) { \ 167 not_implemented(); \ 168 } \ 169} while (0) 170 171#ifdef __cplusplus 172} 173#endif 174