My Project
Macros | Functions | Variables
omtTest.c File Reference
#include "omtTest.h"
#include "omalloc.h"

Go to the source code of this file.

Macros

#define OM_CHECK   CHECK_LEVEL
 

Functions

void omtTestDebug (omMemCell cell)
 
void TestAddrContentEqual (void *s1, void *s2, size_t size)
 
void TestAddrContent (void *addr, unsigned long value, size_t size)
 
void InitCellAddrContent (omMemCell cell)
 
void omCheckCells (int n, int level, omMemCell_t *cells)
 
int MyRandSpec ()
 
void TestAlloc (omMemCell cell, unsigned long spec)
 
void TestRealloc (omMemCell cell, unsigned long spec)
 
void TestDup (omMemCell cell, unsigned long spec)
 
void TestFree (omMemCell cell)
 
omBin omtGetStickyBin (omBin bin)
 
void omtMergeStickyBins (omMemCell cell, int n)
 
void my_exit ()
 
int main (int argc, char *argv[])
 

Variables

omMemCell_t cells [MAX_CELLS]
 
int errors = 0
 
int missed_errors = 0
 
int used_regions = 0
 
int seed
 
int size_range = RANGE_MIN
 
int size_range_number = RANGE_MAX / RANGE_MIN
 

Macro Definition Documentation

◆ OM_CHECK

#define OM_CHECK   CHECK_LEVEL

Definition at line 4 of file omtTest.c.

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

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 340 of file omtTest.c.

