void FragmentMemory(TUint aSize, TUint aFrequency, TBool aDiscard, TBool aTouchMemory, TBool aFragThread) { test_Value(aTouchMemory, !aTouchMemory || !aFragThread); test_Value(aSize, aSize < aFrequency); FragData.iSize = aSize; FragData.iFrequency = aFrequency; FragData.iDiscard = aDiscard; FragData.iFragThread = aFragThread; TChunkCreateInfo chunkInfo; chunkInfo.SetDisconnected(0, 0, TotalRam); chunkInfo.SetPaging(TChunkCreateInfo::EUnpaged); chunkInfo.SetClearByte(0x19); test_KErrNone(Chunk.Create(chunkInfo)); if (aFragThread) { TInt r = FragThread.Create(_L("FragThread"), FragmentMemoryThreadFunc, KDefaultStackSize, PageSize, PageSize, NULL); test_KErrNone(r); FragThread.Logon(FragStatus); FragThreadStop = EFalse; TRequestStatus threadInitialised; FragThread.Rendezvous(threadInitialised); FragThread.Resume(); User::WaitForRequest(threadInitialised); test_KErrNone(threadInitialised.Int()); } else { FragmentMemoryFunc(); } if (aTouchMemory && !ManualTest) { TouchData.iSize = aSize; TouchData.iFrequency = aFrequency; TInt r = TouchThread.Create(_L("TouchThread"), TouchMemory, KDefaultStackSize, PageSize, PageSize, NULL); test_KErrNone(r); TouchThread.Logon(TouchStatus); TouchDataStop = EFalse; TRequestStatus threadInitialised; TouchThread.Rendezvous(threadInitialised); TouchThread.Resume(); User::WaitForRequest(threadInitialised); test_KErrNone(threadInitialised.Int()); } }
GLDEF_C TInt E32Main() { test.Title(); if (!HaveMMU()) { test.Printf(_L("This test requires an MMU\n")); return KErrNone; } test.Start(_L("Load test LDD")); TInt r=User::LoadLogicalDevice(KLddFileName); test(r==KErrNone || r==KErrAlreadyExists); test_KErrNone(UserHal::PageSizeInBytes(PageSize)); // Determine which types of paging are supported TUint32 attrs = DPTest::Attributes(); gRomPagingSupported = (attrs & DPTest::ERomPaging) != 0; gCodePagingSupported = (attrs & DPTest::ECodePaging) != 0; gDataPagingSupported = (attrs & DPTest::EDataPaging) != 0; // Does this memory model support pinning. TInt mm = UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, 0, 0) & EMemModelTypeMask; gPinningSupported = mm >= EMemModelTypeFlexible; RPageMove pagemove; test.Next(_L("Open test LDD")); test_KErrNone(pagemove.Open()); // Determine whether this is a smp device. NumberOfCpus = pagemove.NumberOfCpus(); if (NumberOfCpus > 1) Repitions = 1000; // SMP system therefore likely to get KErrInUse in less repitions. test.Next(_L("Attempting to move regular local data pages")); { const TInt size=16384; TUint8* array = new TUint8[size]; test_NotNull(array); TestUserData(pagemove, array, size); _T_PRINTF(_L("Walk heap\n")); User::Check(); delete [] array; } test.Next(_L("Attempting to move regular global coarse data pages")); { const TInt size=1<<20; // Make this chunk multiple of 1MB so it is a coarse memory object on FMM RChunk chunk; test_KErrNone(chunk.CreateDisconnectedGlobal(_L("Dave"), 0, size, size)); TUint8* array = chunk.Base(); TestUserData(pagemove, array, size); TestMovingRealtime(pagemove, array, size, NULL, EFalse); TestCommitDecommit(pagemove, chunk); chunk.Close(); } if (gDataPagingSupported) { test.Next(_L("Attempting to move demand paged fine local user data pages")); const TInt size=16384; TChunkCreateInfo createInfo; createInfo.SetDisconnected(0, size, size); createInfo.SetPaging(TChunkCreateInfo::EPaged); RChunk chunk; test_KErrNone(chunk.Create(createInfo)); TUint8* array = chunk.Base(); TestUserData(pagemove, array, size, ETrue); TestMovingRealtime(pagemove, array, size, NULL, EFalse, ETrue); TestPageTableDiscard(pagemove, array, size); TestCommitDecommit(pagemove, chunk); chunk.Close(); test.Next(_L("Attempting to move demand paged coarse global user data pages")); const TInt sizeCoarse = 1 << 20; // Make this chunk multiple of 1MB so it is a coarse memory object on FMM TChunkCreateInfo createInfoCoarse; createInfoCoarse.SetDisconnected(0, sizeCoarse, sizeCoarse); createInfoCoarse.SetGlobal(_L("Dave")); createInfoCoarse.SetPaging(TChunkCreateInfo::EPaged); RChunk chunkCoarse; test_KErrNone(chunkCoarse.Create(createInfoCoarse)); array = chunkCoarse.Base(); TestUserData(pagemove, array, sizeCoarse, ETrue); TestMovingRealtime(pagemove, array, sizeCoarse, NULL, EFalse, ETrue); TestPageTableDiscard(pagemove, array, sizeCoarse); TestCommitDecommit(pagemove, chunkCoarse); chunkCoarse.Close(); } test.Next(_L("Attempting to move DLL writable static data pages")); { const TInt size=16384; TUint8* array = DllWsd::Address(); TestUserData(pagemove, array, size); } test.Next(_L("Attempting to move user self-mod code chunk page when IMB'ing and executing")); RChunk codeChunk; test_KErrNone(codeChunk.CreateLocalCode(PageSize,PageSize)); TestMovingCodeChunk(pagemove, codeChunk, EFalse); codeChunk.Close(); if (gDataPagingSupported) { test.Next(_L("Attempting to move paged user self-mod code chunk page when IMB'ing and executing")); TChunkCreateInfo createInfo; createInfo.SetCode(PageSize, PageSize); createInfo.SetPaging(TChunkCreateInfo::EPaged); RChunk pagedCodeChunk; test_KErrNone(pagedCodeChunk.Create(createInfo)); TestMovingCodeChunk(pagemove, pagedCodeChunk, ETrue); pagedCodeChunk.Close(); } test.Next(_L("Attempting to move RAM drive")); if ((MemModelAttributes()&EMemModelTypeMask) == EMemModelTypeMultiple) { for (TInt i=0; i<Repitions; i++) test_KErrNone(pagemove.TryMovingUserPage((TAny*)0xA0000000)); } else if ((MemModelAttributes()&EMemModelTypeMask) == EMemModelTypeMoving) { for (TInt i=0; i<Repitions; i++) test_KErrNone(pagemove.TryMovingUserPage((TAny*)0x40000000)); } else if ((MemModelAttributes()&EMemModelTypeMask) == EMemModelTypeFlexible) { // do nothing, RAM drive is not special } else { test.Printf(_L("Don't know where the RAM drive is!")); test(0); } #if 0 test.Next(_L("Attempting to move kernel heap pages")); for (TInt i=0; i<Repitions; i++) test_KErrNone(pagemove.TryMovingKHeap()); #endif if ((MemModelAttributes()&EMemModelTypeMask) != EMemModelTypeFlexible) {// Only the moving and multiple memory models move kernel stack pages. test.Next(_L("Attempting to move kernel stack pages")); for (TInt i=0; i<Repitions; i++) test_KErrNone(pagemove.TryMovingKStack()); } test.Next(_L("Attempting to move ROM pages")); TestMovingRom(pagemove); test.Next(_L("Attempting to move kernel code pages")); for (TInt i=0; i<Repitions; i++) test_KErrNone(pagemove.TryMovingKCode()); test.Next(_L("Attempting to move regular code pages")); TestMovingCode(pagemove, RamLoadedFunction); TestMovingRealtime(pagemove, NULL, 0, RamLoadedFunction, ETrue, EFalse); if (gCodePagingSupported) { test.Next(_L("Attempting to move demand paged code pages")); TestMovingCode(pagemove, DllTestFunction, ETrue); TestMovingRealtime(pagemove, NULL, 0, DllTestFunction, ETrue, ETrue); } /* Setup CodeModifier Test Driver */ StartCodeModifierDriver(); test(KErrNone==Device.InitialiseCodeModifier(/* Max break points */ 5 )); test.Next(_L("Attempting to move code page being modified\n")); test_KErrNone(TestCodeModification(pagemove)); test.Next(_L("Attempting to move code (async) while page being modified")); test_KErrNone(TestCodeModificationAsync(pagemove)); StopCodeModifierDriver(); test.Next(_L("Attempting to move ROM Locale DLL Page")); test_KErrNone(E32TestLocale(1)); test.Next(_L("Attempting to move RAM Locale DLL Page")); test_KErrNone(E32TestLocale(0)); test.Next(_L("Close test LDD")); pagemove.Close(); User::FreeLogicalDevice(KLddFileName); test.End(); return(KErrNone); }