kerneltest/e32test/demandpaging/t_dpcmn.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32test\demandpaging\t_dpcmn.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32test.h>
       
    19 #include <dptest.h>
       
    20 #include <e32hal.h>
       
    21 #include <u32exec.h>
       
    22 #include <e32svr.h>
       
    23 #include <e32panic.h>
       
    24 #include "u32std.h"
       
    25 
       
    26 TInt gPageSize;
       
    27 TBool gPagingSupported = EFalse;
       
    28 TBool gRomPagingSupported = EFalse;
       
    29 TBool gCodePagingSupported = EFalse;
       
    30 TBool gDataPagingSupported = EFalse;
       
    31 TInt gDataPagingPolicy;
       
    32 TBool gProcessPaged;
       
    33 
       
    34 TBool gGlobalNoPaging = EFalse;		
       
    35 TBool gGlobalAlwaysPage = EFalse;
       
    36 TBool gGlobalDefaultUnpaged = EFalse;	
       
    37 TBool gGlobalDefaultPage = EFalse;
       
    38 
       
    39 // Size of paging cache in pages
       
    40 TUint gMinCacheSize = 0;
       
    41 TUint gMaxCacheSize = 0;
       
    42 TUint gCurrentCacheSize = 0;
       
    43 
       
    44 RChunk gChunk;
       
    45 
       
    46 //
       
    47 // GetGlobalPolicies
       
    48 //
       
    49 // Determine the global dapaging policies as specified at rombuild time
       
    50 //
       
    51 TInt GetGlobalPolicies()
       
    52 	{
       
    53 	// Determine which types of paging are supported
       
    54 	TUint32 attrs = DPTest::Attributes();
       
    55 
       
    56 	gRomPagingSupported = (attrs & DPTest::ERomPaging) != 0;
       
    57 	gCodePagingSupported = (attrs & DPTest::ECodePaging) != 0;
       
    58 	gDataPagingSupported = (attrs & DPTest::EDataPaging) != 0;
       
    59 	gPagingSupported = gRomPagingSupported || gCodePagingSupported || gDataPagingSupported;
       
    60 	
       
    61 	if (gRomPagingSupported)
       
    62 		RDebug::Printf("Rom paging supported");
       
    63 	if (gCodePagingSupported)
       
    64 		RDebug::Printf("Code paging supported");
       
    65 	if (gDataPagingSupported)
       
    66 		RDebug::Printf("Data paging supported");	
       
    67 	
       
    68 	// Determine the data paging attributes
       
    69 	TInt kernelFlags = UserSvr::HalFunction(EHalGroupKernel, EKernelHalConfigFlags, 0, 0);
       
    70 	if (kernelFlags < 0)
       
    71 		return kernelFlags;
       
    72 	
       
    73 	gDataPagingPolicy = kernelFlags & EKernelConfigDataPagingPolicyMask;
       
    74 	if (gDataPagingPolicy == EKernelConfigDataPagingPolicyNoPaging)
       
    75 		{
       
    76 		RDebug::Printf("Global NO PAGING policy is set");
       
    77 		gGlobalNoPaging = ETrue;
       
    78 		}
       
    79 	if (gDataPagingPolicy == EKernelConfigDataPagingPolicyAlwaysPage)
       
    80 		{
       
    81 		RDebug::Printf("Global ALWAYS PAGE policy is set");
       
    82 		gGlobalAlwaysPage = ETrue;
       
    83 		}
       
    84 	if (gDataPagingPolicy == EKernelConfigDataPagingPolicyDefaultUnpaged)
       
    85 		{
       
    86 		RDebug::Printf("Global DEFAULT UNPAGED policy is set");
       
    87 		gGlobalDefaultUnpaged = ETrue;
       
    88 		}
       
    89 	if (gDataPagingPolicy == EKernelConfigDataPagingPolicyDefaultPaged)
       
    90 		{
       
    91 		RDebug::Printf("Global DEFAULT PAGED policy is set");
       
    92 		gGlobalDefaultPage = ETrue;
       
    93 		}
       
    94 
       
    95 	// Determine this process' data paging attribute
       
    96 	RProcess process;	// Default to point to current process.
       
    97 	gProcessPaged = process.DefaultDataPaged();
       
    98 	RDebug::Printf(gProcessPaged ? "This process is paged" : "This process is not paged");
       
    99 
       
   100 	// Get page size
       
   101 	TInt r = UserHal::PageSizeInBytes(gPageSize);
       
   102 	if (r != KErrNone)
       
   103 		return r;
       
   104 
       
   105 	if (gPagingSupported)
       
   106 		{
       
   107 		TUint minSize;
       
   108 		TUint maxSize;
       
   109 		TUint currentSize;
       
   110 		r = DPTest::CacheSize(minSize, maxSize, currentSize);
       
   111 		if (r != KErrNone)
       
   112 			return r;
       
   113 
       
   114 		gMinCacheSize = minSize / gPageSize;
       
   115 		gMaxCacheSize = maxSize / gPageSize;
       
   116 		gCurrentCacheSize = currentSize / gPageSize;
       
   117 		RDebug::Printf("Cache size (pages): min == %d, max == %d, current == %d",
       
   118 					   gMinCacheSize, gMaxCacheSize, gCurrentCacheSize);
       
   119 		}
       
   120 	
       
   121 	return r;
       
   122 	}
       
   123 
       
   124 //
       
   125 // IsDataPagingSupported
       
   126 //
       
   127 // Determine whether data paging is supported
       
   128 //
       
   129 TBool IsDataPagingSupported()
       
   130 	{
       
   131 	return gDataPagingSupported;
       
   132 	}
       
   133 
       
   134 //
       
   135 // UpdatePaged
       
   136 //
       
   137 // Update whether the expected paged status based on the global paging policy.
       
   138 //
       
   139 void UpdatePaged(TBool& aPaged)
       
   140 	{
       
   141 	if (gGlobalNoPaging)
       
   142 		aPaged = EFalse;
       
   143 	if (gGlobalAlwaysPage)
       
   144 		aPaged = ETrue;
       
   145 	if (!gDataPagingSupported)
       
   146 		aPaged = EFalse;
       
   147 	}
       
   148 
       
   149 
       
   150 // 
       
   151 // TestThreadExit
       
   152 //
       
   153 // Resume the specified thread and verify the exit reason.
       
   154 //
       
   155 TInt TestThreadExit(RThread& aThread, TExitType aExitType, TInt aExitReason)
       
   156 	{
       
   157 	// Disable JIT debugging.
       
   158 	TBool justInTime=User::JustInTime();
       
   159 	User::SetJustInTime(EFalse);
       
   160 
       
   161 	TRequestStatus status;
       
   162 	aThread.Logon(status); 
       
   163 	aThread.Resume();
       
   164 	User::WaitForRequest(status);
       
   165 	if (aExitType != aThread.ExitType())
       
   166 		return KErrGeneral;
       
   167 
       
   168 	if (aExitReason != status.Int())
       
   169 		return KErrGeneral;
       
   170 	
       
   171 	if (aExitReason != aThread.ExitReason())
       
   172 		return KErrGeneral;
       
   173 
       
   174 
       
   175 	if (aExitType == EExitPanic)
       
   176 		{
       
   177 		if (aThread.ExitCategory()!=_L("USER"))
       
   178 			{
       
   179 			return KErrGeneral;
       
   180 			}
       
   181 		}
       
   182 			
       
   183 	CLOSE_AND_WAIT(aThread);
       
   184 
       
   185 	// Put JIT debugging back to previous status.
       
   186 	User::SetJustInTime(justInTime);
       
   187 	return KErrNone;
       
   188 	}