示例#1
0
void TestAlignedAllocs()
	{
	TInt align;
	TInt size;
	for (align=PageShift; align<=20; ++align)
		{
		for (size=PageSize; size<=0x100000; size+=PageSize)
			{
			TInt free=FreeRam();
			TUint32 pa=0;
			TInt r=AllocPhysicalRam(pa,size,align);
			test.Printf(_L("Size %08x Align %d r=%d pa=%08x\n"),size,align,r,pa);
			if (r==KErrNone)
				{
				TUint32 as=1u<<align;
				TUint32 am=as-1;
				test(FreeRam()==free-size);
				test((pa&am)==0);
				r=FreePhysicalRam(pa,size);
				test(r==KErrNone);
				}
			test(FreeRam()==free);
			}
		}
	}
示例#2
0
void FragmentMemoryFunc()
	{
	ChunkCommitEnd = 0;
	TInt r;
	while(KErrNone == (r = Chunk.Commit(ChunkCommitEnd,PageSize)) && !FragThreadStop)
		{
		ChunkCommitEnd += PageSize;
		}
	if (FragThreadStop)
		return;
	test_Equal(KErrNoMemory, r);
	TUint freeBlocks = 0;
	for (	TUint offset = 0; 
			(offset + FragData.iSize) < ChunkCommitEnd; 
			offset += FragData.iFrequency, freeBlocks++)
		{
		test_KErrNone(Chunk.Decommit(offset, FragData.iSize));
		}

	if (FragData.iDiscard && CacheSizeAdjustable && !FragThreadStop)
		{
		TUint minCacheSize = FreeRam();
		TUint maxCacheSize = minCacheSize;
		DPTest::SetCacheSize(minCacheSize, maxCacheSize);
		if (OrigMinCacheSize <= maxCacheSize)
			DPTest::SetCacheSize(OrigMinCacheSize, maxCacheSize);
		}
	}
示例#3
0
//------------------------------------------------------------------------------
void testEnd() {
  testOut->println();
  testOut->println(F("Compiled: " __DATE__ " " __TIME__));
  testOut->print(F("FreeRam: "));
  testOut->println(FreeRam());
  testOut->print(F("Test count: "));
  testOut->println(testCount);
  testOut->print(F("Fail count: "));
  testOut->println(failCount);
}
示例#4
0
//------------------------------------------------------------------------------
void testBegin(Print* pr) {
  testOut = pr;
  SerialPrintln_P(PSTR("Type any character to begin."));
  while (!Serial.available());

  print_P(testOut, PSTR("FreeRam: "));
  testOut->println(FreeRam());
  testOut->println();
  failCount = 0;
  testCount = 0;
}
示例#5
0
//------------------------------------------------------------------------------
void testBegin() {
  Serial.begin(9600);
  while (!Serial) {}  // wait for leonardo
  testOut = &Serial;
  SerialPrintln_P(PSTR("Type any character to begin."));
  while (Serial.read() <= 0) {}
  delay(200); // Catch Due reset problem

  testOut->print(F("FreeRam: "));
  testOut->println(FreeRam());
  testOut->println();
  failCount = 0;
  testCount = 0;
}
示例#6
0
void CreateWithOOMCheck(TInt aSize, TBool aPhysicalAddress)
	{
	TInt failResult=KErrGeneral;

	TInt freeRam = FreeRam(); //This will also add a delay

	for(TInt failCount=1; failCount<1000; failCount++)
		{
		test.Printf(_L("alloc fail count = %d\n"),failCount);

		User::__DbgSetAllocFail(ETrue,RAllocator::EFailNext,failCount);
		__KHEAP_MARK;
		
		if (aPhysicalAddress)
			failResult=ldd.CreateBufferPhysAddr(aSize);
		else
			failResult=ldd.CreateBuffer(aSize);

		if(failResult==KErrNone)
			break;

		test(failResult==KErrNoMemory);
		__KHEAP_MARKEND;

		test(freeRam == FreeRam());  //This will also add a delay
		}
	User::__DbgSetAllocFail(ETrue,RAllocator::ENone,0);
	__KHEAP_RESET;

	test.Next(_L("Destroy buffer"));
	if (aPhysicalAddress)
		ldd.DestroyBufferPhysAddr();
	else
		ldd.DestroyBuffer();
	
	test(freeRam == FreeRam());  //This will also add a delay
	}
