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