My Project
Data Structures | Macros | Typedefs | Functions | Variables
omtTest.h File Reference
#include <time.h>
#include <string.h>
#include <limits.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)   (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_t * omMemCell
 

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 25 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 6 of file omtTest.h.

◆ DO_CHECK

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

Definition at line 64 of file omtTest.h.

◆ DO_DUP

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

Definition at line 61 of file omtTest.h.

◆ DO_FREE

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

Definition at line 59 of file omtTest.h.

◆ DO_FREE_CHECK

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

Definition at line 65 of file omtTest.h.

◆ DO_FREE_KEEP

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

Definition at line 81 of file omtTest.h.

◆ DO_KEEP

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

Definition at line 80 of file omtTest.h.

◆ DO_REALLOC

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

Definition at line 60 of file omtTest.h.

◆ DO_TRACK

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

Definition at line 71 of file omtTest.h.

◆ END_CHECK_LEVEL

#define END_CHECK_LEVEL   5

Definition at line 16 of file omtTest.h.

◆ GET_SIZE

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

Definition at line 52 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 72 of file omtTest.h.

◆ IS_ALIGNED

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

Definition at line 54 of file omtTest.h.

◆ IS_BIN

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

Definition at line 56 of file omtTest.h.

◆ IS_FREE_BIN

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

Definition at line 88 of file omtTest.h.

◆ IS_FREE_BINADDR

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

Definition at line 90 of file omtTest.h.

◆ IS_FREE_SIZE

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

Definition at line 87 of file omtTest.h.

◆ IS_INLINE

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

Definition at line 58 of file omtTest.h.

◆ IS_SLOPPY

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

Definition at line 89 of file omtTest.h.

◆ IS_SPEC_BIN

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

Definition at line 57 of file omtTest.h.

◆ IS_STICKY_BIN

#define IS_STICKY_BIN (   spec)    (spec & 1)

Definition at line 50 of file omtTest.h.

◆ IS_ZERO

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

Definition at line 55 of file omtTest.h.

◆ KEEP_ADDR

#define KEEP_ADDR   100

Definition at line 14 of file omtTest.h.

◆ KEEP_LEVEL

#define KEEP_LEVEL   20

Definition at line 8 of file omtTest.h.

◆ MAX_CELLS

#define MAX_CELLS   100000

Definition at line 13 of file omtTest.h.

◆ myfflush

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

Definition at line 47 of file omtTest.h.

◆ myprintf

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

Definition at line 46 of file omtTest.h.

◆ PAGES_PER_REGION

#define PAGES_PER_REGION   128

Definition at line 98 of file omtTest.h.

◆ RANGE_MAX

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

Definition at line 96 of file omtTest.h.

◆ RANGE_MIN

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

Definition at line 95 of file omtTest.h.

◆ SET_SIZE

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

Definition at line 53 of file omtTest.h.

◆ SIZE_MAX

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

Definition at line 94 of file omtTest.h.

◆ SPEC_MAX

#define SPEC_MAX   ULONG_MAX

Definition at line 93 of file omtTest.h.

◆ TRACK_LEVEL

#define TRACK_LEVEL   1

Definition at line 5 of file omtTest.h.

Typedef Documentation

◆ omMemCell

typedef omMemCell_t* omMemCell

Definition at line 34 of file omtTest.h.

Function Documentation

◆ InitCellAddrContent()

void InitCellAddrContent ( omMemCell  cell)

Definition at line 134 of file omtTest.c.

135{
136 size_t sizeW = omSizeWOfAddr(cell->addr);
137 omMemsetW(cell->addr, (IS_ZERO(cell->spec) ? 0 : cell->spec), sizeW);
138}
#define omMemsetW(P1, W, L)
Definition: omMemOps.h:161
#define IS_ZERO(spec)
Definition: omtTest.h:55
#define omSizeWOfAddr(P)
Definition: xalloc.h:262

◆ omtGetStickyBin()

omBin omtGetStickyBin ( omBin  bin)

Definition at line 279 of file omtTest.c.

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

◆ omtTestAlloc()

void omtTestAlloc ( omMemCell  cell,
unsigned long  spec 
)

Definition at line 32 of file omtTestAlloc.c.

