os/kernelhwsrv/kerneltest/f32test/demandpaging/t_paginginfo.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/demandpaging/t_paginginfo.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,218 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// f32test\demandpaging\t_paginginfo.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32test.h>
    1.22 +
    1.23 +RTest test(_L("t_paginginfo"));
    1.24 +
    1.25 +#include <e32rom.h>
    1.26 +#include <e32svr.h>
    1.27 +#include <u32hal.h>
    1.28 +#include <f32file.h>
    1.29 +#include <f32dbg.h>
    1.30 +#include <d32locd.h>
    1.31 +#include "testdefs.h"
    1.32 +#include <hal.h>
    1.33 +
    1.34 +
    1.35 +TInt DriveNumber=-1;   // Parameter - Which drive?  -1 = autodetect.
    1.36 +TInt locDriveNumber;
    1.37 +
    1.38 +TBusLocalDrive Drive;
    1.39 +TBool DisplayStats = ETrue;
    1.40 +TBool ManualTest = EFalse;
    1.41 +
    1.42 +TInt findDataPagingDrive()
    1.43 +/** 
    1.44 +Find the drive containing a swap partition.
    1.45 +
    1.46 +@return		Local drive identifier.
    1.47 +*/
    1.48 +	{
    1.49 +	TInt drive = KErrNotFound;
    1.50 +	
    1.51 +	test.Printf(_L("Searching for data paging drive:\n"));
    1.52 +	
    1.53 +	for(TInt i = 0; i < KMaxLocalDrives && drive < 0; ++i)
    1.54 +		{
    1.55 +		RLocalDrive	d;
    1.56 +		TBool		change = EFalse;
    1.57 +		
    1.58 +		if(d.Connect(i, change) == KErrNone)
    1.59 +			{
    1.60 +			test.Printf(_L("Connected to local drive %d\n"), i);
    1.61 +			TLocalDriveCapsV4			dc;
    1.62 +			TPckg<TLocalDriveCapsV4>	capsPack(dc);
    1.63 +			
    1.64 +			if(d.Caps(capsPack) == KErrNone)
    1.65 +				{
    1.66 +				if ((dc.iMediaAtt & KMediaAttPageable) &&
    1.67 +					(dc.iPartitionType == KPartitionTypePagedData))
    1.68 +					{
    1.69 +					test.Printf(_L("Found swap partition on local drive %d\n"), i);
    1.70 +					drive = i;
    1.71 +
    1.72 +					TPageDeviceInfo pageDeviceInfo;
    1.73 +
    1.74 +					TPtr8 pageDeviceInfoBuf((TUint8*) &pageDeviceInfo, sizeof(pageDeviceInfo));
    1.75 +					pageDeviceInfoBuf.FillZ();
    1.76 +
    1.77 +					TInt r = d.QueryDevice(RLocalDrive::EQueryPageDeviceInfo, pageDeviceInfoBuf);
    1.78 +
    1.79 +					test.Printf(_L("EQueryPageDeviceInfo on local drive %d returned %d\n"), i, r);
    1.80 +					}
    1.81 +				}
    1.82 +			d.Close();
    1.83 +			}
    1.84 +		}
    1.85 +	return drive;
    1.86 +	}
    1.87 +
    1.88 +
    1.89 +
    1.90 +void DisplayPageDeviceInfo(TInt aDataPagingDrive)
    1.91 +	{
    1.92 +	test.Printf(_L("Stats: \n"));
    1.93 +
    1.94 +	SMediaPagingInfo info;
    1.95 +	TInt r = UserSvr::HalFunction(EHalGroupMedia,EMediaHalGetPagingInfo,(TAny*) aDataPagingDrive, &info);
    1.96 +	test.Printf(_L("HAL: EMediaHalGetPagingInfo returned %d\n"), r);
    1.97 +	if (r == KErrNone)
    1.98 +		{
    1.99 +		test.Printf(_L("iRomPageInCount %d\n"), info.iRomPageInCount);
   1.100 +		test.Printf(_L("iCodePageInCount %d\n"), info.iCodePageInCount);
   1.101 +		test.Printf(_L("iDataPageInCount %d\n"), info.iDataPageInCount);
   1.102 +		test.Printf(_L("iDataPageOutCount %d\n"), info.iDataPageOutCount);
   1.103 +		test.Printf(_L("iDataPageOutBackgroundCount %d\n"), info.iDataPageOutBackgroundCount);
   1.104 +		}
   1.105 +
   1.106 +	
   1.107 +	RLocalDrive	d;
   1.108 +	TBool change = EFalse;
   1.109 +	r = d.Connect(aDataPagingDrive, change);
   1.110 +	test (r == KErrNone);
   1.111 +		
   1.112 +	TPageDeviceInfo pageDeviceInfo;
   1.113 +	TPtr8 pageDeviceInfoBuf((TUint8*) &pageDeviceInfo, sizeof(pageDeviceInfo));
   1.114 +	pageDeviceInfoBuf.FillZ();
   1.115 +	r = d.QueryDevice(RLocalDrive::EQueryPageDeviceInfo, pageDeviceInfoBuf);
   1.116 +	test (r == KErrNone || r == KErrNotSupported);
   1.117 +
   1.118 +	d.Close();
   1.119 +	test.Printf(_L("iReservoirBlockCount %d\n"),		pageDeviceInfo.iReservoirBlockCount);
   1.120 +	test.Printf(_L("iBadBlockCount %d\n"),	pageDeviceInfo.iBadBlockCount);
   1.121 +
   1.122 +	}
   1.123 +
   1.124 +//
   1.125 +// The gubbins that starts all the tests
   1.126 +//
   1.127 +// ParseCommandLine reads the arguments and sets globals accordingly.
   1.128 +//
   1.129 +
   1.130 +void ParseCommandLine()
   1.131 +	{
   1.132 +	TBuf<32> args;
   1.133 +	User::CommandLine(args);
   1.134 +	TLex lex(args);
   1.135 +	
   1.136 +	FOREVER
   1.137 +		{
   1.138 +		
   1.139 +		TPtrC token=lex.NextToken();
   1.140 +		if(token.Length()!=0)
   1.141 +			{
   1.142 +			if ((token.Length()==2) && (token[1]==':'))
   1.143 +				DriveNumber=User::UpperCase(token[0])-'A';
   1.144 +			else if (token.Length()==1)
   1.145 +				{
   1.146 +				TChar driveLetter = User::UpperCase(token[0]); 
   1.147 +				if ((driveLetter>='A') && (driveLetter<='Z'))
   1.148 +					DriveNumber=driveLetter - (TChar) 'A';
   1.149 +				else 
   1.150 +					test.Printf(_L("Unknown argument '%S' was ignored.\n"), &token);
   1.151 +				}
   1.152 +			else if ((token==_L("help")) || (token==_L("-h")) || (token==_L("-?")))
   1.153 +				{
   1.154 +				test.Printf(_L("\nUsage:  t_paginginfo [enable] [disable] [stats]\n\n"));
   1.155 +				test.Getch();
   1.156 +				}
   1.157 +			else if (token==_L("stats"))
   1.158 +				{
   1.159 +				DisplayStats = ETrue;
   1.160 +				}
   1.161 +			else if (token==_L("-m"))
   1.162 +				{
   1.163 +				ManualTest = ETrue;
   1.164 +				}
   1.165 +			else
   1.166 +				test.Printf(_L("Unknown argument '%S' was ignored.\n"), &token);
   1.167 +			}
   1.168 +		else
   1.169 +			break;
   1.170 +		
   1.171 +		}
   1.172 +	}
   1.173 +
   1.174 +//
   1.175 +// E32Main
   1.176 +//
   1.177 +
   1.178 +TInt E32Main()
   1.179 +	{
   1.180 +	test.Title();
   1.181 +
   1.182 +	test.Start(_L("Check that the rom is paged"));
   1.183 +
   1.184 +	TRomHeader* romHeader = (TRomHeader*)UserSvr::RomHeaderAddress();
   1.185 +
   1.186 +	if (romHeader->iPageableRomStart==NULL)
   1.187 +		{
   1.188 +		test.Printf(_L("Test ROM is not paged - test skipped!\r\n"));
   1.189 +		test.End();
   1.190 +		return 0;
   1.191 +		}
   1.192 +	ParseCommandLine();	
   1.193 +
   1.194 +	TInt dataPagingDrive = findDataPagingDrive();
   1.195 +	if (dataPagingDrive == KErrNotFound)
   1.196 +		{
   1.197 +		test.Printf(_L("Swap partition not found - test skipped!\r\n"));
   1.198 +		test.End();
   1.199 +		return 0;
   1.200 +		}
   1.201 +
   1.202 +
   1.203 +
   1.204 +	if (DisplayStats)
   1.205 +		{
   1.206 +		DisplayPageDeviceInfo(dataPagingDrive);
   1.207 +
   1.208 +		if (ManualTest)
   1.209 +			test.Getch();
   1.210 +
   1.211 +		test.End();
   1.212 +		return 0;
   1.213 +		}
   1.214 +
   1.215 +
   1.216 +
   1.217 +	test.End();
   1.218 +	return 0;
   1.219 +	}
   1.220 +
   1.221 +