My Project
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions | Variables
omtTest.h File Reference
#include <time.h>
#include <string.h>
#include <limits.h>
#include "omConfig.h"
#include "omStructs.h"

Go to the source code of this file.

Data Structures

struct  omMemCell_t
 

Macros

#define TRACK_LEVEL   1
 
#define CHECK_LEVEL   1
 
#define KEEP_LEVEL   20
 
#define MAX_CELLS   100000
 
#define KEEP_ADDR   100
 
#define END_CHECK_LEVEL   5
 
#define myprintf(format, args...)   do {} while (0)
 
#define myfflush(what)   do {} while (0)
 
#define IS_STICKY_BIN(spec)   (spec & 1)
 
#define GET_SIZE(spec)   OM_ALIGN_SIZE((spec & ((((unsigned long) 1) << 14) -1)))
 
#define SET_SIZE(spec, size)   spec = ((spec & ~((((unsigned long) 1) << 14) -1)) | (size))
 
#define IS_ALIGNED(spec)   (spec & (((unsigned long) 1) << 15))
 
#define IS_ZERO(spec)   (spec & (((unsigned long) 1) << 16))
 
#define IS_BIN(spec)   (spec & (((unsigned long) 1) << 17))
 
#define IS_SPEC_BIN(spec)   (spec & (((unsigned long) 1) << 18))
 
#define IS_INLINE(spec)   (spec & (((unsigned long) 1) << 19))
 
#define DO_FREE(spec)   (!(spec & (((unsigned long) 1) << 20)) && !(spec & (((unsigned long) 1) << 21)))
 
#define DO_REALLOC(spec)   ((spec & (((unsigned long) 1) << 20)) && (spec & (((unsigned long) 1) << 21)))
 
#define DO_DUP(spec)   ((spec & (((unsigned long) 1) << 20)) && ! (spec & (((unsigned long) 1) << 21)))
 
#define DO_CHECK(spec)   (spec & (((unsigned long) 1) << 22))
 
#define DO_FREE_CHECK(spec)   (spec & (((unsigned long) 1) << 23))
 
#define DO_TRACK(spec)   (spec & (((unsigned long) 1) << 24))
 
#define GET_TRACK(spec)   (((spec & ((((unsigned long) 1) << 27) | (((unsigned long) 1) << 26) | (((unsigned long) 1) << 25))) >> 25) % 5) + TRACK_LEVEL
 
#define DO_KEEP(spec)   (DO_CHECK(spec) && (spec % KEEP_LEVEL == 0))
 
#define DO_FREE_KEEP(spec)   (DO_FREE_CHECK(spec) && (spec % KEEP_LEVEL == 0))
 
#define IS_FREE_SIZE(spec)   (spec & (((unsigned long) 1) << 28))
 
#define IS_FREE_BIN(spec)   (spec & (((unsigned long) 1) << 29))
 
#define IS_SLOPPY(spec)   (spec & (((unsigned long) 1) << 30))
 
#define IS_FREE_BINADDR(spec)   (spec & (((unsigned long) 1) << 31))
 
#define SPEC_MAX   ULONG_MAX
 
#define SIZE_MAX   ((((unsigned long) 1) << 14) -1)
 
#define RANGE_MIN   (((unsigned long) 1) << 6)
 
#define RANGE_MAX   (((unsigned long) 1) << 14)
 
#define PAGES_PER_REGION   128
 

Typedefs

typedef omMemCell_tomMemCell
 

Functions

void TestAlloc (omMemCell cell, unsigned long spec)
 
void TestRealloc (omMemCell cell, unsigned long spec)
 
void TestFree (omMemCell cell)
 
void omtTestAlloc (omMemCell cell, unsigned long spec)
 
void omtTestRealloc (omMemCell cell, unsigned long spec)
 
void omtTestDup (omMemCell cell, unsigned long spec)
 
void omtTestFree (omMemCell cell)
 
void omtTestAllocDebug (omMemCell cell, unsigned long spec)
 
void omtTestReallocDebug (omMemCell cell, unsigned long spec)
 
void omtTestDupDebug (omMemCell cell, unsigned long spec)
 
void omtTestFreeDebug (omMemCell cell)
 
void omtTestAllocKeep (omMemCell cell, unsigned long spec)
 
void omtTestReallocKeep (omMemCell cell, unsigned long spec)
 
void omtTestDupKeep (omMemCell cell, unsigned long spec)
 
void omtTestFreeKeep (omMemCell cell)
 
void InitCellAddrContent (omMemCell cell)
 
int omtTestErrors ()
 
omBin omtGetStickyBin (omBin bin)
 
void omtTestDebug (omMemCell cell)
 
void TestAddrContent (void *addr, unsigned long value, size_t size)
 
void TestAddrContentEqual (void *s1, void *s2, size_t size)
 

Variables

omMemCell_t cells []
 

Data Structure Documentation

◆ omMemCell_s

struct omMemCell_s

Definition at line 24 of file omtTest.h.

Data Fields
void * addr
omBin bin
omBin orig_bin
unsigned long spec

Macro Definition Documentation

◆ CHECK_LEVEL

#define CHECK_LEVEL   1

Definition at line 10 of file omtTest.h.

◆ DO_CHECK

#define DO_CHECK (   spec)    (spec & (((unsigned long) 1) << 22))

