1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/system/t_mstim.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,413 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\system\t_mstim.cpp
1.18 +// Overview:
1.19 +// Test millisecond timers
1.20 +// API Information:
1.21 +// NTimer
1.22 +// Details:
1.23 +// - Create and start a number of periodic timers, verify results are
1.24 +// as expected.
1.25 +// - Attempt to start a timer that has already been started. Verify returned
1.26 +// error results.
1.27 +// - Start one shot interrupt and one shot DFC timers and verify that the
1.28 +// delay time is correct.
1.29 +// - Start additional one shot interrupt timers with various values and verify
1.30 +// results are as expected.
1.31 +// - Calculate and print the elapsed time.
1.32 +// - Start some timers, display min. max, avg and count information on each.
1.33 +// Verify results are as expected.
1.34 +// - Cancel a periodic timer and reuse it in a variety of conditions. Time how
1.35 +// long it takes for each to complete.
1.36 +// - Perform some random timer tests and display the results.
1.37 +// - Check idle time while a variety of one shot timers run. Verify results are
1.38 +// within the expected range.
1.39 +// Platforms/Drives/Compatibility:
1.40 +// All.
1.41 +// Assumptions/Requirement/Pre-requisites:
1.42 +// Failures and causes:
1.43 +// Base Port information:
1.44 +//
1.45 +//
1.46 +
1.47 +#include <e32test.h>
1.48 +#include <e32uid.h>
1.49 +#include "d_mstim.h"
1.50 +
1.51 +RTest test(_L("T_MSTIM"));
1.52 +RMsTim mstim;
1.53 +
1.54 +TBool PauseOnError = 0;
1.55 +#define GETCH() (PauseOnError&&test.Getch())
1.56 +
1.57 +#define TEST(c) ((void)((c)||(test.Printf(_L("Failed at line %d\n"),__LINE__),GETCH(),test(0),0)))
1.58 +#define CHECK(c) ((void)(((c)==0)||(test.Printf(_L("Error %d at line %d\n"),(c),__LINE__),GETCH(),test(0),0)))
1.59 +#ifdef __WINS__
1.60 +#define TESTTIME(v,min,max) test.Printf(_L("Expected range [%d,%d]\n"),min,max+1)
1.61 +#else
1.62 +#define TESTTIME(v,min,max) TEST(v>=min && v<max)
1.63 +#endif
1.64 +
1.65 +const TPtrC KLddFileName=_L("D_MSTIM.LDD");
1.66 +
1.67 +void GetInfo(TInt aId)
1.68 + {
1.69 + SMsTimerInfo info;
1.70 + TInt r=mstim.GetInfo(aId,info);
1.71 + CHECK(r);
1.72 + test.Printf(_L("%1d: min=%-6d max=%-6d avg=%-6d count=%d\n"),aId,info.iMin,info.iMax,info.iAvg,info.iCount);
1.73 + }
1.74 +
1.75 +void GetAllInfo()
1.76 + {
1.77 + GetInfo(0);
1.78 + GetInfo(1);
1.79 + GetInfo(2);
1.80 + GetInfo(3);
1.81 + test.Printf(_L("\n"));
1.82 + }
1.83 +
1.84 +TInt GetOneShotTime(TInt aId)
1.85 + {
1.86 + SMsTimerInfo info;
1.87 + TInt r=mstim.GetInfo(aId,info);
1.88 + CHECK(r);
1.89 + TEST(info.iCount==1);
1.90 + return info.iMin/1000;
1.91 + }
1.92 +
1.93 +GLDEF_C TInt E32Main()
1.94 +//
1.95 +// Test millisecond timers
1.96 +//
1.97 + {
1.98 +// test.SetLogged(EFalse);
1.99 + test.Title();
1.100 +
1.101 + test.Start(_L("Load test LDD"));
1.102 + TInt r=User::LoadLogicalDevice(KLddFileName);
1.103 + TEST(r==KErrNone || r==KErrAlreadyExists);
1.104 +
1.105 + r=mstim.Open();
1.106 + CHECK(r);
1.107 +
1.108 + test.Next(_L("Start periodics"));
1.109 + TUint init_count=User::NTickCount();
1.110 + r=mstim.StartPeriodicInt(0,31);
1.111 + CHECK(r);
1.112 + r=mstim.StartPeriodicInt(1,32);
1.113 + CHECK(r);
1.114 + r=mstim.StartPeriodicInt(4,7);
1.115 + CHECK(r);
1.116 + r=mstim.StartPeriodicInt(5,43);
1.117 + CHECK(r);
1.118 + r=mstim.StartPeriodicDfc(6,19);
1.119 + CHECK(r);
1.120 + r=mstim.StartPeriodicDfc(7,71);
1.121 + CHECK(r);
1.122 +
1.123 + test.Next(_L("Start while started"));
1.124 + TRequestStatus s;
1.125 + mstim.StartOneShotInt(s,0,100);
1.126 + User::WaitForRequest(s);
1.127 + TEST(s==KErrInUse);
1.128 +
1.129 + test.Next(_L("One shot interrupt"));
1.130 + mstim.StartOneShotInt(s,2,100);
1.131 + User::WaitForRequest(s);
1.132 + TUint fc1=User::NTickCount();
1.133 + TEST(s==KErrNone);
1.134 + TInt time=GetOneShotTime(2);
1.135 + test.Printf(_L("Took %dms\n"),time);
1.136 + TESTTIME(time,100,102);
1.137 +
1.138 + test.Next(_L("One shot DFC"));
1.139 + mstim.StartOneShotDfc(s,3,200);
1.140 + User::WaitForRequest(s);
1.141 + TUint fc3=User::NTickCount();
1.142 + TEST(s==KErrNone);
1.143 + time=GetOneShotTime(3);
1.144 + test.Printf(_L("Took %dms\n"),time);
1.145 + TESTTIME(time,200,202);
1.146 +
1.147 + test.Next(_L("One shot interrupt again"));
1.148 + TUint fc2=User::NTickCount();
1.149 + mstim.StartOneShotIntAgain(s,2,300);
1.150 + User::WaitForRequest(s);
1.151 + TEST(s==KErrNone);
1.152 + TInt time2=GetOneShotTime(2);
1.153 + test.Printf(_L("Took %dms, delay %dms\n"),time2,fc2-fc1);
1.154 + time2+=TInt(fc2-fc1);
1.155 + TESTTIME(time2,295,306);
1.156 +
1.157 + test.Next(_L("One shot interrupt again too late"));
1.158 + mstim.StartOneShotIntAgain(s,3,10);
1.159 + User::WaitForRequest(s);
1.160 + TEST(s==KErrArgument);
1.161 +
1.162 + test.Next(_L("One shot interrupt again"));
1.163 + fc2=User::NTickCount();
1.164 + mstim.StartOneShotIntAgain(s,3,300);
1.165 + User::WaitForRequest(s);
1.166 + TEST(s==KErrNone);
1.167 + time=GetOneShotTime(3);
1.168 + test.Printf(_L("Took %dms, delay %dms\n"),time,fc2-fc3);
1.169 + time+=TInt(fc2-fc3);
1.170 + TESTTIME(time,295,306);
1.171 +
1.172 + test.Printf(_L("Please wait...\n"));
1.173 + User::After(10000000);
1.174 +
1.175 + SMsTimerInfo info[8];
1.176 + TInt i;
1.177 + for (i=0; i<8; i++)
1.178 + {
1.179 + r=mstim.GetInfo(i,info[i]);
1.180 + CHECK(r);
1.181 + }
1.182 +
1.183 + TUint final_count=User::NTickCount();
1.184 + TInt elapsed=TInt(final_count-init_count);
1.185 + test.Printf(_L("Elapsed time %dms\n"),elapsed);
1.186 +
1.187 + const TInt period[8]={31,32,0,0,7,43,19,71};
1.188 + for (i=0; i<8; i++)
1.189 + {
1.190 + TInt p=period[i];
1.191 + if (p==0)
1.192 + continue;
1.193 + SMsTimerInfo& z=info[i];
1.194 + test.Printf(_L("%1d: min=%-6d max=%-6d avg=%-6d count=%d\n"),i,z.iMin,z.iMax,z.iAvg,z.iCount);
1.195 + TInt count=elapsed/p;
1.196 + TInt cdiff=count-z.iCount;
1.197 + TEST(cdiff>=0 && cdiff<=2);
1.198 +#ifndef __WINS__
1.199 + TEST(Abs(z.iMin-1000*p)<1000);
1.200 + TEST(Abs(z.iMax-1000*p)<1000);
1.201 +#endif
1.202 + TEST(Abs(z.iAvg-1000*p)<1000);
1.203 + }
1.204 +
1.205 + test.Next(_L("Cancel periodic"));
1.206 + r=mstim.StopPeriodic(7);
1.207 + CHECK(r);
1.208 + r=mstim.GetInfo(7,info[7]);
1.209 + CHECK(r);
1.210 + User::After(1000000);
1.211 + r=mstim.GetInfo(7,info[6]);
1.212 + CHECK(r);
1.213 + TEST(info[6].iCount==info[7].iCount);
1.214 +
1.215 + test.Next(_L("Reuse cancelled"));
1.216 + mstim.StartOneShotInt(s,7,128);
1.217 + User::WaitForRequest(s);
1.218 + TEST(s==KErrNone);
1.219 + time=GetOneShotTime(7);
1.220 + test.Printf(_L("Took %dms\n"),time);
1.221 + TESTTIME(time,128,130);
1.222 +
1.223 + TRequestStatus s2;
1.224 + test.Next(_L("Timed Cancel"));
1.225 + mstim.StartOneShotInt(s,2,128);
1.226 + mstim.IntCancel(s2,2,130);
1.227 + User::WaitForRequest(s);
1.228 + TEST(s==KErrNone);
1.229 + User::WaitForRequest(s2);
1.230 + TEST(s2==KErrNone);
1.231 + time=GetOneShotTime(2);
1.232 + test.Printf(_L("Took %dms\n"),time);
1.233 + TESTTIME(time,128,130);
1.234 + time=GetOneShotTime(7);
1.235 + test.Printf(_L("Cancel Took %dms\n"),time);
1.236 + TESTTIME(time,130,132);
1.237 +
1.238 + mstim.StartOneShotInt(s,2,128);
1.239 + mstim.IntCancel(s2,2,126);
1.240 + User::WaitForRequest(s);
1.241 + TEST(s==KErrAbort);
1.242 + User::WaitForRequest(s2);
1.243 + TEST(s2==KErrNone);
1.244 + time=GetOneShotTime(7);
1.245 + test.Printf(_L("Cancel Took %dms\n"),time);
1.246 + TESTTIME(time,126,128);
1.247 +
1.248 + test.Next(_L("Reuse cancelled"));
1.249 + mstim.StartOneShotInt(s,2,64);
1.250 + User::WaitForRequest(s);
1.251 + TEST(s==KErrNone);
1.252 + time=GetOneShotTime(2);
1.253 + test.Printf(_L("Took %dms\n"),time);
1.254 + TESTTIME(time,64,66);
1.255 +
1.256 +#ifdef _DEBUG
1.257 + test.Next(_L("Random test"));
1.258 + r=mstim.BeginRandomTest();
1.259 + CHECK(r);
1.260 +#endif
1.261 +
1.262 + test.Printf(_L("Please wait...\n"));
1.263 + User::After(10000000);
1.264 +
1.265 +#ifdef _DEBUG
1.266 + r=mstim.EndRandomTest();
1.267 + CHECK(r);
1.268 + SRandomTestInfo rInfo;
1.269 + r=mstim.GetRandomTestInfo(rInfo);
1.270 + test.Printf(_L("min error = %d\n"),rInfo.iMin);
1.271 + test.Printf(_L("max error = %d\n"),rInfo.iMax);
1.272 + test.Printf(_L("xfer cancel = %d\n"),rInfo.iXferC);
1.273 + test.Printf(_L("crit cancel = %d\n"),rInfo.iCritC);
1.274 + test.Printf(_L("start fails = %d\n"),rInfo.iStartFail);
1.275 + test.Printf(_L("debug calls = %d\n"),rInfo.iCallBacks);
1.276 + test.Printf(_L("completions = %d\n"),rInfo.iCompletions);
1.277 +#endif
1.278 +
1.279 + for (i=0; i<8; i++)
1.280 + {
1.281 + r=mstim.GetInfo(i,info[i]);
1.282 + CHECK(r);
1.283 + }
1.284 +
1.285 + final_count=User::NTickCount();
1.286 + elapsed=TInt(final_count-init_count);
1.287 + test.Printf(_L("Elapsed time %dms\n"),elapsed);
1.288 +
1.289 + const TInt period2[8]={31,32,0,0,7,43,19,0};
1.290 + for (i=0; i<8; i++)
1.291 + {
1.292 + TInt p=period2[i];
1.293 + if (p==0)
1.294 + continue;
1.295 + r=mstim.StopPeriodic(i);
1.296 + CHECK(r);
1.297 + SMsTimerInfo& z=info[i];
1.298 + test.Printf(_L("%1d: min=%-6d max=%-6d avg=%-6d count=%d\n"),i,z.iMin,z.iMax,z.iAvg,z.iCount);
1.299 + TInt count=elapsed/p;
1.300 + TInt cdiff=count-z.iCount;
1.301 + TEST(cdiff>=0 && cdiff<=2);
1.302 +#ifndef __WINS__
1.303 + TEST(Abs(z.iMin-1000*p)<=1000);
1.304 + TEST(Abs(z.iMax-1000*p)<=1000);
1.305 +#endif
1.306 + TEST(Abs(z.iAvg-1000*p)<=1000);
1.307 + }
1.308 +
1.309 + test.Next(_L("Idle time"));
1.310 + time=0;
1.311 + TInt idle=0;
1.312 + while (time<3000)
1.313 + {
1.314 + idle=mstim.GetIdleTime();
1.315 + if (idle>=1000)
1.316 + break;
1.317 + if (idle<32)
1.318 + idle=32;
1.319 + User::AfterHighRes(idle*1000);
1.320 + time+=idle;
1.321 + }
1.322 + if (time>=3000)
1.323 + test.Printf(_L("Never got long enough idle time\n"));
1.324 + else
1.325 + {
1.326 + mstim.StartOneShotInt(s,0,900);
1.327 + TUint fc0=User::NTickCount();
1.328 + User::AfterHighRes(20000);
1.329 + idle=mstim.GetIdleTime();
1.330 + test.Printf(_L("Idle time %dms\n"),idle);
1.331 + TESTTIME(idle,860,881);
1.332 + mstim.StartOneShotInt(s2,1,200);
1.333 + fc1=User::NTickCount();
1.334 + User::AfterHighRes(20000);
1.335 + idle=mstim.GetIdleTime();
1.336 + test.Printf(_L("Idle time %dms\n"),idle);
1.337 + TESTTIME(idle,160,181);
1.338 + TRequestStatus s3;
1.339 + mstim.StartOneShotInt(s3,2,10);
1.340 + idle=mstim.GetIdleTime();
1.341 + test.Printf(_L("Idle time %dms\n"),idle);
1.342 + TEST(idle==0);
1.343 + User::WaitForRequest(s3);
1.344 + fc2=User::NTickCount();
1.345 + idle=mstim.GetIdleTime();
1.346 + elapsed=fc2-fc1;
1.347 + test.Printf(_L("Idle time %dms elapsed %dms\n"),idle,elapsed);
1.348 + TESTTIME(idle,180-elapsed,201-elapsed);
1.349 + User::WaitForRequest(s2);
1.350 + fc2=User::NTickCount();
1.351 + idle=mstim.GetIdleTime();
1.352 + elapsed=fc2-fc0;
1.353 + test.Printf(_L("Idle time %dms elapsed %dms\n"),idle,elapsed);
1.354 + TESTTIME(idle,880-elapsed,900-elapsed);
1.355 + User::WaitForRequest(s);
1.356 + }
1.357 +
1.358 + TUint fc4, fc5;
1.359 + test.Next(_L("One shot int "));
1.360 + mstim.StartOneShotInt(s,8,100);
1.361 + User::WaitForRequest(s);
1.362 + TEST(s==KErrNone);
1.363 + time=GetOneShotTime(8);
1.364 + test.Printf(_L("Took %dms\n"),time);
1.365 + TESTTIME(time,100,102);
1.366 +
1.367 + test.Next(_L("One shot int "));
1.368 + mstim.StartOneShotInt(s,8,300);
1.369 + User::WaitForRequest(s);
1.370 + fc4=User::NTickCount();
1.371 + TEST(s==KErrNone);
1.372 + time=GetOneShotTime(8);
1.373 + test.Printf(_L("Took %dms\n"),time);
1.374 + TESTTIME(time,300,302);
1.375 +
1.376 + test.Next(_L("One shot int again"));
1.377 + fc5=User::NTickCount();
1.378 + mstim.StartOneShotIntAgain(s,8,300);
1.379 + User::WaitForRequest(s);
1.380 + TEST(s==KErrNone);
1.381 + time2=GetOneShotTime(8);
1.382 + test.Printf(_L("Took %dms, delay %dms\n"),time2,fc5-fc4);
1.383 + time2+=TInt(fc5-fc4);
1.384 + TESTTIME(time2,295,306);
1.385 +
1.386 + test.Next(_L("One shot with provided Dfc queue"));
1.387 + mstim.StartOneShotUserDfc(s,8,100);
1.388 + User::WaitForRequest(s);
1.389 + TEST(s==KErrNone);
1.390 + time=GetOneShotTime(8);
1.391 + test.Printf(_L("Took %dms\n"),time);
1.392 + TESTTIME(time,100,102);
1.393 +
1.394 + test.Next(_L("One shot with provided Dfc queue"));
1.395 + mstim.StartOneShotUserDfc(s,8,300);
1.396 + User::WaitForRequest(s);
1.397 + fc4=User::NTickCount();
1.398 + TEST(s==KErrNone);
1.399 + time=GetOneShotTime(8);
1.400 + test.Printf(_L("Took %dms\n"),time);
1.401 + TESTTIME(time,300,302);
1.402 +
1.403 + test.Next(_L("One shot with provided Dfc queue again"));
1.404 + fc5=User::NTickCount();
1.405 + mstim.StartOneShotUserDfcAgain(s,8,300);
1.406 + User::WaitForRequest(s);
1.407 + TEST(s==KErrNone);
1.408 + time2=GetOneShotTime(8);
1.409 + test.Printf(_L("Took %dms, delay %dms\n"),time2,fc5-fc4);
1.410 + time2+=TInt(fc5-fc4);
1.411 + TESTTIME(time2,295,306);
1.412 +
1.413 + test.End();
1.414 + return(KErrNone);
1.415 + }
1.416 +