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

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

## main()

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

Definition at line 336 of file omtTest.c.

{
int i=0, error_test = 1;
unsigned long spec, j;
int n = 1;
int n_cells = MAX_CELLS;
int decr = 2;
int last_kept_freed = 0;
om_Opts.MinCheck = CHECK_LEVEL;
om_Opts.Keep = KEEP_ADDR;
om_Opts.HowToReportErrors = 3;
seed = time(NULL);
omInitRet_2_Info(argv[0]);
omInitGetBackTrace();
omInitInfo();
om_Opts.PagesPerRegion = PAGES_PER_REGION;
if (argc > 1) sscanf(argv[1], "%d", &error_test);
if (argc > 2) sscanf(argv[2], "%d", &seed);
srandom(seed);
if (argc > 3) sscanf(argv[3], "%d", &n);
if (argc > 4) sscanf(argv[4], "%d", &decr);
if (decr < 2) decr = 2;
printf("seed == %d\n", seed);
fflush(stdout);
while (1)
{
if (i == n_cells)
{
i = 0;
printf("\nCells: %d KeptAddr:%d AlwaysKeptAddr:%d\n", n_cells,
#ifndef OM_NDEBUG
omListLength(om_KeptAddr), omListLength(om_AlwaysKeptAddrs)
#else
0, 0
#endif
);
printf("Checking Memory and all cells ");
fflush(stdout);
omCheckCells(n_cells, END_CHECK_LEVEL, cells);
printf("\n");
omPrintStats(stdout);
omPrintInfo(stdout);
if (om_Info.CurrentRegionsAlloc > 0) omPrintBinStats(stdout);
fflush(stdout);
#if CHECK_LEVEL > 0 && TRACK_LEVEL > 0
if (error_test && errors == 0)
{
missed_errors = omtTestErrors();
if (missed_errors < 0)
{
my_exit();
}
}
#endif
omtMergeStickyBins(cells, n_cells);
while (i< n_cells)
{
TestFree(&cells[i]);
i++;
}
omFreeKeptAddr();
omtMergeStickyBins(cells, -1);
omPrintStats(stdout);
omPrintInfo(stdout);
if (om_Info.CurrentRegionsAlloc > 0)
{
omPrintBinStats(stdout);
used_regions += om_Info.CurrentRegionsAlloc;
}
omPrintUsedAddrs(stdout, 5);
i=0;
n--;
if (n <= 0 || n_cells <= 100)
{
my_exit();
}
else
{
n_cells = n_cells / decr;
}
}
spec = MyRandSpec();
myprintf("%d:%lu:%ld:%ld", i, spec, GET_SIZE(spec), GET_TRACK(spec));
myfflush(stdout);
if (DO_FREE(spec))
{
if (i != 0)
{
myprintf(" FREE");
j = spec % i;
myprintf(" %ld ", j);
myfflush(stdout);
TestFree(&cells[j]);
TestAlloc(&cells[j], spec);
}
}
else if (DO_REALLOC(spec))
{
if (i != 0)
{
myprintf(" REALLOC");
j = spec % i;
myprintf(" %ld ", j);
myfflush(stdout);
TestRealloc(&cells[j], spec);
}
}
else if (DO_DUP(spec))
{
if (i != 0)
{
myprintf(" DUP");
j = spec % i;
myprintf(" %ld ", j);
myfflush(stdout);
TestDup(&cells[j], spec);
}
}
else
{
myprintf(" ALLOC");
myfflush(stdout);
TestAlloc(&cells[i], spec);
i++;
if (i % 1000 == 0)
{
printf("%d:", i / 1000);
fflush(stdout);
}
}
myprintf("\n");
myfflush(stdout);
// free kept addresses from time to time
if ((i % 10000) == 0 && i != n_cells && i!=last_kept_freed)
{
printf("F:");
omFreeKeptAddr();
last_kept_freed = i;
}
#if 0
if (CHECK_LEVEL > 2)
{
for (j=0; j<i; j++)
{
omtTestDebug(&cells[j]);
}
}
#endif
}
return 0;
}
i
int i
Definition cfEzgcd.cc:132
j
int j
Definition facHensel.cc:110
om_AlwaysKeptAddrs
void * om_AlwaysKeptAddrs
Definition omDebug.c:31
omFreeKeptAddr
void omFreeKeptAddr()
Definition omDebug.c:609
om_KeptAddr
void * om_KeptAddr
Definition omDebug.c:28
omInitGetBackTrace
#define omInitGetBackTrace()
Definition omGetBackTrace.h:14
NULL
#define NULL
Definition omList.c:12
omListLength
#define omListLength(ptr)
Definition omList.h:62
om_Opts
omOpts_t om_Opts
Definition omOpts.c:13
om_Info
omInfo_t om_Info
Definition omStats.c:16
TestAlloc
void TestAlloc(omMemCell cell, unsigned long spec)
Definition omtTest.c:182
seed
int seed
Definition omtTest.c:15
cells
omMemCell_t cells[MAX_CELLS]
Definition omtTest.c:11
used_regions
int used_regions
Definition omtTest.c:14
errors
int errors
Definition omtTest.c:12
TestFree
void TestFree(omMemCell cell)
Definition omtTest.c:252
omtMergeStickyBins
void omtMergeStickyBins(omMemCell cell, int n)
Definition omtTest.c:283
my_exit
void my_exit()
Definition omtTest.c:318
missed_errors
int missed_errors
Definition omtTest.c:13
TestRealloc
void TestRealloc(omMemCell cell, unsigned long spec)
Definition omtTest.c:205
omtTestDebug
void omtTestDebug(omMemCell cell)
Definition omtTest.c:36
omCheckCells
void omCheckCells(int n, int level, omMemCell_t *cells)
Definition omtTest.c:136
MyRandSpec
int MyRandSpec()
Definition omtTest.c:166
TestDup
void TestDup(omMemCell cell, unsigned long spec)
Definition omtTest.c:228
KEEP_ADDR
#define KEEP_ADDR
Definition omtTest.h:18
GET_TRACK
#define GET_TRACK(spec)
Definition omtTest.h:71
myprintf
#define myprintf(format, args...)
Definition omtTest.h:45
DO_REALLOC
#define DO_REALLOC(spec)
Definition omtTest.h:59
DO_FREE
#define DO_FREE(spec)
Definition omtTest.h:58
DO_DUP
#define DO_DUP(spec)
Definition omtTest.h:60
PAGES_PER_REGION
#define PAGES_PER_REGION
Definition omtTest.h:97
omtTestErrors
int omtTestErrors()
Definition omtTestError.c:37
GET_SIZE
#define GET_SIZE(spec)
Definition omtTest.h:51
myfflush
#define myfflush(what)
Definition omtTest.h:46
CHECK_LEVEL
#define CHECK_LEVEL
Definition omtTest.h:10
END_CHECK_LEVEL
#define END_CHECK_LEVEL
Definition omtTest.h:20
MAX_CELLS
#define MAX_CELLS
Definition omtTest.h:17
omPrintUsedAddrs
#define omPrintUsedAddrs(F, max)
Definition xalloc.h:268
OM_NDEBUG
#define OM_NDEBUG
Definition xalloc.h:10
omPrintStats
#define omPrintStats(F)
Definition xalloc.h:231
omInitInfo
#define omInitInfo()
Definition xalloc.h:228
omPrintInfo
#define omPrintInfo(F)
Definition xalloc.h:232
omPrintBinStats
#define omPrintBinStats(F)
Definition xalloc.h:233
omInitRet_2_Info
#define omInitRet_2_Info(argv0)
Definition xalloc.h:274