Definition at line 63 of file omtTest.h.

◆ DO_DUP

#define DO_DUP (   spec)    ((spec & (((unsigned long) 1) << 20)) && ! (spec & (((unsigned long) 1) << 21)))

Definition at line 60 of file omtTest.h.

◆ DO_FREE

#define DO_FREE (   spec)    (!(spec & (((unsigned long) 1) << 20)) && !(spec & (((unsigned long) 1) << 21)))

Definition at line 58 of file omtTest.h.

◆ DO_FREE_CHECK

#define DO_FREE_CHECK (   spec)    (spec & (((unsigned long) 1) << 23))

Definition at line 64 of file omtTest.h.

◆ DO_FREE_KEEP

#define DO_FREE_KEEP (   spec)    (DO_FREE_CHECK(spec) && (spec % KEEP_LEVEL == 0))

Definition at line 80 of file omtTest.h.

◆ DO_KEEP

#define DO_KEEP (   spec)    (DO_CHECK(spec) && (spec % KEEP_LEVEL == 0))

Definition at line 79 of file omtTest.h.

◆ DO_REALLOC

#define DO_REALLOC (   spec)    ((spec & (((unsigned long) 1) << 20)) && (spec & (((unsigned long) 1) << 21)))

Definition at line 59 of file omtTest.h.

◆ DO_TRACK

#define DO_TRACK (   spec)    (spec & (((unsigned long) 1) << 24))

Definition at line 70 of file omtTest.h.

◆ END_CHECK_LEVEL

#define END_CHECK_LEVEL   5

Definition at line 20 of file omtTest.h.

◆ GET_SIZE

#define GET_SIZE (   spec)    OM_ALIGN_SIZE((spec & ((((unsigned long) 1) << 14) -1)))

Definition at line 51 of file omtTest.h.

◆ GET_TRACK

#define GET_TRACK (   spec)    (((spec & ((((unsigned long) 1) << 27) | (((unsigned long) 1) << 26) | (((unsigned long) 1) << 25))) >> 25) % 5) + TRACK_LEVEL

Definition at line 71 of file omtTest.h.

◆ IS_ALIGNED

#define IS_ALIGNED (   spec)    (spec & (((unsigned long) 1) << 15))

Definition at line 53 of file omtTest.h.

◆ IS_BIN

#define IS_BIN (   spec)    (spec & (((unsigned long) 1) << 17))

Definition at line 55 of file omtTest.h.

◆ IS_FREE_BIN

#define IS_FREE_BIN (   spec)    (spec & (((unsigned long) 1) << 29))

Definition at line 87 of file omtTest.h.

◆ IS_FREE_BINADDR

#define IS_FREE_BINADDR (   spec)    (spec & (((unsigned long) 1) << 31))

Definition at line 89 of file omtTest.h.

◆ IS_FREE_SIZE

#define IS_FREE_SIZE (   spec)    (spec & (((unsigned long) 1) << 28))

Definition at line 86 of file omtTest.h.

◆ IS_INLINE

#define IS_INLINE (   spec)    (spec & (((unsigned long) 1) << 19))

Definition at line 57 of file omtTest.h.

◆ IS_SLOPPY

#define IS_SLOPPY (   spec)    (spec & (((unsigned long) 1) << 30))

Definition at line 88 of file omtTest.h.

◆ IS_SPEC_BIN

#define IS_SPEC_BIN (   spec)    (spec & (((unsigned long) 1) << 18))

Definition at line 56 of file omtTest.h.

◆ IS_STICKY_BIN

#define IS_STICKY_BIN (   spec)    (spec & 1)

Definition at line 49 of file omtTest.h.

◆ IS_ZERO

#define IS_ZERO (   spec)    (spec & (((unsigned long) 1) << 16))

Definition at line 54 of file omtTest.h.

◆ KEEP_ADDR

#define KEEP_ADDR   100

Definition at line 18 of file omtTest.h.

◆ KEEP_LEVEL

#define KEEP_LEVEL   20

Definition at line 12 of file omtTest.h.

◆ MAX_CELLS

#define MAX_CELLS   100000

Definition at line 17 of file omtTest.h.

◆ myfflush

#define myfflush (   what)    do {} while (0)

Definition at line 46 of file omtTest.h.

◆ myprintf

#define myprintf (   format,
  args... 
)    do {} while (0)

Definition at line 45 of file omtTest.h.

◆ PAGES_PER_REGION

#define PAGES_PER_REGION   128

Definition at line 97 of file omtTest.h.

◆ RANGE_MAX

#define RANGE_MAX   (((unsigned long) 1) << 14)

Definition at line 95 of file omtTest.h.

◆ RANGE_MIN

#define RANGE_MIN   (((unsigned long) 1) << 6)

Definition at line 94 of file omtTest.h.

◆ SET_SIZE

#define SET_SIZE (   spec,
  size 
)    spec = ((spec & ~((((unsigned long) 1) << 14) -1)) | (size))

Definition at line 52 of file omtTest.h.

◆ SIZE_MAX

#define SIZE_MAX   ((((unsigned long) 1) << 14) -1)

Definition at line 93 of file omtTest.h.

◆ SPEC_MAX

#define SPEC_MAX   ULONG_MAX

Definition at line 92 of file omtTest.h.

◆ TRACK_LEVEL

