|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32test\t_smpsoakspin.cpp |
|
15 // |
|
16 |
|
17 #define __E32TEST_EXTENSION__ |
|
18 #include <e32test.h> |
|
19 #include <u32hal.h> |
|
20 #include <f32file.h> |
|
21 |
|
22 |
|
23 #include "d_smpsoak.h" |
|
24 |
|
25 #define PRINT(string) if (!gQuiet) test.Printf(string) |
|
26 #define PRINT1(string,param) if (!gQuiet) test.Printf(string,param) |
|
27 #define TESTNEXT(string) if (!gQuiet) test.Next(string) |
|
28 |
|
29 #define DEBUG_PRINT(__args) test.Printf __args |
|
30 |
|
31 //------------globals--------------------- |
|
32 LOCAL_D RTest test(_L("T_SMPSOAKSPIN")); |
|
33 LOCAL_D TBool gQuiet = EFalse; |
|
34 LOCAL_D TBool gAbort = EFalse; |
|
35 |
|
36 TInt TestCpuCount = 0; |
|
37 |
|
38 const TInt KTimerPeriod = 10000; |
|
39 |
|
40 const TInt KHeapMinSize=0x1000; |
|
41 const TInt KHeapMaxSize=0x1000; |
|
42 |
|
43 // Create a new thread |
|
44 RThread *spinthread = new RThread; |
|
45 |
|
46 //Periadic Bip |
|
47 CPeriodic* Timer; |
|
48 |
|
49 TInt SMPSpinThread(TAny*); |
|
50 |
|
51 |
|
52 struct TThread |
|
53 { |
|
54 RThread thread; |
|
55 TDesC threadName; |
|
56 TInt threadPriority; |
|
57 TInt cpuAffinity; |
|
58 TInt loopCount; |
|
59 TInt endLoopDelay; |
|
60 TBool fixedCPU; |
|
61 TBool endFlag; |
|
62 }; |
|
63 |
|
64 TThread ThreadTable[] = |
|
65 { |
|
66 { RThread(), _L("Thread1"), EPriorityAbsoluteHigh, 0, 1000, 100, EFalse, EFalse}, |
|
67 { RThread(), _L("Thread2"), EPriorityAbsoluteHigh, 0, 1000, 100, EFalse, EFalse}, |
|
68 }; |
|
69 |
|
70 enum |
|
71 { |
|
72 KThreads = (TInt)(sizeof(ThreadTable) / sizeof(TThread)) |
|
73 }; |
|
74 |
|
75 void ShowHelp() |
|
76 { |
|
77 PRINT(_L("***************************************\n")); |
|
78 PRINT(_L("The following are available commands\n")); |
|
79 PRINT(_L("Esc to exit\n")); |
|
80 PRINT(_L("***************************************\n")); |
|
81 } |
|
82 |
|
83 TInt NumberOfCpus() |
|
84 { |
|
85 TInt r = UserSvr::HalFunction(EHalGroupKernel, EKernelHalNumLogicalCpus, 0, 0); |
|
86 test(r>0); |
|
87 return r; |
|
88 } |
|
89 |
|
90 |
|
91 void ParseCommandLine () |
|
92 { |
|
93 TBuf<64> c; |
|
94 |
|
95 User::CommandLine(c); |
|
96 c.LowerCase(); |
|
97 |
|
98 if (c != KNullDesC) |
|
99 { |
|
100 TLex lex(c); |
|
101 TPtrC token; |
|
102 |
|
103 while (token.Set(lex.NextToken()), token != KNullDesC) |
|
104 { |
|
105 if (token.Mid(0) == _L("quiet")) |
|
106 { |
|
107 gQuiet = ETrue; |
|
108 continue; |
|
109 } |
|
110 |
|
111 if (token.Mid(0) == _L("verbose")) |
|
112 { |
|
113 gQuiet = EFalse; |
|
114 continue; |
|
115 } |
|
116 } |
|
117 } |
|
118 } |
|
119 |
|
120 // CActive class to monitor KeyStrokes from User |
|
121 class CActiveConsole : public CActive |
|
122 { |
|
123 public: |
|
124 CActiveConsole(); |
|
125 ~CActiveConsole(); |
|
126 void GetCharacter(); |
|
127 static TInt Callback(TAny* aCtrl); |
|
128 static CPeriodic* TimerL(); |
|
129 private: |
|
130 |
|
131 |
|
132 // Defined as pure virtual by CActive; |
|
133 // implementation provided by this class. |
|
134 virtual void DoCancel(); |
|
135 // Defined as pure virtual by CActive; |
|
136 // implementation provided by this class, |
|
137 virtual void RunL(); |
|
138 void ProcessKeyPressL(TChar aChar); |
|
139 }; |
|
140 |
|
141 // Class CActiveConsole |
|
142 CActiveConsole::CActiveConsole() |
|
143 : CActive(EPriorityHigh) |
|
144 { |
|
145 CActiveScheduler::Add(this); |
|
146 } |
|
147 |
|
148 CActiveConsole::~CActiveConsole() |
|
149 { |
|
150 Cancel(); |
|
151 } |
|
152 |
|
153 CPeriodic* CActiveConsole::TimerL() |
|
154 { |
|
155 return(CPeriodic::NewL(EPriorityNormal)); |
|
156 } |
|
157 |
|
158 // Callback function for timer expiry |
|
159 TInt CActiveConsole::Callback(TAny* aControl) |
|
160 { |
|
161 return KErrNone; |
|
162 } |
|
163 |
|
164 void CActiveConsole::GetCharacter() |
|
165 { |
|
166 test.Console()->Read(iStatus); |
|
167 SetActive(); |
|
168 } |
|
169 |
|
170 void CActiveConsole::DoCancel() |
|
171 { |
|
172 PRINT(_L("CActiveConsole::DoCancel\n")); |
|
173 test.Console()->ReadCancel(); |
|
174 } |
|
175 |
|
176 void CActiveConsole::ProcessKeyPressL(TChar aChar) |
|
177 { |
|
178 if (aChar == EKeyEscape) |
|
179 { |
|
180 PRINT(_L("CActiveConsole: ESC key pressed -> stopping active scheduler...\n")); |
|
181 CActiveScheduler::Stop(); |
|
182 return; |
|
183 } |
|
184 aChar.UpperCase(); |
|
185 GetCharacter(); |
|
186 } |
|
187 |
|
188 void CActiveConsole::RunL() |
|
189 { |
|
190 ProcessKeyPressL(static_cast<TChar>(test.Console()->KeyCode())); |
|
191 } |
|
192 |
|
193 TInt E32Main() |
|
194 { |
|
195 test.Title(); |
|
196 __UHEAP_MARK; |
|
197 test.Start(_L("SMP Soak Test")); |
|
198 |
|
199 test.Next(_L("Load device driver")); |
|
200 TInt r = User::LoadLogicalDevice(_L("d_smpsoak.ldd")); |
|
201 if (r == KErrNotFound) |
|
202 { |
|
203 test.Printf(_L("Test not supported on this platform because the D_SMPSOAK.LDD Driver is Not Present\n")); |
|
204 test.End(); |
|
205 return 0; |
|
206 } |
|
207 |
|
208 test.Next(_L("Calling rt.Open")); |
|
209 RSMPSoak rt; |
|
210 r = rt.Open(); |
|
211 if (r!=KErrNone) |
|
212 { |
|
213 test.Printf(_L("Error- Couldn't able to open soak driver:%d"),r); |
|
214 return r; |
|
215 } |
|
216 test.Next(_L("rt.Open called")); |
|
217 |
|
218 spinthread->Create(_L("SMPSpinThread"), SMPSpinThread, KDefaultStackSize, KHeapMinSize, KHeapMaxSize, &rt); |
|
219 DEBUG_PRINT((_L("SMPSoak Thread is %x\n"), spinthread)); |
|
220 |
|
221 spinthread->SetPriority(EPriorityAbsoluteLow); |
|
222 |
|
223 spinthread->Resume(); |
|
224 |
|
225 ParseCommandLine(); |
|
226 |
|
227 CActiveScheduler* myScheduler = new (ELeave) CActiveScheduler(); |
|
228 test(myScheduler !=NULL); |
|
229 CActiveScheduler::Install(myScheduler); |
|
230 |
|
231 CPeriodic* theTimer=NULL; |
|
232 TRAPD(ret,theTimer=CActiveConsole::TimerL()) |
|
233 test_KErrNone(ret); |
|
234 theTimer->Start(0,KTimerPeriod,TCallBack(CActiveConsole::Callback)); |
|
235 |
|
236 CActiveConsole* myActiveConsole = new CActiveConsole(); |
|
237 test(myActiveConsole !=NULL); |
|
238 myActiveConsole->GetCharacter(); |
|
239 |
|
240 CActiveScheduler::Start(); |
|
241 |
|
242 delete theTimer; |
|
243 |
|
244 __UHEAP_MARKEND; |
|
245 |
|
246 test.End(); |
|
247 |
|
248 return 0; |
|
249 } |
|
250 |
|
251 TInt SMPSpinThread(TAny* rt) |
|
252 { |
|
253 TInt startCpu = 0x00; |
|
254 TInt endCpu = 0x00; |
|
255 RTimer timer; |
|
256 test(timer.CreateLocal()==KErrNone); |
|
257 TRequestStatus s; |
|
258 |
|
259 RSMPSoak* pMyDriver = (RSMPSoak*)rt; |
|
260 RTest test(_L("SMPSpinThread")); |
|
261 test.Title(); |
|
262 |
|
263 FOREVER |
|
264 { |
|
265 startCpu = pMyDriver->TryControl(RSMPSoak::KGETCURRENTCPU, 0); |
|
266 |
|
267 timer.After(s, 250000); |
|
268 User::WaitForRequest(s); |
|
269 test(s==KErrNone); |
|
270 DEBUG_PRINT((_L("+"))); |
|
271 |
|
272 endCpu = pMyDriver->TryControl(RSMPSoak::KGETCURRENTCPU, 0); |
|
273 |
|
274 if(startCpu != endCpu) |
|
275 { |
|
276 DEBUG_PRINT((_L("\r\nSMPSoakSpin app:- Thread moved from cpu %d to cpu %d ************\n"), startCpu, endCpu)); |
|
277 } |
|
278 if (gAbort) |
|
279 break; |
|
280 } |
|
281 |
|
282 timer.Cancel(); |
|
283 DEBUG_PRINT((_L("MyTimer.Cancel() called\n"))); |
|
284 return 0x00; |
|
285 } |
|
286 |
|
287 |