341{
342 int i=0, error_test = 1;
343 unsigned long spec, j;
344 int n = 1;
345 int n_cells = MAX_CELLS;
346 int decr = 2;
347 int last_kept_freed = 0;
348 om_Opts.MinCheck = CHECK_LEVEL;
349 om_Opts.Keep = KEEP_ADDR;
350
351 seed = time(NULL);
352
353 omInitRet_2_Info(argv[0]);
355 omInitInfo();
356 om_Opts.PagesPerRegion = PAGES_PER_REGION;
357
358 if (argc > 1) sscanf(argv[1], "%d", &error_test);
359 if (argc > 2) sscanf(argv[2], "%d", &seed);
360 srandom(seed);
361
362 if (argc > 3) sscanf(argv[3], "%d", &n);
363 if (argc > 4) sscanf(argv[4], "%d", &decr);
364
365 if (decr < 2) decr = 2;
366 printf("seed == %d\n", seed);
367 fflush(stdout);
368 while (1)
369 {
370 if (i == n_cells)
371 {
372 i = 0;
373 printf("\nCells: %d KeptAddr:%d AlwaysKeptAddr:%d\n", n_cells,
374#ifndef OM_NDEBUG
376#else
377 0, 0
378#endif
379 );
380
381 printf("Checking Memory and all cells ");
382 fflush(stdout);
384 printf("\n");
385 omPrintStats(stdout);
386 omPrintInfo(stdout);
387 if (om_Info.CurrentRegionsAlloc > 0) omPrintBinStats(stdout);
388 fflush(stdout);
389#if CHECK_LEVEL > 0 && TRACK_LEVEL > 0
390 if (error_test && errors == 0)
391 {
393 if (missed_errors < 0)
394 {
395 my_exit();
396 }
397 }
398#endif
399 omtMergeStickyBins(cells, n_cells);
400 while (i< n_cells)
401 {
402 TestFree(&cells[i]);
403 i++;
404 }
407 omPrintStats(stdout);
408 omPrintInfo(stdout);
409 if (om_Info.CurrentRegionsAlloc > 0)
410 {
411 omPrintBinStats(stdout);
412 used_regions += om_Info.CurrentRegionsAlloc;
413 }
414 omPrintUsedAddrs(stdout, 5);
415 i=0;
416 n--;
417 if (n <= 0 || n_cells <= 100)
418 {
419 my_exit();
420 }
421 else
422 {
423 n_cells = n_cells / decr;
424 }
425 }
426 spec = MyRandSpec();
427 myprintf("%d:%lu:%ld:%ld", i, spec, GET_SIZE(spec), GET_TRACK(spec));
428 myfflush(stdout);
429 if (DO_FREE(spec))
430 {
431 if (i != 0)
432 {
433 myprintf(" FREE");
434 j = spec % i;
435 myprintf(" %ld ", j);
436 myfflush(stdout);
437 TestFree(&cells[j]);
438 TestAlloc(&cells[j], spec);
439 }
440 }
441 else if (DO_REALLOC(spec))
442 {
443 if (i != 0)
444 {
445 myprintf(" REALLOC");
446 j = spec % i;
447 myprintf(" %ld ", j);
448 myfflush(stdout);
449 TestRealloc(&cells[j], spec);
450 }
451 }
452 else if (DO_DUP(spec))
453 {
454 if (i != 0)
455 {
456 myprintf(" DUP");
457 j = spec % i;
458 myprintf(" %ld ", j);
459 myfflush(stdout);
460 TestDup(&cells[j], spec);
461 }
462 }
463 else
464 {
465 myprintf(" ALLOC");
466 myfflush(stdout);
467 TestAlloc(&cells[i], spec);
468 i++;
469 if (i % 1000 == 0)
470 {
471 printf("%d:", i / 1000);
472 fflush(stdout);
473 }
474 }
475 myprintf("\n");
476 myfflush(stdout);
477 // free kept addresses from time to time
478 if ((i % 10000) == 0 && i != n_cells && i!=last_kept_freed)
479 {
480 printf("F:");
482 last_kept_freed = i;
483 }
484#if 0
485 if (CHECK_LEVEL > 2)
486 {
487 for (j=0; j<i; j++)
488 {
490 }
491 }
492#endif
493 }
494 return 0;
495}
#define NULL
Definition: auxiliary.h:104
int i
Definition: cfEzgcd.cc:132
int j
Definition: facHensel.cc:110
#define OM_NDEBUG
Definition: factoryconf.h:214
void * om_AlwaysKeptAddrs
Definition: omDebug.c:31
void omFreeKeptAddr()
Definition: omDebug.c:609
void * om_KeptAddr
Definition: omDebug.c:28
#define omInitGetBackTrace()
#define omListLength(ptr)
Definition: omList.h:62
omOpts_t om_Opts
Definition: omOpts.c:13
omInfo_t om_Info
Definition: omStats.c:16
void TestAlloc(omMemCell cell, unsigned long spec)
Definition: omtTest.c:186
int seed
Definition: omtTest.c:13
omMemCell_t cells[MAX_CELLS]
Definition: omtTest.c:9
int used_regions
Definition: omtTest.c:12
int errors
Definition: omtTest.c:10
void TestFree(omMemCell cell)
Definition: omtTest.c:256
void omtMergeStickyBins(omMemCell cell, int n)
Definition: omtTest.c:287
void my_exit()
Definition: omtTest.c:322
int missed_errors
Definition: omtTest.c:11
void TestRealloc(omMemCell cell, unsigned long spec)
Definition: omtTest.c:209
void omtTestDebug(omMemCell cell)
Definition: omtTest.c:34
void omCheckCells(int n, int level, omMemCell_t *cells)
Definition: omtTest.c:140
int MyRandSpec()
Definition: omtTest.c:170
void TestDup(omMemCell cell, unsigned long spec)
Definition: omtTest.c:232
#define KEEP_ADDR
Definition: omtTest.h:14
#define GET_TRACK(spec)
Definition: omtTest.h:72
#define myprintf(format, args...)
Definition: omtTest.h:46
#define DO_REALLOC(spec)
Definition: omtTest.h:60
#define DO_FREE(spec)
Definition: omtTest.h:59
#define DO_DUP(spec)
Definition: omtTest.h:61
#define PAGES_PER_REGION
Definition: omtTest.h:98
int omtTestErrors()
Definition: omtTestError.c:36
#define GET_SIZE(spec)
Definition: omtTest.h:52
#define myfflush(what)
Definition: omtTest.h:47
#define CHECK_LEVEL
Definition: omtTest.h:6
#define END_CHECK_LEVEL
Definition: omtTest.h:16
#define MAX_CELLS
Definition: omtTest.h:13
#define omPrintUsedAddrs(F, max)
Definition: xalloc.h:316
#define omPrintStats(F)
Definition: xalloc.h:275
#define omInitInfo()
Definition: xalloc.h:272
#define omPrintInfo(F)
Definition: xalloc.h:276
#define omPrintBinStats(F)
Definition: xalloc.h:277
#define omInitRet_2_Info(argv0)
Definition: xalloc.h:322

◆ my_exit()

void my_exit ( )

Definition at line 322 of file omtTest.c.

323{
324 printf("\nomtTest Summary: ");
326 {
327 printf("***FAILED***errors:%d, missed_errors:%d, used_regions:%d, seed=%d\n", errors, missed_errors, used_regions, seed);
328 if (errors) exit(errors);
329 if (missed_errors) exit(missed_errors);
330 if (used_regions) exit(used_regions);
331 }
332 else
333 {
334 printf("OK\n");
335 exit(0);
336 }
337}

◆ MyRandSpec()

int MyRandSpec ( )

Definition at line 170 of file omtTest.c.