#define TRACK_LEVEL   1

Definition at line 9 of file omtTest.h.

Typedef Documentation

◆ omMemCell

Definition at line 33 of file omtTest.h.

Function Documentation

◆ InitCellAddrContent()

void InitCellAddrContent ( omMemCell  cell)

Definition at line 130 of file omtTest.c.

131{
132 size_t sizeW = omSizeWOfAddr(cell->addr);
133 omMemsetW(cell->addr, (IS_ZERO(cell->spec) ? 0 : cell->spec), sizeW);
134}
#define omMemsetW(P1, W, L)
Definition omMemOps.h:161
#define IS_ZERO(spec)
Definition omtTest.h:54
#define omSizeWOfAddr(P)
Definition xalloc.h:223

◆ omtGetStickyBin()

omBin omtGetStickyBin ( omBin  bin)

Definition at line 275 of file omtTest.c.

276{
277 omBin sticky_bin = omFindInGList(om_StickyBins, next, max_blocks, bin->max_blocks);
278 if (sticky_bin == NULL)
280 return sticky_bin;
281}
ListNode * next
Definition janet.h:31
omBin om_StickyBins
Definition omBin.c:374
#define NULL
Definition omList.c:12
#define omFindInGList(ptr, next, what, value)
Definition omList.h:104
omBin_t * omBin
Definition omStructs.h:12
#define omGetStickyBinOfBin(B)
Definition xalloc.h:247

◆ omtTestAlloc()

void omtTestAlloc ( omMemCell  cell,
unsigned long  spec 
)

Definition at line 33 of file omtTestAlloc.c.

34{
35 size_t size = GET_SIZE(spec);
36 void* addr;
37 omBin bin = NULL;
38 omBin orig_bin = NULL;
39
40 if (IS_BIN(spec) && (size <= OM_MAX_BLOCK_SIZE || IS_SPEC_BIN(spec)))
41 {
42 if (IS_SPEC_BIN(spec))
43 {
44 if (IS_ALIGNED(spec))
46 else
47 bin = omGetSpecBin(size);
48 }
49 else
50 {
51 if (IS_ALIGNED(spec))
53 else
54 bin = omSmallSize2Bin(size);
55 }
56
57 if (IS_STICKY_BIN(spec))
58 {
59 orig_bin = bin;
60 bin = omtGetStickyBin(bin);
61 }
62
63 if (IS_INLINE(spec))
64 {
65 if (IS_ZERO(spec))
66 addr = omAlloc0Bin(bin);
67 else
68 addr = omAllocBin(bin);
69 }
70 else
71 {
72 if (IS_ZERO(spec))
73 omTypeAlloc0Bin(void*, addr, bin);
74 else
75 omTypeAllocBin(void*, addr, bin);
76 }
77 }
78 else
79 {
80 if (IS_INLINE(spec))
81 {
82 if (IS_ZERO(spec))
83 {
84 if (IS_ALIGNED(spec))
85 {
86 if (IS_SLOPPY(spec))
87 addr = omalloc0(size);
88 else
89 addr = omAlloc0Aligned(size);
90 }
91 else
92 addr = omAlloc0(size);
93 }
94 else
95 {
96 if (IS_ALIGNED(spec))
97 {
98 if (IS_SLOPPY(spec))
99 addr = omalloc(size);
100 else
101 addr = omAllocAligned(size);
102 }
103 else
104 addr = omAlloc(size);
105 }
106 }
107 else
108 {
109 if (IS_ZERO(spec))
110 {
111 if (IS_ALIGNED(spec))
112 omTypeAlloc0Aligned(void*, addr, size);
113 else
114 omTypeAlloc0(void*, addr, size);
115 }
116 else
117 {
118 if (IS_ALIGNED(spec))
119 omTypeAllocAligned(void*, addr, size);
120 else
121 omTypeAlloc(void*, addr, size);
122 }
123 }
124 }
125 cell->addr = addr;
126 cell->bin = bin;
127 cell->orig_bin = orig_bin;
128 cell->spec = spec;
129
131
133}
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition cf_ops.cc:600
#define omTypeAlloc0Bin(type, addr, bin)
#define omAlloc0Aligned
#define omAlloc(size)
#define omTypeAllocBin(type, addr, bin)
#define omAllocBin(bin)
#define omAlloc0Bin(bin)
#define omTypeAlloc0(type, addr, size)
#define omalloc0(size)
#define omalloc(size)
#define omTypeAlloc0Aligned
#define omAlloc0(size)
#define omTypeAlloc(type, addr, size)
#define omTypeAllocAligned
#define omAllocAligned
#define omSmallSize2Bin(size)
#define omGetSpecBin(size)
Definition omBin.h:11
#define omGetAlignedSpecBin(size)
Definition omBin.h:10
#define OM_MAX_BLOCK_SIZE
Definition omTables.c:31
#define omSmallSize2AlignedBin
omBin omtGetStickyBin(omBin bin)
Definition omtTest.c:275
void omtTestDebug(omMemCell cell)
Definition omtTest.c:36
void InitCellAddrContent(omMemCell cell)
Definition omtTest.c:130
#define IS_SPEC_BIN(spec)
Definition omtTest.h:56
#define IS_STICKY_BIN(spec)
Definition omtTest.h:49
#define IS_ALIGNED(spec)
Definition omtTest.h:53
#define IS_BIN(spec)
Definition omtTest.h:55
#define IS_SLOPPY(spec)
Definition omtTest.h:88
#define IS_INLINE(spec)
Definition omtTest.h:57
#define GET_SIZE(spec)
Definition omtTest.h:51