## my_exit()

void my_exit | ( |  | ) |

Definition at line 318 of file omtTest.c.

{
printf("\nomtTest Summary: ");
if (errors || missed_errors || used_regions)
{
printf("***FAILED***errors:%d, missed_errors:%d, used_regions:%d, seed=%d\n", errors, missed_errors, used_regions, seed);
if (errors) exit(errors);
if (missed_errors) exit(missed_errors);
if (used_regions) exit(used_regions);
}
else
{
printf("OK\n");
exit(0);
}
}

## MyRandSpec()

int MyRandSpec | ( |  | ) |

Definition at line 166 of file omtTest.c.

{
unsigned long spec = random() + 1;
if (! size_range_number)
{
size_range = size_range << 1;
if (size_range > RANGE_MAX) size_range = RANGE_MIN;
size_range_number = RANGE_MAX / size_range;
}
SET_SIZE(spec, GET_SIZE(spec) & (size_range -1));
size_range_number--;
if (GET_SIZE(spec) == 0) spec++;
return spec;
}
size_range_number
int size_range_number
Definition omtTest.c:164
size_range
int size_range
Definition omtTest.c:163
RANGE_MIN
#define RANGE_MIN
Definition omtTest.h:94
RANGE_MAX
#define RANGE_MAX
Definition omtTest.h:95
SET_SIZE
#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.

