1 | #include <time.h> |
---|
2 | #include <string.h> |
---|
3 | |
---|
4 | #define TRACK_LEVEL 1 |
---|
5 | #define CHECK_LEVEL 1 |
---|
6 | // #define MAX_CELLS 500000 |
---|
7 | #define MAX_CELLS 100000 |
---|
8 | // #define MAX_CELLS 10000 |
---|
9 | #define KEEP_ADDR 100 |
---|
10 | #define END_CHECK_LEVEL 5 |
---|
11 | |
---|
12 | #ifdef OM_TEST_MALLOC |
---|
13 | #define OM_EMULATE_OMALLOC |
---|
14 | #endif |
---|
15 | |
---|
16 | |
---|
17 | #include "omStructs.h" |
---|
18 | |
---|
19 | struct omMemCell_s |
---|
20 | { |
---|
21 | void* addr; |
---|
22 | omBin bin; |
---|
23 | int spec; |
---|
24 | }; |
---|
25 | |
---|
26 | typedef struct omMemCell_s omMemCell_t; |
---|
27 | typedef omMemCell_t* omMemCell; |
---|
28 | |
---|
29 | extern omMemCell_t cells[]; |
---|
30 | void TestAlloc(omMemCell cell, int spec); |
---|
31 | void TestRealloc(omMemCell cell, int spec); |
---|
32 | void TestFree(omMemCell cell); |
---|
33 | |
---|
34 | #if CHECK_LEVEL > 2 |
---|
35 | #define myprintf(format, args...) \ |
---|
36 | printf(format, ## args) |
---|
37 | #define myfflush(what) fflush(what) |
---|
38 | #else |
---|
39 | #define myprintf(format, args...) ((void) 0) |
---|
40 | #define myfflush(what) ((void) 0) |
---|
41 | #endif |
---|
42 | |
---|
43 | #define GET_SIZE(spec) (spec & ((1 << 14) -1)) |
---|
44 | #define SET_SIZE(spec, size) spec = ((spec & ~((1 << 14) -1)) | (size)) |
---|
45 | #define IS_ALIGNED(spec) (spec & (1 << 15)) |
---|
46 | #define IS_ZERO(spec) (spec & (1 << 16)) |
---|
47 | #define IS_BIN(spec) (spec & (1 << 17)) |
---|
48 | #define IS_SPEC_BIN(spec) (spec & (1 << 18)) |
---|
49 | #define IS_INLINE(spec) (spec & (1 << 19)) |
---|
50 | #define DO_FREE(spec) (!(spec & (1 << 20)) && !(spec & (1 << 21))) |
---|
51 | #define DO_REALLOC(spec) ((spec & (1 << 20)) && (spec & (1 << 21))) |
---|
52 | #define DO_DUP(spec) ((spec & (1 << 20)) && ! (spec & (1 << 21))) |
---|
53 | #if CHECK_LEVEL > 0 |
---|
54 | //#define DO_CHECK(spec) 1 |
---|
55 | #define DO_CHECK(spec) (spec & (1 << 22)) |
---|
56 | #define DO_FREE_CHECK(spec) (spec & (1 << 23)) |
---|
57 | #else |
---|
58 | #define DO_CHECK(spec) 0 |
---|
59 | #define DO_FREE_CHECK(spec) 0 |
---|
60 | #endif |
---|
61 | #if CHECK_LEVEL > 0 && TRACK_LEVEL > 0 |
---|
62 | #define DO_TRACK(spec) (spec & (1 << 24)) |
---|
63 | #define GET_TRACK(spec) (((spec & ((1 << 27) | (1 << 26) | (1 << 25))) >> 25) % 5) + TRACK_LEVEL |
---|
64 | // #define DO_TRACK(spec) TRACK_LEVEL |
---|
65 | // #define GET_TRACK(spec) TRACK_LEVEL |
---|
66 | #else |
---|
67 | #define DO_TRACK(spec) 0 |
---|
68 | #define GET_TRACK(spec) 0 |
---|
69 | #endif |
---|
70 | #define IS_FREE_SIZE(spec) (spec & (1 << 28)) |
---|
71 | #define IS_FREE_BIN(spec) (spec & (1 << 29)) |
---|
72 | #define IS_SLOPPY(spec) (spec & (1 << 30)) |
---|
73 | |
---|
74 | |
---|
75 | #define SPEC_MAX (((unsigned long) (1 << 31)) -1) |
---|
76 | #define SIZE_MAX ((1 << 14) -1) |
---|
77 | #define RANGE_MIN (1 << 6) |
---|
78 | #define RANGE_MAX (1 << 14) |
---|
79 | |
---|
80 | #define PAGES_PER_REGION 128 |
---|
81 | |
---|
82 | void omTestAlloc(omMemCell cell, int spec); |
---|
83 | void omTestRealloc(omMemCell cell, int spec); |
---|
84 | void omTestDup(omMemCell cell, int spec); |
---|
85 | void omTestFree(omMemCell cell); |
---|
86 | |
---|
87 | void omTestAllocDebug(omMemCell cell, int spec); |
---|
88 | void omTestReallocDebug(omMemCell cell, int spec); |
---|
89 | void omTestDupDebug(omMemCell cell, int spec); |
---|
90 | void omTestFreeDebug(omMemCell cell); |
---|
91 | void InitCellAddrContent(omMemCell cell); |
---|
92 | int omTestErrors(); |
---|
93 | |
---|
94 | #if CHECK_LEVEL > 0 |
---|
95 | void omTestDebug(omMemCell cell); |
---|
96 | void TestAddrContent(void* addr, unsigned long value, size_t size); |
---|
97 | void TestAddrContentEqual(void* s1, void* s2, size_t size); |
---|
98 | #else |
---|
99 | #define omTestDebug(cell) ((void)0) |
---|
100 | #define TestAddrContent(a,v,s) ((void)0) |
---|
101 | #define TestAddrContentEqual(s1, s2, s) ((void)0) |
---|
102 | #endif |
---|