33{
34 size_t size = GET_SIZE(spec);
35 void* addr;
36 omBin bin = NULL;
37 omBin orig_bin = NULL;
38
39 if (IS_BIN(spec) && (size <= OM_MAX_BLOCK_SIZE || IS_SPEC_BIN(spec)))
40 {
41 if (IS_SPEC_BIN(spec))
42 {
43 if (IS_ALIGNED(spec))
45 else
46 bin = omGetSpecBin(size);
47 }
48 else
49 {
50 if (IS_ALIGNED(spec))
52 else
53 bin = omSmallSize2Bin(size);
54 }
55
56 if (IS_STICKY_BIN(spec))
57 {
58 orig_bin = bin;
59 bin = omtGetStickyBin(bin);
60 }
61
62 if (IS_INLINE(spec))
63 {
64 if (IS_ZERO(spec))
65 addr = omAlloc0Bin(bin);
66 else
67 addr = omAllocBin(bin);
68 }
69 else
70 {
71 if (IS_ZERO(spec))
72 omTypeAlloc0Bin(void*, addr, bin);
73 else
74 omTypeAllocBin(void*, addr, bin);
75 }
76 }
77 else
78 {
79 if (IS_INLINE(spec))
80 {
81 if (IS_ZERO(spec))
82 {
83 if (IS_ALIGNED(spec))
84 {
85 if (IS_SLOPPY(spec))
86 addr = omalloc0(size);
87 else
88 addr = omAlloc0Aligned(size);
89 }
90 else
91 addr = omAlloc0(size);
92 }
93 else
94 {
95 if (IS_ALIGNED(spec))
96 {
97 if (IS_SLOPPY(spec))
98 addr = omalloc(size);
99 else
100 addr = omAllocAligned(size);
101 }
102 else
103 addr = omAlloc(size);
104 }
105 }
106 else
107 {
108 if (IS_ZERO(spec))
109 {
110 if (IS_ALIGNED(spec))
111 omTypeAlloc0Aligned(void*, addr, size);
112 else
113 omTypeAlloc0(void*, addr, size);
114 }
115 else
116 {
117 if (IS_ALIGNED(spec))
118 omTypeAllocAligned(void*, addr, size);
119 else
120 omTypeAlloc(void*, addr, size);
121 }
122 }
123 }
124 cell->addr = addr;
125 cell->bin = bin;
126 cell->orig_bin = orig_bin;
127 cell->spec = spec;
128
130
131 omtTestDebug(cell);
132}
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)
Definition: omAllocDecl.h:204
#define omAlloc0Aligned
Definition: omAllocDecl.h:274
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omTypeAllocBin(type, addr, bin)
Definition: omAllocDecl.h:203
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
#define omTypeAlloc0(type, addr, size)
Definition: omAllocDecl.h:209
#define omalloc0(size)
Definition: omAllocDecl.h:229
#define omalloc(size)
Definition: omAllocDecl.h:228
#define omTypeAlloc0Aligned
Definition: omAllocDecl.h:272
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define omTypeAlloc(type, addr, size)
Definition: omAllocDecl.h:208
#define omTypeAllocAligned
Definition: omAllocDecl.h:271
#define omAllocAligned
Definition: omAllocDecl.h:273
#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
Definition: omtTestAlloc.c:29
omBin omtGetStickyBin(omBin bin)
Definition: omtTest.c:279
void omtTestDebug(omMemCell cell)
Definition: omtTest.c:34
void InitCellAddrContent(omMemCell cell)
Definition: omtTest.c:134
#define IS_SPEC_BIN(spec)
Definition: omtTest.h:57
#define IS_STICKY_BIN(spec)
Definition: omtTest.h:50
#define IS_ALIGNED(spec)
Definition: omtTest.h:54
#define IS_BIN(spec)
Definition: omtTest.h:56
#define IS_SLOPPY(spec)
Definition: omtTest.h:89
#define IS_INLINE(spec)
Definition: omtTest.h:58
#define GET_SIZE(spec)
Definition: omtTest.h:52

◆ omtTestAllocDebug()

void omtTestAllocDebug ( omMemCell  cell,
unsigned long  spec 
)

◆ omtTestAllocKeep()

void omtTestAllocKeep ( omMemCell  cell,
unsigned long  spec 
)

◆ omtTestDebug()

void omtTestDebug ( omMemCell  cell)

Definition at line 34 of file omtTest.c.

