kerneltest/e32utils/demandpaging/dptestcons.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2007-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 // e32utils\demandpaging\dptestcons.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32cons.h>
       
    19 #include <dptest.h>
       
    20 
       
    21 CConsoleBase* TheConsole;
       
    22 
       
    23 
       
    24 void doHelp()
       
    25 	{
       
    26 	TheConsole->Printf(_L("Usage: dptestcons [-h] [-o] [-f] [-sMIN,MAX]\n"));
       
    27 	TheConsole->Printf(_L("\n"));
       
    28 	TheConsole->Printf(_L("-h    Prints this help information\n"));
       
    29 	TheConsole->Printf(_L("-o    Prints all DPTest information\n"));
       
    30 	TheConsole->Printf(_L("-f    Flushes the Demand Paging cache\n"));
       
    31 	TheConsole->Printf(_L("-s    Sets the Demand Paging cache size (MIN and MAX in bytes)\n"));
       
    32 	}
       
    33 
       
    34 void doDPTestInformation()
       
    35 	{
       
    36 	TheConsole->Printf(_L("DPTest information\n==================\n"));
       
    37 	TUint32 attribs = DPTest::Attributes();
       
    38 	_LIT(KOn, "ON");
       
    39 	_LIT(KOff, "OFF");
       
    40 	TheConsole->Printf(_L("ROM Paging:  %S\n"), (attribs&DPTest::ERomPaging) ? &KOn : &KOff);
       
    41 	TheConsole->Printf(_L("Code Paging: %S\n"), (attribs&DPTest::ECodePaging) ? &KOn : &KOff);
       
    42 	TheConsole->Printf(_L("Data Paging: %S\n"), (attribs&DPTest::EDataPaging) ? &KOn : &KOff);
       
    43 	TUint min;
       
    44 	TUint max;
       
    45 	TUint current;
       
    46 	TInt err = DPTest::CacheSize(min, max, current);
       
    47 	if (err == KErrNone)
       
    48 		{
       
    49 		TheConsole->Printf(_L("CacheSize: Min=%u, Max=%u, Current=%u\n"), min, max, current);
       
    50 		}
       
    51 	else
       
    52 		{
       
    53 		TheConsole->Printf(_L("CacheSize failed with err=%d\n"), err);
       
    54 		}
       
    55 	TPckgBuf<DPTest::TEventInfo> eventPckg;
       
    56 	err = DPTest::EventInfo(eventPckg);
       
    57 	if (err == KErrNone)
       
    58 		{
       
    59 		TheConsole->Printf(_L("EventInfo: PageFaultCount=%Lu, PageInCount=%Lu\n"), eventPckg().iPageFaultCount, eventPckg().iPageInReadCount);
       
    60 		}
       
    61 	else
       
    62 		{
       
    63 		TheConsole->Printf(_L("EventInfo failed with err=%d\n"), err);
       
    64 		}
       
    65 	TheConsole->Printf(_L("==================\n"));
       
    66 	}
       
    67 
       
    68 void doFlushCache()
       
    69 	{
       
    70 	TInt err = DPTest::FlushCache();
       
    71 	TheConsole->Printf(_L("FlushCache completed with err=%d\n"), err);
       
    72 	}
       
    73 
       
    74 void doSetCacheSize(const TDesC& aCacheSizes)
       
    75 	{
       
    76 	TLex lex(aCacheSizes);
       
    77 	TChar c = lex.Peek();
       
    78 	while (c != 0 && c != ',')
       
    79 		{
       
    80 		lex.Inc();
       
    81 		c = lex.Peek();
       
    82 		}
       
    83 	TPtrC valDes = lex.MarkedToken();
       
    84 	TUint min;
       
    85 	if (TLex(valDes).Val(min) != KErrNone)
       
    86 		{
       
    87 		TheConsole->Printf(_L("Bad minimum value provided for SetCacheSize: %S\n"), &valDes);
       
    88 		return;
       
    89 		}
       
    90 	if (c != 0)
       
    91 		{
       
    92 		lex.Inc();
       
    93 		}
       
    94 	valDes.Set(lex.Remainder());
       
    95 	TUint max;
       
    96 	if (TLex(valDes).Val(max) != KErrNone)
       
    97 		{
       
    98 		TheConsole->Printf(_L("Bad maximum value provided for SetCacheSize: %S\n"), &valDes);
       
    99 		return;
       
   100 		}
       
   101 	TInt err = DPTest::SetCacheSize(min, max);
       
   102 	TheConsole->Printf(_L("SetCacheSize (Min=%u, Max=%u) completed with err=%d\n"), min, max, err);
       
   103 	}
       
   104 
       
   105 void processCommands(RArray<TPtrC> aArgArray)
       
   106 	{
       
   107 	const TInt count = aArgArray.Count();
       
   108 	if (count == 0)
       
   109 		{
       
   110 		doHelp();
       
   111 		return;
       
   112 		}
       
   113 	for (TInt ii=0; ii<count; ii++)
       
   114 		{
       
   115 		TPtrC current = aArgArray[ii];
       
   116 		if (current.Length() < 2 || current[0] != '-')
       
   117 			{
       
   118 			TheConsole->Printf(_L("Unknown command: %S\n"), &current);
       
   119 			}
       
   120 		switch (current[1])
       
   121 			{
       
   122 		case 'h':
       
   123 			doHelp();
       
   124 			break;
       
   125 		case 'o':
       
   126 			doDPTestInformation();
       
   127 			break;
       
   128 		case 'f':
       
   129 			doFlushCache();
       
   130 			break;
       
   131 		case 's':
       
   132 			doSetCacheSize(current.Mid(2));
       
   133 			break;
       
   134 		default:
       
   135 			TheConsole->Printf(_L("Unknown command: %S\n"), &current);
       
   136 			break;
       
   137 			}
       
   138 		}
       
   139 	}
       
   140 
       
   141 TInt E32Main()
       
   142 	{
       
   143 	// create console...
       
   144 	TFileName exeFile = RProcess().FileName();
       
   145 	TRAPD(err, TheConsole = Console::NewL(exeFile,TSize(KConsFullScreen,KConsFullScreen)));
       
   146 	TheConsole->Printf(_L("---DPTESTCONS---\n"));
       
   147 	if (err != KErrNone)
       
   148 		{
       
   149 		return err;
       
   150 		}
       
   151 	// get command-line...
       
   152 	RBuf clDes;
       
   153 	if (clDes.Create(User::CommandLineLength()+1) != KErrNone)
       
   154 		{
       
   155 		return err;
       
   156 		}
       
   157 	User::CommandLine(clDes);
       
   158 
       
   159 	// split up args...
       
   160 	RArray<TPtrC> argArray;
       
   161 	TLex lex(clDes);
       
   162 	while (!lex.Eos())
       
   163 		{
       
   164 		err = argArray.Append(lex.NextToken());
       
   165 		if (err != KErrNone)
       
   166 			{
       
   167 			return err;
       
   168 			}
       
   169 		}
       
   170 	processCommands(argArray);
       
   171 
       
   172 	TheConsole->Printf(_L("Press any key to continue.\n"));
       
   173 	TheConsole->Getch();
       
   174 	return 0;
       
   175 	}