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