示例#7
0
void ShowMemoryUse()
	{
	PRINT1(_L("RAM free 0x%08X bytes"),FreeRam());
	PRINT1(_L("  Swap free 0x%08X bytes\n"),SwapFree());

	TPckgBuf<DPTest::TEventInfo> infoBuf;
	TInt r = UserSvr::HalFunction(EHalGroupVM,EVMHalGetEventInfo,&infoBuf,0);
	if (r!=KErrNone)
		{
		return;
		}
	PRINT1(_L("Page fault count %d"),infoBuf().iPageFaultCount);
	PRINT1(_L("  Page IN count %d\n"),infoBuf().iPageInReadCount);

	return;
	}
示例#8
0
void debugPrint() {
  cout << pstr("FreeRam: ") << FreeRam() << endl;
  cout << pstr("partStart: ") << relSector << endl;
  cout << pstr("partSize: ") << partSize << endl;
  cout << pstr("reserved: ") << reservedSectors << endl;
  cout << pstr("fatStart: ") << fatStart << endl;
  cout << pstr("fatSize: ") << fatSize << endl;
  cout << pstr("dataStart: ") << dataStart << endl;
  cout << pstr("clusterCount: ");
  cout << ((relSector + partSize - dataStart)/sectorsPerCluster) << endl;
  cout << endl;
  cout << pstr("Heads: ") << int(numberOfHeads) << endl;
  cout << pstr("Sectors: ") << int(sectorsPerTrack) << endl;
  cout << pstr("Cylinders: ");
  cout << cardSizeBlocks/(numberOfHeads*sectorsPerTrack) << endl;
}
示例#9
0
void TestClaimPhys()
	{
	TInt free=FreeRam();
	
	TUint32 pa=0;
	TInt r=AllocPhysicalRam(pa,4*PageSize,0);	
	test(r==KErrNone);
	test(FreeRam()==free-4*PageSize);
	
	r=FreePhysicalRam(pa,4*PageSize);
	test(r==KErrNone);
	test(FreeRam()==free);
	
	r=ClaimPhysicalRam(pa,4*PageSize);	
	test(r==KErrNone);
	test(FreeRam()==free-4*PageSize);
	
	r=FreePhysicalRam(pa,3*PageSize);
	test(r==KErrNone);
	test(FreeRam()==free-PageSize);
	
	r=ClaimPhysicalRam(pa,4*PageSize);
	test(r==KErrInUse);
	test(FreeRam()==free-PageSize);
	
#ifdef MANUAL_PANIC_TEST
//This section of the test should be run as a manual test as it results in
// a panic due to attempting to Free an unclaimed page
	if (HaveVirtMem())
		{
		test.Printf(_L("HaveVirtMem() \n"));
		r=FreePhysicalRam(pa,4*PageSize);
		test.Printf(_L("FreePhysicalRam() \n"));
		test(r==KErrGeneral);
		test(FreeRam()==free-PageSize);
		}
#endif
	
	r=FreePhysicalRam(pa+3*PageSize,PageSize);
	test(r==KErrNone);
	test(FreeRam()==free);
	
	}
