Loading...
Searching...
No Matches
omtTestError.c File Reference
`#include "omtTest.h"`
`#include "omalloc.h"`

Go to the source code of this file.

## Data Structures

struct | LongSpec

## Macros

#define | OM_CHECK 1

## Functions

omMemCell | omFindCell (struct LongSpec spec)
int | omtTestErrors ()

## Data Structure Documentation

## LongSpec

struct LongSpec

Definition at line 6 of file omtTestError.c.

Data Fields
int | MaxSize |
int | MinSize |
int | MinTrack |
int | NotIsBin |
int | NoTrack |
int | NotZero |

## Macro Definition Documentation

## OM_CHECK

#define OM_CHECK 1

Definition at line 2 of file omtTestError.c.

## Function Documentation

## omFindCell()

omMemCell omFindCell | ( | struct LongSpec | spec | ) |

Definition at line 16 of file omtTestError.c.

{
int i;
for (i=0; i<MAX_CELLS; i++)
{
if ((cells[i].addr != NULL) &&
(spec.MinTrack == 0 || (DO_CHECK(cells[i].spec) &&
DO_TRACK(cells[i].spec) &&
GET_TRACK(cells[i].spec) >= spec.MinTrack)) &&
(spec.MinSize == 0 || GET_SIZE(cells[i].spec) >= spec.MinSize) &&
(spec.MaxSize == 0 || GET_SIZE(cells[i].spec) <= spec.MaxSize) &&
(spec.NotIsBin == 0 || cells[i].bin == NULL) &&
(spec.NotZero == 0 || !IS_ZERO(cells[i].spec)) &&
(spec.NoTrack == 0 || !DO_CHECK(cells[i].spec) || !DO_TRACK(cells[i].spec)))
{
return &cells[i];
}
}
return NULL;
}
i
int i
Definition cfEzgcd.cc:132
NULL
#define NULL
Definition omList.c:12
LongSpec::MinTrack
int MinTrack
Definition omtTestError.c:10
cells
omMemCell_t cells[MAX_CELLS]
Definition omtTest.c:11
GET_TRACK
#define GET_TRACK(spec)
Definition omtTest.h:71
IS_ZERO
#define IS_ZERO(spec)
Definition omtTest.h:54
DO_CHECK
#define DO_CHECK(spec)
Definition omtTest.h:63
GET_SIZE
#define GET_SIZE(spec)
Definition omtTest.h:51
DO_TRACK
#define DO_TRACK(spec)
Definition omtTest.h:70
MAX_CELLS
#define MAX_CELLS
Definition omtTest.h:17

## omtTestErrors()

int omtTestErrors | ( |  | ) |

Definition at line 37 of file omtTestError.c.

