My Project
Loading...
Searching...
No Matches
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 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

◆ main()

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

Definition at line 336 of file omtTest.c.

337{
338 int i=0, error_test = 1;
339 unsigned long spec, j;
340 int n = 1;
341 int n_cells = MAX_CELLS;
342 int decr = 2;
343 int last_kept_freed = 0;
344 om_Opts.MinCheck = CHECK_LEVEL;
345 om_Opts.Keep = KEEP_ADDR;
346 om_Opts.HowToReportErrors = 3;
347
348 seed = time(NULL);
349
350 omInitRet_2_Info(argv[0]);
352 omInitInfo();
353 om_Opts.PagesPerRegion = PAGES_PER_REGION;
354
355 if (argc > 1) sscanf(argv[1], "%d", &error_test);
356 if (argc > 2) sscanf(argv[2], "%d", &seed);
357 srandom(seed);
358
359 if (argc > 3) sscanf(argv[3], "%d", &n);
360 if (argc > 4) sscanf(argv[4], "%d", &decr);
361
362 if (decr < 2) decr = 2;
363 printf("seed == %d\n", seed);
364 fflush(stdout);
365 while (1)
366 {
367 if (i == n_cells)
368 {
369 i = 0;
370 printf("\nCells: %d KeptAddr:%d AlwaysKeptAddr:%d\n", n_cells,
371#ifndef OM_NDEBUG
373#else
374 0, 0
375#endif
376 );
377
378 printf("Checking Memory and all cells ");
379 fflush(stdout);
381 printf("\n");
382 omPrintStats(stdout);
383 omPrintInfo(stdout);
384 if (om_Info.CurrentRegionsAlloc > 0) omPrintBinStats(stdout);
385 fflush(stdout);
386#if CHECK_LEVEL > 0 && TRACK_LEVEL > 0
387 if (error_test && errors == 0)
388 {
390 if (missed_errors < 0)
391 {
392 my_exit();
393 }
394 }
395#endif
396 omtMergeStickyBins(cells, n_cells);
397 while (i< n_cells)
398 {
399 TestFree(&cells[i]);
400 i++;
401 }
404 omPrintStats(stdout);
405 omPrintInfo(stdout);
406 if (om_Info.CurrentRegionsAlloc > 0)
407 {
408 omPrintBinStats(stdout);
409 used_regions += om_Info.CurrentRegionsAlloc;
410 }
411 omPrintUsedAddrs(stdout, 5);
412 i=0;
413 n--;
414 if (n <= 0 || n_cells <= 100)
415 {
416 my_exit();
417 }
418 else
419 {
420 n_cells = n_cells / decr;
421 }
422 }
423 spec = MyRandSpec();
424 myprintf("%d:%lu:%ld:%ld", i, spec, GET_SIZE(spec), GET_TRACK(spec));
425 myfflush(stdout);
426 if (DO_FREE(spec))
427 {
428 if (i != 0)
429 {
430 myprintf(" FREE");
431 j = spec % i;
432 myprintf(" %ld ", j);
433 myfflush(stdout);
434 TestFree(&cells[j]);
435 TestAlloc(&cells[j], spec);
436 }
437 }
438 else if (DO_REALLOC(spec))
439 {
440 if (i != 0)
441 {
442 myprintf(" REALLOC");
443 j = spec % i;
444 myprintf(" %ld ", j);
445 myfflush(stdout);
446 TestRealloc(&cells[j], spec);
447 }
448 }
449 else if (DO_DUP(spec))
450 {
451 if (i != 0)
452 {
453 myprintf(" DUP");
454 j = spec % i;
455 myprintf(" %ld ", j);
456 myfflush(stdout);
457 TestDup(&cells[j], spec);
458 }
459 }
460 else
461 {
462 myprintf(" ALLOC");
463 myfflush(stdout);
464 TestAlloc(&cells[i], spec);
465 i++;
466 if (i % 1000 == 0)
467 {
468 printf("%d:", i / 1000);
469 fflush(stdout);
470 }
471 }
472 myprintf("\n");
473 myfflush(stdout);
474 // free kept addresses from time to time
475 if ((i % 10000) == 0 && i != n_cells && i!=last_kept_freed)
476 {
477 printf("F:");
479 last_kept_freed = i;
480 }
481#if 0
482 if (CHECK_LEVEL > 2)
483 {
484 for (j=0; j<i; j++)
485 {
487 }
488 }
489#endif
490 }
491 return 0;
492}
int i
Definition: cfEzgcd.cc:132
int j
Definition: facHensel.cc:110
void * om_AlwaysKeptAddrs
Definition: omDebug.c:31
void omFreeKeptAddr()
Definition: omDebug.c:609
void * om_KeptAddr
Definition: omDebug.c:28
#define omInitGetBackTrace()
#define NULL
Definition: omList.c:12
#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:182
int seed
Definition: omtTest.c:15
omMemCell_t cells[MAX_CELLS]
Definition: omtTest.c:11
int used_regions
Definition: omtTest.c:14
int errors
Definition: omtTest.c:12
void TestFree(omMemCell cell)
Definition: omtTest.c:252
void omtMergeStickyBins(omMemCell cell, int n)
Definition: omtTest.c:283
void my_exit()
Definition: omtTest.c:318
int missed_errors
Definition: omtTest.c:13
void TestRealloc(omMemCell cell, unsigned long spec)
Definition: omtTest.c:205
void omtTestDebug(omMemCell cell)
Definition: omtTest.c:36
void omCheckCells(int n, int level, omMemCell_t *cells)
Definition: omtTest.c:136
int MyRandSpec()
Definition: omtTest.c:166
void TestDup(omMemCell cell, unsigned long spec)
Definition: omtTest.c:228
#define KEEP_ADDR
Definition: omtTest.h:18
#define GET_TRACK(spec)
Definition: omtTest.h:71
#define myprintf(format, args...)
Definition: omtTest.h:45
#define DO_REALLOC(spec)
Definition: omtTest.h:59
#define DO_FREE(spec)
Definition: omtTest.h:58
#define DO_DUP(spec)
Definition: omtTest.h:60
#define PAGES_PER_REGION
Definition: omtTest.h:97
int omtTestErrors()
Definition: omtTestError.c:37
#define GET_SIZE(spec)
Definition: omtTest.h:51
#define myfflush(what)
Definition: omtTest.h:46
#define CHECK_LEVEL
Definition: omtTest.h:10
#define END_CHECK_LEVEL
Definition: omtTest.h:20
#define MAX_CELLS
Definition: omtTest.h:17
#define omPrintUsedAddrs(F, max)
Definition: xalloc.h:268
#define OM_NDEBUG
Definition: xalloc.h:10
#define omPrintStats(F)
Definition: xalloc.h:231
#define omInitInfo()
Definition: xalloc.h:228
#define omPrintInfo(F)
Definition: xalloc.h:232
#define omPrintBinStats(F)
Definition: xalloc.h:233
#define omInitRet_2_Info(argv0)
Definition: xalloc.h:274

