Update contrib.
1 // Copyright (c) 2005-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\mmu\t_wdpsoak.cpp
18 #define __E32TEST_EXTENSION__
22 #include "../mmu/mmudetect.h"
23 #include "../mmu/freeram.h"
26 #define PRINT(string) if (!gQuiet) test.Printf(string)
27 #define PRINT1(string,param) if (!gQuiet) test.Printf(string,param)
28 #define TESTNEXT(string) if (!gQuiet) test.Next(string)
30 //------------globals---------------------
31 LOCAL_D RTest test(_L("T_WDPSOAK"));
32 LOCAL_D TInt gPageSize = 0;
33 LOCAL_D TUint gChunkSize = 0; // default chunk size
34 LOCAL_D RChunk gChunk[MAX_CHUNKS];
35 LOCAL_D TUint gNextChunk = 0;
36 LOCAL_D TBool gQuiet = EFalse;
37 LOCAL_D TUint gPeriod = 0;
38 LOCAL_D TUint gMin = 0;
39 LOCAL_D TUint gMax = 0;
40 LOCAL_D TUint gMemScheme = 0;
42 const TUint32 KFlushQuietLimit = 100000;
47 test_KErrNone(UserSvr::HalFunction(EHalGroupVM, EVMHalGetSwapInfo, &swapInfo, 0));
49 return swapInfo.iSwapFree;
55 test_KErrNone(UserSvr::HalFunction(EHalGroupVM, EVMHalGetSwapInfo, &swapInfo, 0));
57 return swapInfo.iSwapSize;
60 void CacheSize(TUint aMin, TUint aMax)
63 if (UserSvr::HalFunction(EHalGroupVM,EVMHalGetCacheSize,&info,0) != KErrNone)
68 if (aMin > 0 || aMax > 0)
78 UserSvr::HalFunction(EHalGroupVM,EVMHalSetCacheSize,(TAny*)info.iMinSize,(TAny*)info.iMaxSize);
79 if (UserSvr::HalFunction(EHalGroupVM,EVMHalGetCacheSize,&info,0) != KErrNone)
85 PRINT1(_L("Paging Cache min size %d"),info.iMinSize);
86 PRINT1(_L(" max size %d"),info.iMaxSize);
87 PRINT1(_L(" current size %d\n"),info.iCurrentSize);
92 PRINT1(_L("RAM free 0x%08X bytes"),FreeRam());
93 PRINT1(_L(" Swap free 0x%08X bytes\n"),SwapFree());
95 TPckgBuf<DPTest::TEventInfo> infoBuf;
96 TInt r = UserSvr::HalFunction(EHalGroupVM,EVMHalGetEventInfo,&infoBuf,0);
101 PRINT1(_L("Page fault count %d"),infoBuf().iPageFaultCount);
102 PRINT1(_L(" Page IN count %d\n"),infoBuf().iPageInReadCount);
109 PRINT(_L("***************************************\n"));
110 PRINT(_L("The following are immediate commands\n"));
111 PRINT(_L("F flush the paging cache\n"));
112 PRINT(_L("I show memory information\n"));
113 PRINT(_L("? show this help\n"));
114 PRINT(_L("Rn read all pages of chunk n\n"));
115 PRINT(_L("Wn write all pages of chunk n\n"));
116 PRINT(_L("Mn periodic memory scheme n\n"));
117 PRINT(_L("The following require a <CR> termination\n"));
118 PRINT(_L("C=nnnn create a chunnk of size nnnn\n"));
119 PRINT(_L("L=nnnn paging cache min size nnnn\n"));
120 PRINT(_L("H=nnnn paging cache max size nnnn\n"));
121 PRINT(_L("P=nnnn periodic flush/memory scheme nnnn microseconds\n"));
122 PRINT(_L("Esc to exit\n"));
123 PRINT(_L("***************************************\n"));
126 void CreateChunk(RChunk * aChunk, TUint aSize)
128 TESTNEXT(_L("Creating a paged chunk"));
129 TChunkCreateInfo createInfo;
130 PRINT1(_L("Creating chunk size 0x%08X bytes "),aSize);
131 PRINT1(_L("at index %d\n"),gNextChunk);
132 createInfo.SetPaging(TChunkCreateInfo::EPaged);
133 createInfo.SetNormal(aSize,aSize);
134 test_KErrNone(aChunk->Create(createInfo));
137 void ReadChunk(RChunk * aChunk)
139 TESTNEXT(_L("Reading from each page of chunk"));
140 TUint8* chunkBase = aChunk->Base();
143 for (TInt i = 0; i < aChunk->Size(); i += gPageSize)
145 chunkVal = * (chunkBase + i);
148 // only needed to remove compiler warning on unused variable
155 void WriteChunk(RChunk * aChunk, TUint8 aValue = 0)
157 static TUint8 lastWriteValue = 1;
158 TESTNEXT(_L("Writing to each page of chunk"));
159 TUint8* chunkBase = aChunk->Base();
161 lastWriteValue = (TUint8)(aValue == 0 ? lastWriteValue + 1 : aValue);
162 for (TInt i = 0; i < aChunk->Size(); i += gPageSize)
164 * (chunkBase + i) = lastWriteValue;
170 void ParseCommandLine ()
174 User::CommandLine(c);
182 while (token.Set(lex.NextToken()), token != KNullDesC)
184 if (token.Mid(0) == _L("quiet"))
190 if (token.Mid(0) == _L("verbose"))
196 if (token.Left(5) == _L("chunk"))
199 equalPos = token.Locate('=');
200 if (equalPos > 0 && (equalPos+1) < token.Length())
202 TLex lexNum(token.Mid(equalPos+1));
203 lexNum.Val(gChunkSize,EDecimal);
208 if (token.Left(3) == _L("low"))
211 equalPos = token.Locate('=');
212 if (equalPos > 0 && (equalPos+1) < token.Length())
214 TLex lexNum(token.Mid(equalPos+1));
215 lexNum.Val(gMin,EDecimal);
220 if (token.Left(5) == _L("high"))
223 equalPos = token.Locate('=');
224 if (equalPos > 0 && (equalPos+1) < token.Length())
226 TLex lexNum(token.Mid(equalPos+1));
227 lexNum.Val(gMax,EDecimal);
232 if (token.Left(6) == _L("period"))
235 equalPos = token.Locate('=');
236 if (equalPos > 0 && (equalPos+1) < token.Length())
238 TLex lexNum(token.Mid(equalPos+1));
239 lexNum.Val(gPeriod,EDecimal);
244 if (token.Left(3) == _L("mem"))
247 equalPos = token.Locate('=');
248 if (equalPos > 0 && (equalPos+1) < token.Length())
250 TLex lexNum(token.Mid(equalPos+1));
251 lexNum.Val(gMemScheme,EDecimal);
265 EMemScheme1 = 1 << 4,
266 EMemScheme2 = 2 << 4,
267 EMemScheme3 = 3 << 4,
268 EMemScheme4 = 4 << 4,
271 // CActive class to monitor KeyStrokes from User
272 class CActiveConsole : public CActive
278 static TInt Callback(TAny* aCtrl);
290 // Defined as pure virtual by CActive;
291 // implementation provided by this class.
292 virtual void DoCancel();
293 // Defined as pure virtual by CActive;
294 // implementation provided by this class,
296 void ProcessKeyPressL(TChar aChar);
300 // Class CActiveConsole
301 CActiveConsole::CActiveConsole()
302 : CActive(EPriorityHigh)
304 CActiveScheduler::Add(this);
306 iTimer = CPeriodic::NewL(EPriorityNormal);
307 iActions = ENoaction;
314 iActions = (TUint16)(gMemScheme << 4);
318 iActions = (TUint16)(gPeriod < KFlushQuietLimit ? EFlushQuiet : EFlush);
321 iTimer->Start(0,gPeriod,TCallBack(Callback,this));
325 CActiveConsole::~CActiveConsole()
333 // Callback function for timer expiry
334 TInt CActiveConsole::Callback(TAny* aControl)
336 switch (((CActiveConsole*)aControl)->iActions & 0x0F)
342 PRINT(_L("Flush\n"));
343 // drop through to quiet
346 test_KErrNone(DPTest::FlushCache());
353 switch (((CActiveConsole*)aControl)->iActions & 0xF0)
357 for (i = 0; i < gNextChunk; i++)
358 ReadChunk (&gChunk[i]);
362 for (i = 0; i < gNextChunk; i++)
363 WriteChunk (&gChunk[i]);
373 void CActiveConsole::GetCharacter()
377 PRINT(_L("***Command (F,I,Q,V,?,Rn,Wn,Mn,C=nnnnn,H=nnnn,L=nnnn,P=nnnn) or Esc to exit ***\n"));
380 test.Console()->Read(iStatus);
384 void CActiveConsole::DoCancel()
386 PRINT(_L("CActiveConsole::DoCancel\n"));
387 test.Console()->ReadCancel();
390 void CActiveConsole::ProcessKeyPressL(TChar aChar)
392 if (aChar == EKeyEscape)
394 PRINT(_L("CActiveConsole: ESC key pressed -> stopping active scheduler...\n"));
395 CActiveScheduler::Stop();
399 if (iCmdGetValue != 0 && aChar == '\r')
401 if (iLastChar == 'K')
403 iValue *= iGetHexValue ? 0x400 : 1000;
405 if (iLastChar == 'M')
407 iValue *= iGetHexValue ? 0x10000 : 1000000;
409 PRINT1(_L("CActiveConsole: Value %d\n"),iValue);
412 if (iCmdGetValue != 0 )
418 iValue = iValue * 16 + aChar.GetNumericValue();
422 if (aChar.IsHexDigit())
424 iValue = iValue * 16 + (TUint)aChar - 'A' + 10;
428 if (aChar != 'K' && aChar != 'M')
430 PRINT(_L("Illegal hexadecimal character - Enter command\n"));
440 iValue = iValue * 10 + aChar.GetNumericValue();
444 if ((aChar == 'X') && (iLastChar == '0') && (iValue == 0))
445 iGetHexValue = ETrue;
448 if (aChar != 'K' && aChar != 'M')
450 test.Printf(_L("Illegal decimal character - Enter command\n"));
462 TESTNEXT(_L("Flushing Cache"));
463 test_KErrNone(DPTest::FlushCache());
489 iCmdGetValue = iLastChar;
490 iGetHexValue = EFalse;
497 if (iLastChar == 'R')
499 if (aChar.GetNumericValue() < (TInt)gNextChunk)
501 ReadChunk (&gChunk[aChar.GetNumericValue()]);
505 for (TUint i = 0; i < gNextChunk; i++)
506 ReadChunk (&gChunk[i]);
510 if (iLastChar == 'W')
512 if (aChar.GetNumericValue() < (TInt)gNextChunk)
514 WriteChunk (&gChunk[aChar.GetNumericValue()]);
518 for (TUint i = 0; i < gNextChunk; i++)
519 WriteChunk (&gChunk[i]);
523 if (iLastChar == 'M')
525 if (aChar.GetNumericValue() == 0)
527 iActions = (TUint16)(iPeriod < KFlushQuietLimit ? EFlushQuiet : EFlush);
531 iActions = (TUint16)(aChar.GetNumericValue() << 4);
544 void CActiveConsole::ProcessValue()
546 switch (iCmdGetValue)
549 if (iValue > 0 && gNextChunk < MAX_CHUNKS)
551 CreateChunk (&gChunk[gNextChunk], iValue);
552 ReadChunk (&gChunk[gNextChunk]);
559 CacheSize (0,iValue);
563 CacheSize (iValue,0);
568 iActions = (TUint16)(iValue < KFlushQuietLimit ? EFlushQuiet : EFlush);
572 iTimer->Start(0,iValue,TCallBack(Callback,this));
583 void CActiveConsole::RunL()
585 ProcessKeyPressL(static_cast<TChar>(test.Console()->KeyCode()));
591 test.Start(_L("Writable Data Paging Soak Test"));
595 if (DPTest::Attributes() & DPTest::ERomPaging)
596 test.Printf(_L("Rom paging supported\n"));
597 if (DPTest::Attributes() & DPTest::ECodePaging)
598 test.Printf(_L("Code paging supported\n"));
599 if (DPTest::Attributes() & DPTest::EDataPaging)
600 test.Printf(_L("Data paging supported\n"));
603 HAL::Get(HAL::EMemoryRAM,totalRamSize);
604 HAL::Get(HAL::EMemoryPageSize,gPageSize);
605 test.Printf(_L("Total RAM size 0x%08X bytes"),totalRamSize);
606 test.Printf(_L(" Swap size 0x%08X bytes"),SwapSize());
607 test.Printf(_L(" Page size 0x%08X bytes\n"),gPageSize);
608 CacheSize(gMin,gMax);
610 if ((DPTest::Attributes() & DPTest::EDataPaging) == 0)
612 test.Printf(_L("Writable Demand Paging not supported\n"));
619 //User::SetDebugMask(0x00000008); //KMMU
620 //User::SetDebugMask(0x00000080); //KEXEC
621 //User::SetDebugMask(0x90000000); //KPANIC KMMU2
622 //User::SetDebugMask(0x40000000, 1); //KPAGING
626 CreateChunk (&gChunk[gNextChunk], gChunkSize);
627 ReadChunk (&gChunk[gNextChunk]);
632 CActiveScheduler* myScheduler = new (ELeave) CActiveScheduler();
633 CActiveScheduler::Install(myScheduler);
635 CActiveConsole* myActiveConsole = new CActiveConsole();
636 myActiveConsole->GetCharacter();
638 CActiveScheduler::Start();