35{
36 size_t size = GET_SIZE(cell->spec);
37 size_t is_size;
38
39 if (om_ErrorStatus != omError_NoError) return;
40 if (cell->bin != NULL)
41 {
42 if (IS_ALIGNED(cell->spec))
43 omDebugAddrAlignedBin(cell->addr, cell->bin);
44 else
45 omDebugAddrBin(cell->addr, cell->bin);
46 }
47 else
48 {
49 if (IS_ALIGNED(cell->spec))
50 omDebugAddrAlignedSize(cell->addr, size);
51 else
52 omDebugAddrSize(cell->addr, size);
53 }
54 if (om_ErrorStatus != omError_NoError) return;
55
56 if (!OM_IS_ALIGNED(cell->addr))
57 {
59 "addr:%p is unaligned", cell->addr);
60 return;
61 }
62
63 if (IS_ALIGNED(cell->spec) && !OM_IS_STRICT_ALIGNED(cell->addr))
64 {
66 "addr:%p is not strict unaligned", cell->addr);
67 return;
68 }
69
70 is_size = omSizeOfAddr(cell->addr);
71 if (!OM_IS_ALIGNED(is_size))
72 {
74 "is_size == %u is unaligned", is_size);
75 return;
76 }
77 if (is_size < size)
78 {
80 "is_size==%u < size==%u", is_size, size);
81 return;
82 }
83
84 if (is_size >> LOG_SIZEOF_LONG != omSizeWOfAddr(cell->addr))
85 {
87 "is_sizeW==%u < sizeW==%u", is_size >> LOG_SIZEOF_LONG, omSizeWOfAddr(cell->addr));
88 return;
89 }
90
91 TestAddrContent(cell->addr, (IS_ZERO(cell->spec) ? 0 : cell->spec), is_size);
92}
#define omDebugAddrAlignedBin
Definition: omAllocDecl.h:291
#define omDebugAddrAlignedSize
Definition: omAllocDecl.h:292
#define omDebugAddrSize(addr, size)
Definition: omAllocDecl.h:313
#define omDebugAddrBin(addr, bin)
Definition: omAllocDecl.h:311
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:110

◆ omtTestDup()

void omtTestDup ( omMemCell  cell,
unsigned long  spec 
)

Definition at line 347 of file omtTestAlloc.c.

348{
349 omtTestDebug(cell);
350
351 if (DO_STRDUP(spec))
352 {
353 size_t size = omSizeOfAddr(cell->addr);
354 void* new_addr;
355 memset(cell->addr, 'a', size - 1);
356 ((char*) cell->addr)[size-1] = '\0';
357 new_addr = omStrDup(cell->addr);
358 TestAddrContentEqual(new_addr, cell->addr, size);
359 omFree(new_addr);
361 }
362 else
363 {
364 void* new_addr = omMemDup(cell->addr);
365 TestAddrContentEqual(new_addr, cell->addr, omSizeOfAddr(cell->addr));
366 omFree(new_addr);
367 new_addr = omMemDupAligned(cell->addr);
368 TestAddrContentEqual(new_addr, cell->addr, omSizeOfAddr(cell->addr));
369 omDebugAddrAlignedSize(new_addr, omSizeOfAddr(cell->addr));
370 omFree(new_addr);
371 }
372}
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omFree(addr)
Definition: omAllocDecl.h:261
#define omMemDup(s)
Definition: omAllocDecl.h:264
#define omMemDupAligned
Definition: omAllocDecl.h:286
#define DO_STRDUP(l)
Definition: omtTestAlloc.c:346
void TestAddrContentEqual(void *s1, void *s2, size_t size)
Definition: omtTest.c:94

◆ omtTestDupDebug()

void omtTestDupDebug ( omMemCell  cell,
unsigned long  spec 
)

◆ omtTestDupKeep()

void omtTestDupKeep ( omMemCell  cell,
unsigned long  spec 
)

◆ omtTestErrors()

int omtTestErrors ( )

Definition at line 36 of file omtTestError.c.