◆ omtTestAllocDebug()

void omtTestAllocDebug ( omMemCell  cell,
unsigned long  spec 
)

◆ omtTestAllocKeep()

void omtTestAllocKeep ( omMemCell  cell,
unsigned long  spec 
)

◆ omtTestDebug()

void omtTestDebug ( omMemCell  cell)

Definition at line 36 of file omtTest.c.

37{
38 size_t size = GET_SIZE(cell->spec);
39 size_t is_size;
40
41 if (om_ErrorStatus != omError_NoError) return;
42 if (cell->bin != NULL)
43 {
44 if (IS_ALIGNED(cell->spec))
45 omDebugAddrAlignedBin(cell->addr, cell->bin);
46 else
47 omDebugAddrBin(cell->addr, cell->bin);
48 }
49 else
50 {
51 if (IS_ALIGNED(cell->spec))
53 else
55 }
56 if (om_ErrorStatus != omError_NoError) return;
57
58 if (!OM_IS_ALIGNED(cell->addr))
59 {
61 "addr:%p is unaligned", cell->addr);
62 return;
63 }
64
65 if (IS_ALIGNED(cell->spec) && !OM_IS_STRICT_ALIGNED(cell->addr))
66 {
68 "addr:%p is not strict unaligned", cell->addr);
69 return;
70 }
71
72 is_size = omSizeOfAddr(cell->addr);
73 if (is_size < size)
74 {
76 "is_size==%u < size==%u", is_size, size);
77 return;
78 }
79
81 {
83 "is_sizeW==%u < sizeW==%u", is_size >> LOG_SIZEOF_LONG, omSizeWOfAddr(cell->addr));
84 return;
85 }
86
87 TestAddrContent(cell->addr, (IS_ZERO(cell->spec) ? 0 : cell->spec), is_size);
88}
#define omDebugAddrAlignedBin
#define omDebugAddrAlignedSize
#define omDebugAddrSize(addr, size)
#define omDebugAddrBin(addr, bin)
size_t omSizeOfAddr(const void *addr)
omError_t om_ErrorStatus
Definition omError.c:13
omError_t omReportError(omError_t error, omError_t report_error, OM_FLR_DECL, const char *fmt,...)
Definition omError.c:80
@ omError_NoError
Definition omError.h:18
@ omError_Unknown
Definition omError.h:19
void TestAddrContent(void *addr, unsigned long value, size_t size)
Definition omtTest.c:106

◆ omtTestDup()

void omtTestDup ( omMemCell  cell,
unsigned long  spec 
)

Definition at line 348 of file omtTestAlloc.c.

349{
351
352 if (DO_STRDUP(spec))
353 {
354 size_t size = omSizeOfAddr(cell->addr);
355 void* new_addr;
356 memset(cell->addr, 'a', size - 1);
357 ((char*) cell->addr)[size-1] = '\0';
358 new_addr = omStrDup(cell->addr);
362 }
363 else
364 {
365 void* new_addr = omMemDup(cell->addr);
372 }
373}
#define omStrDup(s)
#define omFree(addr)
#define omMemDup(s)
#define omMemDupAligned
#define DO_STRDUP(l)
void TestAddrContentEqual(void *s1, void *s2, size_t size)
Definition omtTest.c:90

◆ omtTestDupDebug()

void omtTestDupDebug ( omMemCell  cell,
unsigned long  spec 
)

◆ omtTestDupKeep()

void omtTestDupKeep ( omMemCell  cell,
unsigned long  spec 
)

◆ omtTestErrors()

int omtTestErrors ( )

Definition at line 37 of file omtTestError.c.

