sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\system\t_mstim.cpp sl@0: // Overview: sl@0: // Test millisecond timers sl@0: // API Information: sl@0: // NTimer sl@0: // Details: sl@0: // - Create and start a number of periodic timers, verify results are sl@0: // as expected. sl@0: // - Attempt to start a timer that has already been started. Verify returned sl@0: // error results. sl@0: // - Start one shot interrupt and one shot DFC timers and verify that the sl@0: // delay time is correct. sl@0: // - Start additional one shot interrupt timers with various values and verify sl@0: // results are as expected. sl@0: // - Calculate and print the elapsed time. sl@0: // - Start some timers, display min. max, avg and count information on each. sl@0: // Verify results are as expected. sl@0: // - Cancel a periodic timer and reuse it in a variety of conditions. Time how sl@0: // long it takes for each to complete. sl@0: // - Perform some random timer tests and display the results. sl@0: // - Check idle time while a variety of one shot timers run. Verify results are sl@0: // within the expected range. sl@0: // Platforms/Drives/Compatibility: sl@0: // All. sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // Failures and causes: sl@0: // Base Port information: sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include "d_mstim.h" sl@0: sl@0: RTest test(_L("T_MSTIM")); sl@0: RMsTim mstim; sl@0: sl@0: TBool PauseOnError = 0; sl@0: #define GETCH() (PauseOnError&&test.Getch()) sl@0: sl@0: #define TEST(c) ((void)((c)||(test.Printf(_L("Failed at line %d\n"),__LINE__),GETCH(),test(0),0))) sl@0: #define CHECK(c) ((void)(((c)==0)||(test.Printf(_L("Error %d at line %d\n"),(c),__LINE__),GETCH(),test(0),0))) sl@0: #ifdef __WINS__ sl@0: #define TESTTIME(v,min,max) test.Printf(_L("Expected range [%d,%d]\n"),min,max+1) sl@0: #else sl@0: #define TESTTIME(v,min,max) TEST(v>=min && v=0 && cdiff<=2); sl@0: #ifndef __WINS__ sl@0: TEST(Abs(z.iMin-1000*p)<1000); sl@0: TEST(Abs(z.iMax-1000*p)<1000); sl@0: #endif sl@0: TEST(Abs(z.iAvg-1000*p)<1000); sl@0: } sl@0: sl@0: test.Next(_L("Cancel periodic")); sl@0: r=mstim.StopPeriodic(7); sl@0: CHECK(r); sl@0: r=mstim.GetInfo(7,info[7]); sl@0: CHECK(r); sl@0: User::After(1000000); sl@0: r=mstim.GetInfo(7,info[6]); sl@0: CHECK(r); sl@0: TEST(info[6].iCount==info[7].iCount); sl@0: sl@0: test.Next(_L("Reuse cancelled")); sl@0: mstim.StartOneShotInt(s,7,128); sl@0: User::WaitForRequest(s); sl@0: TEST(s==KErrNone); sl@0: time=GetOneShotTime(7); sl@0: test.Printf(_L("Took %dms\n"),time); sl@0: TESTTIME(time,128,130); sl@0: sl@0: TRequestStatus s2; sl@0: test.Next(_L("Timed Cancel")); sl@0: mstim.StartOneShotInt(s,2,128); sl@0: mstim.IntCancel(s2,2,130); sl@0: User::WaitForRequest(s); sl@0: TEST(s==KErrNone); sl@0: User::WaitForRequest(s2); sl@0: TEST(s2==KErrNone); sl@0: time=GetOneShotTime(2); sl@0: test.Printf(_L("Took %dms\n"),time); sl@0: TESTTIME(time,128,130); sl@0: time=GetOneShotTime(7); sl@0: test.Printf(_L("Cancel Took %dms\n"),time); sl@0: TESTTIME(time,130,132); sl@0: sl@0: mstim.StartOneShotInt(s,2,128); sl@0: mstim.IntCancel(s2,2,126); sl@0: User::WaitForRequest(s); sl@0: TEST(s==KErrAbort); sl@0: User::WaitForRequest(s2); sl@0: TEST(s2==KErrNone); sl@0: time=GetOneShotTime(7); sl@0: test.Printf(_L("Cancel Took %dms\n"),time); sl@0: TESTTIME(time,126,128); sl@0: sl@0: test.Next(_L("Reuse cancelled")); sl@0: mstim.StartOneShotInt(s,2,64); sl@0: User::WaitForRequest(s); sl@0: TEST(s==KErrNone); sl@0: time=GetOneShotTime(2); sl@0: test.Printf(_L("Took %dms\n"),time); sl@0: TESTTIME(time,64,66); sl@0: sl@0: #ifdef _DEBUG sl@0: test.Next(_L("Random test")); sl@0: r=mstim.BeginRandomTest(); sl@0: CHECK(r); sl@0: #endif sl@0: sl@0: test.Printf(_L("Please wait...\n")); sl@0: User::After(10000000); sl@0: sl@0: #ifdef _DEBUG sl@0: r=mstim.EndRandomTest(); sl@0: CHECK(r); sl@0: SRandomTestInfo rInfo; sl@0: r=mstim.GetRandomTestInfo(rInfo); sl@0: test.Printf(_L("min error = %d\n"),rInfo.iMin); sl@0: test.Printf(_L("max error = %d\n"),rInfo.iMax); sl@0: test.Printf(_L("xfer cancel = %d\n"),rInfo.iXferC); sl@0: test.Printf(_L("crit cancel = %d\n"),rInfo.iCritC); sl@0: test.Printf(_L("start fails = %d\n"),rInfo.iStartFail); sl@0: test.Printf(_L("debug calls = %d\n"),rInfo.iCallBacks); sl@0: test.Printf(_L("completions = %d\n"),rInfo.iCompletions); sl@0: #endif sl@0: sl@0: for (i=0; i<8; i++) sl@0: { sl@0: r=mstim.GetInfo(i,info[i]); sl@0: CHECK(r); sl@0: } sl@0: sl@0: final_count=User::NTickCount(); sl@0: elapsed=TInt(final_count-init_count); sl@0: test.Printf(_L("Elapsed time %dms\n"),elapsed); sl@0: sl@0: const TInt period2[8]={31,32,0,0,7,43,19,0}; sl@0: for (i=0; i<8; i++) sl@0: { sl@0: TInt p=period2[i]; sl@0: if (p==0) sl@0: continue; sl@0: r=mstim.StopPeriodic(i); sl@0: CHECK(r); sl@0: SMsTimerInfo& z=info[i]; sl@0: test.Printf(_L("%1d: min=%-6d max=%-6d avg=%-6d count=%d\n"),i,z.iMin,z.iMax,z.iAvg,z.iCount); sl@0: TInt count=elapsed/p; sl@0: TInt cdiff=count-z.iCount; sl@0: TEST(cdiff>=0 && cdiff<=2); sl@0: #ifndef __WINS__ sl@0: TEST(Abs(z.iMin-1000*p)<=1000); sl@0: TEST(Abs(z.iMax-1000*p)<=1000); sl@0: #endif sl@0: TEST(Abs(z.iAvg-1000*p)<=1000); sl@0: } sl@0: sl@0: test.Next(_L("Idle time")); sl@0: time=0; sl@0: TInt idle=0; sl@0: while (time<3000) sl@0: { sl@0: idle=mstim.GetIdleTime(); sl@0: if (idle>=1000) sl@0: break; sl@0: if (idle<32) sl@0: idle=32; sl@0: User::AfterHighRes(idle*1000); sl@0: time+=idle; sl@0: } sl@0: if (time>=3000) sl@0: test.Printf(_L("Never got long enough idle time\n")); sl@0: else sl@0: { sl@0: mstim.StartOneShotInt(s,0,900); sl@0: TUint fc0=User::NTickCount(); sl@0: User::AfterHighRes(20000); sl@0: idle=mstim.GetIdleTime(); sl@0: test.Printf(_L("Idle time %dms\n"),idle); sl@0: TESTTIME(idle,860,881); sl@0: mstim.StartOneShotInt(s2,1,200); sl@0: fc1=User::NTickCount(); sl@0: User::AfterHighRes(20000); sl@0: idle=mstim.GetIdleTime(); sl@0: test.Printf(_L("Idle time %dms\n"),idle); sl@0: TESTTIME(idle,160,181); sl@0: TRequestStatus s3; sl@0: mstim.StartOneShotInt(s3,2,10); sl@0: idle=mstim.GetIdleTime(); sl@0: test.Printf(_L("Idle time %dms\n"),idle); sl@0: TEST(idle==0); sl@0: User::WaitForRequest(s3); sl@0: fc2=User::NTickCount(); sl@0: idle=mstim.GetIdleTime(); sl@0: elapsed=fc2-fc1; sl@0: test.Printf(_L("Idle time %dms elapsed %dms\n"),idle,elapsed); sl@0: TESTTIME(idle,180-elapsed,201-elapsed); sl@0: User::WaitForRequest(s2); sl@0: fc2=User::NTickCount(); sl@0: idle=mstim.GetIdleTime(); sl@0: elapsed=fc2-fc0; sl@0: test.Printf(_L("Idle time %dms elapsed %dms\n"),idle,elapsed); sl@0: TESTTIME(idle,880-elapsed,900-elapsed); sl@0: User::WaitForRequest(s); sl@0: } sl@0: sl@0: TUint fc4, fc5; sl@0: test.Next(_L("One shot int ")); sl@0: mstim.StartOneShotInt(s,8,100); sl@0: User::WaitForRequest(s); sl@0: TEST(s==KErrNone); sl@0: time=GetOneShotTime(8); sl@0: test.Printf(_L("Took %dms\n"),time); sl@0: TESTTIME(time,100,102); sl@0: sl@0: test.Next(_L("One shot int ")); sl@0: mstim.StartOneShotInt(s,8,300); sl@0: User::WaitForRequest(s); sl@0: fc4=User::NTickCount(); sl@0: TEST(s==KErrNone); sl@0: time=GetOneShotTime(8); sl@0: test.Printf(_L("Took %dms\n"),time); sl@0: TESTTIME(time,300,302); sl@0: sl@0: test.Next(_L("One shot int again")); sl@0: fc5=User::NTickCount(); sl@0: mstim.StartOneShotIntAgain(s,8,300); sl@0: User::WaitForRequest(s); sl@0: TEST(s==KErrNone); sl@0: time2=GetOneShotTime(8); sl@0: test.Printf(_L("Took %dms, delay %dms\n"),time2,fc5-fc4); sl@0: time2+=TInt(fc5-fc4); sl@0: TESTTIME(time2,295,306); sl@0: sl@0: test.Next(_L("One shot with provided Dfc queue")); sl@0: mstim.StartOneShotUserDfc(s,8,100); sl@0: User::WaitForRequest(s); sl@0: TEST(s==KErrNone); sl@0: time=GetOneShotTime(8); sl@0: test.Printf(_L("Took %dms\n"),time); sl@0: TESTTIME(time,100,102); sl@0: sl@0: test.Next(_L("One shot with provided Dfc queue")); sl@0: mstim.StartOneShotUserDfc(s,8,300); sl@0: User::WaitForRequest(s); sl@0: fc4=User::NTickCount(); sl@0: TEST(s==KErrNone); sl@0: time=GetOneShotTime(8); sl@0: test.Printf(_L("Took %dms\n"),time); sl@0: TESTTIME(time,300,302); sl@0: sl@0: test.Next(_L("One shot with provided Dfc queue again")); sl@0: fc5=User::NTickCount(); sl@0: mstim.StartOneShotUserDfcAgain(s,8,300); sl@0: User::WaitForRequest(s); sl@0: TEST(s==KErrNone); sl@0: time2=GetOneShotTime(8); sl@0: test.Printf(_L("Took %dms, delay %dms\n"),time2,fc5-fc4); sl@0: time2+=TInt(fc5-fc4); sl@0: TESTTIME(time2,295,306); sl@0: sl@0: test.End(); sl@0: return(KErrNone); sl@0: } sl@0: