source: git/omalloc/omtTest.h @ 5ef600

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