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