示例#10
0
//////////////////////////////////// SETUP
void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps for debugging
  
  putstring_nl("\nWave test!");  // say we woke up!
  
  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(FreeRam());

  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!)  
    error("Card init. failed!");  // Something went wrong, lets print out why
  }
  
  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
  
  // Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {   // we have up to 5 slots to look in
    if (vol.init(card, part)) 
      break;                           // we found one, lets bail
  }
  if (part == 5) {                     // if we ended up not finding one  :(
    error("No valid FAT partition!");  // Something went wrong, lets print out why
  }
  
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(), DEC);     // FAT16 or FAT32?
  
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    error("Can't open root dir!");      // Something went wrong,
  }
  
  // Whew! We got past the tough parts.
  putstring_nl("Files found (* = fragmented):");

  // Print out all of the files in all the directories.
  root.ls(LS_R | LS_FLAG_FRAGMENTED);
}
示例#11
0
void setup() {


  Serial.begin(9600);

  pinMode(greenLEDandBEEP, OUTPUT);
  pinMode(redLEDpin, OUTPUT);

  PgmPrint("Free RAM: ");
  Serial.println(FreeRam());  

  pinMode(10, OUTPUT);              
  digitalWrite(10, HIGH);              

  if (!card.init(SPI_HALF_SPEED, 4)) error("card.init failed!");

  if (!volume.init(&card)) error("vol.init failed!");

  PgmPrint("Volume is FAT");
  Serial.println(volume.fatType(),DEC);
  Serial.println();

  if (!root.openRoot(&volume)) error("openRoot failed");

  PgmPrintln("Files found in root:");
  root.ls(LS_DATE | LS_SIZE);
  Serial.println();

  PgmPrintln("Files found in all dirs:");
  root.ls(LS_R);

  Serial.println();
  PgmPrintln("Done");

  Ethernet.begin(mac, ip);
  server.begin();
}
示例#12
0
GLDEF_C TInt E32Main()
//
// Test RAM allocation
//
    {
	test.Title();
	test.Start(_L("Load test LDD"));
	TInt r=User::LoadLogicalDevice(KLddFileName);
	test(r==KErrNone || r==KErrAlreadyExists);

	r=UserHal::PageSizeInBytes(PageSize);
	test(r==KErrNone);

	TInt psz=PageSize;
	PageShift=-1;
	for (; psz; psz>>=1, ++PageShift);

	TUint currentCacheSize;
	CacheSizeAdjustable = DPTest::CacheSize(OrigMinCacheSize, OrigMaxCacheSize, currentCacheSize) == KErrNone;

	TUint memodel = UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, NULL, NULL) & EMemModelTypeMask;

	TInt cmdLineLen = User::CommandLineLength();
	if(cmdLineLen)
		{
		_LIT(KManual, "manual");
		RBuf cmdLine;
		test_KErrNone(cmdLine.Create(cmdLineLen));
		User::CommandLine(cmdLine);
		cmdLine.LowerCase();
		ManualTest = cmdLine.Find(KManual) != KErrNotFound;
		}

	// Turn off lazy dll unloading and ensure any supervisor clean up has completed 
	// so the free ram checking isn't affected.
	RLoader l;
	test(l.Connect()==KErrNone);
	test(l.CancelLazyDllUnload()==KErrNone);
	l.Close();
	UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);

	test_KErrNone(HAL::Get(HAL::EMemoryRAM, TotalRam));

	test.Printf(_L("Free RAM=%08x, Page size=%x, Page shift=%d\n"),FreeRam(),PageSize,PageShift);

	test.Next(_L("Open test LDD"));
	r=Shadow.Open();
	test(r==KErrNone);
	
	test.Next(_L("TestAlignedAllocs"));
	TestAlignedAllocs();
	
	test.Next(_L("TestClaimPhys"));
	TestClaimPhys();

	if (memodel >= EMemModelTypeFlexible)
		{
		// To stop these tests taking too long leave only 8MB of RAM free.
		const TUint KFreePages = 2048;
		test.Next(_L("Load gobbler LDD"));
		TInt r = User::LoadLogicalDevice(KGobblerLddFileName);
		test_Value(r, r == KErrNone || r == KErrAlreadyExists);
		RGobbler gobbler;
		r = gobbler.Open();
		test_KErrNone(r);
		TUint32 taken = gobbler.GobbleRAM(KFreePages * PageSize);
		test.Printf(_L("Gobbled: %dK\n"), taken/1024);
		test.Printf(_L("Free RAM 0x%08X bytes\n"),FreeRam());

		test.Next(_L("TestFragmentedAllocation"));
		TestFragmentedAllocation();

		test.Next(_L("TestMultipleContiguousAllocations"));
		TestMultipleContiguousAllocations(20, PageSize * 16, 0);
		TestMultipleContiguousAllocations(20, PageSize * 16, PageShift + 1);
		TestMultipleContiguousAllocations(20, PageSize * 128, PageShift + 2);

		FragmentMemory(PageSize, PageSize * 2, EFalse, EFalse, EFalse);
		TestMultipleContiguousAllocations(20, PageSize * 128, PageShift + 2);
		UnfragmentMemory(EFalse, EFalse, EFalse);

		test.Next(_L("TestMultipleContiguousAllocations while accessing memory"));
		FragmentMemory(PageSize, PageSize * 2, EFalse, ETrue, EFalse);
		TestMultipleContiguousAllocations(20, PageSize * 128, PageShift + 2);
		UnfragmentMemory(EFalse, ETrue, EFalse);
		FragmentMemory(PageSize, PageSize * 2, ETrue, ETrue, EFalse);
		TestMultipleContiguousAllocations(50, PageSize * 256, PageShift + 5);
		UnfragmentMemory(ETrue, ETrue, EFalse);
		FragmentMemory(PageSize * 16, PageSize * 32, ETrue, ETrue, EFalse);
		TestMultipleContiguousAllocations(10, PageSize * 512, PageShift + 8);
		UnfragmentMemory(ETrue, ETrue, EFalse);
		FragmentMemory(PageSize * 32, PageSize * 64, ETrue, ETrue, EFalse);
		TestMultipleContiguousAllocations(10, PageSize * 1024, PageShift + 10);
		UnfragmentMemory(ETrue, ETrue, EFalse);

		test.Next(_L("TestMultipleContiguousAllocations with repeated movable and discardable allocations"));
		FragmentMemory(PageSize, PageSize * 2, EFalse, EFalse, ETrue);
		TestMultipleContiguousAllocations(20, PageSize * 2, PageShift);
		UnfragmentMemory(EFalse, EFalse, ETrue);
		FragmentMemory(PageSize, PageSize * 2, EFalse, EFalse, ETrue);
		TestMultipleContiguousAllocations(20, PageSize * 128, PageShift + 2);
		UnfragmentMemory(EFalse, EFalse, ETrue);
		FragmentMemory(PageSize, PageSize * 2, ETrue, EFalse, ETrue);
		TestMultipleContiguousAllocations(50, PageSize * 256, PageShift + 5);
		UnfragmentMemory(ETrue, EFalse, ETrue);
		FragmentMemory(PageSize * 16, PageSize * 32, ETrue, EFalse, ETrue);
		TestMultipleContiguousAllocations(20, PageSize * 512, PageShift + 8);
		UnfragmentMemory(ETrue, EFalse, ETrue);
		FragmentMemory(PageSize * 32, PageSize * 64, ETrue, EFalse, ETrue);
		TestMultipleContiguousAllocations(20, PageSize * 1024, PageShift + 10);
		UnfragmentMemory(ETrue, EFalse, ETrue);

		gobbler.Close();
		r = User::FreeLogicalDevice(KGobblerLddFileName);
		test_KErrNone(r);
		}

	Shadow.Close();
	r = User::FreeLogicalDevice(KLddFileName);
	test_KErrNone(r);
	test.Printf(_L("Free RAM=%08x at end of test\n"),FreeRam());
	test.End();
	return(KErrNone);
    }
