kerneltest/e32test/mmu/d_memorytest.cpp
changeset 109 b3a1d9898418
parent 39 5d2844f35677
child 257 3e88ff8f41d5
equal deleted inserted replaced
102:ef2a444a7410 109:b3a1d9898418
    40 	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
    40 	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
    41 	virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
    41 	virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
    42 private:
    42 private:
    43 	TInt TestAllocZerosMemory();
    43 	TInt TestAllocZerosMemory();
    44 	TInt TestReAllocZerosMemory();
    44 	TInt TestReAllocZerosMemory();
    45 	TInt AllocTest1();
    45 	TInt AllocTest1(TInt aSize);
    46 	TInt ReAllocTest1();
    46 	TInt ReAllocTest1();
    47 	TInt ReAllocTest2(TUint8*& mem1, TUint8*& mem2, TUint8*& mem3);
    47 	TInt ReAllocTest2(TUint8*& mem1, TUint8*& mem2, TUint8*& mem3);
    48 	TInt AllocPhysTest(TUint32 aIters, TUint32 aSize); 
    48 	TInt AllocPhysTest(TUint32 aIters, TUint32 aSize); 
    49 	TInt AllocPhysTest1(TUint32 aIters, TUint32 aSize); 
    49 	TInt AllocPhysTest1(TUint32 aIters, TUint32 aSize); 
    50 public:
    50 public:
   133 	case RMemoryTestLdd::EWriteMemory:
   133 	case RMemoryTestLdd::EWriteMemory:
   134 		{
   134 		{
   135 		TUint32 value=(TUint32)a2;
   135 		TUint32 value=(TUint32)a2;
   136 #ifdef _DEBUG
   136 #ifdef _DEBUG
   137 		TInt debugMask = Kern::CurrentThread().iDebugMask;
   137 		TInt debugMask = Kern::CurrentThread().iDebugMask;
   138 		Kern::CurrentThread().iDebugMask = debugMask&~(1<<KPANIC);
   138 		Kern::CurrentThread().iDebugMask = debugMask&~(1U<<KPANIC);
   139 #endif
   139 #endif
   140 		XTRAP(r, XT_DEFAULT,
   140 		XTRAP(r, XT_DEFAULT,
   141 			if(aFunction==RMemoryTestLdd::EReadWriteMemory)
   141 			if(aFunction==RMemoryTestLdd::EReadWriteMemory)
   142 				{
   142 				{
   143 				kumemget32(&value,a1,4);
   143 				kumemget32(&value,a1,4);
   213 		{
   213 		{
   214 		TBool old = false;
   214 		TBool old = false;
   215 #ifdef _DEBUG
   215 #ifdef _DEBUG
   216 		DThread& thread = Kern::CurrentThread();
   216 		DThread& thread = Kern::CurrentThread();
   217 		TInt debugMask = thread.iDebugMask;
   217 		TInt debugMask = thread.iDebugMask;
   218 		if(debugMask&(1<<KPANIC))
   218 		if(debugMask&(1U<<KPANIC))
   219 			old = true;
   219 			old = true;
   220 		if(a1)
   220 		if(a1)
   221 			debugMask |= (1<<KPANIC);
   221 			debugMask |= (1U<<KPANIC);
   222 		else
   222 		else
   223 			debugMask &= ~(1<<KPANIC);
   223 			debugMask &= ~(1U<<KPANIC);
   224 		thread.iDebugMask = debugMask;
   224 		thread.iDebugMask = debugMask;
   225 #endif
   225 #endif
   226 		return old;
   226 		return old;
   227 		}
   227 		}
   228 
   228 
   432 
   432 
   433 TInt DMemoryTestChannel::TestAllocZerosMemory()
   433 TInt DMemoryTestChannel::TestAllocZerosMemory()
   434 	{
   434 	{
   435 	TInt count = 100;
   435 	TInt count = 100;
   436 	TInt r = KErrNotSupported;
   436 	TInt r = KErrNotSupported;
       
   437 	TInt size = 256;
   437 
   438 
   438 	do	{	//re-try up to 100 times if memory conditions are not correct
   439 	do	{	//re-try up to 100 times if memory conditions are not correct
   439 		r=AllocTest1();
   440 		r=AllocTest1(size);
   440 		} while(((r == KErrNoMemory)||(r == KErrUnknown)) && --count);
   441 		size -= 2;
       
   442 		} while(((r == KErrNoMemory)||(r == KErrUnknown)) && --count );
   441 
   443 
   442 	return r;
   444 	return r;
   443 	}
   445 	}
   444 
   446 
   445 TInt DMemoryTestChannel::AllocTest1()
   447 TInt DMemoryTestChannel::AllocTest1(TInt aSize)
   446 	{
   448 	{
   447 	const TInt KSize = 256;
       
   448 	TInt err = KErrNone;
   449 	TInt err = KErrNone;
   449 	TUint8* mem1 = (TUint8*)Kern::Alloc(KSize);
   450 	TUint8* mem1 = (TUint8*)Kern::Alloc(aSize);
   450 	if (!mem1)
   451 	if (!mem1)
   451 		return KErrNoMemory;
   452 		return KErrNoMemory;
   452 	memset(mem1, KSize, 0xff);
   453   	memset(mem1, 0xff, aSize);	
   453 	Kern::Free(mem1);
   454 	Kern::Free(mem1);
   454 	TUint8* mem2 = (TUint8*)Kern::Alloc(KSize);
   455 	TUint8* mem2 = (TUint8*)Kern::Alloc(aSize);
   455 	if (!mem2)
   456 	if (!mem2)
   456 		return KErrNoMemory;
   457 		return KErrNoMemory;
       
   458 	
   457 	if (mem1 != mem2)
   459 	if (mem1 != mem2)
   458 		err = KErrUnknown;	// Test inconclusive, can retry
   460 		err = KErrUnknown;	// Test inconclusive, can retry
   459 	for (TInt i = 0 ; i<KSize && err==KErrNone; ++i)
   461 
       
   462 	for (TInt i = 0 ; i<aSize && err==KErrNone; ++i)
   460 		{
   463 		{
   461 		if (mem2[i] != 0)
   464 		if (mem2[i] != 0)
   462 			FAIL_ALLOC_TEST(1, i, mem2[i]);
   465 			FAIL_ALLOC_TEST(1, i, mem2[i]);
   463 		}
   466 		}
   464 	Kern::Free(mem2);
   467 	Kern::Free(mem2);
   496 	}
   499 	}
   497 
   500 
   498 // The actual size of the block allocated given the size requested.
   501 // The actual size of the block allocated given the size requested.
   499 #define ALIGNED_SIZE(aReqSize) (_ALIGN_UP(aReqSize + RHeap::EAllocCellSize, RHeap::ECellAlignment) - RHeap::EAllocCellSize)
   502 #define ALIGNED_SIZE(aReqSize) (_ALIGN_UP(aReqSize + RHeap::EAllocCellSize, RHeap::ECellAlignment) - RHeap::EAllocCellSize)
   500 
   503 
   501 // We only acllocate blocks where the size we get is the size we ask for - this
   504 // We only allocate blocks where the size we get is the size we ask for - this
   502 // just makes testing easier.
   505 // just makes testing easier.
   503 const TInt KSize = ALIGNED_SIZE(200), KHalfSize = ALIGNED_SIZE(100), KSmallSize = ALIGNED_SIZE(50);
   506 const TInt KSize = ALIGNED_SIZE(200), KHalfSize = ALIGNED_SIZE(100), KSmallSize = ALIGNED_SIZE(50);
   504 
   507 
   505 TInt DMemoryTestChannel::ReAllocTest1()
   508 TInt DMemoryTestChannel::ReAllocTest1()
   506 	{
   509 	{
   521 		{
   524 		{
   522 		mem1 = 0;
   525 		mem1 = 0;
   523 		Kern::Free(mem2);
   526 		Kern::Free(mem2);
   524 		return KErrUnknown; // Don't expect move on shrink
   527 		return KErrUnknown; // Don't expect move on shrink
   525 		}
   528 		}
   526 	mem2 = (TUint8*)Kern::ReAlloc(mem1, KSize); // 3
   529 	//
       
   530 	// With DL allocator growth into original area cannot be expected !
       
   531 	//
       
   532 //	mem2 = (TUint8*)Kern::ReAlloc(mem1, KSize); // 3
       
   533 /*	
   527 	if (mem1 != mem2)
   534 	if (mem1 != mem2)
   528 		{
   535 		{
   529 		mem1 = 0;
   536 		mem1 = 0;
   530 		Kern::Free(mem2);
   537 		Kern::Free(mem2);
   531 		return KErrUnknown; // Expect growth into original area
   538 		return KErrUnknown; // Expect growth into original area
   532 		}
   539 		}
   533 	
   540 */
       
   541   	mem1 = (TUint8*)Kern::ReAlloc(mem1, KSize); // 3	
   534 	TInt i;
   542 	TInt i;
   535 	for (i = 0 ; i<KHalfSize && err==KErrNone; ++i)
   543 	for (i = 0 ; i<KHalfSize && err==KErrNone; ++i)
   536 		{
   544 		{
   537 		if (mem1[i] != 0xff)
   545 		if (mem1[i] != 0xff)
   538 			FAIL_ALLOC_TEST(2, i, mem1[i]);
   546 			FAIL_ALLOC_TEST(2, i, mem1[i]);
   562 		return KErrNoMemory;
   570 		return KErrNoMemory;
   563 	memset(mem1, 0xff, KSmallSize);	
   571 	memset(mem1, 0xff, KSmallSize);	
   564 	mem2 = (TUint8*)Kern::Alloc(KSmallSize); // 2
   572 	mem2 = (TUint8*)Kern::Alloc(KSmallSize); // 2
   565 	if (!mem2)
   573 	if (!mem2)
   566 		return KErrNoMemory;
   574 		return KErrNoMemory;
       
   575 	//
       
   576 	// The following exception is not possible with DL allocator
       
   577 	//
       
   578 /*	
   567 	if (mem2 <= (mem1 + KSmallSize))
   579 	if (mem2 <= (mem1 + KSmallSize))
   568 		return KErrUnknown;	// Expect mem2 higher than mem1
   580 		return KErrUnknown;	// Expect mem2 higher than mem1
       
   581 */		
   569 	memset(mem2, 0xee, KSmallSize);		
   582 	memset(mem2, 0xee, KSmallSize);		
   570 	mem3 = (TUint8*)Kern::Alloc(KSize); // 3
   583 	mem3 = (TUint8*)Kern::Alloc(KSize); // 3
   571 	if (!mem3)
   584 	if (!mem3)
   572 		return KErrNoMemory;
   585 		return KErrNoMemory;
       
   586 	//
       
   587 	// The following exception is not possible with DL allocator
       
   588 	//
       
   589 /*	
   573 	if (mem3 <= (mem2 + KSmallSize))
   590 	if (mem3 <= (mem2 + KSmallSize))
   574 		return KErrUnknown;	// Expect mem3 higher than mem2
   591 		return KErrUnknown+2;	// Expect mem3 higher than mem2
       
   592 */		
   575 	memset(mem3, 0xdd, KSize);
   593 	memset(mem3, 0xdd, KSize);
   576 	Kern::Free(mem3);
   594 	Kern::Free(mem3);
       
   595 
       
   596 /*	
   577 	TUint8* m3 = mem3;
   597 	TUint8* m3 = mem3;
       
   598 */	
   578 	mem3 = NULL;
   599 	mem3 = NULL;
       
   600 
   579 	TUint8* mem4 = (TUint8*)Kern::ReAlloc(mem1, KSize); // 4
   601 	TUint8* mem4 = (TUint8*)Kern::ReAlloc(mem1, KSize); // 4
   580 	if (!mem4)
   602 	if (!mem4)
   581 		return KErrNoMemory;	
   603 		return KErrNoMemory;
       
   604 	//
       
   605 	// The following exceptions are not possible with DL allocator
       
   606 	//
       
   607 /*	
       
   608 	if (mem3 <= (mem2 + KSmallSize))
       
   609 		return KErrUnknown+2;	// Expect mem3 higher than mem2
   582 	if (mem4 == mem1)
   610 	if (mem4 == mem1)
   583 		return KErrUnknown; // Expect move on grow
   611 		return KErrUnknown; // Expect move on grow
   584 	mem1=mem4;
   612 	mem1=mem4;
   585 	if (mem4 != m3)
   613 	if (mem4 != m3)
   586 		return KErrUnknown; // Expect to realloc to use old mem3 space
   614 		return KErrUnknown; // Expect to realloc to use old mem3 space
   587 	
   615 */
       
   616 	mem1=mem4;	
   588 	TInt i;
   617 	TInt i;
   589 	TInt err = KErrNone;
   618 	TInt err = KErrNone;
   590 	for (i = 0 ; i<KSmallSize && err==KErrNone; ++i)
   619 	for (i = 0 ; i<KSmallSize && err==KErrNone; ++i)
   591 		{
   620 		{
   592 		if (mem1[i] != 0xff)
   621 		if (mem1[i] != 0xff)