171{
172 unsigned long spec = random() + 1;
173 if (! size_range_number)
174 {
175 size_range = size_range << 1;
178 }
179 SET_SIZE(spec, GET_SIZE(spec) & (size_range -1));
181 if (GET_SIZE(spec) == 0) spec++;
182 return spec;
183}
int size_range_number
Definition: omtTest.c:168
int size_range
Definition: omtTest.c:167
#define RANGE_MIN
Definition: omtTest.h:95
#define RANGE_MAX
Definition: omtTest.h:96
#define SET_SIZE(spec, size)
Definition: omtTest.h:53

◆ omCheckCells()

void omCheckCells ( int  n,
int  level,
omMemCell_t *  cells 
)

Definition at line 140 of file omtTest.c.

141{
142#if END_CHECK_LEVEL > 0
143 int l = om_Opts.MinCheck;
144 int i;
145
147 om_Opts.MinCheck = 1;
148 for (i=0; i<n; i++)
149 {
152 {
153 errors++;
155 }
156 if ((i % 10000) == 0)
157 {
158 printf(".");
159 fflush(stdout);
160 }
161 }
162 om_Opts.MinCheck = l;
163#endif
164}
int level(const CanonicalForm &f)
int l
Definition: cfEzgcd.cc:100
omError_t omTestMemory(int check_level)
Definition: omDebug.c:94
omError_t om_ErrorStatus
Definition: omError.c:13
@ omError_NoError
Definition: omError.h:18

◆ 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}
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

◆ omtMergeStickyBins()

void omtMergeStickyBins ( omMemCell  cell,
int  n 
)

Definition at line 287 of file omtTest.c.

288{
289 int i;
290 omBin bin;
291
292 for (i=0; i<n; i++)
293 {
294 if (cell[i].orig_bin != NULL)
295 {
296 if (omIsOnGList(om_StickyBins, next, cell[i].bin))
297 omMergeStickyBinIntoBin(cell[i].bin, cell[i].orig_bin);
298
299 cell[i].bin = cell[i].orig_bin;
300 cell[i].orig_bin = NULL;
301 }
302 }
303
304 bin = om_StickyBins;
305 while (bin != NULL)
306 {
307 if (bin->current_page == om_ZeroPage)
308 {
309 omBin next_bin = bin->next;
311 __omFreeBinAddr(bin);
312 bin = next_bin;
313 }
314 else
315 {
316 bin = bin->next;
317 }
318 }
319}
#define __omFreeBinAddr(addr)
#define omRemoveFromGList(ptr, next, addr)
Definition: omList.h:102
#define omIsOnGList(ptr, next, addr)
Definition: omList.h:100
omBinPage_t om_ZeroPage[]
Definition: om_Alloc.c:19
#define omMergeStickyBinIntoBin(A, B)
Definition: xalloc.h:323

◆ 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}
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
#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 omReportError(omError_t error, omError_t report_error, OM_FLR_DECL, const char *fmt,...)
Definition: omError.c:80
@ omError_Unknown
Definition: omError.h:19
void TestAddrContent(void *addr, unsigned long value, size_t size)
Definition: omtTest.c:110
#define IS_ALIGNED(spec)
Definition: omtTest.h:54

◆ 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}

◆ 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}
#define DO_KEEP(spec)
Definition: omtTest.h:80
void omtTestAlloc(omMemCell cell, unsigned long spec)
Definition: omtTestAlloc.c:32
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

◆ TestDup()

void TestDup ( omMemCell  cell,
unsigned long  spec 
)

Definition at line 232 of file omtTest.c.

233{
234 if (DO_CHECK(spec))
235 {
236 if (DO_TRACK(spec))
237 om_Opts.MinTrack = GET_TRACK(spec);
238 else
239 om_Opts.MinTrack = 0;
240
241 if (DO_KEEP(spec))
242 omtTestDupKeep(cell, spec);
243 else
244 omtTestDupDebug(cell, spec);
245 }
246 else
247 omtTestDup(cell, spec);
248
250 {
251 errors++;
253 }
254}
void omtTestDup(omMemCell cell, unsigned long spec)
Definition: omtTestAlloc.c:347
void omtTestDupDebug(omMemCell cell, unsigned long spec)
void omtTestDupKeep(omMemCell cell, unsigned long spec)

◆ 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[MAX_CELLS]

Definition at line 9 of file omtTest.c.

◆ errors

int errors = 0

Definition at line 10 of file omtTest.c.

◆ missed_errors

int missed_errors = 0

Definition at line 11 of file omtTest.c.

◆ seed

int seed

Definition at line 13 of file omtTest.c.

◆ size_range

int size_range = RANGE_MIN

Definition at line 167 of file omtTest.c.

◆ size_range_number

int size_range_number = RANGE_MAX / RANGE_MIN

Definition at line 168 of file omtTest.c.

◆ used_regions

int used_regions = 0

Definition at line 12 of file omtTest.c.