示例#13
0
TInt FillPhysicalRam(TAny* aArgs)
	{
	SPhysAllocData allocData = *((SPhysAllocData*)aArgs);
	TUint maxAllocs = FreeRam() / allocData.iSize;
	TUint32* physAddrs = new TUint32[maxAllocs + 1];
	if (!physAddrs)
		return KErrNoMemory;
	TUint32* pa = physAddrs;
	TUint32 alignMask = (1 << allocData.iAlign) - 1;
	TUint initialFreeRam = FreeRam();
	TInt r = KErrNone;
	TUint allocations = 0;
	for(; allocations <= maxAllocs; ++allocations)
		{
		TUint freeRam = FreeRam();			
		r = AllocPhysicalRam(*pa, allocData.iSize, allocData.iAlign);
		if (r != KErrNone)
			break;
		if (*pa++ & alignMask)
			{
			r = KErrGeneral;
			RDebug::Printf("Error alignment phys addr 0x%08x", *(pa - 1));
			break;
			}
		TUint newFreeRam = FreeRam();
		if (allocData.iCheckFreeRam && freeRam - allocData.iSize != newFreeRam)
			{
			r = KErrGeneral;
			RDebug::Printf("Error in free ram 0x%08x orig 0x%08x", newFreeRam, freeRam);
			break;
			}
		}

	TUint32* physEnd = pa;
	TBool failFrees = EFalse;
	for (pa = physAddrs; pa < physEnd; pa++)
		{
		if (FreePhysicalRam(*pa, allocData.iSize) != KErrNone)
			failFrees = ETrue;
		}
	if (failFrees)
		r = KErrNotFound;
	if (allocData.iCheckMaxAllocs && allocations > maxAllocs)
		{
		r = KErrOverflow;
		RDebug::Printf("Error able to allocate too many pages");
		}
	TUint finalFreeRam = FreeRam();
	if (allocData.iCheckFreeRam && initialFreeRam != finalFreeRam)
		{
		r = KErrGeneral;
		RDebug::Printf("Error in free ram 0x%08x initial 0x%08x", finalFreeRam, initialFreeRam);
		}
	delete[] physAddrs;
	if (r != KErrNone && r != KErrNoMemory)
		return r;
	TUint possibleAllocs = initialFreeRam / allocData.iSize;
	if (allocData.iCheckMaxAllocs && possibleAllocs != allocations)
		{
		RDebug::Printf("Error in number of allocations possibleAllocs %d allocations %d", possibleAllocs, allocations);
		return KErrGeneral;
		}
	return allocations;
	}