예제 #1
0
int main(int arg, char** argv)
{
  /* Test SectionReader
   * -------------------
   * To run this code : 
   *   cd storage/ndb/src/kernel/vm
   *   make testSectionReader
   *   ./testSectionReader
   *
   * Will print "OK" in success case and return 0
   */

  g_sectionSegmentPool.setSize(1024);
  
  printf("g_sectionSegmentPool size is %u\n",
         g_sectionSegmentPool.getSize());

  const Uint32 Iterations= 2000;
  const Uint32 Sections= 5;
  Uint32 sizes[ Sections ];
  Uint32 iVals[ Sections ];

  for (Uint32 t=0; t < Iterations; t++)
  {
    for (Uint32 i=0; i<Sections; i++)
    {
      Uint32 available= g_sectionSegmentPool.getNoOfFree();
      sizes[i] = available ? 
        myRandom48(SectionSegment::DataLength * 
                   available)
        : 0;

      //if (0 == (sizes[i] % 60))
      //  printf("Iteration %u, section %u, allocating %u words\n",
      //         t, i, sizes[i]);
      if (t % 100 == 0)
        if (i==0)
          printf("\nIteration %u", t);
      
      if (sizes[i] > 0)
      {
        iVals[i]= createSection(&g_sectionSegmentPool, sizes[i]);

        VERIFY(testSR(iVals[i], &g_sectionSegmentPool, sizes[i]) == 0);
      }
      else
        iVals[i]= RNIL;
    }

    
    for (Uint32 i=0; i < Sections; i++)
    {
      if (sizes[i] > 0)
        freeSection(&g_sectionSegmentPool, iVals[i]);
    }
  }
  
  printf("\nOK\n");
  return 0;
}
예제 #2
0
파일: test.cpp 프로젝트: 4T-Shirt/mysql
void
test(Uint32 sz, Uint32 loops, Uint32 iter){

  ndbout_c("SimplePropertiesSection sz=%d loops=%d iter=%d", sz, loops, iter);
  
  while(loops-- > 0){
    Uint32 size = sz*((10 + (rand() % (10 * sz)) + sz - 1)/sz);
    
    Buffer buf(size);
    SectionSegmentPool thePool; thePool.setSize(size);

    for(Uint32 i = 0; i<iter; i++){
      Uint32 c = 0 + (rand() % (2));
      
      const Uint32 alloc = 1 + (rand() % (size - 1));
      SegmentedSectionPtr dst;

      if(0)
	ndbout_c("size: %d loops: %d iter: %d c=%d alloc=%d", 
		 size, loops, i, c, alloc);
      
      switch(c){ 
      case 0:{
	for(Uint32 i = 0; i<alloc; i++)
	  buf.buffer[i] = i; //rand();
	buf.m_len = alloc;
	
	SimplePropertiesSectionWriter w(thePool);
	for(Uint32 i = 0; i<alloc; i++){
	  w.putWord(buf.buffer[i]);
	}
	w.getPtr(dst);
	break;
      }
      case 1:{
	for(Uint32 i = 0; i<alloc; i++)
	  buf.buffer[i] = i; //rand();
	buf.m_len = alloc;
	
	SimplePropertiesSectionWriter w(thePool);
	Uint32 i = 0;
	while(i < alloc){
	  Uint32 sz = rand() % (alloc - i + 1);
	  w.putWords(&buf.buffer[i], sz);
	  i += sz;
	}
	w.getPtr(dst);
	break;
      }
      case 2:{
	break;
      }
      }
      SimplePropertiesSectionReader r(dst, thePool);
      compare(r, buf);
      release(thePool, dst);
      require(thePool.getSize() == thePool.getNoOfFree());
    }
  }
}