{
#if END_CHECK_LEVEL > 0
int l = om_Opts.MinCheck;
int i;
omTestMemory(level);
om_Opts.MinCheck = 1;
for (i=0; i<n; i++)
{
omtTestDebug(&cells[i]);
if (om_ErrorStatus != omError_NoError)
{
errors++;
om_ErrorStatus = omError_NoError;
}
if ((i % 10000) == 0)
{
printf(".");
fflush(stdout);
}
}
om_Opts.MinCheck = l;
#endif
}
level
int level(const CanonicalForm &f)
Definition canonicalform.h:331
l
int l
Definition cfEzgcd.cc:100
omTestMemory
omError_t omTestMemory(int check_level)
Definition omDebug.c:94
om_ErrorStatus
omError_t om_ErrorStatus
Definition omError.c:13
omError_NoError
@ omError_NoError
Definition omError.h:18

## omtGetStickyBin()

omBin omtGetStickyBin | ( | omBin | bin | ) |

Definition at line 275 of file omtTest.c.

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

## omtMergeStickyBins()

void omtMergeStickyBins | ( | omMemCell | cell,
|  | int | n )

Definition at line 283 of file omtTest.c.

{
int i;
omBin bin;
for (i=0; i<n; i++)
{
if (cell[i].orig_bin != NULL)
{
if (omIsOnGList(om_StickyBins, next, cell[i].bin))
omMergeStickyBinIntoBin(cell[i].bin, cell[i].orig_bin);
cell[i].bin = cell[i].orig_bin;
cell[i].orig_bin = NULL;
}
}
bin = om_StickyBins;
while (bin != NULL)
{
if (bin->current_page == om_ZeroPage)
{
omBin next_bin = bin->next;
om_StickyBins = omRemoveFromGList(om_StickyBins, next, bin);
__omFreeBinAddr(bin);
bin = next_bin;
}
else
{
bin = bin->next;
}
}
}
__omFreeBinAddr
#define __omFreeBinAddr(addr)
Definition omAllocPrivate.h:163
omRemoveFromGList
#define omRemoveFromGList(ptr, next, addr)
Definition omList.h:102
omIsOnGList
#define omIsOnGList(ptr, next, addr)
Definition omList.h:100
om_ZeroPage
omBinPage_t om_ZeroPage[]
Definition om_Alloc.c:19
omMergeStickyBinIntoBin
#define omMergeStickyBinIntoBin(A, B)
Definition xalloc.h:275

## omtTestDebug()

void omtTestDebug | ( | omMemCell | cell | ) |

Definition at line 36 of file omtTest.c.

