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