37{
38#ifndef OM_NDEBUG
39 int level = om_Opts.MinCheck;
41 struct LongSpec spec;
42 int missed = 0, alloc;
43 omMemCell cell = NULL;
44
45 printf("omtTestErrors: Start\n");
46 om_Opts.MinCheck = 2;
48 {
51 printf("!!!expect %s\n", omError2Serror(error));
52 memset(&spec, 0, sizeof(struct LongSpec));
53 cell = NULL;
54 alloc = 0;
55 switch (error)
56 {
58 {
59 spec.MaxSize = OM_MAX_BLOCK_SIZE;
60 cell = omFindCell(spec);
61 if (cell != NULL)
62 {
63 omBin bin = omGetTopBinOfAddr(cell->addr);
64 omBinPage last_page = bin->last_page;
65 omAssume(last_page != NULL);
66 bin->last_page = NULL;
67 omDebugBin(cell->bin);
68 bin->last_page = last_page;
69 }
70 else printf("cell not found\n");
71 break;
72 }
73
75 {
77 break;
78 }
79
81 {
82 omDebugAddr((void*) om_MaxAddr);
83 break;
84 }
85
87 {
88 spec.MinSize = 8;
89 spec.MaxSize = OM_MAX_BLOCK_SIZE;
90 spec.NoTrack = 1;
91 cell = omFindCell(spec);
92 if (cell != NULL)
93 {
94 omDebugAddr(cell->addr + SIZEOF_VOIDP);
95 }
96 else printf("cell not found\n");
97 break;
98 }
99
101 {
102 spec.MinSize = 8;
103 spec.MinTrack = 3;
104 cell = omFindCell(spec);
105 if (cell != NULL)
106 {
107 omDebugAddr(cell->addr + SIZEOF_VOIDP);
108 }
109 else printf("cell not found\n");
110 break;
111 }
112
114 {
115 spec.MaxSize = OM_MAX_BLOCK_SIZE;
116 cell = omFindCell(spec);
117 if (cell != NULL)
118 {
119 omDebugAddrSize(cell->addr, OM_MAX_BLOCK_SIZE + 1);
121 {
123 spec.MaxSize = 0;
124 spec.MinTrack = 3;
125 spec.NotIsBin = 1;
126 spec.MinSize = 2;
127 cell = omFindCell(spec);
128 if (cell != NULL)
129 {
130 omDebugAddrSize(cell->addr, GET_SIZE(cell->spec) + SIZEOF_OM_ALIGNMENT);
132 {
134 spec.MaxSize = OM_MAX_BLOCK_SIZE;
135 spec.MinTrack = 0;
136 spec.NotIsBin = 0;
137 cell = omFindCell(spec);
138 if (cell != NULL)
139 omDebugBinAddrSize(cell->addr, GET_SIZE(cell->spec) - 1);
140 else printf("cell not found");
141 }
142 }
143 else printf("cell not found\n");
144 }
145 }
146 else printf("cell not found\n");
147 break;
148 }
149
151 {
152#if KEEP_LEVEL > 0
153 void* addr = om_AlwaysKeptAddrs;
154 while (addr != NULL && omIsTrackAddr(addr))
155 {
156 addr = *((void**) addr);
157 }
158 if (addr != NULL)
159 {
160 omFree(addr);
162 {
164 addr = om_AlwaysKeptAddrs;
165 while (addr != NULL && ! omIsTrackAddr(addr))
166 {
167 addr = *((void**) addr);
168 }
169 if (addr != NULL)
170 {
171 addr = omAddr_2_OutAddr(addr);
172 omFree(addr);
173 }
174 }
175 }
176 if (addr == NULL)
177 {
178 printf("addr not found\n");
179 break;
180 }
182 break;
183#endif
184 spec.MinTrack = 5;
185 spec.NotIsBin = 1;
186 cell = omFindCell(spec);
187 if (cell != NULL)
188 {
189 omFree(cell->addr);
190 omFree(cell->addr);
191 alloc = 1;
192 cell->addr=NULL;
193 }
194 else printf("cell not found\n");
195 break;
196 }
197
199 {
200 spec.MaxSize = OM_MAX_BLOCK_SIZE;
201 spec.NoTrack = 1;
202 cell = omFindCell(spec);
203 if (cell != NULL)
204 {
205 omBinPage page = omGetBinPageOfAddr(cell->addr);
206 omBinPageRegion region = page->region;
207 page->region = NULL;
208 om_Opts.MinCheck = 1;
209 omDebugAddr(cell->addr);
210 om_Opts.MinCheck = 2;
211 page->region = region;
212 }
213 else printf("cell not found\n");
214 break;
215 }
216
217 case omError_WrongBin:
218 {
219 spec.MaxSize = 32;
220 spec.NoTrack = 1;
221 cell = omFindCell(spec);
222 if (cell != NULL)
223 {
225 }
226 else printf("cell not found\n");
227 break;
228 }
229
231 {
232 spec.MaxSize = OM_MAX_BLOCK_SIZE;
233 cell = omFindCell(spec);
234 if (cell != NULL)
235 {
236 omDebugAddrBin(cell->addr, (void*) omGetTopBinOfAddr(cell->addr) + SIZEOF_VOIDP);
237 }
238 else printf("cell not found\n");
239 break;
240 }
241
243 {
244 spec.NotIsBin = 1;
245 spec.MinSize = OM_MAX_BLOCK_SIZE + 1;
246 cell = omFindCell(spec);
247 if (cell != NULL)
248 {
249 omDebugBinAddr(cell->addr);
250 }
251 else printf("cell not found");
252 break;
253 }
254
256 {
257 cell = omFindCell(spec);
258 if (cell != NULL)
259 {
260 omDebugAddr(cell->addr + 1);
261 }
262 else printf("cell not found\n");
263 break;
264 }
265
267 {
268 void* addr = omAlloc(0);
269 addr = omRealloc(addr, 0);
270 omFree(addr);
271 break;
272 }
273
275 {
276 void* last = omListLast(om_SpecBin);
277 if (last != NULL)
278 {
279 *((void**)last) = om_SpecBin;
281 *((void**)last) = NULL;
282 } else printf("last == NULL\n");
283 break;
284 }
285
287 {
288 if (om_SpecBin != NULL && om_SpecBin->next != NULL)
289 {
290 int max_blocks = om_SpecBin->max_blocks;
291 om_SpecBin->max_blocks = om_SpecBin->next->max_blocks + 1;
292 omCheckSortedList(om_SpecBin, max_blocks, 5, omError_NoError, OM_FLR);
293 om_SpecBin->max_blocks = max_blocks;
294 } else printf("om_SpecBin->next == NULL\n");
295 break;
296 }
297
299 {
300 if (om_KeptAddr != NULL)
301 {
302 void* last = omListLast(om_KeptAddr);
303 *((void**)last) = om_KeptAddr;
304 om_Opts.MinCheck = 5;
306 om_Opts.MinCheck = 2;
307 *((void**)last) = NULL;
308 }
309 else printf("om_KeptAddr == NULL\n");
310 break;
311 }
312
314 {
315 if (om_Opts.Keep > 0)
316 {
317 spec.MinTrack=3;
318 spec.NotIsBin = 1;
319 cell = omFindCell(spec);
320 if (cell != NULL)
321 {
322 void* value;
323 omFree(cell->addr);
324 value = *((void**) cell->addr);
325 *((void**) cell->addr) = value -1;
327 *((void**) cell->addr) = value;
328 alloc = 1;
329 cell->addr = NULL;
330 }
331 else printf("cell not found\n");
332 }
333 else printf("om_Opts.Keep == 0");
334 break;
335 }
336
338 {
339 spec.MinTrack = 3;
340 spec.NotIsBin = 1;
341 cell = omFindCell(spec);
342 if (cell != NULL)
343 {
344 void* addr = cell->addr + omSizeOfAddr(cell->addr);
345 void* value = *((void**) addr);
346 *((void**) addr) = value -1;
347 omDebugAddr(cell->addr);
348 *((void**) addr) = value;
349 }
350 else printf("cell not found\n");
351 break;
352 }
353
355 {
356 spec.MinTrack=3;
357 cell = omFindCell(spec);
358 if (cell != NULL)
359 {
360 void* addr = cell->addr - SIZEOF_VOIDP;
361 void* value = *((void**) addr);
362 *((void**) addr) = value -1;
363 omDebugAddr(cell->addr);
364 *((void**) addr) = value;
365 }
366 else printf("cell not found\n");
367 break;
368 }
369
371 {
372/* can only test for NULL string */
373#if 0
374 spec.MaxSize = OM_MAX_BLOCK_SIZE;
375 cell = omFindCell(spec);
376 if (cell != NULL)
377 {
378 char* addr = (char*) cell->addr;
379 char* s;
380 memset(cell->addr, 1, omSizeOfAddr(cell->addr));
381 omDebugAddr(cell->addr);
382 s = omStrDup(addr);
383 omFree(s);
385 }
386 else printf("cell not found\n");
387 break;
388#endif
389 omStrDup(NULL);
390 break;
391 }
392
394 {
396 break;
397 }
398
399 default:
400 printf("No Error test implemented\n");
401 }
402
403 if (om_ErrorStatus != error)
404 {
405 printf("---missed %s\n", omError2Serror(error));
406 missed++;
407 }
408 else
409 {
410 printf("+++ok %s\n", omError2Serror(error));
411 }
412
414 if (cell != NULL)
415 {
416 if (alloc) TestAlloc(cell, cell->spec);
417 omtTestDebug(cell);
418 }
419 else
420 {
422 }
424 {
425 printf("omtTest panik: memory corrupted\n\n");
426 return -1;
427 }
428 printf("\n");
429 }
430 printf("omtTestErrors: Summary: missed = %d\n\n", missed);
431 om_Opts.MinCheck = level;
432 return missed;
433#else
434 return 0;
435#endif
436}
int level(const CanonicalForm &f)
void error(const char *fmt,...)
Definition: emacs.cc:55
const CanonicalForm int s
Definition: facAbsFact.cc:51
STATIC_VAR poly last
Definition: hdegree.cc:1150
#define omDebugMemory()
Definition: omAllocDecl.h:318
#define omDebugBinAddrSize(addr, size)
Definition: omAllocDecl.h:312
#define omDebugAddr(addr)
Definition: omAllocDecl.h:314
#define omDebugBinAddr(addr)
Definition: omAllocDecl.h:310
#define omRealloc(addr, size)
Definition: omAllocDecl.h:225
#define omDebugBin(bin)
Definition: omAllocDecl.h:317
#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
Definition: omDebugCheck.c:19
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)
Definition: omtTestError.c:15
void TestAlloc(omMemCell cell, unsigned long spec)
Definition: omtTest.c:186
omMemCell_t * omMemCell
Definition: omtTest.h:34
#define omMergeStickyBinIntoBin(A, B)
Definition: xalloc.h:323