38{
39#ifndef OM_NDEBUG
40 int level = om_Opts.MinCheck;
42 struct LongSpec spec;
43 int missed = 0, alloc;
45
46 printf("omtTestErrors: Start\n");
47 om_Opts.MinCheck = 2;
49 {
52 printf("!!!expect %s\n", omError2Serror(error));
53 memset(&spec, 0, sizeof(struct LongSpec));
54 cell = NULL;
55 alloc = 0;
56 switch (error)
57 {
59 {
60 spec.MaxSize = OM_MAX_BLOCK_SIZE;
61 cell = omFindCell(spec);
62 if (cell != NULL)
63 {
64 omBin bin = omGetTopBinOfAddr(cell->addr);
65 omBinPage last_page = bin->last_page;
66 omAssume(last_page != NULL);
67 bin->last_page = NULL;
68 omDebugBin(cell->bin);
69 bin->last_page = last_page;
70 }
71 else printf("cell not found\n");
72 break;
73 }
74
76 {
78 break;
79 }
80
82 {
83 omDebugAddr((void*) om_MaxAddr);
84 break;
85 }
86
88 {
89 spec.MinSize = 8;
90 spec.MaxSize = OM_MAX_BLOCK_SIZE;
91 spec.NoTrack = 1;
92 cell = omFindCell(spec);
93 if (cell != NULL)
94 {
96 }
97 else printf("cell not found\n");
98 break;
99 }
100
102 {
103 spec.MinSize = 8;
104 spec.MinTrack = 3;
105 cell = omFindCell(spec);
106 if (cell != NULL)
107 {
109 }
110 else printf("cell not found\n");
111 break;
112 }
113
115 {
116 spec.MaxSize = OM_MAX_BLOCK_SIZE;
117 cell = omFindCell(spec);
118 if (cell != NULL)
119 {
122 {
124 spec.MaxSize = 0;
125 spec.MinTrack = 3;
126 spec.NotIsBin = 1;
127 spec.MinSize = 2;
128 cell = omFindCell(spec);
129 if (cell != NULL)
130 {
133 {
135 spec.MaxSize = OM_MAX_BLOCK_SIZE;
136 spec.MinTrack = 0;
137 spec.NotIsBin = 0;
138 cell = omFindCell(spec);
139 if (cell != NULL)
140 omDebugBinAddrSize(cell->addr, GET_SIZE(cell->spec) - 1);
141 else printf("cell not found");
142 }
143 }
144 else printf("cell not found\n");
145 }
146 }
147 else printf("cell not found\n");
148 break;
149 }
150
152 {
153#if KEEP_LEVEL > 0
154 void* addr = om_AlwaysKeptAddrs;
155 while (addr != NULL && omIsTrackAddr(addr))
156 {
157 addr = *((void**) addr);
158 }
159 if (addr != NULL)
160 {
161 omFree(addr);
163 {
165 addr = om_AlwaysKeptAddrs;
166 while (addr != NULL && ! omIsTrackAddr(addr))
167 {
168 addr = *((void**) addr);
169 }
170 if (addr != NULL)
171 {
172 addr = omAddr_2_OutAddr(addr);
173 omFree(addr);
174 }
175 }
176 }
177 if (addr == NULL)
178 {
179 printf("addr not found\n");
180 break;
181 }
183 break;
184#endif
185 spec.MinTrack = 5;
186 spec.NotIsBin = 1;
187 cell = omFindCell(spec);
188 if (cell != NULL)
189 {
190 omFree(cell->addr);
191 omFree(cell->addr);
192 alloc = 1;
193 cell->addr=NULL;
194 }
195 else printf("cell not found\n");
196 break;
197 }
198
200 {
201 spec.MaxSize = OM_MAX_BLOCK_SIZE;
202 spec.NoTrack = 1;
203 cell = omFindCell(spec);
204 if (cell != NULL)
205 {
207 omBinPageRegion region = page->region;
208 page->region = NULL;
209 om_Opts.MinCheck = 1;
210 omDebugAddr(cell->addr);
211 om_Opts.MinCheck = 2;
212 page->region = region;
213 }
214 else printf("cell not found\n");
215 break;
216 }
217
218 case omError_WrongBin:
219 {
220 spec.MaxSize = 32;
221 spec.NoTrack = 1;
222 cell = omFindCell(spec);
223 if (cell != NULL)
224 {
226 }
227 else printf("cell not found\n");
228 break;
229 }
230
232 {
233 spec.MaxSize = OM_MAX_BLOCK_SIZE;
234 cell = omFindCell(spec);
235 if (cell != NULL)
236 {
237 omDebugAddrBin(cell->addr, (void*) omGetTopBinOfAddr(cell->addr) + SIZEOF_VOIDP);
238 }
239 else printf("cell not found\n");
240 break;
241 }
242
244 {
245 spec.NotIsBin = 1;
246 spec.MinSize = OM_MAX_BLOCK_SIZE + 1;
247 cell = omFindCell(spec);
248 if (cell != NULL)
249 {
250 omDebugBinAddr(cell->addr);
251 }
252 else printf("cell not found");
253 break;
254 }
255
257 {
258 cell = omFindCell(spec);
259 if (cell != NULL)
260 {
261 omDebugAddr(cell->addr + 1);
262 }
263 else printf("cell not found\n");
264 break;
265 }
266
268 {
269 void* addr = omAlloc(0);
270 addr = omRealloc(addr, 0);
271 omFree(addr);
272 break;
273 }
274
276 {
277 void* last = omListLast(om_SpecBin);
278 if (last != NULL)
279 {
280 *((void**)last) = om_SpecBin;
282 *((void**)last) = NULL;
283 } else printf("last == NULL\n");
284 break;
285 }
286
288 {
289 if (om_SpecBin != NULL && om_SpecBin->next != NULL)
290 {
291 int max_blocks = om_SpecBin->max_blocks;
292 om_SpecBin->max_blocks = om_SpecBin->next->max_blocks + 1;
294 om_SpecBin->max_blocks = max_blocks;
295 } else printf("om_SpecBin->next == NULL\n");
296 break;
297 }
298
300 {
301 if (om_KeptAddr != NULL)
302 {
303 void* last = omListLast(om_KeptAddr);
304 *((void**)last) = om_KeptAddr;
305 om_Opts.MinCheck = 5;
307 om_Opts.MinCheck = 2;
308 *((void**)last) = NULL;
309 }
310 else printf("om_KeptAddr == NULL\n");
311 break;
312 }
313
315 {
316 if (om_Opts.Keep > 0)
317 {
318 spec.MinTrack=3;
319 spec.NotIsBin = 1;
320 cell = omFindCell(spec);
321 if (cell != NULL)
322 {
323 void* value;
324 omFree(cell->addr);
325 value = *((void**) cell->addr);
326 *((void**) cell->addr) = value -1;
328 *((void**) cell->addr) = value;
329 alloc = 1;
330 cell->addr = NULL;
331 }
332 else printf("cell not found\n");
333 }
334 else printf("om_Opts.Keep == 0");
335 break;
336 }
337
339 {
340 spec.MinTrack = 3;
341 spec.NotIsBin = 1;
342 cell = omFindCell(spec);
343 if (cell != NULL)
344 {
345 void* addr = cell->addr + omSizeOfAddr(cell->addr);
346 void* value = *((void**) addr);
347 *((void**) addr) = value -1;
348 omDebugAddr(cell->addr);
349 *((void**) addr) = value;
350 }
351 else printf("cell not found\n");
352 break;
353 }
354
356 {
357 spec.MinTrack=3;
358 cell = omFindCell(spec);
359 if (cell != NULL)
360 {
361 void* addr = cell->addr - SIZEOF_VOIDP;
362 void* value = *((void**) addr);
363 *((void**) addr) = value -1;
364 omDebugAddr(cell->addr);
365 *((void**) addr) = value;
366 }
367 else printf("cell not found\n");
368 break;
369 }
370
372 {
373/* can only test for NULL string */
374#if 0
375 spec.MaxSize = OM_MAX_BLOCK_SIZE;
376 cell = omFindCell(spec);
377 if (cell != NULL)
378 {
379 char* addr = (char*) cell->addr;
380 char* s;
381 memset(cell->addr, 1, omSizeOfAddr(cell->addr));
382 omDebugAddr(cell->addr);
383 s = omStrDup(addr);
384 omFree(s);
386 }
387 else printf("cell not found\n");
388 break;
389#endif
390 omStrDup(NULL);
391 break;
392 }
393
395 {
397 break;
398 }
399
400 default:
401 printf("No Error test implemented\n");
402 }
403
404 if (om_ErrorStatus != error)
405 {
406 printf("---missed %s\n", omError2Serror(error));
407 missed++;
408 }
409 else
410 {
411 printf("+++ok %s\n", omError2Serror(error));
412 }
413
415 if (cell != NULL)
416 {
417 if (alloc) TestAlloc(cell, cell->spec);
419 }
420 else
421 {
423 }
425 {
426 printf("omtTest panik: memory corrupted\n\n");
427 return -1;
428 }
429 printf("\n");
430 }
431 printf("omtTestErrors: Summary: missed = %d\n\n", missed);
432 om_Opts.MinCheck = level;
433 return missed;
434#else
435 return 0;
436#endif
437}
int level(const CanonicalForm &f)
const CanonicalForm int s
Definition facAbsFact.cc:51
STATIC_VAR poly last
Definition hdegree.cc:1148
#define error(a)
#define omDebugMemory()
#define omDebugBinAddrSize(addr, size)
#define omDebugAddr(addr)
#define omDebugBinAddr(addr)
#define omRealloc(addr, size)
#define omDebugBin(bin)
#define omGetTopBinOfAddr(addr)
omBin_t om_StaticBin[]
#define omGetBinPageOfAddr(addr)
Definition omBinPage.h:22
void * om_AlwaysKeptAddrs
Definition omDebug.c:31
void * om_KeptAddr
Definition omDebug.c:28
unsigned long om_MaxAddr
void * omAddr_2_OutAddr(void *addr)
#define omIsTrackAddr(addr)
Definition omDebug.h:12
const char * omError2Serror(omError_t error)
Definition omError.c:65
omError_t om_InternalErrorStatus
Definition omError.c:14
#define omAssume(x)
Definition omError.h:85
@ omError_WrongSize
Definition omError.h:26
@ omError_ListCycleError
Definition omError.h:34
@ omError_BackPattern
Definition omError.h:38
@ omError_NullAddr
Definition omError.h:22
@ omError_NullSizeAlloc
Definition omError.h:33
@ omError_MaxError
Definition omError.h:42
@ omError_FrontPattern
Definition omError.h:39
@ omError_UnalignedAddr
Definition omError.h:32
@ omError_MemoryCorrupted
Definition omError.h:21
@ omError_FreedAddr
Definition omError.h:27
@ omError_UnknownBin
Definition omError.h:30
@ omError_FreedAddrOrMemoryCorrupted
Definition omError.h:28
@ omError_NotString
Definition omError.h:40
@ omError_SortedListError
Definition omError.h:35
@ omError_KeptAddrListCorrupted
Definition omError.h:36
@ omError_NotBinAddr
Definition omError.h:31
@ omError_InvalidRangeAddr
Definition omError.h:23
@ omError_FalseAddr
Definition omError.h:24
@ omError_WrongBin
Definition omError.h:29
@ omError_StickyBin
Definition omError.h:41
@ omError_FreePattern
Definition omError.h:37
@ omError_FalseAddrOrMemoryCorrupted
Definition omError.h:25
enum omError_e omError_t
Definition omError.h:44
#define omCheckSortedList(ptr, what, level, report, OM_FLR_VAL)
Definition omList.h:85
#define omListLast(ptr)
Definition omList.h:64
#define omCheckList(ptr, level, report, OM_FLR_VAL)
Definition omList.h:83
omOpts_t om_Opts
Definition omOpts.c:13
omBinPage_t * omBinPage
Definition omStructs.h:16
omBinPageRegion_t * omBinPageRegion
Definition omStructs.h:20
#define OM_MAX_BIN_INDEX
Definition omTables.h:4
omSpecBin om_SpecBin
Definition om_Alloc.c:20
omMemCell omFindCell(struct LongSpec spec)
void TestAlloc(omMemCell cell, unsigned long spec)
Definition omtTest.c:182
omMemCell_t * omMemCell
Definition omtTest.h:33
#define omMergeStickyBinIntoBin(A, B)
Definition xalloc.h:275

