[e70e45] | 1 | #include <time.h> |
---|
| 2 | #include <string.h> |
---|
[8d0069] | 3 | #include <mylimits.h> |
---|
[e70e45] | 4 | |
---|
| 5 | #define TRACK_LEVEL 1 |
---|
| 6 | #define CHECK_LEVEL 1 |
---|
[36ee6f] | 7 | // keep every ith address: define to 0 if no keeping |
---|
| 8 | #define KEEP_LEVEL 20 |
---|
[384936] | 9 | // #define KEEP_LEVEL 0 |
---|
[36ee6f] | 10 | |
---|
[e70e45] | 11 | // #define MAX_CELLS 500000 |
---|
[f103fb] | 12 | // #define MAX_CELLS 100000 |
---|
[fa2a43] | 13 | #define MAX_CELLS 100000 |
---|
[e70e45] | 14 | #define KEEP_ADDR 100 |
---|
[384936] | 15 | // #define KEEP_ADDR 0 |
---|
[e70e45] | 16 | #define END_CHECK_LEVEL 5 |
---|
| 17 | |
---|
| 18 | #ifdef OM_TEST_MALLOC |
---|
| 19 | #define OM_EMULATE_OMALLOC |
---|
| 20 | #endif |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | #include "omStructs.h" |
---|
| 24 | |
---|
| 25 | struct omMemCell_s |
---|
| 26 | { |
---|
| 27 | void* addr; |
---|
| 28 | omBin bin; |
---|
[78f1ab] | 29 | unsigned long spec; |
---|
[f103fb] | 30 | omBin orig_bin; |
---|
[e70e45] | 31 | }; |
---|
| 32 | |
---|
| 33 | typedef struct omMemCell_s omMemCell_t; |
---|
| 34 | typedef omMemCell_t* omMemCell; |
---|
| 35 | |
---|
| 36 | extern omMemCell_t cells[]; |
---|
[78f1ab] | 37 | void TestAlloc(omMemCell cell, unsigned long spec); |
---|
| 38 | void TestRealloc(omMemCell cell, unsigned long spec); |
---|
[e70e45] | 39 | void TestFree(omMemCell cell); |
---|
| 40 | |
---|
| 41 | #if CHECK_LEVEL > 2 |
---|
| 42 | #define myprintf(format, args...) \ |
---|
| 43 | printf(format, ## args) |
---|
| 44 | #define myfflush(what) fflush(what) |
---|
| 45 | #else |
---|
| 46 | #define myprintf(format, args...) ((void) 0) |
---|
| 47 | #define myfflush(what) ((void) 0) |
---|
| 48 | #endif |
---|
| 49 | |
---|
[f103fb] | 50 | #define IS_STICKY_BIN(spec) (spec & 1) |
---|
| 51 | // #define IS_STICKY_BIN(spec) (0) |
---|
[384936] | 52 | #define GET_SIZE(spec) (spec & ((((unsigned long) 1) << 14) -1)) |
---|
| 53 | #define SET_SIZE(spec, size) spec = ((spec & ~((((unsigned long) 1) << 14) -1)) | (size)) |
---|
| 54 | #define IS_ALIGNED(spec) (spec & (((unsigned long) 1) << 15)) |
---|
| 55 | #define IS_ZERO(spec) (spec & (((unsigned long) 1) << 16)) |
---|
| 56 | #define IS_BIN(spec) (spec & (((unsigned long) 1) << 17)) |
---|
| 57 | #define IS_SPEC_BIN(spec) (spec & (((unsigned long) 1) << 18)) |
---|
| 58 | #define IS_INLINE(spec) (spec & (((unsigned long) 1) << 19)) |
---|
| 59 | #define DO_FREE(spec) (!(spec & (((unsigned long) 1) << 20)) && !(spec & (((unsigned long) 1) << 21))) |
---|
| 60 | #define DO_REALLOC(spec) ((spec & (((unsigned long) 1) << 20)) && (spec & (((unsigned long) 1) << 21))) |
---|
| 61 | #define DO_DUP(spec) ((spec & (((unsigned long) 1) << 20)) && ! (spec & (((unsigned long) 1) << 21))) |
---|
[e70e45] | 62 | #if CHECK_LEVEL > 0 |
---|
| 63 | //#define DO_CHECK(spec) 1 |
---|
[384936] | 64 | #define DO_CHECK(spec) (spec & (((unsigned long) 1) << 22)) |
---|
| 65 | #define DO_FREE_CHECK(spec) (spec & (((unsigned long) 1) << 23)) |
---|
[e70e45] | 66 | #else |
---|
| 67 | #define DO_CHECK(spec) 0 |
---|
| 68 | #define DO_FREE_CHECK(spec) 0 |
---|
| 69 | #endif |
---|
| 70 | #if CHECK_LEVEL > 0 && TRACK_LEVEL > 0 |
---|
[384936] | 71 | #define DO_TRACK(spec) (spec & (((unsigned long) 1) << 24)) |
---|
| 72 | #define GET_TRACK(spec) (((spec & ((((unsigned long) 1) << 27) | (((unsigned long) 1) << 26) | (((unsigned long) 1) << 25))) >> 25) % 5) + TRACK_LEVEL |
---|
[e70e45] | 73 | // #define DO_TRACK(spec) TRACK_LEVEL |
---|
| 74 | // #define GET_TRACK(spec) TRACK_LEVEL |
---|
| 75 | #else |
---|
| 76 | #define DO_TRACK(spec) 0 |
---|
| 77 | #define GET_TRACK(spec) 0 |
---|
| 78 | #endif |
---|
[36ee6f] | 79 | #if KEEP_LEVEL > 0 |
---|
| 80 | #define DO_KEEP(spec) (DO_CHECK(spec) && (spec % KEEP_LEVEL == 0)) |
---|
| 81 | #define DO_FREE_KEEP(spec) (DO_FREE_CHECK(spec) && (spec % KEEP_LEVEL == 0)) |
---|
| 82 | #else |
---|
| 83 | #define DO_KEEP(spec) 0 |
---|
| 84 | #define DO_FREE_KEEP(spec) 0 |
---|
| 85 | #endif |
---|
| 86 | |
---|
[384936] | 87 | #define IS_FREE_SIZE(spec) (spec & (((unsigned long) 1) << 28)) |
---|
| 88 | #define IS_FREE_BIN(spec) (spec & (((unsigned long) 1) << 29)) |
---|
| 89 | #define IS_SLOPPY(spec) (spec & (((unsigned long) 1) << 30)) |
---|
| 90 | #define IS_FREE_BINADDR(spec) (spec & (((unsigned long) 1) << 31)) |
---|
[e70e45] | 91 | |
---|
| 92 | |
---|
[91c4012] | 93 | #define SPEC_MAX ULONG_MAX |
---|
[384936] | 94 | #define SIZE_MAX ((((unsigned long) 1) << 14) -1) |
---|
| 95 | #define RANGE_MIN (((unsigned long) 1) << 6) |
---|
| 96 | #define RANGE_MAX (((unsigned long) 1) << 14) |
---|
[e70e45] | 97 | |
---|
| 98 | #define PAGES_PER_REGION 128 |
---|
| 99 | |
---|
[78f1ab] | 100 | void omtTestAlloc(omMemCell cell, unsigned long spec); |
---|
| 101 | void omtTestRealloc(omMemCell cell, unsigned long spec); |
---|
| 102 | void omtTestDup(omMemCell cell, unsigned long spec); |
---|
| 103 | void omtTestFree(omMemCell cell); |
---|
[e70e45] | 104 | |
---|
[78f1ab] | 105 | void omtTestAllocDebug(omMemCell cell, unsigned long spec); |
---|
| 106 | void omtTestReallocDebug(omMemCell cell, unsigned long spec); |
---|
| 107 | void omtTestDupDebug(omMemCell cell, unsigned long spec); |
---|
| 108 | void omtTestFreeDebug(omMemCell cell); |
---|
[36ee6f] | 109 | |
---|
| 110 | void omtTestAllocKeep(omMemCell cell, unsigned long spec); |
---|
| 111 | void omtTestReallocKeep(omMemCell cell, unsigned long spec); |
---|
| 112 | void omtTestDupKeep(omMemCell cell, unsigned long spec); |
---|
| 113 | void omtTestFreeKeep(omMemCell cell); |
---|
| 114 | |
---|
[e70e45] | 115 | void InitCellAddrContent(omMemCell cell); |
---|
[78f1ab] | 116 | int omtTestErrors(); |
---|
[f103fb] | 117 | omBin omtGetStickyBin(omBin bin); |
---|
[e70e45] | 118 | |
---|
| 119 | #if CHECK_LEVEL > 0 |
---|
[78f1ab] | 120 | void omtTestDebug(omMemCell cell); |
---|
[e70e45] | 121 | void TestAddrContent(void* addr, unsigned long value, size_t size); |
---|
| 122 | void TestAddrContentEqual(void* s1, void* s2, size_t size); |
---|
| 123 | #else |
---|
[78f1ab] | 124 | #define omtTestDebug(cell) ((void)0) |
---|
[e70e45] | 125 | #define TestAddrContent(a,v,s) ((void)0) |
---|
| 126 | #define TestAddrContentEqual(s1, s2, s) ((void)0) |
---|
| 127 | #endif |
---|