◆ omtTestFree()

void omtTestFree ( omMemCell  cell)

Definition at line 134 of file omtTestAlloc.c.

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

◆ omtTestFreeDebug()

void omtTestFreeDebug ( omMemCell  cell)

◆ omtTestFreeKeep()

void omtTestFreeKeep ( omMemCell  cell)

◆ omtTestRealloc()

void omtTestRealloc ( omMemCell  cell,
unsigned long  spec 
)

Definition at line 179 of file omtTestAlloc.c.

180{
181 void* old_addr = cell->addr;
182 unsigned long old_spec = cell->spec;
183 omBin old_bin = cell->bin;
184 omBin old_orig_bin = cell->orig_bin;
185 size_t old_size = GET_SIZE(old_spec);
186 void* new_addr;
187 omBin new_bin = NULL;
188 omBin new_orig_bin = NULL;
189 size_t new_size = GET_SIZE(new_spec);
190 size_t real_old_size = omSizeOfAddr(old_addr);
191 size_t min_size;
192
193 omtTestDebug(cell);
194
195 if (old_bin != NULL && IS_FREE_BIN(old_spec) &&
196 IS_BIN(new_spec) && ((new_size <= OM_MAX_BLOCK_SIZE) || IS_SPEC_BIN(new_spec)))
197 {
198 if (IS_SPEC_BIN(new_spec))
199 {
200 if (IS_ALIGNED(new_spec))
201 new_bin = omGetAlignedSpecBin(new_size);
202 else
203 new_bin = omGetSpecBin(new_size);
204 }
205 else
206 {
207 if (IS_ALIGNED(new_spec))
208 new_bin = omSmallSize2AlignedBin(new_size);
209 else
210 new_bin = omSmallSize2Bin(new_size);
211 }
212
213 if (IS_STICKY_BIN(new_spec))
214 {
215 new_orig_bin = new_bin;
216 new_bin = omtGetStickyBin(new_bin);
217 }
218
219 if (IS_INLINE(new_spec))
220 {
221 if (IS_ZERO(new_spec)) new_addr = omRealloc0Bin(old_addr, old_bin, new_bin);
222 else new_addr = omReallocBin(old_addr, old_bin, new_bin);
223 }
224 else
225 {
226 if (IS_ZERO(new_spec)) omTypeRealloc0Bin(old_addr, old_bin, void*, new_addr, new_bin);
227 else omTypeReallocBin(old_addr, old_bin, void*, new_addr, new_bin);
228 }
229 }
230 else
231 {
232 if (IS_FREE_SIZE(old_spec))
233 {
234 if (IS_INLINE(new_spec))
235 {
236 if (IS_ZERO(new_spec))
237 {
238 if (IS_ALIGNED(new_spec))
239 {
240 if (IS_SLOPPY(new_spec))
241 new_addr = omrealloc0Size(old_addr, old_size, new_size);
242 else
243 new_addr = omRealloc0AlignedSize(old_addr, old_size, new_size);
244 }
245 else
246 new_addr = omRealloc0Size(old_addr, old_size, new_size);
247 }
248 else
249 {
250 if (IS_ALIGNED(new_spec))
251 {
252 if (IS_SLOPPY(new_spec))
253 new_addr = omreallocSize(old_addr, old_size, new_size);
254 else
255 new_addr = omReallocAlignedSize(old_addr, old_size, new_size);
256 }
257 else new_addr = omReallocSize(old_addr, old_size, new_size);
258 }
259 }
260 else
261 {
262 if (IS_ZERO(new_spec))
263 {
264 if (IS_ALIGNED(new_spec)) omTypeRealloc0AlignedSize(old_addr, old_size, void*, new_addr, new_size);
265 else omTypeRealloc0Size(old_addr, old_size, void*, new_addr, new_size);
266 }
267 else
268 {
269 if (IS_ALIGNED(new_spec)) omTypeReallocAlignedSize(old_addr, old_size, void*, new_addr, new_size);
270 else omTypeReallocSize(old_addr, old_size, void*, new_addr, new_size);
271 }
272 }
273 }
274 else
275 {
276 if (IS_INLINE(new_spec))
277 {
278 if (IS_ZERO(new_spec))
279 {
280 if (IS_ALIGNED(new_spec))
281 {
282 if (IS_SLOPPY(new_spec))
283 new_addr = omrealloc0(old_addr, new_size);
284 else
285 new_addr = omRealloc0Aligned(old_addr, new_size);
286 }
287 else new_addr = omRealloc0(old_addr, new_size);
288 }
289 else
290 {
291 if (IS_ALIGNED(new_spec))
292 {
293 if (IS_SLOPPY(new_spec))
294 new_addr = omrealloc(old_addr, new_size);
295 else
296 new_addr = omReallocAligned(old_addr, new_size);
297 }
298 else new_addr = omRealloc(old_addr, new_size);
299 }
300 }
301 else
302 {
303 if (IS_ZERO(new_spec))
304 {
305 if (IS_ALIGNED(new_spec)) omTypeRealloc0Aligned(old_addr, void*, new_addr, new_size);
306 else omTypeRealloc0(old_addr, void*, new_addr, new_size);
307 }
308 else
309 {
310 if (IS_ALIGNED(new_spec)) omTypeReallocAligned(old_addr, void*, new_addr, new_size);
311 else omTypeRealloc(old_addr, void*, new_addr, new_size);
312 }
313 }
314 }
315 }
316
317 if (old_bin != NULL && IS_SPEC_BIN(old_spec))
318 {
319 if (old_orig_bin != NULL)
320 omUnGetSpecBin(&old_orig_bin);
321 else
322 omUnGetSpecBin(&old_bin);
323 }
324
325 new_size = omSizeOfAddr(new_addr);
326 old_size = real_old_size;
327 min_size = (new_size < old_size ? new_size : old_size);
328
329 if (IS_ZERO(old_spec) && IS_ZERO(new_spec))
330 TestAddrContent(new_addr, 0, new_size);
331 else
332 {
333 TestAddrContent(new_addr, (IS_ZERO(old_spec) ? 0 : old_spec), min_size);
334 if (IS_ZERO(new_spec) && old_size < new_size)
335 TestAddrContent((char *)new_addr + old_size, 0, new_size - old_size);
336 }
337
338 cell->addr = new_addr;
339 cell->spec = new_spec;
340 cell->bin = new_bin;
341 cell->orig_bin = new_orig_bin;
343 omtTestDebug(cell);
344}
#define omrealloc(addr, size)
Definition: omAllocDecl.h:233
#define omTypeReallocAlignedSize
Definition: omAllocDecl.h:276
#define omTypeRealloc0(o_addr, type, addr, size)
Definition: omAllocDecl.h:224
#define omTypeRealloc0Size(o_addr, o_size, type, addr, size)
Definition: omAllocDecl.h:219
#define omRealloc0AlignedSize
Definition: omAllocDecl.h:279
#define omrealloc0Size(addr, o_size, size)
Definition: omAllocDecl.h:232
#define omRealloc0Aligned
Definition: omAllocDecl.h:284
#define omreallocSize(addr, o_size, size)
Definition: omAllocDecl.h:231
#define omReallocSize(addr, o_size, size)
Definition: omAllocDecl.h:220
#define omReallocAligned
Definition: omAllocDecl.h:283
#define omTypeRealloc0AlignedSize
Definition: omAllocDecl.h:277
#define omrealloc0(addr, size)
Definition: omAllocDecl.h:234
#define omRealloc0Bin(o_addr, o_bin, bin)
Definition: omAllocDecl.h:216
#define omTypeRealloc0Bin(o_addr, o_bin, type, addr, bin)
Definition: omAllocDecl.h:214
#define omReallocAlignedSize
Definition: omAllocDecl.h:278
#define omTypeRealloc0Aligned
Definition: omAllocDecl.h:282
#define omReallocBin(o_addr, o_bin, bin)
Definition: omAllocDecl.h:215
#define omRealloc0Size(addr, o_size, size)
Definition: omAllocDecl.h:221
#define omTypeReallocAligned
Definition: omAllocDecl.h:281
#define omRealloc0(addr, size)
Definition: omAllocDecl.h:226
#define omTypeReallocSize(o_addr, o_size, type, addr, size)
Definition: omAllocDecl.h:218
#define omTypeReallocBin(o_addr, o_bin, type, addr, bin)
Definition: omAllocDecl.h:213
#define omTypeRealloc(o_addr, type, addr, size)
Definition: omAllocDecl.h:223

