kerneltest/e32test/heap/t_heapdl.cpp
changeset 259 57b9594f5772
parent 109 b3a1d9898418
equal deleted inserted replaced
247:d8d70de2bd36 259:57b9594f5772
    26 #include "dla.h"
    26 #include "dla.h"
    27 #include "slab.h"
    27 #include "slab.h"
    28 #include "page_alloc.h"
    28 #include "page_alloc.h"
    29 #include "heap_hybrid.h"
    29 #include "heap_hybrid.h"
    30 
    30 
       
    31 const TUint KTestIterations = 100;
       
    32 
    31 const TInt KHeadSize = (TInt)RHeap::EAllocCellSize;
    33 const TInt KHeadSize = (TInt)RHeap::EAllocCellSize;
    32 
    34 
    33 class TestHybridHeap
    35 class TestHybridHeap
    34   {
    36   {
    35 public:
    37 public:
   317 void TestRHeap::Test3(void)
   319 void TestRHeap::Test3(void)
   318   {
   320   {
   319   //
   321   //
   320   // Allocation of approximate sized cells from 'small cell' lists (smallbin)
   322   // Allocation of approximate sized cells from 'small cell' lists (smallbin)
   321   //
   323   //
   322   TInt ArraySize=32;
   324   const TInt ArraySize=32;
   323   TInt cellSize=0;
   325   TInt cellSize=0;
   324   TAny** ArrayOfCells;
   326   TAny** ArrayOfCells;
   325   ArrayOfCells= new TAny*[ArraySize];
   327   ArrayOfCells= new TAny*[ArraySize];
   326   TInt ArrayIndex;
   328   TInt ArrayIndex;
   327   TInt topSizeBefore, topSizeAfter;
   329   TInt topSizeBefore, topSizeAfter;
   328     
   330     
   329   // Allocate small approximate sized cells and put
   331   // Allocate small approximate sized cells and put
   330   //them to the array. They are allocated from TOP chunk
   332   //them to the array. They are allocated from TOP chunk
   331   TUint8 randomSize;
   333   TUint8 randomSize[ArraySize];
   332   for(ArrayIndex=0; ArrayIndex<ArraySize;ArrayIndex++)
   334   for(ArrayIndex=0; ArrayIndex<ArraySize;ArrayIndex++)
   333     {
   335     {
   334     TestHybridHeap::TopSize(topSizeBefore,iHybridHeap);
   336     TestHybridHeap::TopSize(topSizeBefore,iHybridHeap);
   335     do
   337     // Ensure that the size of the cell does not exceed 256 bytes on debug builds
   336       {
   338     randomSize[ArrayIndex] = (TUint8) (Math::Random() % (MAX_SMALL_REQUEST + 1 - RHeap::EDebugHdrSize));
   337       randomSize= (TUint8)Math::Random();
   339   	cellSize=randomSize[ArrayIndex];
   338       }
       
   339     while (randomSize>240);
       
   340        
       
   341   	cellSize=randomSize;
       
   342   	ArrayOfCells[ArrayIndex]=iHeap->Alloc(cellSize);
   340   	ArrayOfCells[ArrayIndex]=iHeap->Alloc(cellSize);
   343   	TestHybridHeap::TopSize(topSizeAfter,iHybridHeap);
   341   	TestHybridHeap::TopSize(topSizeAfter,iHybridHeap);
   344   	test(topSizeBefore > topSizeAfter);
   342   	test(topSizeBefore > topSizeAfter);
   345   	}
   343   	}
   346   iHeap->Check();
   344   iHeap->Check();
   356   TestHybridHeap::SmallMap(smallMap2,iHybridHeap);
   354   TestHybridHeap::SmallMap(smallMap2,iHybridHeap);
   357   test(smallMap<=smallMap2);
   355   test(smallMap<=smallMap2);
   358   iHeap->Check();
   356   iHeap->Check();
   359   
   357   
   360   // Allocate approximate sized cells from smallbin
   358   // Allocate approximate sized cells from smallbin
   361   TInt ArraySize2=6;
   359   const TInt ArraySize2=6;
   362   TInt cellSize2=0;    
   360   TInt cellSize2=0;
   363   TAny** ArrayOfCells2;
   361   TAny** ArrayOfCells2;
   364   ArrayOfCells2= new TAny*[ArraySize2];
   362   ArrayOfCells2= new TAny*[ArraySize2];
   365   TInt ArrayIndex2;
   363   TInt ArrayIndex2;
   366   TestHybridHeap::SmallMap(smallMap,iHybridHeap);
   364   TestHybridHeap::SmallMap(smallMap,iHybridHeap);
       
   365   TUint8 randomSize2[ArraySize2];
   367   for(ArrayIndex2=0; ArrayIndex2<ArraySize2;ArrayIndex2++)
   366   for(ArrayIndex2=0; ArrayIndex2<ArraySize2;ArrayIndex2++)
   368     {
   367     {
   369     TUint8 randomSize2 = (TUint8)Math::Random();
   368     randomSize2[ArrayIndex2]=randomSize[2+ArrayIndex2*5];
   370     cellSize2=(randomSize2);
   369     cellSize2=randomSize2[ArrayIndex2];
   371     ArrayOfCells2[ArrayIndex2]=iHeap->Alloc(cellSize2);
   370     ArrayOfCells2[ArrayIndex2]=iHeap->Alloc(cellSize2);
   372     }
   371     }
   373   TestHybridHeap::SmallMap(smallMap2,iHybridHeap);
   372   TestHybridHeap::SmallMap(smallMap2,iHybridHeap);
   374   test(smallMap>=smallMap2);              
   373   test(smallMap>=smallMap2);
   375   iHeap->Check();
   374   iHeap->Check();
   376   
   375   
   377   // Freeing of approximate sized cells back to smallbin
   376   // Freeing of approximate sized cells back to smallbin
   378   for(ArrayIndex2=0; ArrayIndex2<ArraySize2-1; ArrayIndex2+=1)
   377   for(ArrayIndex2=0; ArrayIndex2<ArraySize2-1; ArrayIndex2+=1)
   379     {
   378     {
   394   {
   393   {
   395   //
   394   //
   396   // Allocation of approximate sized cells from digital trees (treebin) and splitting
   395   // Allocation of approximate sized cells from digital trees (treebin) and splitting
   397   // Freeing of approximate sized cells back to digital trees (treebin)
   396   // Freeing of approximate sized cells back to digital trees (treebin)
   398   //
   397   //
   399   TInt ArraySize=32;
   398   const TInt ArraySize=32;
   400   TInt cellSize=0;
   399   TInt cellSize=0;
   401   TAny** ArrayOfCells;
   400   TAny** ArrayOfCells;
   402   ArrayOfCells= new TAny*[ArraySize];
   401   ArrayOfCells= new TAny*[ArraySize];
   403   TInt ArrayIndex;
   402   TInt ArrayIndex;
   404         
   403         
   405   // Allocate approximate sized cells bigger than 256
   404   // Allocate approximate sized cells bigger than 256
   406   // and put them to the array. They are allocated from TOP chunk
   405   // and put them to the array. They are allocated from TOP chunk
       
   406   TUint8 randomSize[ArraySize];
   407   for(ArrayIndex=0; ArrayIndex<ArraySize;ArrayIndex++)
   407   for(ArrayIndex=0; ArrayIndex<ArraySize;ArrayIndex++)
   408     {
   408     {
   409     TUint8 randomSize = (TUint8)Math::Random();
   409     randomSize[ArrayIndex] = (TUint8)Math::Random();
   410     cellSize=(randomSize+256);
   410     cellSize=(randomSize[ArrayIndex]+MAX_SMALL_REQUEST+1);
   411     ArrayOfCells[ArrayIndex]=iHeap->Alloc(cellSize);
   411     ArrayOfCells[ArrayIndex]=iHeap->Alloc(cellSize);
   412     }
   412     }
   413   iHeap->Check();
   413   iHeap->Check();
   414   
   414   
   415   TUint treeMap,treeMap2;    
   415   TUint treeMap,treeMap2;
   416   // Free some of allocated cells from the array. So they are inserted
   416   // Free some of allocated cells from the array. So they are inserted
   417   // to the treebin
   417   // to the treebin
   418   for(ArrayIndex=2; ArrayIndex<ArraySize-1; ArrayIndex+=5)
   418   for(ArrayIndex=2; ArrayIndex<ArraySize-1; ArrayIndex+=5)
   419     {
   419     {
   420     TestHybridHeap::TreeMap(treeMap,iHybridHeap);
   420     TestHybridHeap::TreeMap(treeMap,iHybridHeap);
   423     test(treeMap <= treeMap2);
   423     test(treeMap <= treeMap2);
   424     }
   424     }
   425   iHeap->Check();
   425   iHeap->Check();
   426   
   426   
   427   // Allocate approximate sized cells from treebin
   427   // Allocate approximate sized cells from treebin
   428   TInt ArraySize2=16;
   428   const TInt ArraySize2=16;
   429   TInt cellSize2=0;    
   429   TInt cellSize2=0;    
   430   TAny** ArrayOfCells2;
   430   TAny** ArrayOfCells2;
   431   ArrayOfCells2= new TAny*[ArraySize2];
   431   ArrayOfCells2= new TAny*[ArraySize2];
   432   TInt ArrayIndex2;
   432   TInt ArrayIndex2;
       
   433   TUint8 randomSize2[ArraySize2];
   433   for(ArrayIndex2=0; ArrayIndex2<ArraySize2;ArrayIndex2++)
   434   for(ArrayIndex2=0; ArrayIndex2<ArraySize2;ArrayIndex2++)
   434     {
   435     {
   435     TestHybridHeap::TreeMap(treeMap,iHybridHeap);
   436     TestHybridHeap::TreeMap(treeMap,iHybridHeap);
   436     TUint8 randomSize2 = (TUint8)Math::Random();
   437     randomSize2[ArrayIndex2] = (TUint8)Math::Random();
   437     cellSize2=(randomSize2+256);
   438     cellSize2=(randomSize2[ArrayIndex2]+MAX_SMALL_REQUEST+1);
   438     ArrayOfCells2[ArrayIndex2]=iHeap->Alloc(cellSize2);
   439     ArrayOfCells2[ArrayIndex2]=iHeap->Alloc(cellSize2);
   439     TestHybridHeap::TreeMap(treeMap2,iHybridHeap);
   440     TestHybridHeap::TreeMap(treeMap2,iHybridHeap);
   440     test(treeMap >= treeMap2);
   441     test(treeMap >= treeMap2);
   441     }
   442     }
   442   iHeap->Check();
   443   iHeap->Check();
   472   test.Title();
   473   test.Title();
   473 
   474 
   474   __KHEAP_MARK;
   475   __KHEAP_MARK;
   475 
   476 
   476   TestRHeap T;
   477   TestRHeap T;
       
   478   TUint i;
   477   test.Start(_L("Init DL allocator tests"));
   479   test.Start(_L("Init DL allocator tests"));
   478   T.InitTests();
   480   T.InitTests();
   479   test.Next(_L("Test DL allocator 1"));
   481   test.Next(_L("Test DL allocator 1"));
   480   T.Test1();
   482   for(i = 0; i < KTestIterations; i++)
       
   483     {
       
   484     T.Test1();
       
   485     }
   481   test.Next(_L("Test DL allocator 2"));
   486   test.Next(_L("Test DL allocator 2"));
   482   T.Test2();
   487   for(i = 0; i < KTestIterations; i++)
       
   488     {
       
   489     T.Test2();
       
   490     }
   483   test.Next(_L("Test DL allocator 3"));
   491   test.Next(_L("Test DL allocator 3"));
   484   T.Test3();
   492   for(i = 0; i < KTestIterations; i++)
       
   493     {
       
   494     T.Test3();
       
   495     }
   485   test.Next(_L("Test DL allocator 4"));
   496   test.Next(_L("Test DL allocator 4"));
   486   T.Test4();
   497   for(i = 0; i < KTestIterations; i++)
       
   498     {
       
   499     T.Test4();
       
   500     }
   487   test.Next(_L("Close DL allocator tests"));
   501   test.Next(_L("Close DL allocator tests"));
   488   T.CloseTests();
   502   T.CloseTests();
   489 	
   503 	
   490   __KHEAP_CHECK(0);
   504   __KHEAP_CHECK(0);
   491   __KHEAP_MARKEND;
   505   __KHEAP_MARKEND;