xref: /haiku/src/tests/kits/support/bblockcache/BlockCacheExerciseTest.cpp (revision 8a8c62d587f69e41548158cf7ecc8d724c230694)
1bfdb37ccSIngo Weinhold /*
2bfdb37ccSIngo Weinhold 	This file tests basic functionality of BBlockCache.
3bfdb37ccSIngo Weinhold */
4bfdb37ccSIngo Weinhold 
5bfdb37ccSIngo Weinhold 
6bfdb37ccSIngo Weinhold #include "BlockCacheExerciseTest.h"
7*8a8c62d5SAxel Dörfler 
8*8a8c62d5SAxel Dörfler #include <stdlib.h>
9*8a8c62d5SAxel Dörfler 
10bfdb37ccSIngo Weinhold #include <BlockCache.h>
11bfdb37ccSIngo Weinhold 
12*8a8c62d5SAxel Dörfler #include "cppunit/TestCaller.h"
13*8a8c62d5SAxel Dörfler 
14bfdb37ccSIngo Weinhold 
15bfdb37ccSIngo Weinhold /*
16bfdb37ccSIngo Weinhold  *  Method: BlockCacheExerciseTest::BlockCacheExerciseTest()
17bfdb37ccSIngo Weinhold  *   Descr: This method is the only constructor for the BlockCacheExerciseTest
18bfdb37ccSIngo Weinhold  *          class.
19bfdb37ccSIngo Weinhold  */
BlockCacheExerciseTest(std::string name)20*8a8c62d5SAxel Dörfler BlockCacheExerciseTest::BlockCacheExerciseTest(std::string name)
21*8a8c62d5SAxel Dörfler 	:
22bfdb37ccSIngo Weinhold 	TestCase(name),
23bfdb37ccSIngo Weinhold 	theCache(NULL),
24bfdb37ccSIngo Weinhold 	numBlocksInCache(0),
25bfdb37ccSIngo Weinhold 	sizeOfBlocksInCache(0),
26bfdb37ccSIngo Weinhold 	sizeOfNonCacheBlocks(0),
27bfdb37ccSIngo Weinhold 	isMallocTest(false)
28bfdb37ccSIngo Weinhold {
29bfdb37ccSIngo Weinhold }
30bfdb37ccSIngo Weinhold 
31bfdb37ccSIngo Weinhold 
32bfdb37ccSIngo Weinhold /*
33bfdb37ccSIngo Weinhold  *  Method: BlockCacheExerciseTest::~BlockCacheExerciseTest()
34bfdb37ccSIngo Weinhold  *   Descr: This method is the destructor for the BlockCacheExerciseTest class.
35bfdb37ccSIngo Weinhold  */
~BlockCacheExerciseTest()36bfdb37ccSIngo Weinhold BlockCacheExerciseTest::~BlockCacheExerciseTest()
37bfdb37ccSIngo Weinhold {
38bfdb37ccSIngo Weinhold }
39bfdb37ccSIngo Weinhold 
40bfdb37ccSIngo Weinhold 
41bfdb37ccSIngo Weinhold /*
42bfdb37ccSIngo Weinhold  *  Method:  BlockCacheExerciseTest::TestBlockCache()
43bfdb37ccSIngo Weinhold  *   Descr:  This method performs the tests on a particular BBlockCache.
44bfdb37ccSIngo Weinhold  *           The goal of the method is to perform the following basic
45bfdb37ccSIngo Weinhold  *           sequence:
46bfdb37ccSIngo Weinhold  *             1. Get (numBlocksInCache + 10) blocks of "cache size" from the
47bfdb37ccSIngo Weinhold  *                BBlockCache.  By doing this, we can guarantee that the cache
48bfdb37ccSIngo Weinhold  *                has been exhausted and some elements are allocated to
49bfdb37ccSIngo Weinhold  *                satisfy the caller.  Then, they are all returned to the
50bfdb37ccSIngo Weinhold  *                cache in most recent block to oldest block order.  This
51bfdb37ccSIngo Weinhold  *                confirms that regardless whether the block was initially
52bfdb37ccSIngo Weinhold  *                part of the cache or created because the cache was empty,
53bfdb37ccSIngo Weinhold  *                once it is returned to the cache, it is just placed on the
54bfdb37ccSIngo Weinhold  *                cache.  Imagine a cache of 4 blocks.  Initally, the cache
55bfdb37ccSIngo Weinhold  *                has the following blocks:
56bfdb37ccSIngo Weinhold  *                   A, B, C, D
57bfdb37ccSIngo Weinhold  *                If five blocks are gotten from the cache, the caller will get
58bfdb37ccSIngo Weinhold  *                   A, B, C, D, E
59bfdb37ccSIngo Weinhold  *                However, E wasn't initially part of the cache.  It was allocated
60bfdb37ccSIngo Weinhold  *                dynamically to satisfy the caller's request because the cache
61bfdb37ccSIngo Weinhold  *                was empty.  Now, if they are returned in the order E, D, C, B, A
62bfdb37ccSIngo Weinhold  *                the cache will have the following blocks available in it:
63bfdb37ccSIngo Weinhold  *                   B, C, D, E
64bfdb37ccSIngo Weinhold  *                When A is returned, the cache will find there is no more room
65bfdb37ccSIngo Weinhold  *                for more free blocks and it will be freed.  This is the
66bfdb37ccSIngo Weinhold  *                behaviour which is confirmed initially.
67bfdb37ccSIngo Weinhold  *
68bfdb37ccSIngo Weinhold  *             2. After this is done, the cache is just "exercised".  The following
69bfdb37ccSIngo Weinhold  *                is done "numBlocksInCache" times:
70bfdb37ccSIngo Weinhold  *                  - 4 "cache sized" blocks are gotten from the cache
71bfdb37ccSIngo Weinhold  *                  - 4 "non-cache sized" blocks are gotten from the cache
72bfdb37ccSIngo Weinhold  *                  - 1 "cache sized" block is returned back to the cache
73bfdb37ccSIngo Weinhold  *                  - 1 "non-cache sized" block is returned back to the cache
74bfdb37ccSIngo Weinhold  *                  - 1 "cache sized" block is freed and not returned to the cache
75bfdb37ccSIngo Weinhold  *                  - 1 "non-cache sized" block is freed and not returned to the
76bfdb37ccSIngo Weinhold  *                    cache (but even if given to the BBlockCache, it would just
77bfdb37ccSIngo Weinhold  *                    be freed anyhow)
78bfdb37ccSIngo Weinhold  *                 What this means is that everytime through the loop, 2 "cache sized"
79bfdb37ccSIngo Weinhold  *                 and 2 "non-cache sized" blocks are kept in memory.  At the end,
80bfdb37ccSIngo Weinhold  *                 2 * numBlocksInCache items of size "cache size" and "non cache size"
81bfdb37ccSIngo Weinhold  *                 will exist.
82bfdb37ccSIngo Weinhold  *
83bfdb37ccSIngo Weinhold  *                 Then, numBlocksInCache / 4 items are returned to the cache and
84bfdb37ccSIngo Weinhold  *                 numBlocksInCache / 4 are freed.  This ensures at the end of the
85bfdb37ccSIngo Weinhold  *                 test that there are some available blocks in the cache.
86bfdb37ccSIngo Weinhold  *
87bfdb37ccSIngo Weinhold  *           The sum total of these actions test the BBlockCache.
88bfdb37ccSIngo Weinhold  */
89*8a8c62d5SAxel Dörfler void
TestBlockCache(void)90*8a8c62d5SAxel Dörfler BlockCacheExerciseTest::TestBlockCache(void)
91bfdb37ccSIngo Weinhold {
92bfdb37ccSIngo Weinhold 
93bfdb37ccSIngo Weinhold 	// First get all items from the cache plus ten more
94bfdb37ccSIngo Weinhold 	for (int i = 0; i < numBlocksInCache + 10; i++) {
95bfdb37ccSIngo Weinhold 		GetBlock(sizeOfBlocksInCache);
96bfdb37ccSIngo Weinhold 	}
97bfdb37ccSIngo Weinhold 
98bfdb37ccSIngo Weinhold 	// Put them all back in reverse order to confirm 1 from above
99bfdb37ccSIngo Weinhold 	while (!usedList.IsEmpty()) {
100bfdb37ccSIngo Weinhold 		SaveBlock(usedList.LastItem(), sizeOfBlocksInCache);
101bfdb37ccSIngo Weinhold 	}
102bfdb37ccSIngo Weinhold 
103bfdb37ccSIngo Weinhold 	// Get a bunch of blocks and send some back to the cache
104bfdb37ccSIngo Weinhold 	// to confirm 2 from above.
105bfdb37ccSIngo Weinhold 	for (int i = 0; i < numBlocksInCache; i++) {
106bfdb37ccSIngo Weinhold 		GetBlock(sizeOfBlocksInCache);
107bfdb37ccSIngo Weinhold 		GetBlock(sizeOfBlocksInCache);
108bfdb37ccSIngo Weinhold 		GetBlock(sizeOfNonCacheBlocks);
109bfdb37ccSIngo Weinhold 		GetBlock(sizeOfNonCacheBlocks);
110bfdb37ccSIngo Weinhold 
111bfdb37ccSIngo Weinhold 		// We send one back from the middle of the lists so
112bfdb37ccSIngo Weinhold 		// the most recent block is not the one returned.
113bfdb37ccSIngo Weinhold 		SaveBlock(usedList.ItemAt(usedList.CountItems() / 2),
114bfdb37ccSIngo Weinhold 		          sizeOfBlocksInCache);
115bfdb37ccSIngo Weinhold 		SaveBlock(nonCacheList.ItemAt(nonCacheList.CountItems() / 2),
116bfdb37ccSIngo Weinhold 		          sizeOfNonCacheBlocks);
117bfdb37ccSIngo Weinhold 
118bfdb37ccSIngo Weinhold 		GetBlock(sizeOfBlocksInCache);
119bfdb37ccSIngo Weinhold 		GetBlock(sizeOfBlocksInCache);
120bfdb37ccSIngo Weinhold 		GetBlock(sizeOfNonCacheBlocks);
121bfdb37ccSIngo Weinhold 		GetBlock(sizeOfNonCacheBlocks);
122bfdb37ccSIngo Weinhold 
123bfdb37ccSIngo Weinhold 		// We free one from the middle of the lists so the
124bfdb37ccSIngo Weinhold 		// most recent block is not the one freed.
125bfdb37ccSIngo Weinhold 		FreeBlock(usedList.ItemAt(usedList.CountItems() / 2),
126bfdb37ccSIngo Weinhold 		          sizeOfBlocksInCache);
127bfdb37ccSIngo Weinhold 		FreeBlock(nonCacheList.ItemAt(nonCacheList.CountItems() / 2),
128bfdb37ccSIngo Weinhold 		          sizeOfNonCacheBlocks);
129bfdb37ccSIngo Weinhold 		}
130bfdb37ccSIngo Weinhold 
131bfdb37ccSIngo Weinhold 	// Now, send some blocks back to the cache and free some blocks
132bfdb37ccSIngo Weinhold 	// so the cache is not empty at the end of the test.
133bfdb37ccSIngo Weinhold 	for (int i = 0; i < numBlocksInCache / 4; i++) {
134bfdb37ccSIngo Weinhold 		// Return the blocks which are 2/3s of the way through the
135bfdb37ccSIngo Weinhold 		// lists.
136bfdb37ccSIngo Weinhold 		SaveBlock(usedList.ItemAt(usedList.CountItems() * 2 / 3),
137bfdb37ccSIngo Weinhold 		          sizeOfBlocksInCache);
138bfdb37ccSIngo Weinhold 		SaveBlock(nonCacheList.ItemAt(nonCacheList.CountItems() * 2 / 3),
139bfdb37ccSIngo Weinhold 		          sizeOfNonCacheBlocks);
140bfdb37ccSIngo Weinhold 
141bfdb37ccSIngo Weinhold 		// Free the blocks which are 1/3 of the way through the lists.
142bfdb37ccSIngo Weinhold 		FreeBlock(usedList.ItemAt(usedList.CountItems() / 3),
143bfdb37ccSIngo Weinhold 		          sizeOfBlocksInCache);
144bfdb37ccSIngo Weinhold 		FreeBlock(nonCacheList.ItemAt(nonCacheList.CountItems() / 3),
145bfdb37ccSIngo Weinhold 		          sizeOfNonCacheBlocks);
146bfdb37ccSIngo Weinhold 	}
147bfdb37ccSIngo Weinhold }
148bfdb37ccSIngo Weinhold 
149bfdb37ccSIngo Weinhold 
150bfdb37ccSIngo Weinhold /*
151bfdb37ccSIngo Weinhold  *  Method:  BlockCacheExerciseTest::BuildLists()
152bfdb37ccSIngo Weinhold  *   Descr:  This method gets all of the blocks from the cache in order to
153bfdb37ccSIngo Weinhold  *           track them for future tests.  The assumption here is that the
154bfdb37ccSIngo Weinhold  *           blocks are not deallocated and reallocated in the implementation
155bfdb37ccSIngo Weinhold  *           of BBlockCache.  Given the purpose is to provide a cheap way to
156bfdb37ccSIngo Weinhold  *           access allocated memory without resorting to malloc()'s or new's,
157bfdb37ccSIngo Weinhold  *           this should be a fair assumption.
158bfdb37ccSIngo Weinhold  */
159*8a8c62d5SAxel Dörfler void
BuildLists()160*8a8c62d5SAxel Dörfler BlockCacheExerciseTest::BuildLists()
161bfdb37ccSIngo Weinhold {
162bfdb37ccSIngo Weinhold 	freeList.MakeEmpty();
163bfdb37ccSIngo Weinhold 	usedList.MakeEmpty();
164bfdb37ccSIngo Weinhold 	nonCacheList.MakeEmpty();
165bfdb37ccSIngo Weinhold 
166bfdb37ccSIngo Weinhold 	for(int i = 0; i < numBlocksInCache; i++) {
167bfdb37ccSIngo Weinhold 		freeList.AddItem(theCache->Get(sizeOfBlocksInCache));
168bfdb37ccSIngo Weinhold 	}
169bfdb37ccSIngo Weinhold 	for(int i = 0; i < numBlocksInCache; i++) {
170bfdb37ccSIngo Weinhold 		theCache->Save(freeList.ItemAt(i), sizeOfBlocksInCache);
171bfdb37ccSIngo Weinhold 	}
172bfdb37ccSIngo Weinhold }
173bfdb37ccSIngo Weinhold 
174bfdb37ccSIngo Weinhold 
175bfdb37ccSIngo Weinhold /*
176bfdb37ccSIngo Weinhold  *  Method:  BlockCacheExerciseTest::GetBlock()
177bfdb37ccSIngo Weinhold  *   Descr:  This method returns a pointer from the BBlockCache, checking
178bfdb37ccSIngo Weinhold  *           the value before passing it to the caller.
179bfdb37ccSIngo Weinhold  */
180*8a8c62d5SAxel Dörfler void *
GetBlock(size_t blockSize)181*8a8c62d5SAxel Dörfler BlockCacheExerciseTest::GetBlock(size_t blockSize)
182bfdb37ccSIngo Weinhold {
183bfdb37ccSIngo Weinhold 	void *thePtr = theCache->Get(blockSize);
184bfdb37ccSIngo Weinhold 
185bfdb37ccSIngo Weinhold 	// This new pointer should not be one which we already
186bfdb37ccSIngo Weinhold 	// have from the BBlockCache which we haven't given back
187bfdb37ccSIngo Weinhold 	// yet.
188*8a8c62d5SAxel Dörfler 	CPPUNIT_ASSERT(!usedList.HasItem(thePtr));
189*8a8c62d5SAxel Dörfler 	CPPUNIT_ASSERT(!nonCacheList.HasItem(thePtr));
190bfdb37ccSIngo Weinhold 
191bfdb37ccSIngo Weinhold 	if (blockSize == sizeOfBlocksInCache) {
192bfdb37ccSIngo Weinhold 		// If this block was one which could have come from the
193bfdb37ccSIngo Weinhold 		// cache and there are free items on the cache, it
194bfdb37ccSIngo Weinhold 		// should be one of those free blocks.
195bfdb37ccSIngo Weinhold 		if (freeList.CountItems() > 0) {
196*8a8c62d5SAxel Dörfler 			CPPUNIT_ASSERT(freeList.RemoveItem(thePtr));
197bfdb37ccSIngo Weinhold 		}
198*8a8c62d5SAxel Dörfler 		CPPUNIT_ASSERT(usedList.AddItem(thePtr));
199bfdb37ccSIngo Weinhold 	} else {
200bfdb37ccSIngo Weinhold 		// A "non-cache sized" block should never come from the
201bfdb37ccSIngo Weinhold 		// free list.
202*8a8c62d5SAxel Dörfler 		CPPUNIT_ASSERT(!freeList.HasItem(thePtr));
203*8a8c62d5SAxel Dörfler 		CPPUNIT_ASSERT(nonCacheList.AddItem(thePtr));
204bfdb37ccSIngo Weinhold 	}
205bfdb37ccSIngo Weinhold 	return(thePtr);
206bfdb37ccSIngo Weinhold }
207bfdb37ccSIngo Weinhold 
208bfdb37ccSIngo Weinhold 
209bfdb37ccSIngo Weinhold /*
210bfdb37ccSIngo Weinhold  *  Method:  BlockCacheExerciseTest::SavedCacheBlock()
211bfdb37ccSIngo Weinhold  *   Descr:  This method passes the pointer back to the BBlockCache
212bfdb37ccSIngo Weinhold  *           and checks the sanity of the lists.
213bfdb37ccSIngo Weinhold  */
214*8a8c62d5SAxel Dörfler void
SaveBlock(void * thePtr,size_t blockSize)215*8a8c62d5SAxel Dörfler BlockCacheExerciseTest::SaveBlock(void *thePtr, size_t blockSize)
216bfdb37ccSIngo Weinhold {
217bfdb37ccSIngo Weinhold 	// The memory block being returned to the cache should
218bfdb37ccSIngo Weinhold 	// not already be free.
219*8a8c62d5SAxel Dörfler 	CPPUNIT_ASSERT(!freeList.HasItem(thePtr));
220bfdb37ccSIngo Weinhold 
221bfdb37ccSIngo Weinhold 	if (blockSize == sizeOfBlocksInCache) {
222bfdb37ccSIngo Weinhold 		// If there is room on the free list, when this block
223bfdb37ccSIngo Weinhold 		// is returned to the cache, it will be put on the
224bfdb37ccSIngo Weinhold 		// free list.  Therefore we will also track it as
225bfdb37ccSIngo Weinhold 		// a free block on the cache.
226bfdb37ccSIngo Weinhold 		if (freeList.CountItems() < numBlocksInCache) {
227*8a8c62d5SAxel Dörfler 			CPPUNIT_ASSERT(freeList.AddItem(thePtr));
228bfdb37ccSIngo Weinhold 		}
229bfdb37ccSIngo Weinhold 
230bfdb37ccSIngo Weinhold 		// This block should not be on the non-cache list but it
231bfdb37ccSIngo Weinhold 		// should be on the used list.
232*8a8c62d5SAxel Dörfler 		CPPUNIT_ASSERT(!nonCacheList.HasItem(thePtr));
233*8a8c62d5SAxel Dörfler 		CPPUNIT_ASSERT(usedList.RemoveItem(thePtr));
234bfdb37ccSIngo Weinhold 	} else {
235bfdb37ccSIngo Weinhold 		// This block should not be on the used list but it should
236bfdb37ccSIngo Weinhold 		// be on the non-cache list.
237*8a8c62d5SAxel Dörfler 		CPPUNIT_ASSERT(!usedList.HasItem(thePtr));
238*8a8c62d5SAxel Dörfler 		CPPUNIT_ASSERT(nonCacheList.RemoveItem(thePtr));
239bfdb37ccSIngo Weinhold 	}
240bfdb37ccSIngo Weinhold 	theCache->Save(thePtr, blockSize);
241bfdb37ccSIngo Weinhold }
242bfdb37ccSIngo Weinhold 
243bfdb37ccSIngo Weinhold 
244bfdb37ccSIngo Weinhold /*
245bfdb37ccSIngo Weinhold  *  Method:  BlockCacheExerciseTest::FreeBlock()
246bfdb37ccSIngo Weinhold  *   Descr:  This method frees the block directly using delete[] or free(),
247bfdb37ccSIngo Weinhold  *           checking the sanity of the lists as it does the operation.
248bfdb37ccSIngo Weinhold  */
249*8a8c62d5SAxel Dörfler void
FreeBlock(void * thePtr,size_t blockSize)250*8a8c62d5SAxel Dörfler BlockCacheExerciseTest::FreeBlock(void *thePtr, size_t blockSize)
251bfdb37ccSIngo Weinhold {
252bfdb37ccSIngo Weinhold 	// The block being freed should not already have been
253bfdb37ccSIngo Weinhold 	// returned to the cache.
254*8a8c62d5SAxel Dörfler 	CPPUNIT_ASSERT(!freeList.HasItem(thePtr));
255bfdb37ccSIngo Weinhold 
256bfdb37ccSIngo Weinhold 	if (blockSize == sizeOfBlocksInCache) {
257bfdb37ccSIngo Weinhold 		// This block should not be on the non-cache list but it
258bfdb37ccSIngo Weinhold 		// should be on the used list.
259*8a8c62d5SAxel Dörfler 		CPPUNIT_ASSERT(!nonCacheList.HasItem(thePtr));
260*8a8c62d5SAxel Dörfler 		CPPUNIT_ASSERT(usedList.RemoveItem(thePtr));
261bfdb37ccSIngo Weinhold 	} else {
262bfdb37ccSIngo Weinhold 		// This block should not be on the used list but it should
263bfdb37ccSIngo Weinhold 		// be on the non-cache list.
264*8a8c62d5SAxel Dörfler 		CPPUNIT_ASSERT(!usedList.HasItem(thePtr));
265*8a8c62d5SAxel Dörfler 		CPPUNIT_ASSERT(nonCacheList.RemoveItem(thePtr));
266bfdb37ccSIngo Weinhold 	}
267bfdb37ccSIngo Weinhold 	if (isMallocTest) {
268bfdb37ccSIngo Weinhold 		free(thePtr);
269bfdb37ccSIngo Weinhold 	} else {
2709ec6636cSshatty 		delete[] (uint8*)thePtr;
271bfdb37ccSIngo Weinhold 	}
272bfdb37ccSIngo Weinhold }
273bfdb37ccSIngo Weinhold 
274bfdb37ccSIngo Weinhold 
275bfdb37ccSIngo Weinhold /*
276bfdb37ccSIngo Weinhold  *  Method:  BlockCacheExerciseTest::PerformTest()
277bfdb37ccSIngo Weinhold  *   Descr:  This method performs the tests on a series of BBlockCache
278bfdb37ccSIngo Weinhold  *           instances.  It performs the tests with a series of
279bfdb37ccSIngo Weinhold  *           block sizes and numbers of blocks.  Also, it does the
280bfdb37ccSIngo Weinhold  *           test using a B_OBJECT_CACHE and B_MALLOC_CACHE type
281bfdb37ccSIngo Weinhold  *           cache.  For each individual BBlockCache to be tested, it:
282bfdb37ccSIngo Weinhold  *             1. Queries the cache to find out the blocks which are
283bfdb37ccSIngo Weinhold  *                on it.
284bfdb37ccSIngo Weinhold  *             2. Performs the test.
285bfdb37ccSIngo Weinhold  *             3. Frees all blocks left after the test to prevent
286bfdb37ccSIngo Weinhold  *                memory leaks.
287bfdb37ccSIngo Weinhold  */
288*8a8c62d5SAxel Dörfler void
PerformTest(void)289*8a8c62d5SAxel Dörfler BlockCacheExerciseTest::PerformTest(void)
290bfdb37ccSIngo Weinhold {
291bfdb37ccSIngo Weinhold 	for (numBlocksInCache = 8; numBlocksInCache < 513; numBlocksInCache *= 2) {
292bfdb37ccSIngo Weinhold 		for (sizeOfBlocksInCache = 13; sizeOfBlocksInCache < 9478; sizeOfBlocksInCache *= 3) {
293bfdb37ccSIngo Weinhold 
294bfdb37ccSIngo Weinhold 			// To test getting blocks which are not from the cache,
295bfdb37ccSIngo Weinhold 			// we will get blocks of 6 bytes less than the size of
296bfdb37ccSIngo Weinhold 			// the blocks on the cache.
297bfdb37ccSIngo Weinhold 			sizeOfNonCacheBlocks = sizeOfBlocksInCache - 6;
298bfdb37ccSIngo Weinhold 
299bfdb37ccSIngo Weinhold 			isMallocTest = false;
300bfdb37ccSIngo Weinhold 			theCache = new BBlockCache(numBlocksInCache, sizeOfBlocksInCache, B_OBJECT_CACHE);
301*8a8c62d5SAxel Dörfler 			CPPUNIT_ASSERT(theCache != NULL);
302bfdb37ccSIngo Weinhold 
303bfdb37ccSIngo Weinhold 			// Query the cache and determine the blocks in it.
304bfdb37ccSIngo Weinhold 			BuildLists();
305bfdb37ccSIngo Weinhold 			// Perform the test on this instance.
306bfdb37ccSIngo Weinhold 			TestBlockCache();
307bfdb37ccSIngo Weinhold 			delete theCache;
308bfdb37ccSIngo Weinhold 			// Clean up remaining memory.
309bfdb37ccSIngo Weinhold 			while (!usedList.IsEmpty()) {
310bfdb37ccSIngo Weinhold 				FreeBlock(usedList.LastItem(), sizeOfBlocksInCache);
311bfdb37ccSIngo Weinhold 			}
312bfdb37ccSIngo Weinhold 			while (!nonCacheList.IsEmpty()) {
313bfdb37ccSIngo Weinhold 				FreeBlock(nonCacheList.LastItem(), sizeOfNonCacheBlocks);
314bfdb37ccSIngo Weinhold 			}
315bfdb37ccSIngo Weinhold 
316bfdb37ccSIngo Weinhold 			isMallocTest = true;
317bfdb37ccSIngo Weinhold 			theCache = new BBlockCache(numBlocksInCache, sizeOfBlocksInCache, B_MALLOC_CACHE);
318*8a8c62d5SAxel Dörfler 			CPPUNIT_ASSERT(theCache != NULL);
319bfdb37ccSIngo Weinhold 
320bfdb37ccSIngo Weinhold 			// Query the cache and determine the blocks in it.
321bfdb37ccSIngo Weinhold 			BuildLists();
322bfdb37ccSIngo Weinhold 			// Perform the test on this instance.
323bfdb37ccSIngo Weinhold 			TestBlockCache();
324bfdb37ccSIngo Weinhold 			delete theCache;
325bfdb37ccSIngo Weinhold 			// Clean up remaining memory.
326bfdb37ccSIngo Weinhold 			while (!usedList.IsEmpty()) {
327bfdb37ccSIngo Weinhold 				FreeBlock(usedList.LastItem(), sizeOfBlocksInCache);
328bfdb37ccSIngo Weinhold 			}
329bfdb37ccSIngo Weinhold 			while (!nonCacheList.IsEmpty()) {
330bfdb37ccSIngo Weinhold 				FreeBlock(nonCacheList.LastItem(), sizeOfNonCacheBlocks);
331bfdb37ccSIngo Weinhold 			}
332bfdb37ccSIngo Weinhold 		}
333bfdb37ccSIngo Weinhold 	}
334bfdb37ccSIngo Weinhold }
335bfdb37ccSIngo Weinhold 
336bfdb37ccSIngo Weinhold 
337bfdb37ccSIngo Weinhold /*
338bfdb37ccSIngo Weinhold  *  Method:  BlockCacheExerciseTest::suite()
339bfdb37ccSIngo Weinhold  *   Descr:  This static member function returns a test caller for performing
340bfdb37ccSIngo Weinhold  *           the "BlockCacheExerciseTest" test.
341bfdb37ccSIngo Weinhold  */
suite()342*8a8c62d5SAxel Dörfler CppUnit::Test *BlockCacheExerciseTest::suite()
343bfdb37ccSIngo Weinhold {
344bfdb37ccSIngo Weinhold 	typedef CppUnit::TestCaller<BlockCacheExerciseTest>
345bfdb37ccSIngo Weinhold 		BlockCacheExerciseTestCaller;
346bfdb37ccSIngo Weinhold 
347bfdb37ccSIngo Weinhold 	return(new BlockCacheExerciseTestCaller("BBlockCache::Exercise Test", &BlockCacheExerciseTest::PerformTest));
348bfdb37ccSIngo Weinhold }
349bfdb37ccSIngo Weinhold 
350bfdb37ccSIngo Weinhold 
351bfdb37ccSIngo Weinhold 
352