◆ 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 110 of file omtTest.c.

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

◆ TestAddrContentEqual()

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

Definition at line 94 of file omtTest.c.

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

◆ TestAlloc()

void TestAlloc ( omMemCell  cell,
unsigned long  spec 
)

Definition at line 186 of file omtTest.c.

187{
188 if (DO_CHECK(spec))
189 {
190 if (DO_TRACK(spec))
191 om_Opts.MinTrack = GET_TRACK(spec);
192 else
193 om_Opts.MinTrack = 0;
194
195 if (DO_KEEP(spec))
196 omtTestAllocKeep(cell, spec);
197 else
198 omtTestAllocDebug(cell, spec);
199 }
200 else
201 omtTestAlloc(cell, spec);
203 {
204 errors++;
206 }
207}
int errors
Definition: omtTest.c:10
#define DO_KEEP(spec)
Definition: omtTest.h:80
void omtTestAlloc(omMemCell cell, unsigned long spec)
Definition: omtTestAlloc.c:32
#define GET_TRACK(spec)
Definition: omtTest.h:72
void omtTestAllocKeep(omMemCell cell, unsigned long spec)
void omtTestAllocDebug(omMemCell cell, unsigned long spec)
#define DO_CHECK(spec)
Definition: omtTest.h:64
#define DO_TRACK(spec)
Definition: omtTest.h:71

