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

#define OM_CHECK   CHECK_LEVEL

Definition at line 4 of file omtTest.c.

Function Documentation

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 IS_ZERO(spec)
Definition: omtTest.h:55
size_t omSizeWOfAddr(void *addr)
#define omMemsetW(P1, W, L)
Definition: omMemOps.h:161
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  }
405  omFreeKeptAddr();
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:");
481  omFreeKeptAddr();
482  last_kept_freed = i;
483  }
484 #if 0
485  if (CHECK_LEVEL > 2)
486  {
487  for (j=0; j<i; j++)
488  {
489  omtTestDebug(&cells[j]);
490  }
491  }
492 #endif
493  }
494  return 0;
495 }
#define myfflush(what)
Definition: omtTest.h:47
void * om_KeptAddr
Definition: omDebug.c:28
void omPrintInfo(FILE *fd)
Definition: omStats.c:127
#define omInitGetBackTrace()
void TestDup(omMemCell cell, unsigned long spec)
Definition: omtTest.c:232
void omPrintBinStats(FILE *fd)
Definition: omBin.c:692
void omInitRet_2_Info(const char *argv0)
Definition: omRet2Info.c:34
void TestRealloc(omMemCell cell, unsigned long spec)
Definition: omtTest.c:209
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
void TestFree(omMemCell cell)
Definition: omtTest.c:256
#define omListLength(ptr)
Definition: omList.h:62
void omPrintStats(FILE *fd)
Definition: omStats.c:114
void my_exit()
Definition: omtTest.c:322
#define PAGES_PER_REGION
Definition: omtTest.h:98
#define KEEP_ADDR
Definition: omtTest.h:14
#define GET_SIZE(spec)
Definition: omtTest.h:52
void omCheckCells(int n, int level, omMemCell_t *cells)
Definition: omtTest.c:140
omOpts_t om_Opts
Definition: omOpts.c:11
int missed_errors
Definition: omtTest.c:11
void omInitInfo()
Definition: omStats.c:17
#define DO_REALLOC(spec)
Definition: omtTest.h:60
#define myprintf(format, args...)
Definition: omtTest.h:46
int j
Definition: myNF.cc:70
omInfo_t om_Info
Definition: omStats.c:13
int errors
Definition: omtTest.c:10
#define DO_FREE(spec)
Definition: omtTest.h:59
#define GET_TRACK(spec)
Definition: omtTest.h:72
#define END_CHECK_LEVEL
Definition: omtTest.h:16
int i
Definition: cfEzgcd.cc:123
void omtMergeStickyBins(omMemCell cell, int n)
Definition: omtTest.c:287
#define OM_NDEBUG
Definition: int_int.h:32
void omtTestDebug(omMemCell cell)
Definition: omtTest.c:34
int used_regions
Definition: omtTest.c:12
int seed
Definition: omtTest.c:13
#define DO_DUP(spec)
Definition: omtTest.h:61
#define NULL
Definition: omList.c:10
#define CHECK_LEVEL
Definition: omtTest.h:6
#define MAX_CELLS
Definition: omtTest.h:13
int MyRandSpec()
Definition: omtTest.c:170
void TestAlloc(omMemCell cell, unsigned long spec)
Definition: omtTest.c:186
int omtTestErrors()
Definition: omtTestError.c:36
void * om_AlwaysKeptAddrs
Definition: omDebug.c:31
void omPrintUsedAddrs(FILE *fd, int max_frames)
Definition: omDebugCheck.c:557
void omFreeKeptAddr()
Definition: omDebug.c:609
omMemCell_t cells[MAX_CELLS]
Definition: omtTest.c:9
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 }
int missed_errors
Definition: omtTest.c:11
int errors
Definition: omtTest.c:10
int used_regions
Definition: omtTest.c:12
int seed
Definition: omtTest.c:13
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 }
#define RANGE_MAX
Definition: omtTest.h:96
#define GET_SIZE(spec)
Definition: omtTest.h:52
int size_range
Definition: omtTest.c:167
#define RANGE_MIN
Definition: omtTest.h:95
#define SET_SIZE(spec, size)
Definition: omtTest.h:53
int size_range_number
Definition: omtTest.c:168
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  {
150  omtTestDebug(&cells[i]);
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)
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
omOpts_t om_Opts
Definition: omOpts.c:11
omError_t omTestMemory(int check_level)
Definition: omDebug.c:94
omError_t om_ErrorStatus
Definition: omError.c:11
int errors
Definition: omtTest.c:10
int i
Definition: cfEzgcd.cc:123
void omtTestDebug(omMemCell cell)
Definition: omtTest.c:34
int l
Definition: cfEzgcd.cc:94
omMemCell_t cells[MAX_CELLS]
Definition: omtTest.c:9
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 }
omBin_t * omBin
Definition: omStructs.h:12
omBin om_StickyBins
Definition: omBin.c:372
omBin omGetStickyBinOfBin(omBin bin)
Definition: omBin.c:373
#define NULL
Definition: omList.c:10
#define omFindInGList(ptr, next, what, value)
Definition: omList.h:104
ListNode * next
Definition: janet.h:31
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 }
void omMergeStickyBinIntoBin(omBin sticky_bin, omBin into_bin)
Definition: omBin.c:396
#define omRemoveFromGList(ptr, next, addr)
Definition: omList.h:102
omBin_t * omBin
Definition: omStructs.h:12
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
omBinPage_t om_ZeroPage[]
Definition: om_Alloc.c:17
omBin om_StickyBins
Definition: omBin.c:372
int i
Definition: cfEzgcd.cc:123
#define NULL
Definition: omList.c:10
#define __omFreeBinAddr(addr)
#define omIsOnGList(ptr, next, addr)
Definition: omList.h:100
ListNode * next
Definition: janet.h:31
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 }
omError_t omReportError(omError_t error, omError_t report_error, OM_FLR_DECL, const char *fmt,...)
Definition: omError.c:78
#define IS_ZERO(spec)
Definition: omtTest.h:55
size_t omSizeOfAddr(const void *addr)
Definition: omAllocSystem.c:97
#define omDebugAddrSize(addr, size)
Definition: omAllocDecl.h:313
size_t omSizeWOfAddr(void *addr)
#define omDebugAddrAlignedBin
Definition: omAllocDecl.h:291
#define omDebugAddrAlignedSize
Definition: omAllocDecl.h:292
#define GET_SIZE(spec)
Definition: omtTest.h:52
void TestAddrContent(void *addr, unsigned long value, size_t size)
Definition: omtTest.c:110
omError_t om_ErrorStatus
Definition: omError.c:11
#define IS_ALIGNED(spec)
Definition: omtTest.h:54
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
#define NULL
Definition: omList.c:10
#define omDebugAddrBin(addr, bin)
Definition: omAllocDecl.h:311
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 }
omError_t omReportError(omError_t error, omError_t report_error, OM_FLR_DECL, const char *fmt,...)
Definition: omError.c:78
int i
Definition: cfEzgcd.cc:123
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
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 }
omError_t omReportError(omError_t error, omError_t report_error, OM_FLR_DECL, const char *fmt,...)
Definition: omError.c:78
int i
Definition: cfEzgcd.cc:123
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
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 }
void omtTestAllocDebug(omMemCell cell, unsigned long spec)
void omtTestAllocKeep(omMemCell cell, unsigned long spec)
#define DO_CHECK(spec)
Definition: omtTest.h:64
#define DO_TRACK(spec)
Definition: omtTest.h:71
omOpts_t om_Opts
Definition: omOpts.c:11
omError_t om_ErrorStatus
Definition: omError.c:11
int errors
Definition: omtTest.c:10
#define GET_TRACK(spec)
Definition: omtTest.h:72
#define DO_KEEP(spec)
Definition: omtTest.h:80
void omtTestAlloc(omMemCell cell, unsigned long spec)
Definition: omtTestAlloc.c:32
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 }
#define DO_CHECK(spec)
Definition: omtTest.h:64
#define DO_TRACK(spec)
Definition: omtTest.h:71
void omtTestDupDebug(omMemCell cell, unsigned long spec)
omOpts_t om_Opts
Definition: omOpts.c:11
void omtTestDupKeep(omMemCell cell, unsigned long spec)
omError_t om_ErrorStatus
Definition: omError.c:11
int errors
Definition: omtTest.c:10
#define GET_TRACK(spec)
Definition: omtTest.h:72
#define DO_KEEP(spec)
Definition: omtTest.h:80
void omtTestDup(omMemCell cell, unsigned long spec)
Definition: omtTestAlloc.c:347
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
omError_t om_ErrorStatus
Definition: omError.c:11
int errors
Definition: omtTest.c:10
void omtTestFreeDebug(omMemCell cell)
#define DO_KEEP(spec)
Definition: omtTest.h:80
#define NULL
Definition: omList.c:10
void omtTestFreeKeep(omMemCell cell)
void omtTestFree(omMemCell cell)
Definition: omtTestAlloc.c:134
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)
#define DO_CHECK(spec)
Definition: omtTest.h:64
#define DO_TRACK(spec)
Definition: omtTest.h:71
omOpts_t om_Opts
Definition: omOpts.c:11
void omtTestRealloc(omMemCell cell, unsigned long spec)
Definition: omtTestAlloc.c:179
omError_t om_ErrorStatus
Definition: omError.c:11
int errors
Definition: omtTest.c:10
#define GET_TRACK(spec)
Definition: omtTest.h:72
#define DO_KEEP(spec)
Definition: omtTest.h:80
void omtTestReallocKeep(omMemCell cell, unsigned long spec)

Variable Documentation

omMemCell_t cells[MAX_CELLS]

Definition at line 9 of file omtTest.c.

int errors = 0

Definition at line 10 of file omtTest.c.

int missed_errors = 0

Definition at line 11 of file omtTest.c.

int seed

Definition at line 13 of file omtTest.c.

int size_range = RANGE_MIN

Definition at line 167 of file omtTest.c.

int size_range_number = RANGE_MAX / RANGE_MIN

Definition at line 168 of file omtTest.c.

int used_regions = 0

Definition at line 12 of file omtTest.c.