◆ my_exit()

void my_exit ( )

Definition at line 318 of file omtTest.c.

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

◆ MyRandSpec()

int MyRandSpec ( )

Definition at line 166 of file omtTest.c.

167{
168 unsigned long spec = random() + 1;
169 if (! size_range_number)
170 {
171 size_range = size_range << 1;
174 }
175 SET_SIZE(spec, GET_SIZE(spec) & (size_range -1));
177 if (GET_SIZE(spec) == 0) spec++;
178 return spec;
179}
int size_range_number
Definition: omtTest.c:164
int size_range
Definition: omtTest.c:163
#define RANGE_MIN
Definition: omtTest.h:94
#define RANGE_MAX
Definition: omtTest.h:95
#define SET_SIZE(spec, size)
Definition: omtTest.h:52

◆ omCheckCells()

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

Definition at line 136 of file omtTest.c.

137{
138#if END_CHECK_LEVEL > 0
139 int l = om_Opts.MinCheck;
140 int i;
141
143 om_Opts.MinCheck = 1;
144 for (i=0; i<n; i++)
145 {
148 {
149 errors++;
151 }
152 if ((i % 10000) == 0)
153 {
154 printf(".");
155 fflush(stdout);
156 }
157 }
158 om_Opts.MinCheck = l;
159#endif
160}
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 275 of file omtTest.c.