◆ TestFree()

void TestFree ( omMemCell  cell)

Definition at line 256 of file omtTest.c.

257{
258 if (cell->addr != NULL)
259 {
260 if (DO_FREE_CHECK(cell->spec))
261 {
262 if (DO_KEEP(cell->spec))
263 omtTestFreeKeep(cell);
264 else
265 omtTestFreeDebug(cell);
266 }
267 else
268 {
269 omtTestFree(cell);
270 }
272 {
273 errors++;
275 }
276 }
277}
#define DO_FREE_CHECK(spec)
Definition: omtTest.h:65
void omtTestFreeDebug(omMemCell cell)
void omtTestFree(omMemCell cell)
Definition: omtTestAlloc.c:134
void omtTestFreeKeep(omMemCell cell)

◆ TestRealloc()

void TestRealloc ( omMemCell  cell,
unsigned long  spec 
)

Definition at line 209 of file omtTest.c.

210{
211 if (DO_CHECK(spec))
212 {
213 if (DO_TRACK(spec))
214 om_Opts.MinTrack = GET_TRACK(spec);
215 else
216 om_Opts.MinTrack = 0;
217
218 if (DO_KEEP(spec))
219 omtTestReallocKeep(cell, spec);
220 else
221 omtTestReallocDebug(cell, spec);
222 }
223 else
224 omtTestRealloc(cell, spec);
226 {
227 errors++;
229 }
230}
void omtTestReallocDebug(omMemCell cell, unsigned long spec)
void omtTestReallocKeep(omMemCell cell, unsigned long spec)
void omtTestRealloc(omMemCell cell, unsigned long spec)
Definition: omtTestAlloc.c:179

Variable Documentation

◆ cells

omMemCell_t cells[]
extern

Definition at line 9 of file omtTest.c.