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