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