{
size_t size = GET_SIZE(cell->spec);
size_t is_size;
if (om_ErrorStatus != omError_NoError) return;
if (cell->bin != NULL)
{
if (IS_ALIGNED(cell->spec))
omDebugAddrAlignedBin(cell->addr, cell->bin);
else
omDebugAddrBin(cell->addr, cell->bin);
}
else
{
if (IS_ALIGNED(cell->spec))
omDebugAddrAlignedSize(cell->addr, size);
else
omDebugAddrSize(cell->addr, size);
}
if (om_ErrorStatus != omError_NoError) return;
if (!OM_IS_ALIGNED(cell->addr))
{
omReportError(omError_Unknown, omError_NoError, OM_FLR,
"addr:%p is unaligned", cell->addr);
return;
}
if (IS_ALIGNED(cell->spec) && !OM_IS_STRICT_ALIGNED(cell->addr))
{
omReportError(omError_Unknown, omError_NoError, OM_FLR,
"addr:%p is not strict unaligned", cell->addr);
return;
}
is_size = omSizeOfAddr(cell->addr);
if (is_size < size)
{
omReportError(omError_Unknown, omError_NoError, OM_FLR,
"is_size==%u < size==%u", is_size, size);
return;
}
if (is_size >> LOG_SIZEOF_LONG != omSizeWOfAddr(cell->addr))
{
omReportError(omError_Unknown, omError_NoError, OM_FLR,
"is_sizeW==%u < sizeW==%u", is_size >> LOG_SIZEOF_LONG, omSizeWOfAddr(cell->addr));
return;
}
TestAddrContent(cell->addr, (IS_ZERO(cell->spec) ? 0 : cell->spec), is_size);
}
size
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition cf_ops.cc:600
omDebugAddrAlignedBin
#define omDebugAddrAlignedBin
Definition omAllocDecl.h:291
omDebugAddrAlignedSize
#define omDebugAddrAlignedSize
Definition omAllocDecl.h:292
omDebugAddrSize
#define omDebugAddrSize(addr, size)
Definition omAllocDecl.h:313
omDebugAddrBin
#define omDebugAddrBin(addr, bin)
Definition omAllocDecl.h:311
omSizeOfAddr
size_t omSizeOfAddr(const void *addr)
Definition omAllocSystem.c:110
omReportError
omError_t omReportError(omError_t error, omError_t report_error, OM_FLR_DECL, const char *fmt,...)
Definition omError.c:80
omError_Unknown
@ omError_Unknown
Definition omError.h:19
TestAddrContent
void TestAddrContent(void *addr, unsigned long value, size_t size)
Definition omtTest.c:106
IS_ALIGNED
#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.

{
size_t sizeW = OM_ALIGN_SIZE(size) >> LOG_SIZEOF_LONG;
int i;
if (!OM_IS_ALIGNED(addr))
{
omReportError(omError_Unknown, omError_NoError, OM_FLR,
"addr %p unaligned", addr);
return;
}
for (i=0; i<sizeW; i++)
{
if (((unsigned long*)addr)[i] != value)
{
omReportError(omError_Unknown, omError_NoError, OM_FLR,
"word %d modified: is %u should be %u", i, ((unsigned long*)addr)[i], value);
return;
}
}
}

## TestAddrContentEqual()

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

Definition at line 90 of file omtTest.c.

{
int i;
size_t sizeW = OM_ALIGN_SIZE(size) >> LOG_SIZEOF_LONG;
for (i=0; i<sizeW; i++)
{
if (((unsigned long*)s1)[i] != ((unsigned long*)s2)[i])
{
omReportError(omError_Unknown, omError_NoError, OM_FLR,
"s1[%u]==%d != s2[%u]==%d", i, ((unsigned long*)s1)[i], i, ((unsigned long*)s2)[i]);
return;
}
}
}

## TestAlloc()