◆ omtTestFree()

void omtTestFree ( omMemCell  cell)

Definition at line 135 of file omtTestAlloc.c.

136{
137 void* addr = cell->addr;
138 unsigned long spec = cell->spec;
139 omBin bin = cell->bin;
140 omBin orig_bin = cell->orig_bin;
141 size_t size = GET_SIZE(spec);
142
144
145 if (IS_FREE_SIZE(spec))
146 {
147 if (IS_SLOPPY(spec))
148 omfreeSize(addr, size);
149 else
150 omFreeSize(addr, size);
151 }
152 else if (bin != NULL && IS_FREE_BIN(spec))
153 omFreeBin(addr, bin);
154 else if (IS_FREE_BINADDR(spec) && (bin != NULL) && (size <= OM_MAX_BLOCK_SIZE))
155 {
156 omFreeBinAddr(addr);
157 }
158 else
159 {
160 if (IS_SLOPPY(spec))
161 omfree(addr);
162 else
163 omFree(addr);
164 }
165
166 if (bin != NULL && IS_SPEC_BIN(spec))
167 {
168 if (orig_bin != NULL)
169 omUnGetSpecBin(&orig_bin);
170 else
171 omUnGetSpecBin(&bin);
172 }
173
174 cell->addr = NULL;
175 cell->spec = 0;
176 cell->bin = NULL;
177 cell->orig_bin = NULL;
178}
#define omfree(addr)
#define omFreeSize(addr, size)
#define omFreeBin(addr, bin)
#define omFreeBinAddr(addr)
#define omfreeSize(addr, size)
#define omUnGetSpecBin(bin_ptr)
Definition omBin.h:14
#define IS_FREE_BINADDR(spec)
Definition omtTest.h:89
#define IS_FREE_SIZE(spec)
Definition omtTest.h:86
#define IS_FREE_BIN(spec)
Definition omtTest.h:87

