Update contrib.
1 // Copyright (c) 2002-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\t_smpsoakspin.cpp
17 #define __E32TEST_EXTENSION__
24 #include "d_smpsoak.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 #define DEBUG_PRINT(__args) test.Printf __args
32 //------------globals---------------------
33 LOCAL_D RTest test(_L("T_SMPSOAKSPIN"));
34 LOCAL_D TBool gQuiet = EFalse;
35 LOCAL_D TBool gAbort = EFalse;
37 TInt TestCpuCount = 0;
39 const TInt KTimerPeriod = 10000;
41 const TInt KHeapMinSize=0x1000;
42 const TInt KHeapMaxSize=0x1000;
44 // Create a new thread
45 RThread *spinthread = new RThread;
50 TInt SMPSpinThread(TAny*);
65 TThread ThreadTable[] =
67 { RThread(), _L("Thread1"), EPriorityAbsoluteHigh, 0, 1000, 100, EFalse, EFalse},
68 { RThread(), _L("Thread2"), EPriorityAbsoluteHigh, 0, 1000, 100, EFalse, EFalse},
73 KThreads = (TInt)(sizeof(ThreadTable) / sizeof(TThread))
78 PRINT(_L("***************************************\n"));
79 PRINT(_L("The following are available commands\n"));
80 PRINT(_L("Esc to exit\n"));
81 PRINT(_L("***************************************\n"));
86 TInt r = UserSvr::HalFunction(EHalGroupKernel, EKernelHalNumLogicalCpus, 0, 0);
92 void ParseCommandLine ()
104 while (token.Set(lex.NextToken()), token != KNullDesC)
106 if (token.Mid(0) == _L("quiet"))
112 if (token.Mid(0) == _L("verbose"))
121 // CActive class to monitor KeyStrokes from User
122 class CActiveConsole : public CActive
128 static TInt Callback(TAny* aCtrl);
129 static CPeriodic* TimerL();
133 // Defined as pure virtual by CActive;
134 // implementation provided by this class.
135 virtual void DoCancel();
136 // Defined as pure virtual by CActive;
137 // implementation provided by this class,
139 void ProcessKeyPressL(TChar aChar);
142 // Class CActiveConsole
143 CActiveConsole::CActiveConsole()
144 : CActive(EPriorityHigh)
146 CActiveScheduler::Add(this);
149 CActiveConsole::~CActiveConsole()
154 CPeriodic* CActiveConsole::TimerL()
156 return(CPeriodic::NewL(EPriorityNormal));
159 // Callback function for timer expiry
160 TInt CActiveConsole::Callback(TAny* aControl)
165 void CActiveConsole::GetCharacter()
167 test.Console()->Read(iStatus);
171 void CActiveConsole::DoCancel()
173 PRINT(_L("CActiveConsole::DoCancel\n"));
174 test.Console()->ReadCancel();
177 void CActiveConsole::ProcessKeyPressL(TChar aChar)
179 if (aChar == EKeyEscape)
181 PRINT(_L("CActiveConsole: ESC key pressed -> stopping active scheduler...\n"));
182 CActiveScheduler::Stop();
189 void CActiveConsole::RunL()
191 ProcessKeyPressL(static_cast<TChar>(test.Console()->KeyCode()));
198 test.Start(_L("SMP Soak Test"));
200 test.Next(_L("Load device driver"));
201 TInt r = User::LoadLogicalDevice(_L("d_smpsoak.ldd"));
202 if (r == KErrNotFound)
204 test.Printf(_L("Test not supported on this platform because the D_SMPSOAK.LDD Driver is Not Present\n"));
209 test.Next(_L("Calling rt.Open"));
214 test.Printf(_L("Error- Couldn't able to open soak driver:%d"),r);
217 test.Next(_L("rt.Open called"));
219 spinthread->Create(_L("SMPSpinThread"), SMPSpinThread, KDefaultStackSize, KHeapMinSize, KHeapMaxSize, &rt);
220 DEBUG_PRINT((_L("SMPSoak Thread is %x\n"), spinthread));
222 spinthread->SetPriority(EPriorityAbsoluteLow);
224 spinthread->Resume();
228 CActiveScheduler* myScheduler = new (ELeave) CActiveScheduler();
229 test(myScheduler !=NULL);
230 CActiveScheduler::Install(myScheduler);
232 CPeriodic* theTimer=NULL;
233 TRAPD(ret,theTimer=CActiveConsole::TimerL())
235 theTimer->Start(0,KTimerPeriod,TCallBack(CActiveConsole::Callback));
237 CActiveConsole* myActiveConsole = new CActiveConsole();
238 test(myActiveConsole !=NULL);
239 myActiveConsole->GetCharacter();
241 CActiveScheduler::Start();
252 TInt SMPSpinThread(TAny* rt)
254 TInt startCpu = 0x00;
257 test(timer.CreateLocal()==KErrNone);
260 RSMPSoak* pMyDriver = (RSMPSoak*)rt;
261 RTest test(_L("SMPSpinThread"));
266 startCpu = pMyDriver->TryControl(RSMPSoak::KGETCURRENTCPU, 0);
268 timer.After(s, 250000);
269 User::WaitForRequest(s);
271 DEBUG_PRINT((_L("+")));
273 endCpu = pMyDriver->TryControl(RSMPSoak::KGETCURRENTCPU, 0);
275 if(startCpu != endCpu)
277 DEBUG_PRINT((_L("\r\nSMPSoakSpin app:- Thread moved from cpu %d to cpu %d ************\n"), startCpu, endCpu));
284 DEBUG_PRINT((_L("MyTimer.Cancel() called\n")));