{
#ifndef OM_NDEBUG
int level = om_Opts.MinCheck;
omError_t error;
struct LongSpec spec;
int missed = 0, alloc;
omMemCell cell = NULL;
printf("omtTestErrors: Start\n");
om_Opts.MinCheck = 2;
for (error = omError_MemoryCorrupted; error < omError_MaxError; error++)
{
om_InternalErrorStatus = omError_NoError;
om_ErrorStatus = omError_NoError;
printf("!!!expect %s\n", omError2Serror(error));
memset(&spec, 0, sizeof(struct LongSpec));
cell = NULL;
alloc = 0;
switch (error)
{
case omError_MemoryCorrupted:
{
spec.MaxSize = OM_MAX_BLOCK_SIZE;
cell = omFindCell(spec);
if (cell != NULL)
{
omBin bin = omGetTopBinOfAddr(cell->addr);
omBinPage last_page = bin->last_page;
omAssume(last_page != NULL);
bin->last_page = NULL;
omDebugBin(cell->bin);
bin->last_page = last_page;
}
else printf("cell not found\n");
break;
}
case omError_NullAddr:
{
omDebugAddr(NULL);
break;
}
case omError_InvalidRangeAddr:
{
omDebugAddr((void*) om_MaxAddr);
break;
}
case omError_FalseAddr:
{
spec.MinSize = 8;
spec.MaxSize = OM_MAX_BLOCK_SIZE;
spec.NoTrack = 1;
cell = omFindCell(spec);
if (cell != NULL)
{
omDebugAddr(cell->addr + SIZEOF_VOIDP);
}
else printf("cell not found\n");
break;
}
case omError_FalseAddrOrMemoryCorrupted:
{
spec.MinSize = 8;
spec.MinTrack = 3;
cell = omFindCell(spec);
if (cell != NULL)
{
omDebugAddr(cell->addr + SIZEOF_VOIDP);
}
else printf("cell not found\n");
break;
}
case omError_WrongSize:
{
spec.MaxSize = OM_MAX_BLOCK_SIZE;
cell = omFindCell(spec);
if (cell != NULL)
{
omDebugAddrSize(cell->addr, OM_MAX_BLOCK_SIZE + 1);
if (om_ErrorStatus != omError_NoError)
{
om_ErrorStatus = omError_NoError;
spec.MaxSize = 0;
spec.MinTrack = 3;
spec.NotIsBin = 1;
spec.MinSize = 2;
cell = omFindCell(spec);
if (cell != NULL)
{
omDebugAddrSize(cell->addr, GET_SIZE(cell->spec) + SIZEOF_OM_ALIGNMENT);
if (om_ErrorStatus != omError_NoError)
{
om_ErrorStatus = omError_NoError;
spec.MaxSize = OM_MAX_BLOCK_SIZE;
spec.MinTrack = 0;
spec.NotIsBin = 0;
cell = omFindCell(spec);
if (cell != NULL)
omDebugBinAddrSize(cell->addr, GET_SIZE(cell->spec) - 1);
else printf("cell not found");
}
}
else printf("cell not found\n");
}
}
else printf("cell not found\n");
break;
}
case omError_FreedAddr:
{
#if KEEP_LEVEL > 0
void* addr = om_AlwaysKeptAddrs;
while (addr != NULL && omIsTrackAddr(addr))
{
addr = *((void**) addr);
}
if (addr != NULL)
{
omFree(addr);
if (om_ErrorStatus == omError_FreedAddr)
{
om_ErrorStatus = omError_NoError;
addr = om_AlwaysKeptAddrs;
while (addr != NULL && ! omIsTrackAddr(addr))
{
addr = *((void**) addr);
}
if (addr != NULL)
{
addr = omAddr_2_OutAddr(addr);
omFree(addr);
}
}
}
if (addr == NULL)
{
printf("addr not found\n");
break;
}
if (om_ErrorStatus != omError_FreedAddr)
break;
#endif
spec.MinTrack = 5;
spec.NotIsBin = 1;
cell = omFindCell(spec);
if (cell != NULL)
{
omFree(cell->addr);
omFree(cell->addr);
alloc = 1;
cell->addr=NULL;
}
else printf("cell not found\n");
break;
}
case omError_FreedAddrOrMemoryCorrupted:
{
spec.MaxSize = OM_MAX_BLOCK_SIZE;
spec.NoTrack = 1;
cell = omFindCell(spec);
if (cell != NULL)
{
omBinPage page = omGetBinPageOfAddr(cell->addr);
omBinPageRegion region = page->region;
page->region = NULL;
om_Opts.MinCheck = 1;
omDebugAddr(cell->addr);
om_Opts.MinCheck = 2;
page->region = region;
}
else printf("cell not found\n");
break;
}
case omError_WrongBin:
{
spec.MaxSize = 32;
spec.NoTrack = 1;
cell = omFindCell(spec);
if (cell != NULL)
{
omDebugAddrBin(cell->addr, &om_StaticBin[OM_MAX_BIN_INDEX]);
}
else printf("cell not found\n");
break;
}
case omError_UnknownBin:
{
spec.MaxSize = OM_MAX_BLOCK_SIZE;
cell = omFindCell(spec);
if (cell != NULL)
{
omDebugAddrBin(cell->addr, (void*) omGetTopBinOfAddr(cell->addr) + SIZEOF_VOIDP);
}
else printf("cell not found\n");
break;
}
case omError_NotBinAddr:
{
spec.NotIsBin = 1;
spec.MinSize = OM_MAX_BLOCK_SIZE + 1;
cell = omFindCell(spec);
if (cell != NULL)
{
omDebugBinAddr(cell->addr);
}
else printf("cell not found");
break;
}
case omError_UnalignedAddr:
{
cell = omFindCell(spec);
if (cell != NULL)
{
omDebugAddr(cell->addr + 1);
}
else printf("cell not found\n");
break;
}
case omError_NullSizeAlloc:
{
void* addr = omAlloc(0);
addr = omRealloc(addr, 0);
omFree(addr);
break;
}
case omError_ListCycleError:
{
void* last = omListLast(om_SpecBin);
if (last != NULL)
{
*((void**)last) = om_SpecBin;
omCheckList(om_SpecBin, 5, omError_NoError, OM_FLR);
*((void**)last) = NULL;
} else printf("last == NULL\n");
break;
}
case omError_SortedListError:
{
if (om_SpecBin != NULL && om_SpecBin->next != NULL)
{
int max_blocks = om_SpecBin->max_blocks;
om_SpecBin->max_blocks = om_SpecBin->next->max_blocks + 1;
omCheckSortedList(om_SpecBin, max_blocks, 5, omError_NoError, OM_FLR);
om_SpecBin->max_blocks = max_blocks;
} else printf("om_SpecBin->next == NULL\n");
break;
}
case omError_KeptAddrListCorrupted:
{
if (om_KeptAddr != NULL)
{
void* last = omListLast(om_KeptAddr);
*((void**)last) = om_KeptAddr;
om_Opts.MinCheck = 5;
omDebugMemory();
om_Opts.MinCheck = 2;
*((void**)last) = NULL;
}
else printf("om_KeptAddr == NULL\n");
break;
}
case omError_FreePattern:
{
if (om_Opts.Keep > 0)
{
spec.MinTrack=3;
spec.NotIsBin = 1;
cell = omFindCell(spec);
if (cell != NULL)
{
void* value;
omFree(cell->addr);
value = *((void**) cell->addr);
*((void**) cell->addr) = value -1;
omDebugMemory();
*((void**) cell->addr) = value;
alloc = 1;
cell->addr = NULL;
}
else printf("cell not found\n");
}
else printf("om_Opts.Keep == 0");
break;
}
case omError_BackPattern:
{
spec.MinTrack = 3;
spec.NotIsBin = 1;
cell = omFindCell(spec);
if (cell != NULL)
{
void* addr = cell->addr + omSizeOfAddr(cell->addr);
void* value = *((void**) addr);
*((void**) addr) = value -1;
omDebugAddr(cell->addr);
*((void**) addr) = value;
}
else printf("cell not found\n");
break;
}
case omError_FrontPattern:
{
spec.MinTrack=3;
cell = omFindCell(spec);
if (cell != NULL)
{
void* addr = cell->addr - SIZEOF_VOIDP;
void* value = *((void**) addr);
*((void**) addr) = value -1;
omDebugAddr(cell->addr);
*((void**) addr) = value;
}
else printf("cell not found\n");
break;
}
case omError_NotString:
{
/* can only test for NULL string */
#if 0
spec.MaxSize = OM_MAX_BLOCK_SIZE;
cell = omFindCell(spec);
if (cell != NULL)
{
char* addr = (char*) cell->addr;
char* s;
memset(cell->addr, 1, omSizeOfAddr(cell->addr));
omDebugAddr(cell->addr);
s = omStrDup(addr);
omFree(s);
InitCellAddrContent(cell);
}
else printf("cell not found\n");
break;
#endif
omStrDup(NULL);
break;
}
case omError_StickyBin:
{
omMergeStickyBinIntoBin(NULL, NULL);
break;
}
default:
printf("No Error test implemented\n");
}
if (om_ErrorStatus != error)
{
printf("---missed %s\n", omError2Serror(error));
missed++;
}
else
{
printf("+++ok %s\n", omError2Serror(error));
}
om_ErrorStatus = omError_NoError;
if (cell != NULL)
{
if (alloc) TestAlloc(cell, cell->spec);
omtTestDebug(cell);
}
else
{
omDebugMemory();
}
if (om_ErrorStatus != omError_NoError)
{
printf("omtTest panik: memory corrupted\n\n");
return -1;
}
printf("\n");
}
printf("omtTestErrors: Summary: missed = %d\n\n", missed);
om_Opts.MinCheck = level;
return missed;
#else
return 0;
#endif
}
level
int level(const CanonicalForm &f)
Definition canonicalform.h:331
s
const CanonicalForm int s
Definition facAbsFact.cc:51
last
STATIC_VAR poly last
Definition hdegree.cc:1138
error
#define error(a)
Definition mpr_numeric.cc:966
omStrDup
#define omStrDup(s)
Definition omAllocDecl.h:263
omAlloc
#define omAlloc(size)
Definition omAllocDecl.h:210
omDebugMemory
#define omDebugMemory()
Definition omAllocDecl.h:318
omDebugBinAddrSize
#define omDebugBinAddrSize(addr, size)
Definition omAllocDecl.h:312
omDebugAddr
#define omDebugAddr(addr)
Definition omAllocDecl.h:314
omDebugBinAddr
#define omDebugBinAddr(addr)
Definition omAllocDecl.h:310
omRealloc
#define omRealloc(addr, size)
Definition omAllocDecl.h:225
omDebugAddrSize
#define omDebugAddrSize(addr, size)
Definition omAllocDecl.h:313
omFree
#define omFree(addr)
Definition omAllocDecl.h:261
omDebugBin
#define omDebugBin(bin)
Definition omAllocDecl.h:317
omDebugAddrBin
#define omDebugAddrBin(addr, bin)
Definition omAllocDecl.h:311
omGetTopBinOfAddr
#define omGetTopBinOfAddr(addr)
Definition omAllocPrivate.h:78
om_StaticBin
omBin_t om_StaticBin[]
omSizeOfAddr
size_t omSizeOfAddr(const void *addr)
Definition omAllocSystem.c:110
omGetBinPageOfAddr
#define omGetBinPageOfAddr(addr)
Definition omBinPage.h:22
om_AlwaysKeptAddrs
void * om_AlwaysKeptAddrs
Definition omDebug.c:31
om_KeptAddr
void * om_KeptAddr
Definition omDebug.c:28
om_MaxAddr
unsigned long om_MaxAddr
Definition omDebugCheck.c:19
omAddr_2_OutAddr
void * omAddr_2_OutAddr(void *addr)
omIsTrackAddr
#define omIsTrackAddr(addr)
Definition omDebug.h:12
om_ErrorStatus
omError_t om_ErrorStatus
Definition omError.c:13
omError2Serror
const char * omError2Serror(omError_t error)
Definition omError.c:65
om_InternalErrorStatus
omError_t om_InternalErrorStatus
Definition omError.c:14
omAssume
#define omAssume(x)
Definition omError.h:85
omError_WrongSize
@ omError_WrongSize
Definition omError.h:26
omError_ListCycleError
@ omError_ListCycleError
Definition omError.h:34
omError_BackPattern
@ omError_BackPattern
Definition omError.h:38
omError_NullAddr
@ omError_NullAddr
Definition omError.h:22
omError_NullSizeAlloc
@ omError_NullSizeAlloc
Definition omError.h:33
omError_MaxError
@ omError_MaxError
Definition omError.h:42
omError_FrontPattern
@ omError_FrontPattern
Definition omError.h:39
omError_UnalignedAddr
@ omError_UnalignedAddr
Definition omError.h:32
omError_MemoryCorrupted
@ omError_MemoryCorrupted
Definition omError.h:21
omError_FreedAddr
@ omError_FreedAddr
Definition omError.h:27
omError_UnknownBin
@ omError_UnknownBin
Definition omError.h:30
omError_FreedAddrOrMemoryCorrupted
@ omError_FreedAddrOrMemoryCorrupted
Definition omError.h:28
omError_NotString
@ omError_NotString
Definition omError.h:40
omError_SortedListError
@ omError_SortedListError
Definition omError.h:35
omError_KeptAddrListCorrupted
@ omError_KeptAddrListCorrupted
Definition omError.h:36
omError_NotBinAddr
@ omError_NotBinAddr
Definition omError.h:31
omError_InvalidRangeAddr
@ omError_InvalidRangeAddr
Definition omError.h:23
omError_FalseAddr
@ omError_FalseAddr
Definition omError.h:24
omError_WrongBin
@ omError_WrongBin
Definition omError.h:29
omError_NoError
@ omError_NoError
Definition omError.h:18
omError_StickyBin
@ omError_StickyBin
Definition omError.h:41
omError_FreePattern
@ omError_FreePattern
Definition omError.h:37
omError_FalseAddrOrMemoryCorrupted
@ omError_FalseAddrOrMemoryCorrupted
Definition omError.h:25
omError_t
enum omError_e omError_t
Definition omError.h:44
omCheckSortedList
#define omCheckSortedList(ptr, what, level, report, OM_FLR_VAL)
Definition omList.h:85
omListLast
#define omListLast(ptr)
Definition omList.h:64
omCheckList
#define omCheckList(ptr, level, report, OM_FLR_VAL)
Definition omList.h:83
om_Opts
omOpts_t om_Opts
Definition omOpts.c:13
omBinPage
omBinPage_t * omBinPage
Definition omStructs.h:16
omBin
omBin_t * omBin
Definition omStructs.h:12
omBinPageRegion
omBinPageRegion_t * omBinPageRegion
Definition omStructs.h:20
OM_MAX_BLOCK_SIZE
#define OM_MAX_BLOCK_SIZE
Definition omTables.c:31
OM_MAX_BIN_INDEX
#define OM_MAX_BIN_INDEX
Definition omTables.h:4
om_SpecBin
omSpecBin om_SpecBin
Definition om_Alloc.c:20
omFindCell
omMemCell omFindCell(struct LongSpec spec)
Definition omtTestError.c:16
LongSpec
Definition omtTestError.c:7
TestAlloc
void TestAlloc(omMemCell cell, unsigned long spec)
Definition omtTest.c:182
omtTestDebug
void omtTestDebug(omMemCell cell)
Definition omtTest.c:36
InitCellAddrContent
void InitCellAddrContent(omMemCell cell)
Definition omtTest.c:130
omMemCell
omMemCell_t * omMemCell
Definition omtTest.h:33
omMergeStickyBinIntoBin
#define omMergeStickyBinIntoBin(A, B)
Definition xalloc.h:275