0
|
1 |
// Copyright (c) 1997-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\system\t_mstim.cpp
|
|
15 |
// Overview:
|
|
16 |
// Test millisecond timers
|
|
17 |
// API Information:
|
|
18 |
// NTimer
|
|
19 |
// Details:
|
|
20 |
// - Create and start a number of periodic timers, verify results are
|
|
21 |
// as expected.
|
|
22 |
// - Attempt to start a timer that has already been started. Verify returned
|
|
23 |
// error results.
|
|
24 |
// - Start one shot interrupt and one shot DFC timers and verify that the
|
|
25 |
// delay time is correct.
|
|
26 |
// - Start additional one shot interrupt timers with various values and verify
|
|
27 |
// results are as expected.
|
|
28 |
// - Calculate and print the elapsed time.
|
|
29 |
// - Start some timers, display min. max, avg and count information on each.
|
|
30 |
// Verify results are as expected.
|
|
31 |
// - Cancel a periodic timer and reuse it in a variety of conditions. Time how
|
|
32 |
// long it takes for each to complete.
|
|
33 |
// - Perform some random timer tests and display the results.
|
|
34 |
// - Check idle time while a variety of one shot timers run. Verify results are
|
|
35 |
// within the expected range.
|
|
36 |
// Platforms/Drives/Compatibility:
|
|
37 |
// All.
|
|
38 |
// Assumptions/Requirement/Pre-requisites:
|
|
39 |
// Failures and causes:
|
|
40 |
// Base Port information:
|
|
41 |
//
|
|
42 |
//
|
|
43 |
|
|
44 |
#include <e32test.h>
|
|
45 |
#include <e32uid.h>
|
|
46 |
#include "d_mstim.h"
|
|
47 |
|
|
48 |
RTest test(_L("T_MSTIM"));
|
|
49 |
RMsTim mstim;
|
|
50 |
|
|
51 |
TBool PauseOnError = 0;
|
|
52 |
#define GETCH() (PauseOnError&&test.Getch())
|
|
53 |
|
|
54 |
#define TEST(c) ((void)((c)||(test.Printf(_L("Failed at line %d\n"),__LINE__),GETCH(),test(0),0)))
|
|
55 |
#define CHECK(c) ((void)(((c)==0)||(test.Printf(_L("Error %d at line %d\n"),(c),__LINE__),GETCH(),test(0),0)))
|
|
56 |
#ifdef __WINS__
|
|
57 |
#define TESTTIME(v,min,max) test.Printf(_L("Expected range [%d,%d]\n"),min,max+1)
|
|
58 |
#else
|
|
59 |
#define TESTTIME(v,min,max) TEST(v>=min && v<max)
|
|
60 |
#endif
|
|
61 |
|
|
62 |
const TPtrC KLddFileName=_L("D_MSTIM.LDD");
|
|
63 |
|
|
64 |
void GetInfo(TInt aId)
|
|
65 |
{
|
|
66 |
SMsTimerInfo info;
|
|
67 |
TInt r=mstim.GetInfo(aId,info);
|
|
68 |
CHECK(r);
|
|
69 |
test.Printf(_L("%1d: min=%-6d max=%-6d avg=%-6d count=%d\n"),aId,info.iMin,info.iMax,info.iAvg,info.iCount);
|
|
70 |
}
|
|
71 |
|
|
72 |
void GetAllInfo()
|
|
73 |
{
|
|
74 |
GetInfo(0);
|
|
75 |
GetInfo(1);
|
|
76 |
GetInfo(2);
|
|
77 |
GetInfo(3);
|
|
78 |
test.Printf(_L("\n"));
|
|
79 |
}
|
|
80 |
|
|
81 |
TInt GetOneShotTime(TInt aId)
|
|
82 |
{
|
|
83 |
SMsTimerInfo info;
|
|
84 |
TInt r=mstim.GetInfo(aId,info);
|
|
85 |
CHECK(r);
|
|
86 |
TEST(info.iCount==1);
|
|
87 |
return info.iMin/1000;
|
|
88 |
}
|
|
89 |
|
|
90 |
GLDEF_C TInt E32Main()
|
|
91 |
//
|
|
92 |
// Test millisecond timers
|
|
93 |
//
|
|
94 |
{
|
|
95 |
// test.SetLogged(EFalse);
|
|
96 |
test.Title();
|
|
97 |
|
|
98 |
test.Start(_L("Load test LDD"));
|
|
99 |
TInt r=User::LoadLogicalDevice(KLddFileName);
|
|
100 |
TEST(r==KErrNone || r==KErrAlreadyExists);
|
|
101 |
|
|
102 |
r=mstim.Open();
|
|
103 |
CHECK(r);
|
|
104 |
|
|
105 |
test.Next(_L("Start periodics"));
|
|
106 |
TUint init_count=User::NTickCount();
|
|
107 |
r=mstim.StartPeriodicInt(0,31);
|
|
108 |
CHECK(r);
|
|
109 |
r=mstim.StartPeriodicInt(1,32);
|
|
110 |
CHECK(r);
|
|
111 |
r=mstim.StartPeriodicInt(4,7);
|
|
112 |
CHECK(r);
|
|
113 |
r=mstim.StartPeriodicInt(5,43);
|
|
114 |
CHECK(r);
|
|
115 |
r=mstim.StartPeriodicDfc(6,19);
|
|
116 |
CHECK(r);
|
|
117 |
r=mstim.StartPeriodicDfc(7,71);
|
|
118 |
CHECK(r);
|
|
119 |
|
|
120 |
test.Next(_L("Start while started"));
|
|
121 |
TRequestStatus s;
|
|
122 |
mstim.StartOneShotInt(s,0,100);
|
|
123 |
User::WaitForRequest(s);
|
|
124 |
TEST(s==KErrInUse);
|
|
125 |
|
|
126 |
test.Next(_L("One shot interrupt"));
|
|
127 |
mstim.StartOneShotInt(s,2,100);
|
|
128 |
User::WaitForRequest(s);
|
|
129 |
TUint fc1=User::NTickCount();
|
|
130 |
TEST(s==KErrNone);
|
|
131 |
TInt time=GetOneShotTime(2);
|
|
132 |
test.Printf(_L("Took %dms\n"),time);
|
|
133 |
TESTTIME(time,100,102);
|
|
134 |
|
|
135 |
test.Next(_L("One shot DFC"));
|
|
136 |
mstim.StartOneShotDfc(s,3,200);
|
|
137 |
User::WaitForRequest(s);
|
|
138 |
TUint fc3=User::NTickCount();
|
|
139 |
TEST(s==KErrNone);
|
|
140 |
time=GetOneShotTime(3);
|
|
141 |
test.Printf(_L("Took %dms\n"),time);
|
|
142 |
TESTTIME(time,200,202);
|
|
143 |
|
|
144 |
test.Next(_L("One shot interrupt again"));
|
|
145 |
TUint fc2=User::NTickCount();
|
|
146 |
mstim.StartOneShotIntAgain(s,2,300);
|
|
147 |
User::WaitForRequest(s);
|
|
148 |
TEST(s==KErrNone);
|
|
149 |
TInt time2=GetOneShotTime(2);
|
|
150 |
test.Printf(_L("Took %dms, delay %dms\n"),time2,fc2-fc1);
|
|
151 |
time2+=TInt(fc2-fc1);
|
|
152 |
TESTTIME(time2,295,306);
|
|
153 |
|
|
154 |
test.Next(_L("One shot interrupt again too late"));
|
|
155 |
mstim.StartOneShotIntAgain(s,3,10);
|
|
156 |
User::WaitForRequest(s);
|
|
157 |
TEST(s==KErrArgument);
|
|
158 |
|
|
159 |
test.Next(_L("One shot interrupt again"));
|
|
160 |
fc2=User::NTickCount();
|
|
161 |
mstim.StartOneShotIntAgain(s,3,300);
|
|
162 |
User::WaitForRequest(s);
|
|
163 |
TEST(s==KErrNone);
|
|
164 |
time=GetOneShotTime(3);
|
|
165 |
test.Printf(_L("Took %dms, delay %dms\n"),time,fc2-fc3);
|
|
166 |
time+=TInt(fc2-fc3);
|
|
167 |
TESTTIME(time,295,306);
|
|
168 |
|
|
169 |
test.Printf(_L("Please wait...\n"));
|
|
170 |
User::After(10000000);
|
|
171 |
|
|
172 |
SMsTimerInfo info[8];
|
|
173 |
TInt i;
|
|
174 |
for (i=0; i<8; i++)
|
|
175 |
{
|
|
176 |
r=mstim.GetInfo(i,info[i]);
|
|
177 |
CHECK(r);
|
|
178 |
}
|
|
179 |
|
|
180 |
TUint final_count=User::NTickCount();
|
|
181 |
TInt elapsed=TInt(final_count-init_count);
|
|
182 |
test.Printf(_L("Elapsed time %dms\n"),elapsed);
|
|
183 |
|
|
184 |
const TInt period[8]={31,32,0,0,7,43,19,71};
|
|
185 |
for (i=0; i<8; i++)
|
|
186 |
{
|
|
187 |
TInt p=period[i];
|
|
188 |
if (p==0)
|
|
189 |
continue;
|
|
190 |
SMsTimerInfo& z=info[i];
|
|
191 |
test.Printf(_L("%1d: min=%-6d max=%-6d avg=%-6d count=%d\n"),i,z.iMin,z.iMax,z.iAvg,z.iCount);
|
|
192 |
TInt count=elapsed/p;
|
|
193 |
TInt cdiff=count-z.iCount;
|
|
194 |
TEST(cdiff>=0 && cdiff<=2);
|
|
195 |
#ifndef __WINS__
|
|
196 |
TEST(Abs(z.iMin-1000*p)<1000);
|
|
197 |
TEST(Abs(z.iMax-1000*p)<1000);
|
|
198 |
#endif
|
|
199 |
TEST(Abs(z.iAvg-1000*p)<1000);
|
|
200 |
}
|
|
201 |
|
|
202 |
test.Next(_L("Cancel periodic"));
|
|
203 |
r=mstim.StopPeriodic(7);
|
|
204 |
CHECK(r);
|
|
205 |
r=mstim.GetInfo(7,info[7]);
|
|
206 |
CHECK(r);
|
|
207 |
User::After(1000000);
|
|
208 |
r=mstim.GetInfo(7,info[6]);
|
|
209 |
CHECK(r);
|
|
210 |
TEST(info[6].iCount==info[7].iCount);
|
|
211 |
|
|
212 |
test.Next(_L("Reuse cancelled"));
|
|
213 |
mstim.StartOneShotInt(s,7,128);
|
|
214 |
User::WaitForRequest(s);
|
|
215 |
TEST(s==KErrNone);
|
|
216 |
time=GetOneShotTime(7);
|
|
217 |
test.Printf(_L("Took %dms\n"),time);
|
|
218 |
TESTTIME(time,128,130);
|
|
219 |
|
|
220 |
TRequestStatus s2;
|
|
221 |
test.Next(_L("Timed Cancel"));
|
|
222 |
mstim.StartOneShotInt(s,2,128);
|
|
223 |
mstim.IntCancel(s2,2,130);
|
|
224 |
User::WaitForRequest(s);
|
|
225 |
TEST(s==KErrNone);
|
|
226 |
User::WaitForRequest(s2);
|
|
227 |
TEST(s2==KErrNone);
|
|
228 |
time=GetOneShotTime(2);
|
|
229 |
test.Printf(_L("Took %dms\n"),time);
|
|
230 |
TESTTIME(time,128,130);
|
|
231 |
time=GetOneShotTime(7);
|
|
232 |
test.Printf(_L("Cancel Took %dms\n"),time);
|
|
233 |
TESTTIME(time,130,132);
|
|
234 |
|
|
235 |
mstim.StartOneShotInt(s,2,128);
|
|
236 |
mstim.IntCancel(s2,2,126);
|
|
237 |
User::WaitForRequest(s);
|
|
238 |
TEST(s==KErrAbort);
|
|
239 |
User::WaitForRequest(s2);
|
|
240 |
TEST(s2==KErrNone);
|
|
241 |
time=GetOneShotTime(7);
|
|
242 |
test.Printf(_L("Cancel Took %dms\n"),time);
|
|
243 |
TESTTIME(time,126,128);
|
|
244 |
|
|
245 |
test.Next(_L("Reuse cancelled"));
|
|
246 |
mstim.StartOneShotInt(s,2,64);
|
|
247 |
User::WaitForRequest(s);
|
|
248 |
TEST(s==KErrNone);
|
|
249 |
time=GetOneShotTime(2);
|
|
250 |
test.Printf(_L("Took %dms\n"),time);
|
|
251 |
TESTTIME(time,64,66);
|
|
252 |
|
|
253 |
#ifdef _DEBUG
|
|
254 |
test.Next(_L("Random test"));
|
|
255 |
r=mstim.BeginRandomTest();
|
|
256 |
CHECK(r);
|
|
257 |
#endif
|
|
258 |
|
|
259 |
test.Printf(_L("Please wait...\n"));
|
|
260 |
User::After(10000000);
|
|
261 |
|
|
262 |
#ifdef _DEBUG
|
|
263 |
r=mstim.EndRandomTest();
|
|
264 |
CHECK(r);
|
|
265 |
SRandomTestInfo rInfo;
|
|
266 |
r=mstim.GetRandomTestInfo(rInfo);
|
|
267 |
test.Printf(_L("min error = %d\n"),rInfo.iMin);
|
|
268 |
test.Printf(_L("max error = %d\n"),rInfo.iMax);
|
|
269 |
test.Printf(_L("xfer cancel = %d\n"),rInfo.iXferC);
|
|
270 |
test.Printf(_L("crit cancel = %d\n"),rInfo.iCritC);
|
|
271 |
test.Printf(_L("start fails = %d\n"),rInfo.iStartFail);
|
|
272 |
test.Printf(_L("debug calls = %d\n"),rInfo.iCallBacks);
|
|
273 |
test.Printf(_L("completions = %d\n"),rInfo.iCompletions);
|
|
274 |
#endif
|
|
275 |
|
|
276 |
for (i=0; i<8; i++)
|
|
277 |
{
|
|
278 |
r=mstim.GetInfo(i,info[i]);
|
|
279 |
CHECK(r);
|
|
280 |
}
|
|
281 |
|
|
282 |
final_count=User::NTickCount();
|
|
283 |
elapsed=TInt(final_count-init_count);
|
|
284 |
test.Printf(_L("Elapsed time %dms\n"),elapsed);
|
|
285 |
|
|
286 |
const TInt period2[8]={31,32,0,0,7,43,19,0};
|
|
287 |
for (i=0; i<8; i++)
|
|
288 |
{
|
|
289 |
TInt p=period2[i];
|
|
290 |
if (p==0)
|
|
291 |
continue;
|
|
292 |
r=mstim.StopPeriodic(i);
|
|
293 |
CHECK(r);
|
|
294 |
SMsTimerInfo& z=info[i];
|
|
295 |
test.Printf(_L("%1d: min=%-6d max=%-6d avg=%-6d count=%d\n"),i,z.iMin,z.iMax,z.iAvg,z.iCount);
|
|
296 |
TInt count=elapsed/p;
|
|
297 |
TInt cdiff=count-z.iCount;
|
|
298 |
TEST(cdiff>=0 && cdiff<=2);
|
|
299 |
#ifndef __WINS__
|
|
300 |
TEST(Abs(z.iMin-1000*p)<=1000);
|
|
301 |
TEST(Abs(z.iMax-1000*p)<=1000);
|
|
302 |
#endif
|
|
303 |
TEST(Abs(z.iAvg-1000*p)<=1000);
|
|
304 |
}
|
|
305 |
|
|
306 |
test.Next(_L("Idle time"));
|
|
307 |
time=0;
|
|
308 |
TInt idle=0;
|
|
309 |
while (time<3000)
|
|
310 |
{
|
|
311 |
idle=mstim.GetIdleTime();
|
|
312 |
if (idle>=1000)
|
|
313 |
break;
|
|
314 |
if (idle<32)
|
|
315 |
idle=32;
|
|
316 |
User::AfterHighRes(idle*1000);
|
|
317 |
time+=idle;
|
|
318 |
}
|
|
319 |
if (time>=3000)
|
|
320 |
test.Printf(_L("Never got long enough idle time\n"));
|
|
321 |
else
|
|
322 |
{
|
|
323 |
mstim.StartOneShotInt(s,0,900);
|
|
324 |
TUint fc0=User::NTickCount();
|
|
325 |
User::AfterHighRes(20000);
|
|
326 |
idle=mstim.GetIdleTime();
|
|
327 |
test.Printf(_L("Idle time %dms\n"),idle);
|
|
328 |
TESTTIME(idle,860,881);
|
|
329 |
mstim.StartOneShotInt(s2,1,200);
|
|
330 |
fc1=User::NTickCount();
|
|
331 |
User::AfterHighRes(20000);
|
|
332 |
idle=mstim.GetIdleTime();
|
|
333 |
test.Printf(_L("Idle time %dms\n"),idle);
|
|
334 |
TESTTIME(idle,160,181);
|
|
335 |
TRequestStatus s3;
|
|
336 |
mstim.StartOneShotInt(s3,2,10);
|
|
337 |
idle=mstim.GetIdleTime();
|
|
338 |
test.Printf(_L("Idle time %dms\n"),idle);
|
|
339 |
TEST(idle==0);
|
|
340 |
User::WaitForRequest(s3);
|
|
341 |
fc2=User::NTickCount();
|
|
342 |
idle=mstim.GetIdleTime();
|
|
343 |
elapsed=fc2-fc1;
|
|
344 |
test.Printf(_L("Idle time %dms elapsed %dms\n"),idle,elapsed);
|
|
345 |
TESTTIME(idle,180-elapsed,201-elapsed);
|
|
346 |
User::WaitForRequest(s2);
|
|
347 |
fc2=User::NTickCount();
|
|
348 |
idle=mstim.GetIdleTime();
|
|
349 |
elapsed=fc2-fc0;
|
|
350 |
test.Printf(_L("Idle time %dms elapsed %dms\n"),idle,elapsed);
|
|
351 |
TESTTIME(idle,880-elapsed,900-elapsed);
|
|
352 |
User::WaitForRequest(s);
|
|
353 |
}
|
|
354 |
|
|
355 |
TUint fc4, fc5;
|
|
356 |
test.Next(_L("One shot int "));
|
|
357 |
mstim.StartOneShotInt(s,8,100);
|
|
358 |
User::WaitForRequest(s);
|
|
359 |
TEST(s==KErrNone);
|
|
360 |
time=GetOneShotTime(8);
|
|
361 |
test.Printf(_L("Took %dms\n"),time);
|
|
362 |
TESTTIME(time,100,102);
|
|
363 |
|
|
364 |
test.Next(_L("One shot int "));
|
|
365 |
mstim.StartOneShotInt(s,8,300);
|
|
366 |
User::WaitForRequest(s);
|
|
367 |
fc4=User::NTickCount();
|
|
368 |
TEST(s==KErrNone);
|
|
369 |
time=GetOneShotTime(8);
|
|
370 |
test.Printf(_L("Took %dms\n"),time);
|
|
371 |
TESTTIME(time,300,302);
|
|
372 |
|
|
373 |
test.Next(_L("One shot int again"));
|
|
374 |
fc5=User::NTickCount();
|
|
375 |
mstim.StartOneShotIntAgain(s,8,300);
|
|
376 |
User::WaitForRequest(s);
|
|
377 |
TEST(s==KErrNone);
|
|
378 |
time2=GetOneShotTime(8);
|
|
379 |
test.Printf(_L("Took %dms, delay %dms\n"),time2,fc5-fc4);
|
|
380 |
time2+=TInt(fc5-fc4);
|
|
381 |
TESTTIME(time2,295,306);
|
|
382 |
|
|
383 |
test.Next(_L("One shot with provided Dfc queue"));
|
|
384 |
mstim.StartOneShotUserDfc(s,8,100);
|
|
385 |
User::WaitForRequest(s);
|
|
386 |
TEST(s==KErrNone);
|
|
387 |
time=GetOneShotTime(8);
|
|
388 |
test.Printf(_L("Took %dms\n"),time);
|
|
389 |
TESTTIME(time,100,102);
|
|
390 |
|
|
391 |
test.Next(_L("One shot with provided Dfc queue"));
|
|
392 |
mstim.StartOneShotUserDfc(s,8,300);
|
|
393 |
User::WaitForRequest(s);
|
|
394 |
fc4=User::NTickCount();
|
|
395 |
TEST(s==KErrNone);
|
|
396 |
time=GetOneShotTime(8);
|
|
397 |
test.Printf(_L("Took %dms\n"),time);
|
|
398 |
TESTTIME(time,300,302);
|
|
399 |
|
|
400 |
test.Next(_L("One shot with provided Dfc queue again"));
|
|
401 |
fc5=User::NTickCount();
|
|
402 |
mstim.StartOneShotUserDfcAgain(s,8,300);
|
|
403 |
User::WaitForRequest(s);
|
|
404 |
TEST(s==KErrNone);
|
|
405 |
time2=GetOneShotTime(8);
|
|
406 |
test.Printf(_L("Took %dms, delay %dms\n"),time2,fc5-fc4);
|
|
407 |
time2+=TInt(fc5-fc4);
|
|
408 |
TESTTIME(time2,295,306);
|
|
409 |
|
|
410 |
test.End();
|
|
411 |
return(KErrNone);
|
|
412 |
}
|
|
413 |
|