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