sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\demandpaging\t_dpcmn.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "u32std.h" sl@0: sl@0: TInt gPageSize; sl@0: TBool gPagingSupported = EFalse; sl@0: TBool gRomPagingSupported = EFalse; sl@0: TBool gCodePagingSupported = EFalse; sl@0: TBool gDataPagingSupported = EFalse; sl@0: TInt gDataPagingPolicy; sl@0: TBool gProcessPaged; sl@0: sl@0: TBool gGlobalNoPaging = EFalse; sl@0: TBool gGlobalAlwaysPage = EFalse; sl@0: TBool gGlobalDefaultUnpaged = EFalse; sl@0: TBool gGlobalDefaultPage = EFalse; sl@0: sl@0: // Size of paging cache in pages sl@0: TUint gMinCacheSize = 0; sl@0: TUint gMaxCacheSize = 0; sl@0: TUint gCurrentCacheSize = 0; sl@0: sl@0: RChunk gChunk; sl@0: sl@0: // sl@0: // GetGlobalPolicies sl@0: // sl@0: // Determine the global dapaging policies as specified at rombuild time sl@0: // sl@0: TInt GetGlobalPolicies() sl@0: { sl@0: // Determine which types of paging are supported sl@0: TUint32 attrs = DPTest::Attributes(); sl@0: sl@0: gRomPagingSupported = (attrs & DPTest::ERomPaging) != 0; sl@0: gCodePagingSupported = (attrs & DPTest::ECodePaging) != 0; sl@0: gDataPagingSupported = (attrs & DPTest::EDataPaging) != 0; sl@0: gPagingSupported = gRomPagingSupported || gCodePagingSupported || gDataPagingSupported; sl@0: sl@0: if (gRomPagingSupported) sl@0: RDebug::Printf("Rom paging supported"); sl@0: if (gCodePagingSupported) sl@0: RDebug::Printf("Code paging supported"); sl@0: if (gDataPagingSupported) sl@0: RDebug::Printf("Data paging supported"); sl@0: sl@0: // Determine the data paging attributes sl@0: TInt kernelFlags = UserSvr::HalFunction(EHalGroupKernel, EKernelHalConfigFlags, 0, 0); sl@0: if (kernelFlags < 0) sl@0: return kernelFlags; sl@0: sl@0: gDataPagingPolicy = kernelFlags & EKernelConfigDataPagingPolicyMask; sl@0: if (gDataPagingPolicy == EKernelConfigDataPagingPolicyNoPaging) sl@0: { sl@0: RDebug::Printf("Global NO PAGING policy is set"); sl@0: gGlobalNoPaging = ETrue; sl@0: } sl@0: if (gDataPagingPolicy == EKernelConfigDataPagingPolicyAlwaysPage) sl@0: { sl@0: RDebug::Printf("Global ALWAYS PAGE policy is set"); sl@0: gGlobalAlwaysPage = ETrue; sl@0: } sl@0: if (gDataPagingPolicy == EKernelConfigDataPagingPolicyDefaultUnpaged) sl@0: { sl@0: RDebug::Printf("Global DEFAULT UNPAGED policy is set"); sl@0: gGlobalDefaultUnpaged = ETrue; sl@0: } sl@0: if (gDataPagingPolicy == EKernelConfigDataPagingPolicyDefaultPaged) sl@0: { sl@0: RDebug::Printf("Global DEFAULT PAGED policy is set"); sl@0: gGlobalDefaultPage = ETrue; sl@0: } sl@0: sl@0: // Determine this process' data paging attribute sl@0: RProcess process; // Default to point to current process. sl@0: gProcessPaged = process.DefaultDataPaged(); sl@0: RDebug::Printf(gProcessPaged ? "This process is paged" : "This process is not paged"); sl@0: sl@0: // Get page size sl@0: TInt r = UserHal::PageSizeInBytes(gPageSize); sl@0: if (r != KErrNone) sl@0: return r; sl@0: sl@0: if (gPagingSupported) sl@0: { sl@0: TUint minSize; sl@0: TUint maxSize; sl@0: TUint currentSize; sl@0: r = DPTest::CacheSize(minSize, maxSize, currentSize); sl@0: if (r != KErrNone) sl@0: return r; sl@0: sl@0: gMinCacheSize = minSize / gPageSize; sl@0: gMaxCacheSize = maxSize / gPageSize; sl@0: gCurrentCacheSize = currentSize / gPageSize; sl@0: RDebug::Printf("Cache size (pages): min == %d, max == %d, current == %d", sl@0: gMinCacheSize, gMaxCacheSize, gCurrentCacheSize); sl@0: } sl@0: sl@0: return r; sl@0: } sl@0: sl@0: // sl@0: // IsDataPagingSupported sl@0: // sl@0: // Determine whether data paging is supported sl@0: // sl@0: TBool IsDataPagingSupported() sl@0: { sl@0: return gDataPagingSupported; sl@0: } sl@0: sl@0: // sl@0: // UpdatePaged sl@0: // sl@0: // Update whether the expected paged status based on the global paging policy. sl@0: // sl@0: void UpdatePaged(TBool& aPaged) sl@0: { sl@0: if (gGlobalNoPaging) sl@0: aPaged = EFalse; sl@0: if (gGlobalAlwaysPage) sl@0: aPaged = ETrue; sl@0: if (!gDataPagingSupported) sl@0: aPaged = EFalse; sl@0: } sl@0: sl@0: sl@0: // sl@0: // TestThreadExit sl@0: // sl@0: // Resume the specified thread and verify the exit reason. sl@0: // sl@0: TInt TestThreadExit(RThread& aThread, TExitType aExitType, TInt aExitReason) sl@0: { sl@0: // Disable JIT debugging. sl@0: TBool justInTime=User::JustInTime(); sl@0: User::SetJustInTime(EFalse); sl@0: sl@0: TRequestStatus status; sl@0: aThread.Logon(status); sl@0: aThread.Resume(); sl@0: User::WaitForRequest(status); sl@0: if (aExitType != aThread.ExitType()) sl@0: return KErrGeneral; sl@0: sl@0: if (aExitReason != status.Int()) sl@0: return KErrGeneral; sl@0: sl@0: if (aExitReason != aThread.ExitReason()) sl@0: return KErrGeneral; sl@0: sl@0: sl@0: if (aExitType == EExitPanic) sl@0: { sl@0: if (aThread.ExitCategory()!=_L("USER")) sl@0: { sl@0: return KErrGeneral; sl@0: } sl@0: } sl@0: sl@0: CLOSE_AND_WAIT(aThread); sl@0: sl@0: // Put JIT debugging back to previous status. sl@0: User::SetJustInTime(justInTime); sl@0: return KErrNone; sl@0: }