276{
277 omBin sticky_bin = omFindInGList(om_StickyBins, next, max_blocks, bin->max_blocks);
278 if (sticky_bin == NULL)
279 sticky_bin = omGetStickyBinOfBin(bin);
280 return sticky_bin;
281}
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:247

◆ omtMergeStickyBins()

void omtMergeStickyBins ( omMemCell  cell,
int  n 
)

Definition at line 283 of file omtTest.c.

284{
285 int i;
286 omBin bin;
287
288 for (i=0; i<n; i++)
289 {
290 if (cell[i].orig_bin != NULL)
291 {
292 if (omIsOnGList(om_StickyBins, next, cell[i].bin))
293 omMergeStickyBinIntoBin(cell[i].bin, cell[i].orig_bin);
294
295 cell[i].bin = cell[i].orig_bin;
296 cell[i].orig_bin = NULL;
297 }
298 }
299
300 bin = om_StickyBins;
301 while (bin != NULL)
302 {
303 if (bin->current_page == om_ZeroPage)
304 {
305 omBin next_bin = bin->next;
307 __omFreeBinAddr(bin);
308 bin = next_bin;
309 }
310 else
311 {
312 bin = bin->next;
313 }
314 }
315}
#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:275

◆ 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))
52 omDebugAddrAlignedSize(cell->addr, size);
53 else
54 omDebugAddrSize(cell->addr, size);
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
80 if (is_size >> LOG_SIZEOF_LONG != omSizeWOfAddr(cell->addr))
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}
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:106
#define IS_ALIGNED(spec)
Definition: omtTest.h:53

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

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

◆ TestDup()

void TestDup ( omMemCell  cell,
unsigned long  spec 
)

Definition at line 228 of file omtTest.c.

229{
230 if (DO_CHECK(spec))
231 {
232 if (DO_TRACK(spec))
233 om_Opts.MinTrack = GET_TRACK(spec);
234 else
235 om_Opts.MinTrack = 0;
236
237 if (DO_KEEP(spec))
238 omtTestDupKeep(cell, spec);
239 else
240 omtTestDupDebug(cell, spec);
241 }
242 else
243 omtTestDup(cell, spec);
244
246 {
247 errors++;
249 }
250}
void omtTestDup(omMemCell cell, unsigned long spec)
Definition: omtTestAlloc.c:348
void omtTestDupDebug(omMemCell cell, unsigned long spec)
void omtTestDupKeep(omMemCell cell, unsigned long spec)

◆ 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))
259 omtTestFreeKeep(cell);
260 else
261 omtTestFreeDebug(cell);
262 }
263 else
264 {
265 omtTestFree(cell);
266 }
268 {
269 errors++;
271 }
272 }
273}
#define DO_FREE_CHECK(spec)
Definition: omtTest.h:64
void omtTestFreeDebug(omMemCell cell)
void omtTestFree(omMemCell cell)
Definition: omtTestAlloc.c:135
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))
215 omtTestReallocKeep(cell, spec);
216 else
217 omtTestReallocDebug(cell, spec);
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)
Definition: omtTestAlloc.c:180

Variable Documentation

◆ cells

omMemCell_t cells[MAX_CELLS]

Definition at line 11 of file omtTest.c.

◆ errors

int errors = 0

Definition at line 12 of file omtTest.c.

◆ missed_errors

int missed_errors = 0

Definition at line 13 of file omtTest.c.

◆ seed

int seed

Definition at line 15 of file omtTest.c.

◆ size_range

int size_range = RANGE_MIN

Definition at line 163 of file omtTest.c.

◆ size_range_number

int size_range_number = RANGE_MAX / RANGE_MIN

Definition at line 164 of file omtTest.c.

◆ used_regions

int used_regions = 0

Definition at line 14 of file omtTest.c.