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(TInt aSize); |
45 TInt AllocTest1(); |
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&~(1U<<KPANIC); |
138 Kern::CurrentThread().iDebugMask = debugMask&~(1<<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&(1U<<KPANIC)) |
218 if(debugMask&(1<<KPANIC)) |
219 old = true; |
219 old = true; |
220 if(a1) |
220 if(a1) |
221 debugMask |= (1U<<KPANIC); |
221 debugMask |= (1<<KPANIC); |
222 else |
222 else |
223 debugMask &= ~(1U<<KPANIC); |
223 debugMask &= ~(1<<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; |
|
438 |
437 |
439 do { //re-try up to 100 times if memory conditions are not correct |
438 do { //re-try up to 100 times if memory conditions are not correct |
440 r=AllocTest1(size); |
439 r=AllocTest1(); |
441 size -= 2; |
440 } while(((r == KErrNoMemory)||(r == KErrUnknown)) && --count); |
442 } while(((r == KErrNoMemory)||(r == KErrUnknown)) && --count ); |
|
443 |
441 |
444 return r; |
442 return r; |
445 } |
443 } |
446 |
444 |
447 TInt DMemoryTestChannel::AllocTest1(TInt aSize) |
445 TInt DMemoryTestChannel::AllocTest1() |
448 { |
446 { |
|
447 const TInt KSize = 256; |
449 TInt err = KErrNone; |
448 TInt err = KErrNone; |
450 TUint8* mem1 = (TUint8*)Kern::Alloc(aSize); |
449 TUint8* mem1 = (TUint8*)Kern::Alloc(KSize); |
451 if (!mem1) |
450 if (!mem1) |
452 return KErrNoMemory; |
451 return KErrNoMemory; |
453 memset(mem1, 0xff, aSize); |
452 memset(mem1, KSize, 0xff); |
454 Kern::Free(mem1); |
453 Kern::Free(mem1); |
455 TUint8* mem2 = (TUint8*)Kern::Alloc(aSize); |
454 TUint8* mem2 = (TUint8*)Kern::Alloc(KSize); |
456 if (!mem2) |
455 if (!mem2) |
457 return KErrNoMemory; |
456 return KErrNoMemory; |
458 |
|
459 if (mem1 != mem2) |
457 if (mem1 != mem2) |
460 err = KErrUnknown; // Test inconclusive, can retry |
458 err = KErrUnknown; // Test inconclusive, can retry |
461 |
459 for (TInt i = 0 ; i<KSize && err==KErrNone; ++i) |
462 for (TInt i = 0 ; i<aSize && err==KErrNone; ++i) |
|
463 { |
460 { |
464 if (mem2[i] != 0) |
461 if (mem2[i] != 0) |
465 FAIL_ALLOC_TEST(1, i, mem2[i]); |
462 FAIL_ALLOC_TEST(1, i, mem2[i]); |
466 } |
463 } |
467 Kern::Free(mem2); |
464 Kern::Free(mem2); |
499 } |
496 } |
500 |
497 |
501 // The actual size of the block allocated given the size requested. |
498 // The actual size of the block allocated given the size requested. |
502 #define ALIGNED_SIZE(aReqSize) (_ALIGN_UP(aReqSize + RHeap::EAllocCellSize, RHeap::ECellAlignment) - RHeap::EAllocCellSize) |
499 #define ALIGNED_SIZE(aReqSize) (_ALIGN_UP(aReqSize + RHeap::EAllocCellSize, RHeap::ECellAlignment) - RHeap::EAllocCellSize) |
503 |
500 |
504 // We only allocate blocks where the size we get is the size we ask for - this |
501 // We only acllocate blocks where the size we get is the size we ask for - this |
505 // just makes testing easier. |
502 // just makes testing easier. |
506 const TInt KSize = ALIGNED_SIZE(200), KHalfSize = ALIGNED_SIZE(100), KSmallSize = ALIGNED_SIZE(50); |
503 const TInt KSize = ALIGNED_SIZE(200), KHalfSize = ALIGNED_SIZE(100), KSmallSize = ALIGNED_SIZE(50); |
507 |
504 |
508 TInt DMemoryTestChannel::ReAllocTest1() |
505 TInt DMemoryTestChannel::ReAllocTest1() |
509 { |
506 { |
524 { |
521 { |
525 mem1 = 0; |
522 mem1 = 0; |
526 Kern::Free(mem2); |
523 Kern::Free(mem2); |
527 return KErrUnknown; // Don't expect move on shrink |
524 return KErrUnknown; // Don't expect move on shrink |
528 } |
525 } |
529 // |
526 mem2 = (TUint8*)Kern::ReAlloc(mem1, KSize); // 3 |
530 // With DL allocator growth into original area cannot be expected ! |
|
531 // |
|
532 // mem2 = (TUint8*)Kern::ReAlloc(mem1, KSize); // 3 |
|
533 /* |
|
534 if (mem1 != mem2) |
527 if (mem1 != mem2) |
535 { |
528 { |
536 mem1 = 0; |
529 mem1 = 0; |
537 Kern::Free(mem2); |
530 Kern::Free(mem2); |
538 return KErrUnknown; // Expect growth into original area |
531 return KErrUnknown; // Expect growth into original area |
539 } |
532 } |
540 */ |
533 |
541 mem1 = (TUint8*)Kern::ReAlloc(mem1, KSize); // 3 |
|
542 TInt i; |
534 TInt i; |
543 for (i = 0 ; i<KHalfSize && err==KErrNone; ++i) |
535 for (i = 0 ; i<KHalfSize && err==KErrNone; ++i) |
544 { |
536 { |
545 if (mem1[i] != 0xff) |
537 if (mem1[i] != 0xff) |
546 FAIL_ALLOC_TEST(2, i, mem1[i]); |
538 FAIL_ALLOC_TEST(2, i, mem1[i]); |
570 return KErrNoMemory; |
562 return KErrNoMemory; |
571 memset(mem1, 0xff, KSmallSize); |
563 memset(mem1, 0xff, KSmallSize); |
572 mem2 = (TUint8*)Kern::Alloc(KSmallSize); // 2 |
564 mem2 = (TUint8*)Kern::Alloc(KSmallSize); // 2 |
573 if (!mem2) |
565 if (!mem2) |
574 return KErrNoMemory; |
566 return KErrNoMemory; |
575 // |
|
576 // The following exception is not possible with DL allocator |
|
577 // |
|
578 /* |
|
579 if (mem2 <= (mem1 + KSmallSize)) |
567 if (mem2 <= (mem1 + KSmallSize)) |
580 return KErrUnknown; // Expect mem2 higher than mem1 |
568 return KErrUnknown; // Expect mem2 higher than mem1 |
581 */ |
|
582 memset(mem2, 0xee, KSmallSize); |
569 memset(mem2, 0xee, KSmallSize); |
583 mem3 = (TUint8*)Kern::Alloc(KSize); // 3 |
570 mem3 = (TUint8*)Kern::Alloc(KSize); // 3 |
584 if (!mem3) |
571 if (!mem3) |
585 return KErrNoMemory; |
572 return KErrNoMemory; |
586 // |
|
587 // The following exception is not possible with DL allocator |
|
588 // |
|
589 /* |
|
590 if (mem3 <= (mem2 + KSmallSize)) |
573 if (mem3 <= (mem2 + KSmallSize)) |
591 return KErrUnknown+2; // Expect mem3 higher than mem2 |
574 return KErrUnknown; // Expect mem3 higher than mem2 |
592 */ |
|
593 memset(mem3, 0xdd, KSize); |
575 memset(mem3, 0xdd, KSize); |
594 Kern::Free(mem3); |
576 Kern::Free(mem3); |
595 |
|
596 /* |
|
597 TUint8* m3 = mem3; |
577 TUint8* m3 = mem3; |
598 */ |
|
599 mem3 = NULL; |
578 mem3 = NULL; |
600 |
|
601 TUint8* mem4 = (TUint8*)Kern::ReAlloc(mem1, KSize); // 4 |
579 TUint8* mem4 = (TUint8*)Kern::ReAlloc(mem1, KSize); // 4 |
602 if (!mem4) |
580 if (!mem4) |
603 return KErrNoMemory; |
581 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 |
|
610 if (mem4 == mem1) |
582 if (mem4 == mem1) |
611 return KErrUnknown; // Expect move on grow |
583 return KErrUnknown; // Expect move on grow |
612 mem1=mem4; |
584 mem1=mem4; |
613 if (mem4 != m3) |
585 if (mem4 != m3) |
614 return KErrUnknown; // Expect to realloc to use old mem3 space |
586 return KErrUnknown; // Expect to realloc to use old mem3 space |
615 */ |
587 |
616 mem1=mem4; |
|
617 TInt i; |
588 TInt i; |
618 TInt err = KErrNone; |
589 TInt err = KErrNone; |
619 for (i = 0 ; i<KSmallSize && err==KErrNone; ++i) |
590 for (i = 0 ; i<KSmallSize && err==KErrNone; ++i) |
620 { |
591 { |
621 if (mem1[i] != 0xff) |
592 if (mem1[i] != 0xff) |