0
|
1 |
// Copyright (c) 1999-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\realtime\t_lat2.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include <e32test.h>
|
|
19 |
#include <e32svr.h>
|
|
20 |
#include <e32property.h>
|
|
21 |
#include <e32atomics.h>
|
|
22 |
#include "runtests.h"
|
|
23 |
#include "d_latncy.h"
|
|
24 |
|
|
25 |
_LIT(KLatencyLddFileName,"D_LATNCY");
|
|
26 |
_LIT(KThreadName,"LatencyThreadU");
|
|
27 |
|
|
28 |
RTest test(_L("Latency"));
|
|
29 |
RThread Main;
|
|
30 |
TUint TicksPerMs;
|
|
31 |
|
|
32 |
struct SFullLatencyResults : public SLatencyResults
|
|
33 |
{
|
|
34 |
TUint iKernRetAddr;
|
|
35 |
TUint iUserRetAddr;
|
|
36 |
TInt64 iCount;
|
|
37 |
TInt64 iSumIntTicks;
|
|
38 |
TInt64 iSumKernTicks;
|
|
39 |
TInt64 iSumUserTicks;
|
|
40 |
TUint iIntCpsr;
|
|
41 |
TUint iKernCpsr;
|
|
42 |
TUint iKernR14;
|
|
43 |
TUint iUserCpsr;
|
|
44 |
TUint iUserR14;
|
|
45 |
|
|
46 |
void Update(SLatencyResults& aResults);
|
|
47 |
};
|
|
48 |
|
|
49 |
SFullLatencyResults Latencies;
|
|
50 |
volatile TUint32 UpdateCount=0;
|
|
51 |
|
|
52 |
TUint TimerToMicroseconds(TUint aTimerValue)
|
|
53 |
{
|
|
54 |
return (aTimerValue*1000+TicksPerMs-1)/TicksPerMs;
|
|
55 |
}
|
|
56 |
|
|
57 |
void SFullLatencyResults::Update(SLatencyResults& aResults)
|
|
58 |
{
|
|
59 |
__e32_atomic_add_acq32(&UpdateCount, 1);
|
|
60 |
|
|
61 |
// memory barrier
|
|
62 |
|
|
63 |
if (aResults.iIntTicks>iIntTicks)
|
|
64 |
{
|
|
65 |
iIntTicks=aResults.iIntTicks;
|
|
66 |
iIntRetAddr=aResults.iIntRetAddr;
|
|
67 |
#ifdef __CAPTURE_EXTRAS
|
|
68 |
iIntCpsr=aResults.iIntSpsr;
|
|
69 |
iIntR14=aResults.iIntR14;
|
|
70 |
#endif
|
|
71 |
}
|
|
72 |
if (aResults.iKernThreadTicks>iKernThreadTicks)
|
|
73 |
{
|
|
74 |
iKernThreadTicks=aResults.iKernThreadTicks;
|
|
75 |
iKernRetAddr=aResults.iIntRetAddr;
|
|
76 |
#ifdef __CAPTURE_EXTRAS
|
|
77 |
iKernCpsr=aResults.iIntSpsr;
|
|
78 |
iKernR14=aResults.iIntR14;
|
|
79 |
#endif
|
|
80 |
}
|
|
81 |
if (aResults.iUserThreadTicks>iUserThreadTicks)
|
|
82 |
{
|
|
83 |
iUserThreadTicks=aResults.iUserThreadTicks;
|
|
84 |
iUserRetAddr=aResults.iIntRetAddr;
|
|
85 |
#ifdef __CAPTURE_EXTRAS
|
|
86 |
iUserCpsr=aResults.iIntSpsr;
|
|
87 |
iUserR14=aResults.iIntR14;
|
|
88 |
#endif
|
|
89 |
}
|
|
90 |
iSumIntTicks+=aResults.iIntTicks;
|
|
91 |
iSumKernTicks+=aResults.iKernThreadTicks;
|
|
92 |
iSumUserTicks+=aResults.iUserThreadTicks;
|
|
93 |
++iCount;
|
|
94 |
|
|
95 |
// memory barrier
|
|
96 |
|
|
97 |
__e32_atomic_add_rel32(&UpdateCount, 1);
|
|
98 |
}
|
|
99 |
|
|
100 |
TInt LatencyThread(TAny* aStatus)
|
|
101 |
{
|
|
102 |
TRequestStatus* pS=(TRequestStatus*)aStatus;
|
|
103 |
RLatency l;
|
|
104 |
TInt r=l.Open();
|
|
105 |
if (r!=KErrNone)
|
|
106 |
return r;
|
|
107 |
TicksPerMs=l.TicksPerMs();
|
|
108 |
Mem::FillZ(&Latencies,sizeof(Latencies));
|
|
109 |
Main.RequestComplete(pS,0);
|
|
110 |
SLatencyResults results;
|
|
111 |
|
|
112 |
l.Start();
|
121
|
113 |
volatile TInt forever = 1;
|
|
114 |
while(forever)
|
0
|
115 |
{
|
|
116 |
User::WaitForAnyRequest();
|
|
117 |
l.GetResults(results);
|
|
118 |
Latencies.Update(results);
|
|
119 |
}
|
121
|
120 |
return 0;
|
0
|
121 |
}
|
|
122 |
|
|
123 |
void GetLatencies(SFullLatencyResults& aResults)
|
|
124 |
{
|
|
125 |
FOREVER
|
|
126 |
{
|
|
127 |
TUint32 u1 = UpdateCount;
|
|
128 |
__e32_memory_barrier();
|
|
129 |
aResults=Latencies;
|
|
130 |
__e32_memory_barrier();
|
|
131 |
TUint32 u2 = UpdateCount;
|
|
132 |
if (u1==u2 && !(u1&1)) // no good if it changed partway through or was changing when we started
|
|
133 |
break;
|
|
134 |
}
|
|
135 |
}
|
|
136 |
|
|
137 |
_LIT(KPrefixRuntests, "RUNTESTS: RT");
|
|
138 |
void DisplayMaxValues(const TDesC& aPrefix)
|
|
139 |
{
|
|
140 |
SFullLatencyResults v;
|
|
141 |
GetLatencies(v);
|
|
142 |
TUint i=TimerToMicroseconds(v.iIntTicks);
|
|
143 |
TUint k=TimerToMicroseconds(v.iKernThreadTicks);
|
|
144 |
TUint u=TimerToMicroseconds(v.iUserThreadTicks);
|
|
145 |
TUint ia=v.iIntRetAddr;
|
|
146 |
TUint ka=v.iKernRetAddr;
|
|
147 |
TUint ua=v.iUserRetAddr;
|
|
148 |
test.Printf(_L("%SMAX: Int %4d %08x Kern %4d %08x User %4d %08x\n"),&aPrefix,i,ia,k,ka,u,ua);
|
|
149 |
}
|
|
150 |
|
|
151 |
void DisplayAvgValues(const TDesC& aPrefix)
|
|
152 |
{
|
|
153 |
SFullLatencyResults v;
|
|
154 |
GetLatencies(v);
|
|
155 |
TUint i=TimerToMicroseconds(I64LOW(v.iSumIntTicks/v.iCount));
|
|
156 |
TUint k=TimerToMicroseconds(I64LOW(v.iSumKernTicks/v.iCount));
|
|
157 |
TUint u=TimerToMicroseconds(I64LOW(v.iSumUserTicks/v.iCount));
|
|
158 |
test.Printf(_L("%SAVG: Int %4d Kern %4d User %4d Count %Ld\n"),&aPrefix,i,k,u,v.iCount);
|
|
159 |
}
|
|
160 |
|
|
161 |
#ifdef __CAPTURE_EXTRAS
|
|
162 |
void DisplayExtras(const TDesC& aPrefix)
|
|
163 |
{
|
|
164 |
SFullLatencyResults v;
|
|
165 |
GetLatencies(v);
|
|
166 |
test.Printf(_L("%SInt : Cpsr %08x R14 %08x\n"),&aPrefix,v.iIntCpsr,v.iIntR14);
|
|
167 |
test.Printf(_L("%SKern: Cpsr %08x R14 %08x\n"),&aPrefix,v.iKernCpsr,v.iKernR14);
|
|
168 |
test.Printf(_L("%SUser: Cpsr %08x R14 %08x\n"),&aPrefix,v.iUserCpsr,v.iUserR14);
|
|
169 |
}
|
|
170 |
#endif
|
|
171 |
|
|
172 |
void ClearMaxValues()
|
|
173 |
{
|
|
174 |
Mem::FillZ(&Latencies,6*sizeof(TUint));
|
|
175 |
}
|
|
176 |
|
|
177 |
void ClearAvgValues()
|
|
178 |
{
|
|
179 |
Mem::FillZ(&Latencies.iCount,4*sizeof(TInt64));
|
|
180 |
}
|
|
181 |
|
|
182 |
_LIT_SECURITY_POLICY_PASS(KPersistencePropReadPolicy);
|
|
183 |
_LIT_SECURITY_POLICY_PASS(KPersistencePropWritePolicy);
|
|
184 |
void AnnouncePersistence()
|
|
185 |
{
|
|
186 |
TInt r = RProperty::Define(KRuntestsIntentionalPersistenceKey, RProperty::EInt, KPersistencePropReadPolicy, KPersistencePropWritePolicy);
|
|
187 |
test(r==KErrNone || r==KErrAlreadyExists);
|
|
188 |
r = RProperty::Set(RProcess().SecureId(), KRuntestsIntentionalPersistenceKey, KRuntestsIntentionalPersistenceValue);
|
|
189 |
test(r==KErrNone);
|
|
190 |
}
|
|
191 |
|
|
192 |
class CConsoleReader : public CActive
|
|
193 |
{
|
|
194 |
public:
|
|
195 |
CConsoleReader();
|
|
196 |
static void New();
|
|
197 |
void Start();
|
|
198 |
virtual void RunL();
|
|
199 |
virtual void DoCancel();
|
|
200 |
public:
|
|
201 |
CConsoleBase* iConsole;
|
|
202 |
};
|
|
203 |
|
|
204 |
CConsoleReader::CConsoleReader()
|
|
205 |
: CActive(0)
|
|
206 |
{
|
|
207 |
}
|
|
208 |
|
|
209 |
void CConsoleReader::RunL()
|
|
210 |
{
|
|
211 |
TKeyCode k = iConsole->KeyCode();
|
|
212 |
switch(k)
|
|
213 |
{
|
|
214 |
case '1':
|
|
215 |
test.Printf(_L("Clearing Maximum Values\n"));
|
|
216 |
ClearMaxValues();
|
|
217 |
break;
|
|
218 |
case '2':
|
|
219 |
DisplayMaxValues(KNullDesC);
|
|
220 |
break;
|
|
221 |
case '3':
|
|
222 |
test.Printf(_L("Clearing Average Values\n"));
|
|
223 |
ClearAvgValues();
|
|
224 |
break;
|
|
225 |
case '4':
|
|
226 |
DisplayAvgValues(KNullDesC);
|
|
227 |
break;
|
|
228 |
#ifdef __CAPTURE_EXTRAS
|
|
229 |
case '5':
|
|
230 |
DisplayExtras(KNullDesC);
|
|
231 |
break;
|
|
232 |
#endif
|
|
233 |
case 'x':
|
|
234 |
case 'X':
|
|
235 |
CActiveScheduler::Stop();
|
|
236 |
return;
|
|
237 |
default:
|
|
238 |
break;
|
|
239 |
}
|
|
240 |
Start();
|
|
241 |
}
|
|
242 |
|
|
243 |
void CConsoleReader::DoCancel()
|
|
244 |
{
|
|
245 |
iConsole->ReadCancel();
|
|
246 |
}
|
|
247 |
|
|
248 |
void CConsoleReader::New()
|
|
249 |
{
|
|
250 |
CConsoleReader* crdr = new CConsoleReader;
|
|
251 |
test(crdr != NULL);
|
|
252 |
crdr->iConsole = test.Console();
|
|
253 |
CActiveScheduler::Add(crdr);
|
|
254 |
crdr->Start();
|
|
255 |
}
|
|
256 |
|
|
257 |
void CConsoleReader::Start()
|
|
258 |
{
|
|
259 |
iConsole->Read(iStatus);
|
|
260 |
SetActive();
|
|
261 |
}
|
|
262 |
|
|
263 |
class CPubSubWatcher : public CActive
|
|
264 |
{
|
|
265 |
public:
|
|
266 |
CPubSubWatcher();
|
|
267 |
static void New();
|
|
268 |
void Start();
|
|
269 |
virtual ~CPubSubWatcher();
|
|
270 |
virtual void RunL();
|
|
271 |
virtual void DoCancel();
|
|
272 |
public:
|
|
273 |
RProperty iProperty;
|
|
274 |
};
|
|
275 |
|
|
276 |
CPubSubWatcher::CPubSubWatcher()
|
|
277 |
: CActive(0)
|
|
278 |
{
|
|
279 |
}
|
|
280 |
|
|
281 |
void CPubSubWatcher::RunL()
|
|
282 |
{
|
|
283 |
Start();
|
|
284 |
DisplayMaxValues(KPrefixRuntests);
|
|
285 |
DisplayAvgValues(KPrefixRuntests);
|
|
286 |
}
|
|
287 |
|
|
288 |
void CPubSubWatcher::DoCancel()
|
|
289 |
{
|
|
290 |
iProperty.Cancel();
|
|
291 |
}
|
|
292 |
|
|
293 |
void CPubSubWatcher::New()
|
|
294 |
{
|
|
295 |
CPubSubWatcher* psw = new CPubSubWatcher;
|
|
296 |
test(psw != NULL);
|
|
297 |
TInt r = psw->iProperty.Attach(KRuntestsCategory, KRuntestsCurrentTestKey, EOwnerThread);
|
|
298 |
test(r==KErrNone);
|
|
299 |
CActiveScheduler::Add(psw);
|
|
300 |
psw->Start();
|
|
301 |
}
|
|
302 |
|
|
303 |
void CPubSubWatcher::Start()
|
|
304 |
{
|
|
305 |
iProperty.Subscribe(iStatus);
|
|
306 |
SetActive();
|
|
307 |
}
|
|
308 |
|
|
309 |
CPubSubWatcher::~CPubSubWatcher()
|
|
310 |
{
|
|
311 |
iProperty.Close();
|
|
312 |
}
|
|
313 |
|
|
314 |
GLDEF_C TInt E32Main()
|
|
315 |
{
|
|
316 |
#ifdef _DEBUG
|
|
317 |
// Don't run automatically on debug builds
|
|
318 |
TUint32 creator_sid = User::CreatorSecureId();
|
|
319 |
if (creator_sid == TUint32(KRuntestsCategoryValue))
|
|
320 |
return KErrNone;
|
|
321 |
#endif
|
|
322 |
// disable anything which will interfere, e.g. plat sec diagnostics
|
|
323 |
User::SetDebugMask(UserSvr::DebugMask(2)|4, 2);
|
|
324 |
|
|
325 |
test.Title();
|
|
326 |
|
|
327 |
test.Printf(_L("*** Please note ***\n"));
|
|
328 |
test.Printf(_L("\n"));
|
|
329 |
test.Printf(_L("t_lat2 runs in the backgroud to measure latency while other tests are\n"));
|
|
330 |
test.Printf(_L("running. It should not be run as a standalone test, only as part of a\n"));
|
|
331 |
test.Printf(_L("test run coordinated by runtests. If run on its owm, it will simply wait\n"));
|
|
332 |
test.Printf(_L("forever.\n"));
|
|
333 |
test.Printf(_L("\n"));
|
|
334 |
|
|
335 |
test.Start(_L("Load LDD"));
|
|
336 |
TInt r=User::LoadLogicalDevice(KLatencyLddFileName);
|
|
337 |
test(r==KErrNone || r==KErrAlreadyExists);
|
|
338 |
|
|
339 |
test.Next(_L("Duplicate handle"));
|
|
340 |
r=Main.Duplicate(RThread());
|
|
341 |
test(r==KErrNone);
|
|
342 |
|
|
343 |
test.Next(_L("Create thread"));
|
|
344 |
RThread t;
|
|
345 |
TRequestStatus sx;
|
|
346 |
TRequestStatus sc;
|
|
347 |
r=t.Create(KThreadName,LatencyThread,0x1000,NULL,&sc);
|
|
348 |
test(r==KErrNone);
|
|
349 |
t.Logon(sx);
|
|
350 |
t.Resume();
|
|
351 |
User::WaitForRequest(sx,sc);
|
|
352 |
if (sx!=KRequestPending)
|
|
353 |
{
|
|
354 |
if (t.ExitType()==EExitKill && t.ExitReason()==KErrAlreadyExists)
|
|
355 |
{
|
|
356 |
test.Printf(_L("T_LAT2 already running.\n"));
|
|
357 |
test.End();
|
|
358 |
return 0;
|
|
359 |
}
|
|
360 |
test.Printf(_L("Initialisation failed, error %d\n"),sx.Int());
|
|
361 |
test(0);
|
|
362 |
}
|
|
363 |
test(sc==KErrNone);
|
|
364 |
|
|
365 |
CTrapCleanup* tcln = CTrapCleanup::New();
|
|
366 |
test(tcln != NULL);
|
|
367 |
CActiveScheduler* as = new CActiveScheduler;
|
|
368 |
test(as != NULL);
|
|
369 |
CActiveScheduler::Install(as);
|
|
370 |
CConsoleReader::New();
|
|
371 |
CPubSubWatcher::New();
|
|
372 |
AnnouncePersistence();
|
|
373 |
RProcess::Rendezvous(KErrNone);
|
|
374 |
|
|
375 |
CActiveScheduler::Start();
|
|
376 |
|
|
377 |
// latency test over
|
|
378 |
User::SetDebugMask(UserSvr::DebugMask(2)&~4, 2);
|
|
379 |
|
|
380 |
test.End();
|
|
381 |
return 0;
|
|
382 |
}
|