source: git/omalloc/omtTest.h @ 8d0069

spielwiese
Last change on this file since 8d0069 was 8d0069, checked in by Hans Schönemann <hannes@…>, 23 years ago
*hannes: mylimits.h.in git-svn-id: file:///usr/local/Singular/svn/trunk@5332 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 4.3 KB
Line 
1#include <time.h>
2#include <string.h>
3#include <mylimits.h>
4
5#define TRACK_LEVEL   1
6#define CHECK_LEVEL   1
7// keep every ith address: define to 0 if no keeping
8#define KEEP_LEVEL    20
9// #define KEEP_LEVEL    0
10
11// #define MAX_CELLS  500000   
12// #define MAX_CELLS     100000
13#define MAX_CELLS     100000
14#define KEEP_ADDR     100
15// #define KEEP_ADDR     0
16#define END_CHECK_LEVEL 5
17
18#ifdef OM_TEST_MALLOC
19#define OM_EMULATE_OMALLOC
20#endif
21
22
23#include "omStructs.h"
24
25struct omMemCell_s
26{
27  void* addr;
28  omBin bin;
29  unsigned long spec;
30  omBin orig_bin;
31};
32
33typedef struct omMemCell_s omMemCell_t;
34typedef omMemCell_t* omMemCell;
35
36extern omMemCell_t cells[];
37void TestAlloc(omMemCell cell, unsigned long spec);
38void TestRealloc(omMemCell cell, unsigned long spec);
39void TestFree(omMemCell cell);
40
41#if CHECK_LEVEL > 2
42#define myprintf(format, args...) \
43  printf(format, ## args)
44#define myfflush(what) fflush(what)
45#else
46#define myprintf(format, args...) ((void) 0)
47#define myfflush(what)            ((void) 0)
48#endif
49
50#define IS_STICKY_BIN(spec) (spec & 1)
51// #define IS_STICKY_BIN(spec) (0)
52#define GET_SIZE(spec)      (spec & ((((unsigned long) 1) << 14) -1))
53#define SET_SIZE(spec, size) spec = ((spec & ~((((unsigned long) 1) << 14) -1)) | (size))
54#define IS_ALIGNED(spec)    (spec & (((unsigned long) 1) << 15))
55#define IS_ZERO(spec)       (spec & (((unsigned long) 1) << 16))
56#define IS_BIN(spec)        (spec & (((unsigned long) 1) << 17))
57#define IS_SPEC_BIN(spec)   (spec & (((unsigned long) 1) << 18))
58#define IS_INLINE(spec)     (spec & (((unsigned long) 1) << 19))
59#define DO_FREE(spec)       (!(spec & (((unsigned long) 1) << 20))  && !(spec & (((unsigned long) 1) << 21)))
60#define DO_REALLOC(spec)    ((spec & (((unsigned long) 1) << 20))  && (spec & (((unsigned long) 1) << 21)))
61#define DO_DUP(spec)        ((spec & (((unsigned long) 1) << 20)) && ! (spec & (((unsigned long) 1) << 21)))
62#if CHECK_LEVEL > 0
63//#define DO_CHECK(spec)      1
64#define DO_CHECK(spec)      (spec & (((unsigned long) 1) << 22))
65#define DO_FREE_CHECK(spec) (spec & (((unsigned long) 1) << 23))
66#else
67#define DO_CHECK(spec)      0
68#define DO_FREE_CHECK(spec) 0
69#endif
70#if CHECK_LEVEL > 0 && TRACK_LEVEL > 0
71#define DO_TRACK(spec)      (spec & (((unsigned long) 1) << 24))
72#define GET_TRACK(spec)     (((spec & ((((unsigned long) 1) << 27) | (((unsigned long) 1) << 26) | (((unsigned long) 1) << 25))) >> 25) % 5) + TRACK_LEVEL
73// #define DO_TRACK(spec)      TRACK_LEVEL
74// #define GET_TRACK(spec)     TRACK_LEVEL
75#else
76#define DO_TRACK(spec)      0
77#define GET_TRACK(spec)     0
78#endif
79#if KEEP_LEVEL > 0
80#define DO_KEEP(spec)           (DO_CHECK(spec) && (spec % KEEP_LEVEL == 0))
81#define DO_FREE_KEEP(spec)      (DO_FREE_CHECK(spec) && (spec % KEEP_LEVEL == 0))
82#else
83#define DO_KEEP(spec)       0
84#define DO_FREE_KEEP(spec)  0
85#endif
86
87#define IS_FREE_SIZE(spec)      (spec & (((unsigned long) 1) << 28))
88#define IS_FREE_BIN(spec)       (spec & (((unsigned long) 1) << 29))
89#define IS_SLOPPY(spec)         (spec & (((unsigned long) 1) << 30))
90#define IS_FREE_BINADDR(spec)   (spec & (((unsigned long) 1) << 31))
91
92
93#define SPEC_MAX   ULONG_MAX
94#define SIZE_MAX  ((((unsigned long) 1) << 14) -1)
95#define RANGE_MIN (((unsigned long) 1) << 6)
96#define RANGE_MAX (((unsigned long) 1) << 14)
97
98#define PAGES_PER_REGION 128
99
100void omtTestAlloc(omMemCell cell, unsigned long spec);
101void omtTestRealloc(omMemCell cell, unsigned long spec);
102void omtTestDup(omMemCell cell, unsigned long spec);
103void omtTestFree(omMemCell cell);
104
105void omtTestAllocDebug(omMemCell cell, unsigned long spec);
106void omtTestReallocDebug(omMemCell cell, unsigned long spec);
107void omtTestDupDebug(omMemCell cell, unsigned long spec);
108void omtTestFreeDebug(omMemCell cell);
109
110void omtTestAllocKeep(omMemCell cell, unsigned long spec);
111void omtTestReallocKeep(omMemCell cell, unsigned long spec);
112void omtTestDupKeep(omMemCell cell, unsigned long spec);
113void omtTestFreeKeep(omMemCell cell);
114
115void InitCellAddrContent(omMemCell cell);
116int omtTestErrors();
117omBin omtGetStickyBin(omBin bin);
118
119#if CHECK_LEVEL > 0
120void omtTestDebug(omMemCell cell);
121void TestAddrContent(void* addr, unsigned long value, size_t size);
122void TestAddrContentEqual(void* s1, void* s2, size_t size);
123#else
124#define omtTestDebug(cell)               ((void)0)
125#define TestAddrContent(a,v,s)          ((void)0)
126#define TestAddrContentEqual(s1, s2, s) ((void)0)
127#endif
Note: See TracBrowser for help on using the repository browser.