void TestAlloc | ( | omMemCell | cell,
|  | unsigned long | spec )

Definition at line 182 of file omtTest.c.

{
if (DO_CHECK(spec))
{
if (DO_TRACK(spec))
om_Opts.MinTrack = GET_TRACK(spec);
else
om_Opts.MinTrack = 0;
if (DO_KEEP(spec))
omtTestAllocKeep(cell, spec);
else
omtTestAllocDebug(cell, spec);
}
else
omtTestAlloc(cell, spec);
if (om_ErrorStatus != omError_NoError)
{
errors++;
om_ErrorStatus = omError_NoError;
}
}
DO_KEEP
#define DO_KEEP(spec)
Definition omtTest.h:79
omtTestAlloc
void omtTestAlloc(omMemCell cell, unsigned long spec)
Definition omtTestAlloc.c:33
omtTestAllocKeep
void omtTestAllocKeep(omMemCell cell, unsigned long spec)
omtTestAllocDebug
void omtTestAllocDebug(omMemCell cell, unsigned long spec)
DO_CHECK
#define DO_CHECK(spec)
Definition omtTest.h:63
DO_TRACK
#define DO_TRACK(spec)
Definition omtTest.h:70

## TestDup()

void TestDup | ( | omMemCell | cell,
|  | unsigned long | spec )

Definition at line 228 of file omtTest.c.

{
if (DO_CHECK(spec))
{
if (DO_TRACK(spec))
om_Opts.MinTrack = GET_TRACK(spec);
else
om_Opts.MinTrack = 0;
if (DO_KEEP(spec))
omtTestDupKeep(cell, spec);
else
omtTestDupDebug(cell, spec);
}
else
omtTestDup(cell, spec);
if (om_ErrorStatus != omError_NoError)
{
errors++;
om_ErrorStatus = omError_NoError;
}
}
omtTestDup
void omtTestDup(omMemCell cell, unsigned long spec)
Definition omtTestAlloc.c:348
omtTestDupDebug
void omtTestDupDebug(omMemCell cell, unsigned long spec)
omtTestDupKeep
void omtTestDupKeep(omMemCell cell, unsigned long spec)

## TestFree()

void TestFree | ( | omMemCell | cell | ) |

Definition at line 252 of file omtTest.c.

{
if (cell->addr != NULL)
{
if (DO_FREE_CHECK(cell->spec))
{
if (DO_KEEP(cell->spec))
omtTestFreeKeep(cell);
else
omtTestFreeDebug(cell);
}
else
{
omtTestFree(cell);
}
if (om_ErrorStatus != omError_NoError)
{
errors++;
om_ErrorStatus = omError_NoError;
}
}
}
DO_FREE_CHECK
#define DO_FREE_CHECK(spec)
Definition omtTest.h:64
omtTestFreeDebug
void omtTestFreeDebug(omMemCell cell)
omtTestFree
void omtTestFree(omMemCell cell)
Definition omtTestAlloc.c:135
omtTestFreeKeep
void omtTestFreeKeep(omMemCell cell)

## TestRealloc()

void TestRealloc | ( | omMemCell | cell,
|  | unsigned long | spec )

Definition at line 205 of file omtTest.c.

{
if (DO_CHECK(spec))
{
if (DO_TRACK(spec))
om_Opts.MinTrack = GET_TRACK(spec);
else
om_Opts.MinTrack = 0;
if (DO_KEEP(spec))
omtTestReallocKeep(cell, spec);
else
omtTestReallocDebug(cell, spec);
}
else
omtTestRealloc(cell, spec);
if (om_ErrorStatus != omError_NoError)
{
errors++;
om_ErrorStatus = omError_NoError;
}
}
omtTestReallocDebug
void omtTestReallocDebug(omMemCell cell, unsigned long spec)
omtTestReallocKeep
void omtTestReallocKeep(omMemCell cell, unsigned long spec)
omtTestRealloc
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.