◆ omtTestFreeDebug()

void omtTestFreeDebug ( omMemCell  cell)

◆ omtTestFreeKeep()

void omtTestFreeKeep ( omMemCell  cell)

◆ omtTestRealloc()

void omtTestRealloc ( omMemCell  cell,
unsigned long  spec 
)

Definition at line 180 of file omtTestAlloc.c.

181{
182 void* old_addr = cell->addr;
183 unsigned long old_spec = cell->spec;
184 omBin old_bin = cell->bin;
185 omBin old_orig_bin = cell->orig_bin;
186 size_t old_size = GET_SIZE(old_spec);
187 void* new_addr;
190 size_t new_size = GET_SIZE(new_spec);
192 size_t min_size;
193
195
196 if (old_bin != NULL && IS_FREE_BIN(old_spec) &&
198 {
200 {
201 if (IS_ALIGNED(new_spec))
203 else
205 }
206 else
207 {
208 if (IS_ALIGNED(new_spec))
210 else
212 }
213
215 {
218 }
219
220 if (IS_INLINE(new_spec))
221 {
224 }
225 else
226 {
229 }
230 }
231 else
232 {
234 {
235 if (IS_INLINE(new_spec))
236 {
237 if (IS_ZERO(new_spec))
238 {
239 if (IS_ALIGNED(new_spec))
240 {
241 if (IS_SLOPPY(new_spec))
243 else
245 }
246 else
248 }
249 else
250 {
251 if (IS_ALIGNED(new_spec))
252 {
253 if (IS_SLOPPY(new_spec))
255 else
257 }
259 }
260 }
261 else
262 {
263 if (IS_ZERO(new_spec))
264 {
267 }
268 else
269 {
272 }
273 }
274 }
275 else
276 {
277 if (IS_INLINE(new_spec))
278 {
279 if (IS_ZERO(new_spec))
280 {
281 if (IS_ALIGNED(new_spec))
282 {
283 if (IS_SLOPPY(new_spec))
285 else
287 }
289 }
290 else
291 {
292 if (IS_ALIGNED(new_spec))
293 {
294 if (IS_SLOPPY(new_spec))
296 else
298 }
300 }
301 }
302 else
303 {
304 if (IS_ZERO(new_spec))
305 {
308 }
309 else
310 {
313 }
314 }
315 }
316 }
317
318 if (old_bin != NULL && IS_SPEC_BIN(old_spec))
319 {
320 if (old_orig_bin != NULL)
322 else
324 }
325
329
332 else
333 {
337 }
338
339 cell->addr = new_addr;
340 cell->spec = new_spec;
341 cell->bin = new_bin;
342 cell->orig_bin = new_orig_bin;
345}
#define omrealloc(addr, size)
#define omTypeReallocAlignedSize
#define omTypeRealloc0(o_addr, type, addr, size)
#define omTypeRealloc0Size(o_addr, o_size, type, addr, size)
#define omRealloc0AlignedSize
#define omrealloc0Size(addr, o_size, size)
#define omRealloc0Aligned
#define omreallocSize(addr, o_size, size)
#define omReallocSize(addr, o_size, size)
#define omReallocAligned
#define omTypeRealloc0AlignedSize
#define omrealloc0(addr, size)
#define omRealloc0Bin(o_addr, o_bin, bin)
#define omTypeRealloc0Bin(o_addr, o_bin, type, addr, bin)
#define omReallocAlignedSize
#define omTypeRealloc0Aligned
#define omReallocBin(o_addr, o_bin, bin)
#define omRealloc0Size(addr, o_size, size)
#define omTypeReallocAligned
#define omRealloc0(addr, size)
#define omTypeReallocSize(o_addr, o_size, type, addr, size)
#define omTypeReallocBin(o_addr, o_bin, type, addr, bin)
#define omTypeRealloc(o_addr, type, addr, size)

◆ omtTestReallocDebug()

void omtTestReallocDebug ( omMemCell  cell,
unsigned long  spec 
)

◆ omtTestReallocKeep()

void omtTestReallocKeep ( omMemCell  cell,
unsigned long  spec 
)

◆ TestAddrContent()

void TestAddrContent ( void addr,
unsigned long  value,
size_t  size 
)

Definition at line 106 of file omtTest.c.

107{
108 size_t sizeW = OM_ALIGN_SIZE(size) >> LOG_SIZEOF_LONG;
109 int i;
110
111 if (!OM_IS_ALIGNED(addr))
112 {
114 "addr %p unaligned", addr);
115 return;
116 }
117
118 for (i=0; i<sizeW; i++)
119 {
120 if (((unsigned long*)addr)[i] != value)
121 {
123 "word %d modified: is %u should be %u", i, ((unsigned long*)addr)[i], value);
124 return;
125 }
126 }
127}
int i
Definition cfEzgcd.cc:132

