2 make -f Makefile -f - testSuperPool <<
'_eof_'
3 testSuperPool: testSuperPool.cpp libkernel.a
LinearPool.hpp
4 $(CXXCOMPILE) -o $@ $@.cpp libkernel.a -L../../common/util/.libs -lgeneral
27 #include
"SuperPool.hpp"
28 #include
"LinearPool.hpp"
36 for (Uint32
i = 0;
i + 1 < sz;
i++) {
44 for (Uint32
i = 0;
i + 1 < sz;
i++) {
47 assert(a[sz - 1] == c);
54 return (Uint32)random() %
n;
58 random_coprime(Uint32 n)
60 Uint32 prime[] = { 101, 211, 307, 401, 503, 601, 701, 809, 907 };
61 Uint32 count =
sizeof(prime) /
sizeof(prime[0]);
64 Uint32
i = urandom(count);
65 if (n % prime[i] != 0)
71 cmpPtrI(
const void* a,
const void* b)
75 return u.i < v.i ? -1 : u.i > v.i ? +1 : 0;
79 cmpPtrP(
const void* a,
const void* b)
83 return u.p < v.p ? -1 : u.p > v.p ? +1 : 0;
86 static Uint32 loopcount = 3;
94 assert(gp.m_totPages == gp.m_freeList.m_pageCount);
96 Uint32 pageCount = sp.m_totPages;
97 Uint32 perPage = rp.m_recInfo.m_maxPerPage;
98 Uint32 perPool = perPage * pageCount;
99 ndbout <<
"pages=" << pageCount <<
" perpage=" << perPage <<
" perpool=" << perPool << endl;
101 memset(ptrList, 0x1f, perPool *
sizeof(
Ptr<T>));
102 Uint32 verify = 1000;
105 for (loop = 0; loop < loopcount; loop++) {
106 ndbout <<
"loop " << loop << endl;
109 ndbout <<
"seize all" << endl;
110 for (i = 0; i < perPool + 1; i++) {
111 if (verify == 0 || urandom(perPool) < verify)
114 Ptr<T> ptr1 = { 0, RNIL };
115 if (! rp.seize(ptr1))
119 Ptr<T> ptr2 = { 0, ptr1.i };
121 assert(ptr1.i == ptr2.i && ptr1.p == ptr2.p);
125 ndbout <<
"seized " << i << endl;
126 assert(i == perPool);
127 useCount = sp.getRecUseCount(ri);
128 assert(useCount == perPool);
130 ndbout <<
"check dups" << endl;
133 memcpy(ptrList2, ptrList, perPool *
sizeof(
Ptr<T>));
134 qsort(ptrList2, perPool,
sizeof(
Ptr<T>), cmpPtrI);
135 for (i = 1; i < perPool; i++)
136 assert(ptrList2[i - 1].i != ptrList2[i].i);
137 qsort(ptrList2, perPool,
sizeof(
Ptr<T>), cmpPtrP);
138 for (i = 1; i < perPool; i++)
139 assert(ptrList2[i - 1].p != ptrList2[i].p);
143 ndbout <<
"release all" << endl;
144 Uint32 coprime = random_coprime(perPool);
145 for (i = 0; i < perPool; i++) {
146 if (verify == 0 || urandom(perPool) < verify)
156 j = (coprime *
i) % perPool;
160 assert(ptr.i != RNIL && ptr.p != 0);
163 assert(ptr.i == RNIL && ptr.p == 0);
166 useCount = sp.getRecUseCount(ri);
167 assert(useCount == 0);
169 ndbout <<
"seize/release at random" << endl;
170 for (i = 0; i < loopcount * perPool; i++) {
171 if (verify == 0 || urandom(perPool) < verify)
173 j = urandom(perPool);
183 ndbout <<
"used " << ri.m_useCount << endl;
186 ndbout <<
"release all" << endl;
187 for (i = 0; i < perPool; i++) {
188 if (verify == 0 || urandom(perPool) < verify)
198 useCount = sp.getRecUseCount(ri);
199 assert(useCount == 0);
211 ndbout <<
"linear pool test" << endl;
214 for (loop = 0; loop < loopcount; loop++) {
217 bool ret = lp.seize(ptr);
221 assert(ptr.i == count);
226 assert(ptr.p == ptr2.p);
230 ndbout <<
"seized " << count << endl;
241 ndbout <<
"released in order" << endl;
253 ndbout <<
"released in reverse" << endl;
258 int coprime = random_coprime(count);
261 int m = (coprime *
n) % count;
267 ndbout <<
"released at random" << endl;
271 { Uint32 cnt = lp.count(); assert(cnt == 0); }
273 char *used =
new char [10 * count];
274 memset(used,
false,
sizeof(used));
275 Uint32
i, ns = 0, nr = 0;
276 for (i = 0; i < count; i++) {
277 Uint32
index = urandom(10 * count);
284 int i = lp.seize_index(ptr, index);
289 assert(ptr.i == index);
294 assert(ptr.p == ptr2.p);
299 ndbout <<
"random sparse seize " << ns <<
" release " << nr << endl;
301 for (i = 0; i < 10 * count; i++) {
310 ndbout <<
"released " << nr << endl;
311 { Uint32 cnt = lp.count(); assert(cnt == 0); }
315 static Uint32 pageSize = 32768;
316 static Uint32 pageBits = 17;
318 const Uint32 sz1 = 3;
319 const Uint32 sz2 = 4;
320 const Uint32 sz3 = 53;
321 const Uint32 sz4 = 424;
322 const Uint32 sz5 = 5353;
330 template static void sp_test<T1>(
GroupPool& sp);
331 template static void sp_test<T2>(
GroupPool& sp);
332 template static void sp_test<T3>(
GroupPool& sp);
333 template static void sp_test<T4>(
GroupPool& sp);
334 template static void sp_test<T5>(
GroupPool& sp);
336 template static void lp_test<T3>(
GroupPool& sp);
339 main(
int argc,
char** argv)
341 if (argc > 1 && strncmp(argv[1],
"-l", 2) == 0)
342 loopcount = atoi(argv[1] + 2);
346 if (! sp.allocMemory())
349 Uint16 s = (Uint16)getpid();
351 ndbout <<
"rand " << s << endl;
354 while (++count <= 0) {
362 while (++count <= 1) {