Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\system\t_mstim.cpp
16 // Test millisecond timers
20 // - Create and start a number of periodic timers, verify results are
22 // - Attempt to start a timer that has already been started. Verify returned
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:
38 // Assumptions/Requirement/Pre-requisites:
39 // Failures and causes:
40 // Base Port information:
48 RTest test(_L("T_MSTIM"));
51 TBool PauseOnError = 0;
52 #define GETCH() (PauseOnError&&test.Getch())
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)))
57 #define TESTTIME(v,min,max) test.Printf(_L("Expected range [%d,%d]\n"),min,max+1)
59 #define TESTTIME(v,min,max) TEST(v>=min && v<max)
62 const TPtrC KLddFileName=_L("D_MSTIM.LDD");
64 void GetInfo(TInt aId)
67 TInt r=mstim.GetInfo(aId,info);
69 test.Printf(_L("%1d: min=%-6d max=%-6d avg=%-6d count=%d\n"),aId,info.iMin,info.iMax,info.iAvg,info.iCount);
78 test.Printf(_L("\n"));
81 TInt GetOneShotTime(TInt aId)
84 TInt r=mstim.GetInfo(aId,info);
87 return info.iMin/1000;
90 GLDEF_C TInt E32Main()
92 // Test millisecond timers
95 // test.SetLogged(EFalse);
98 test.Start(_L("Load test LDD"));
99 TInt r=User::LoadLogicalDevice(KLddFileName);
100 TEST(r==KErrNone || r==KErrAlreadyExists);
105 test.Next(_L("Start periodics"));
106 TUint init_count=User::NTickCount();
107 r=mstim.StartPeriodicInt(0,31);
109 r=mstim.StartPeriodicInt(1,32);
111 r=mstim.StartPeriodicInt(4,7);
113 r=mstim.StartPeriodicInt(5,43);
115 r=mstim.StartPeriodicDfc(6,19);
117 r=mstim.StartPeriodicDfc(7,71);
120 test.Next(_L("Start while started"));
122 mstim.StartOneShotInt(s,0,100);
123 User::WaitForRequest(s);
126 test.Next(_L("One shot interrupt"));
127 mstim.StartOneShotInt(s,2,100);
128 User::WaitForRequest(s);
129 TUint fc1=User::NTickCount();
131 TInt time=GetOneShotTime(2);
132 test.Printf(_L("Took %dms\n"),time);
133 TESTTIME(time,100,102);
135 test.Next(_L("One shot DFC"));
136 mstim.StartOneShotDfc(s,3,200);
137 User::WaitForRequest(s);
138 TUint fc3=User::NTickCount();
140 time=GetOneShotTime(3);
141 test.Printf(_L("Took %dms\n"),time);
142 TESTTIME(time,200,202);
144 test.Next(_L("One shot interrupt again"));
145 TUint fc2=User::NTickCount();
146 mstim.StartOneShotIntAgain(s,2,300);
147 User::WaitForRequest(s);
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);
154 test.Next(_L("One shot interrupt again too late"));
155 mstim.StartOneShotIntAgain(s,3,10);
156 User::WaitForRequest(s);
157 TEST(s==KErrArgument);
159 test.Next(_L("One shot interrupt again"));
160 fc2=User::NTickCount();
161 mstim.StartOneShotIntAgain(s,3,300);
162 User::WaitForRequest(s);
164 time=GetOneShotTime(3);
165 test.Printf(_L("Took %dms, delay %dms\n"),time,fc2-fc3);
167 TESTTIME(time,295,306);
169 test.Printf(_L("Please wait...\n"));
170 User::After(10000000);
172 SMsTimerInfo info[8];
176 r=mstim.GetInfo(i,info[i]);
180 TUint final_count=User::NTickCount();
181 TInt elapsed=TInt(final_count-init_count);
182 test.Printf(_L("Elapsed time %dms\n"),elapsed);
184 const TInt period[8]={31,32,0,0,7,43,19,71};
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);
196 TEST(Abs(z.iMin-1000*p)<1000);
197 TEST(Abs(z.iMax-1000*p)<1000);
199 TEST(Abs(z.iAvg-1000*p)<1000);
202 test.Next(_L("Cancel periodic"));
203 r=mstim.StopPeriodic(7);
205 r=mstim.GetInfo(7,info[7]);
207 User::After(1000000);
208 r=mstim.GetInfo(7,info[6]);
210 TEST(info[6].iCount==info[7].iCount);
212 test.Next(_L("Reuse cancelled"));
213 mstim.StartOneShotInt(s,7,128);
214 User::WaitForRequest(s);
216 time=GetOneShotTime(7);
217 test.Printf(_L("Took %dms\n"),time);
218 TESTTIME(time,128,130);
221 test.Next(_L("Timed Cancel"));
222 mstim.StartOneShotInt(s,2,128);
223 mstim.IntCancel(s2,2,130);
224 User::WaitForRequest(s);
226 User::WaitForRequest(s2);
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);
235 mstim.StartOneShotInt(s,2,128);
236 mstim.IntCancel(s2,2,126);
237 User::WaitForRequest(s);
239 User::WaitForRequest(s2);
241 time=GetOneShotTime(7);
242 test.Printf(_L("Cancel Took %dms\n"),time);
243 TESTTIME(time,126,128);
245 test.Next(_L("Reuse cancelled"));
246 mstim.StartOneShotInt(s,2,64);
247 User::WaitForRequest(s);
249 time=GetOneShotTime(2);
250 test.Printf(_L("Took %dms\n"),time);
251 TESTTIME(time,64,66);
254 test.Next(_L("Random test"));
255 r=mstim.BeginRandomTest();
259 test.Printf(_L("Please wait...\n"));
260 User::After(10000000);
263 r=mstim.EndRandomTest();
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);
278 r=mstim.GetInfo(i,info[i]);
282 final_count=User::NTickCount();
283 elapsed=TInt(final_count-init_count);
284 test.Printf(_L("Elapsed time %dms\n"),elapsed);
286 const TInt period2[8]={31,32,0,0,7,43,19,0};
292 r=mstim.StopPeriodic(i);
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);
300 TEST(Abs(z.iMin-1000*p)<=1000);
301 TEST(Abs(z.iMax-1000*p)<=1000);
303 TEST(Abs(z.iAvg-1000*p)<=1000);
306 test.Next(_L("Idle time"));
311 idle=mstim.GetIdleTime();
316 User::AfterHighRes(idle*1000);
320 test.Printf(_L("Never got long enough idle time\n"));
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);
336 mstim.StartOneShotInt(s3,2,10);
337 idle=mstim.GetIdleTime();
338 test.Printf(_L("Idle time %dms\n"),idle);
340 User::WaitForRequest(s3);
341 fc2=User::NTickCount();
342 idle=mstim.GetIdleTime();
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();
350 test.Printf(_L("Idle time %dms elapsed %dms\n"),idle,elapsed);
351 TESTTIME(idle,880-elapsed,900-elapsed);
352 User::WaitForRequest(s);
356 test.Next(_L("One shot int "));
357 mstim.StartOneShotInt(s,8,100);
358 User::WaitForRequest(s);
360 time=GetOneShotTime(8);
361 test.Printf(_L("Took %dms\n"),time);
362 TESTTIME(time,100,102);
364 test.Next(_L("One shot int "));
365 mstim.StartOneShotInt(s,8,300);
366 User::WaitForRequest(s);
367 fc4=User::NTickCount();
369 time=GetOneShotTime(8);
370 test.Printf(_L("Took %dms\n"),time);
371 TESTTIME(time,300,302);
373 test.Next(_L("One shot int again"));
374 fc5=User::NTickCount();
375 mstim.StartOneShotIntAgain(s,8,300);
376 User::WaitForRequest(s);
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);
383 test.Next(_L("One shot with provided Dfc queue"));
384 mstim.StartOneShotUserDfc(s,8,100);
385 User::WaitForRequest(s);
387 time=GetOneShotTime(8);
388 test.Printf(_L("Took %dms\n"),time);
389 TESTTIME(time,100,102);
391 test.Next(_L("One shot with provided Dfc queue"));
392 mstim.StartOneShotUserDfc(s,8,300);
393 User::WaitForRequest(s);
394 fc4=User::NTickCount();
396 time=GetOneShotTime(8);
397 test.Printf(_L("Took %dms\n"),time);
398 TESTTIME(time,300,302);
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);
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);