os/kernelhwsrv/kerneltest/e32utils/demandpaging/dptestcons.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32utils/demandpaging/dptestcons.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,175 @@
     1.4 +// Copyright (c) 2007-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 +// e32utils\demandpaging\dptestcons.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32cons.h>
    1.22 +#include <dptest.h>
    1.23 +
    1.24 +CConsoleBase* TheConsole;
    1.25 +
    1.26 +
    1.27 +void doHelp()
    1.28 +	{
    1.29 +	TheConsole->Printf(_L("Usage: dptestcons [-h] [-o] [-f] [-sMIN,MAX]\n"));
    1.30 +	TheConsole->Printf(_L("\n"));
    1.31 +	TheConsole->Printf(_L("-h    Prints this help information\n"));
    1.32 +	TheConsole->Printf(_L("-o    Prints all DPTest information\n"));
    1.33 +	TheConsole->Printf(_L("-f    Flushes the Demand Paging cache\n"));
    1.34 +	TheConsole->Printf(_L("-s    Sets the Demand Paging cache size (MIN and MAX in bytes)\n"));
    1.35 +	}
    1.36 +
    1.37 +void doDPTestInformation()
    1.38 +	{
    1.39 +	TheConsole->Printf(_L("DPTest information\n==================\n"));
    1.40 +	TUint32 attribs = DPTest::Attributes();
    1.41 +	_LIT(KOn, "ON");
    1.42 +	_LIT(KOff, "OFF");
    1.43 +	TheConsole->Printf(_L("ROM Paging:  %S\n"), (attribs&DPTest::ERomPaging) ? &KOn : &KOff);
    1.44 +	TheConsole->Printf(_L("Code Paging: %S\n"), (attribs&DPTest::ECodePaging) ? &KOn : &KOff);
    1.45 +	TheConsole->Printf(_L("Data Paging: %S\n"), (attribs&DPTest::EDataPaging) ? &KOn : &KOff);
    1.46 +	TUint min;
    1.47 +	TUint max;
    1.48 +	TUint current;
    1.49 +	TInt err = DPTest::CacheSize(min, max, current);
    1.50 +	if (err == KErrNone)
    1.51 +		{
    1.52 +		TheConsole->Printf(_L("CacheSize: Min=%u, Max=%u, Current=%u\n"), min, max, current);
    1.53 +		}
    1.54 +	else
    1.55 +		{
    1.56 +		TheConsole->Printf(_L("CacheSize failed with err=%d\n"), err);
    1.57 +		}
    1.58 +	TPckgBuf<DPTest::TEventInfo> eventPckg;
    1.59 +	err = DPTest::EventInfo(eventPckg);
    1.60 +	if (err == KErrNone)
    1.61 +		{
    1.62 +		TheConsole->Printf(_L("EventInfo: PageFaultCount=%Lu, PageInCount=%Lu\n"), eventPckg().iPageFaultCount, eventPckg().iPageInReadCount);
    1.63 +		}
    1.64 +	else
    1.65 +		{
    1.66 +		TheConsole->Printf(_L("EventInfo failed with err=%d\n"), err);
    1.67 +		}
    1.68 +	TheConsole->Printf(_L("==================\n"));
    1.69 +	}
    1.70 +
    1.71 +void doFlushCache()
    1.72 +	{
    1.73 +	TInt err = DPTest::FlushCache();
    1.74 +	TheConsole->Printf(_L("FlushCache completed with err=%d\n"), err);
    1.75 +	}
    1.76 +
    1.77 +void doSetCacheSize(const TDesC& aCacheSizes)
    1.78 +	{
    1.79 +	TLex lex(aCacheSizes);
    1.80 +	TChar c = lex.Peek();
    1.81 +	while (c != 0 && c != ',')
    1.82 +		{
    1.83 +		lex.Inc();
    1.84 +		c = lex.Peek();
    1.85 +		}
    1.86 +	TPtrC valDes = lex.MarkedToken();
    1.87 +	TUint min;
    1.88 +	if (TLex(valDes).Val(min) != KErrNone)
    1.89 +		{
    1.90 +		TheConsole->Printf(_L("Bad minimum value provided for SetCacheSize: %S\n"), &valDes);
    1.91 +		return;
    1.92 +		}
    1.93 +	if (c != 0)
    1.94 +		{
    1.95 +		lex.Inc();
    1.96 +		}
    1.97 +	valDes.Set(lex.Remainder());
    1.98 +	TUint max;
    1.99 +	if (TLex(valDes).Val(max) != KErrNone)
   1.100 +		{
   1.101 +		TheConsole->Printf(_L("Bad maximum value provided for SetCacheSize: %S\n"), &valDes);
   1.102 +		return;
   1.103 +		}
   1.104 +	TInt err = DPTest::SetCacheSize(min, max);
   1.105 +	TheConsole->Printf(_L("SetCacheSize (Min=%u, Max=%u) completed with err=%d\n"), min, max, err);
   1.106 +	}
   1.107 +
   1.108 +void processCommands(RArray<TPtrC> aArgArray)
   1.109 +	{
   1.110 +	const TInt count = aArgArray.Count();
   1.111 +	if (count == 0)
   1.112 +		{
   1.113 +		doHelp();
   1.114 +		return;
   1.115 +		}
   1.116 +	for (TInt ii=0; ii<count; ii++)
   1.117 +		{
   1.118 +		TPtrC current = aArgArray[ii];
   1.119 +		if (current.Length() < 2 || current[0] != '-')
   1.120 +			{
   1.121 +			TheConsole->Printf(_L("Unknown command: %S\n"), &current);
   1.122 +			}
   1.123 +		switch (current[1])
   1.124 +			{
   1.125 +		case 'h':
   1.126 +			doHelp();
   1.127 +			break;
   1.128 +		case 'o':
   1.129 +			doDPTestInformation();
   1.130 +			break;
   1.131 +		case 'f':
   1.132 +			doFlushCache();
   1.133 +			break;
   1.134 +		case 's':
   1.135 +			doSetCacheSize(current.Mid(2));
   1.136 +			break;
   1.137 +		default:
   1.138 +			TheConsole->Printf(_L("Unknown command: %S\n"), &current);
   1.139 +			break;
   1.140 +			}
   1.141 +		}
   1.142 +	}
   1.143 +
   1.144 +TInt E32Main()
   1.145 +	{
   1.146 +	// create console...
   1.147 +	TFileName exeFile = RProcess().FileName();
   1.148 +	TRAPD(err, TheConsole = Console::NewL(exeFile,TSize(KConsFullScreen,KConsFullScreen)));
   1.149 +	TheConsole->Printf(_L("---DPTESTCONS---\n"));
   1.150 +	if (err != KErrNone)
   1.151 +		{
   1.152 +		return err;
   1.153 +		}
   1.154 +	// get command-line...
   1.155 +	RBuf clDes;
   1.156 +	if (clDes.Create(User::CommandLineLength()+1) != KErrNone)
   1.157 +		{
   1.158 +		return err;
   1.159 +		}
   1.160 +	User::CommandLine(clDes);
   1.161 +
   1.162 +	// split up args...
   1.163 +	RArray<TPtrC> argArray;
   1.164 +	TLex lex(clDes);
   1.165 +	while (!lex.Eos())
   1.166 +		{
   1.167 +		err = argArray.Append(lex.NextToken());
   1.168 +		if (err != KErrNone)
   1.169 +			{
   1.170 +			return err;
   1.171 +			}
   1.172 +		}
   1.173 +	processCommands(argArray);
   1.174 +
   1.175 +	TheConsole->Printf(_L("Press any key to continue.\n"));
   1.176 +	TheConsole->Getch();
   1.177 +	return 0;
   1.178 +	}