◆ TestAddrContentEqual()

void TestAddrContentEqual ( void s1,
void s2,
size_t  size 
)

Definition at line 90 of file omtTest.c.

91{
92 int i;
93 size_t sizeW = OM_ALIGN_SIZE(size) >> LOG_SIZEOF_LONG;
94
95 for (i=0; i<sizeW; i++)
96 {
97 if (((unsigned long*)s1)[i] != ((unsigned long*)s2)[i])
98 {
100 "s1[%u]==%d != s2[%u]==%d", i, ((unsigned long*)s1)[i], i, ((unsigned long*)s2)[i]);
101 return;
102 }
103 }
104}

◆ TestAlloc()

void TestAlloc ( omMemCell  cell,
unsigned long  spec 
)

Definition at line 182 of file omtTest.c.

183{
184 if (DO_CHECK(spec))
185 {
186 if (DO_TRACK(spec))
187 om_Opts.MinTrack = GET_TRACK(spec);
188 else
189 om_Opts.MinTrack = 0;
190
191 if (DO_KEEP(spec))
192 omtTestAllocKeep(cell, spec);
193 else
194 omtTestAllocDebug(cell, spec);
195 }
196 else
197 omtTestAlloc(cell, spec);
199 {
200 errors++;
202 }
203}
int errors
Definition omtTest.c:12
#define DO_KEEP(spec)
Definition omtTest.h:79
void omtTestAlloc(omMemCell cell, unsigned long spec)
#define GET_TRACK(spec)
Definition omtTest.h:71
void omtTestAllocKeep(omMemCell cell, unsigned long spec)
void omtTestAllocDebug(omMemCell cell, unsigned long spec)
#define DO_CHECK(spec)
Definition omtTest.h:63
#define DO_TRACK(spec)
Definition omtTest.h:70

◆ TestFree()

void TestFree ( omMemCell  cell)

Definition at line 252 of file omtTest.c.

253{
254 if (cell->addr != NULL)
255 {
256 if (DO_FREE_CHECK(cell->spec))
257 {
258 if (DO_KEEP(cell->spec))
260 else
262 }
263 else
264 {
266 }
268 {
269 errors++;
271 }
272 }
273}
#define DO_FREE_CHECK(spec)
Definition omtTest.h:64
void omtTestFreeDebug(omMemCell cell)
void omtTestFree(omMemCell cell)
void omtTestFreeKeep(omMemCell cell)

◆ TestRealloc()

void TestRealloc ( omMemCell  cell,
unsigned long  spec 
)

Definition at line 205 of file omtTest.c.

206{
207 if (DO_CHECK(spec))
208 {
209 if (DO_TRACK(spec))
210 om_Opts.MinTrack = GET_TRACK(spec);
211 else
212 om_Opts.MinTrack = 0;
213
214 if (DO_KEEP(spec))
216 else
218 }
219 else
220 omtTestRealloc(cell, spec);
222 {
223 errors++;
225 }
226}
void omtTestReallocDebug(omMemCell cell, unsigned long spec)
void omtTestReallocKeep(omMemCell cell, unsigned long spec)
void omtTestRealloc(omMemCell cell, unsigned long spec)

Variable Documentation

◆ cells

omMemCell_t cells[]
extern

Definition at line 11 of file omtTest.c.