My Project
omtTest.h
Go to the documentation of this file.
1#include <time.h>
2#include <string.h>
3#include <limits.h>
4
5#define TRACK_LEVEL 1
6#define CHECK_LEVEL 1
7// keep every ith address: define to 0 if no keeping
8#define KEEP_LEVEL 20
9// #define KEEP_LEVEL 0
10
11// #define MAX_CELLS 500000
12// #define MAX_CELLS 100000
13#define MAX_CELLS 100000
14#define KEEP_ADDR 100
15// #define KEEP_ADDR 0
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
26{
27 void* addr;
29 unsigned long spec;
31};
32
33typedef struct omMemCell_s omMemCell_t;
34typedef omMemCell_t* omMemCell;
35
36extern omMemCell_t cells[];
37void TestAlloc(omMemCell cell, unsigned long spec);
38void TestRealloc(omMemCell cell, unsigned long spec);
39void 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...) do {} while (0)
47#define myfflush(what) do {} while (0)
48#endif
49
50#define IS_STICKY_BIN(spec) (spec & 1)
51// #define IS_STICKY_BIN(spec) (0)
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)))
62#if CHECK_LEVEL > 0
63//#define DO_CHECK(spec) 1
64#define DO_CHECK(spec) (spec & (((unsigned long) 1) << 22))
65#define DO_FREE_CHECK(spec) (spec & (((unsigned long) 1) << 23))
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
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
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
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
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))
91
92
93#define SPEC_MAX ULONG_MAX
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)
97
98#define PAGES_PER_REGION 128
99
100void omtTestAlloc(omMemCell cell, unsigned long spec);
101void omtTestRealloc(omMemCell cell, unsigned long spec);
102void omtTestDup(omMemCell cell, unsigned long spec);
103void omtTestFree(omMemCell cell);
104
105void omtTestAllocDebug(omMemCell cell, unsigned long spec);
106void omtTestReallocDebug(omMemCell cell, unsigned long spec);
107void omtTestDupDebug(omMemCell cell, unsigned long spec);
109
110void omtTestAllocKeep(omMemCell cell, unsigned long spec);
111void omtTestReallocKeep(omMemCell cell, unsigned long spec);
112void omtTestDupKeep(omMemCell cell, unsigned long spec);
114
116int omtTestErrors();
118
119#if CHECK_LEVEL > 0
120void omtTestDebug(omMemCell cell);
121void TestAddrContent(void* addr, unsigned long value, size_t size);
122void TestAddrContentEqual(void* s1, void* s2, size_t size);
123#else
124#define omtTestDebug(cell) do {} while (0)
125#define TestAddrContent(a,v,s) do {} while (0)
126#define TestAddrContentEqual(s1, s2, s) do {} while (0)
127#endif
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
omBin_t * omBin
Definition: omStructs.h:12
void TestAlloc(omMemCell cell, unsigned long spec)
Definition: omtTest.c:186
void TestAddrContent(void *addr, unsigned long value, size_t size)
Definition: omtTest.c:110
void omtTestAlloc(omMemCell cell, unsigned long spec)
Definition: omtTestAlloc.c:32
omBin omtGetStickyBin(omBin bin)
Definition: omtTest.c:279
omBin orig_bin
Definition: omtTest.h:30
void omtTestReallocDebug(omMemCell cell, unsigned long spec)
void omtTestAllocKeep(omMemCell cell, unsigned long spec)
void omtTestDup(omMemCell cell, unsigned long spec)
Definition: omtTestAlloc.c:347
void omtTestReallocKeep(omMemCell cell, unsigned long spec)
void TestFree(omMemCell cell)
Definition: omtTest.c:256
void TestRealloc(omMemCell cell, unsigned long spec)
Definition: omtTest.c:209
omMemCell_t * omMemCell
Definition: omtTest.h:34
void omtTestAllocDebug(omMemCell cell, unsigned long spec)
void omtTestDebug(omMemCell cell)
Definition: omtTest.c:34
void omtTestFreeDebug(omMemCell cell)
void omtTestRealloc(omMemCell cell, unsigned long spec)
Definition: omtTestAlloc.c:179
void InitCellAddrContent(omMemCell cell)
Definition: omtTest.c:134
void omtTestFree(omMemCell cell)
Definition: omtTestAlloc.c:134
unsigned long spec
Definition: omtTest.h:29
void omtTestDupDebug(omMemCell cell, unsigned long spec)
int omtTestErrors()
Definition: omtTestError.c:36
void omtTestFreeKeep(omMemCell cell)
omBin bin
Definition: omtTest.h:28
void * addr
Definition: omtTest.h:27
void omtTestDupKeep(omMemCell cell, unsigned long spec)
omMemCell_t cells[]
Definition: omtTest.c:9
void TestAddrContentEqual(void *s1, void *s2, size_t size)
Definition: omtTest.c:94