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#include <sys/time.h> 15 16#ifdef _WIN32 17# include <windows.h> 18# include "msvc_compat/windows_extra.h" 19#else 20# include <pthread.h> 21#endif 22 23/******************************************************************************/ 24/* 25 * Define always-enabled assertion macros, so that test assertions execute even 26 * if assertions are disabled in the library code. These definitions must 27 * exist prior to including "jemalloc/internal/util.h". 28 */ 29#define assert(e) do { \ 30 if (!(e)) { \ 31 malloc_printf( \ 32 "<jemalloc>: %s:%d: Failed assertion: \"%s\"\n", \ 33 __FILE__, __LINE__, #e); \ 34 abort(); \ 35 } \ 36} while (0) 37 38#define not_reached() do { \ 39 malloc_printf( \ 40 "<jemalloc>: %s:%d: Unreachable code reached\n", \ 41 __FILE__, __LINE__); \ 42 abort(); \ 43} while (0) 44 45#define not_implemented() do { \ 46 malloc_printf("<jemalloc>: %s:%d: Not implemented\n", \ 47 __FILE__, __LINE__); \ 48 abort(); \ 49} while (0) 50 51#define assert_not_implemented(e) do { \ 52 if (!(e)) \ 53 not_implemented(); \ 54} while (0) 55 56#include "test/jemalloc_test_defs.h" 57 58#ifdef JEMALLOC_OSSPIN 59# include <libkern/OSAtomic.h> 60#endif 61 62#if defined(HAVE_ALTIVEC) && !defined(__APPLE__) 63# include <altivec.h> 64#endif 65#ifdef HAVE_SSE2 66# include <emmintrin.h> 67#endif 68 69/******************************************************************************/ 70/* 71 * For unit tests, expose all public and private interfaces. 72 */ 73#ifdef JEMALLOC_UNIT_TEST 74# define JEMALLOC_JET 75# define JEMALLOC_MANGLE 76# include "jemalloc/internal/jemalloc_internal.h" 77 78/******************************************************************************/ 79/* 80 * For integration tests, expose the public jemalloc interfaces, but only 81 * expose the minimum necessary internal utility code (to avoid re-implementing 82 * essentially identical code within the test infrastructure). 83 */ 84#elif defined(JEMALLOC_INTEGRATION_TEST) 85# define JEMALLOC_MANGLE 86# include "jemalloc/jemalloc@[email protected]" 87# include "jemalloc/internal/jemalloc_internal_defs.h" 88# include "jemalloc/internal/jemalloc_internal_macros.h" 89 90# define JEMALLOC_N(n) @private_namespace@##n 91# include "jemalloc/internal/private_namespace.h" 92 93# define JEMALLOC_H_TYPES 94# define JEMALLOC_H_STRUCTS 95# define JEMALLOC_H_EXTERNS 96# define JEMALLOC_H_INLINES 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@[email protected]" 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