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_tick.cpp
16 // Test tick-based timers
20 // - Create a number of periodic timers, start each and wait for them to
21 // complete. Print results.
22 // - Create a number of random relative timers, start each and wait for
23 // them to complete. Print results.
24 // - Create a number of separate random relative timers, start each and
25 // wait for them to complete. Print results.
26 // - Create a number of random absolute timers, start each and wait for
27 // them to complete. Print results.
28 // Platforms/Drives/Compatibility:
30 // Assumptions/Requirement/Pre-requisites:
31 // Failures and causes:
32 // Base Port information:
40 RTest test(_L("T_TICK"));
45 TBool PauseOnError = 0;
46 #define GETCH() (PauseOnError&&test.Getch())
48 #define TEST(c) ((void)((c)||(test.Printf(_L("Failed at line %d\n"),__LINE__),GETCH(),test(0),0)))
49 #define CHECK(c) ((void)(((c)==0)||(test.Printf(_L("Error %d at line %d\n"),(c),__LINE__),GETCH(),test(0),0)))
51 const TPtrC KLddFileName=_L("D_TICK.LDD");
53 class CTickTest : public CActive
56 CTickTest(TInt aPriority, TInt aId, RTickTest aLdd);
59 virtual void DoCancel();
61 void StartPeriodic(TInt aInterval, TInt aCount);
62 void StartNShotRel(TInt aMin, TInt aRange, TInt aCount);
63 void StartNShotAbs(TInt aMin, TInt aRange, TInt aCount);
64 void GetInfo(STickTestInfo& aInfo);
75 class CBackgroundTimer : public CActive
78 static CBackgroundTimer* NewL(TInt aPriority);
79 CBackgroundTimer(TInt aPriority);
82 virtual void DoCancel();
87 TRequestStatus iLongStatus;
90 CTickTest* TickTest[KMaxTimers];
92 CBackgroundTimer* BackgroundTimer;
94 CTickTest::CTickTest(TInt aPriority, TInt aId, RTickTest aLdd)
101 CTickTest::~CTickTest()
107 void CTickTest::StartPeriodic(TInt aInterval, TInt aCount)
109 TInt r=iLdd.StartPeriodic(iStatus,iId,aInterval,aCount);
112 TRequestStatus* pS=&iStatus;
113 User::RequestComplete(pS,r);
118 void CTickTest::StartNShotRel(TInt aMin, TInt aRange, TInt aCount)
129 iInfo.iMinErr=KMaxTInt;
130 iInfo.iMaxErr=KMinTInt;
132 iInfo.iRequestedCount=iCount;
134 TInt r=iLdd.StartNShotRel(iStatus,iId,aMin,aRange,c);
137 TRequestStatus* pS=&iStatus;
138 User::RequestComplete(pS,r);
143 void CTickTest::StartNShotAbs(TInt aMin, TInt aRange, TInt aCount)
145 TInt r=iLdd.StartNShotAbs(iStatus,iId,aMin,aRange,aCount);
148 TRequestStatus* pS=&iStatus;
149 User::RequestComplete(pS,r);
154 void CTickTest::GetInfo(STickTestInfo& aInfo)
156 iLdd.GetInfo(iId,aInfo);
159 void CTickTest::RunL()
161 if (iStatus!=KErrNone)
163 test.Printf(_L("Timer %d error %d\n"),iId,iStatus.Int());
165 CActiveScheduler::Stop();
173 iLdd.GetInfo(iId,info);
174 TInt err=info.iMinErr;
175 if (err<iInfo.iMinErr)
177 if (err>iInfo.iMaxErr)
183 TInt r=iLdd.StartNShotRel(iStatus,iId,iMin,iRange,1);
186 TRequestStatus* pS=&iStatus;
187 User::RequestComplete(pS,r);
192 iInfo.iAvgErr=I64INT(iErrorAcc/TInt64(iInfo.iCount));
194 test.Printf(_L("Timer %d\n"),iId);
196 CActiveScheduler::Stop();
199 void CTickTest::DoCancel()
204 CBackgroundTimer::CBackgroundTimer(TInt aPriority)
209 CBackgroundTimer::~CBackgroundTimer()
215 void CBackgroundTimer::Start()
217 iLong.After(iLongStatus, 100000);
218 iShort.After(iStatus, 20000);
222 void CBackgroundTimer::RunL()
228 void CBackgroundTimer::DoCancel()
234 CBackgroundTimer* CBackgroundTimer::NewL(TInt aPriority)
236 CBackgroundTimer* pB=new (ELeave) CBackgroundTimer(aPriority);
237 TInt r=pB->iShort.CreateLocal();
239 r=pB->iLong.CreateLocal();
250 CActiveScheduler* pS=new (ELeave) CActiveScheduler;
251 CActiveScheduler::Install(pS);
253 for (i=0; i<KMaxTimers; ++i)
255 TickTest[i]=new (ELeave) CTickTest(0,i,ticktest);
256 CActiveScheduler::Add(TickTest[i]);
258 Idler=CIdle::NewL(-100);
259 BackgroundTimer=CBackgroundTimer::NewL(-10);
260 CActiveScheduler::Add(BackgroundTimer);
263 void PrintInfo(TInt aId, STickTestInfo& a)
265 test.Printf(_L("%1d: min=%-6d max=%-6d avg=%-6d tot=%-10u count=%d rcount=%d\n"),aId,a.iMinErr,a.iMaxErr,a.iAvgErr,a.iTotalTime,a.iCount,a.iRequestedCount);
268 void PrintInfo(TInt aId)
270 PrintInfo(aId, TickTest[aId]->iInfo);
276 for (i=0; i<KMaxTimers; ++i)
280 TInt ChangeTime(TAny*)
284 User::SetUTCTime(now+TTimeIntervalSeconds(1000));
285 User::SetUTCTime(now);
286 return 1; // so we run again
289 GLDEF_C TInt E32Main()
291 // Test tick-based timers
297 test.Start(_L("Load test LDD"));
298 TInt r=User::LoadLogicalDevice(KLddFileName);
299 TEST(r==KErrNone || r==KErrAlreadyExists);
304 test.Next(_L("Create test objects"));
305 TRAP(r, InitialiseL());
308 test.Next(_L("Start periodics"));
309 TickTest[0]->StartPeriodic(3,1000);
310 TickTest[1]->StartPeriodic(5,600);
311 TickTest[2]->StartPeriodic(7,400);
312 TickTest[3]->StartPeriodic(11,300);
313 TickTest[4]->StartPeriodic(13,30);
314 TickTest[5]->StartPeriodic(19,30);
315 TickTest[6]->StartPeriodic(23,30);
316 TickTest[7]->StartPeriodic(37,30);
319 CActiveScheduler::Start();
322 test.Next(_L("Start random relative"));
323 TickTest[0]->StartNShotRel(1,10,1000);
324 TickTest[1]->StartNShotRel(5,25,300);
325 TickTest[2]->StartNShotRel(7,93,100);
326 TickTest[3]->StartNShotRel(2,2,1000);
327 TickTest[4]->StartPeriodic(13,30);
328 TickTest[5]->StartPeriodic(19,30);
329 TickTest[6]->StartPeriodic(23,30);
330 TickTest[7]->StartPeriodic(37,30);
333 CActiveScheduler::Start();
336 test.Next(_L("Start separate random relative"));
337 TickTest[0]->StartNShotRel(1,10,1000);
338 TickTest[1]->StartNShotRel(5,25,300);
339 TickTest[2]->StartNShotRel(7,93,100);
340 TickTest[3]->StartNShotRel(2,2,1000);
341 TickTest[4]->StartNShotRel(1,10,-1000);
342 TickTest[5]->StartNShotRel(5,25,-300);
343 TickTest[6]->StartNShotRel(7,93,-100);
344 TickTest[7]->StartNShotRel(2,2,-1000);
347 CActiveScheduler::Start();
350 test.Next(_L("Start random absolute"));
351 TickTest[0]->StartNShotAbs(1,10,10);
352 TickTest[1]->StartNShotAbs(5,13,3);
353 TickTest[2]->StartNShotAbs(1,3,20);
354 TickTest[3]->StartNShotAbs(10,1,4);
355 TickTest[4]->StartPeriodic(13,30);
356 TickTest[5]->StartPeriodic(19,30);
357 TickTest[6]->StartPeriodic(23,30);
358 TickTest[7]->StartPeriodic(37,30);
361 CActiveScheduler::Start();