kerneltest/e32test/system/t_mstim.cpp
changeset 300 1d28c8722707
parent 189 a5496987b1da
equal deleted inserted replaced
293:0659d0e1a03c 300:1d28c8722707
    41 // 
    41 // 
    42 //
    42 //
    43 
    43 
    44 #include <e32test.h>
    44 #include <e32test.h>
    45 #include <e32uid.h>
    45 #include <e32uid.h>
       
    46 #include <e32svr.h>
       
    47 #include <u32hal.h>
    46 #include "d_mstim.h"
    48 #include "d_mstim.h"
    47 
    49 
    48 RTest test(_L("T_MSTIM"));
    50 RTest test(_L("T_MSTIM"));
    49 RMsTim mstim;
    51 RMsTim mstim;
    50 
    52 
    90 GLDEF_C TInt E32Main()
    92 GLDEF_C TInt E32Main()
    91 //
    93 //
    92 // Test millisecond timers
    94 // Test millisecond timers
    93 //
    95 //
    94     {
    96     {
       
    97 	// RTest::Printf and Next are very high latency under SMP, so suppress them
       
    98 	const TBool unicore = (UserSvr::HalFunction(EHalGroupKernel, EKernelHalSmpSupported, 0, 0) == KErrNotSupported);
       
    99 
    95 //	test.SetLogged(EFalse);
   100 //	test.SetLogged(EFalse);
    96 	test.Title();
   101 	test.Title();
       
   102 
       
   103 	if (!unicore)
       
   104 		test.Printf(_L("Running on a SMP system - output reduced\n"));
    97 
   105 
    98 	test.Start(_L("Load test LDD"));
   106 	test.Start(_L("Load test LDD"));
    99 	TInt r=User::LoadLogicalDevice(KLddFileName);
   107 	TInt r=User::LoadLogicalDevice(KLddFileName);
   100 	TEST(r==KErrNone || r==KErrAlreadyExists);
   108 	TEST(r==KErrNone || r==KErrAlreadyExists);
   101 	
   109 	
   115 	r=mstim.StartPeriodicDfc(6,19);
   123 	r=mstim.StartPeriodicDfc(6,19);
   116 	CHECK(r);
   124 	CHECK(r);
   117 	r=mstim.StartPeriodicDfc(7,71);
   125 	r=mstim.StartPeriodicDfc(7,71);
   118 	CHECK(r);
   126 	CHECK(r);
   119 
   127 
   120 	test.Next(_L("Start while started"));
   128 	if (unicore)
       
   129 		test.Next(_L("Start while started"));
   121 	TRequestStatus s;
   130 	TRequestStatus s;
   122 	mstim.StartOneShotInt(s,0,100);
   131 	mstim.StartOneShotInt(s,0,100);
   123 	User::WaitForRequest(s);
   132 	User::WaitForRequest(s);
   124 	TEST(s==KErrInUse);
   133 	TEST(s==KErrInUse);
   125 
   134 
   126 	test.Next(_L("One shot interrupt"));
   135 	if (unicore)
       
   136 		test.Next(_L("One shot interrupt"));
   127 	mstim.StartOneShotInt(s,2,100);
   137 	mstim.StartOneShotInt(s,2,100);
   128 	User::WaitForRequest(s);
   138 	User::WaitForRequest(s);
   129 	TUint fc1=User::NTickCount();
   139 	TUint fc1=User::NTickCount();
   130 	TEST(s==KErrNone);
   140 	TEST(s==KErrNone);
   131 	TInt time=GetOneShotTime(2);
   141 	TInt time=GetOneShotTime(2);
   132 	test.Printf(_L("Took %dms\n"),time);
   142 	if (unicore)
       
   143 		test.Printf(_L("Took %dms\n"),time);
   133 	TESTTIME(time,100,102);
   144 	TESTTIME(time,100,102);
   134 
   145 
   135 	test.Next(_L("One shot DFC"));
   146 	if (unicore)
       
   147 		test.Next(_L("One shot DFC"));
   136 	mstim.StartOneShotDfc(s,3,200);
   148 	mstim.StartOneShotDfc(s,3,200);
   137 	User::WaitForRequest(s);
   149 	User::WaitForRequest(s);
   138 	TUint fc3=User::NTickCount();
   150 	TUint fc3=User::NTickCount();
   139 	TEST(s==KErrNone);
   151 	TEST(s==KErrNone);
   140 	time=GetOneShotTime(3);
   152 	time=GetOneShotTime(3);
   141 	test.Printf(_L("Took %dms\n"),time);
   153 	if (unicore)
       
   154 		test.Printf(_L("Took %dms\n"),time);
   142 	TESTTIME(time,200,202);
   155 	TESTTIME(time,200,202);
   143 
   156 
   144 	test.Next(_L("One shot interrupt again"));
   157 	if (unicore)
       
   158 		test.Next(_L("One shot interrupt again"));
   145 	TUint fc2=User::NTickCount();
   159 	TUint fc2=User::NTickCount();
   146 	mstim.StartOneShotIntAgain(s,2,300);
   160 	mstim.StartOneShotIntAgain(s,2,300);
   147 	User::WaitForRequest(s);
   161 	User::WaitForRequest(s);
   148 	TEST(s==KErrNone);
   162 	TEST(s==KErrNone);
   149 	TInt time2=GetOneShotTime(2);
   163 	TInt time2=GetOneShotTime(2);
   150 	test.Printf(_L("Took %dms, delay %dms\n"),time2,fc2-fc1);
   164 	if (unicore)
       
   165 		test.Printf(_L("Took %dms, delay %dms\n"),time2,fc2-fc1);
   151 	time2+=TInt(fc2-fc1);
   166 	time2+=TInt(fc2-fc1);
   152 	TESTTIME(time2,295,306);
   167 	TESTTIME(time2,295,306);
   153 
   168 
   154 	test.Next(_L("One shot interrupt again too late"));
   169 	if (unicore)
       
   170 		test.Next(_L("One shot interrupt again too late"));
   155 	mstim.StartOneShotIntAgain(s,3,10);
   171 	mstim.StartOneShotIntAgain(s,3,10);
   156 	User::WaitForRequest(s);
   172 	User::WaitForRequest(s);
   157 	TEST(s==KErrArgument);
   173 	TEST(s==KErrArgument);
   158 
   174 
   159 	test.Next(_L("One shot interrupt again"));
   175 	if (unicore)
       
   176 		test.Next(_L("One shot interrupt again"));
   160 	fc2=User::NTickCount();
   177 	fc2=User::NTickCount();
   161 	mstim.StartOneShotIntAgain(s,3,300);
   178 	mstim.StartOneShotIntAgain(s,3,300);
   162 	User::WaitForRequest(s);
   179 	User::WaitForRequest(s);
   163 	TEST(s==KErrNone);
   180 	TEST(s==KErrNone);
   164 	time=GetOneShotTime(3);
   181 	time=GetOneShotTime(3);
   165 	test.Printf(_L("Took %dms, delay %dms\n"),time,fc2-fc3);
   182 	if (unicore)
       
   183 		test.Printf(_L("Took %dms, delay %dms\n"),time,fc2-fc3);
   166 	time+=TInt(fc2-fc3);
   184 	time+=TInt(fc2-fc3);
   167 	TESTTIME(time,295,306);
   185 	TESTTIME(time,295,306);
   168 
   186 
   169 	test.Printf(_L("Please wait...\n"));
   187 	if (unicore)
       
   188 		test.Printf(_L("Please wait...\n"));
   170 	User::After(10000000);
   189 	User::After(10000000);
   171 
   190 
   172 	SMsTimerInfo info[8];
   191 	SMsTimerInfo info[8];
   173 	TInt i;
   192 	TInt i;
   174 	for (i=0; i<8; i++)
   193 	for (i=0; i<8; i++)
   177 		CHECK(r);
   196 		CHECK(r);
   178 		}
   197 		}
   179 
   198 
   180 	TUint final_count=User::NTickCount();
   199 	TUint final_count=User::NTickCount();
   181 	TInt elapsed=TInt(final_count-init_count);
   200 	TInt elapsed=TInt(final_count-init_count);
   182 	test.Printf(_L("Elapsed time %dms\n"),elapsed);
   201 	if (unicore)
       
   202 		test.Printf(_L("Elapsed time %dms\n"),elapsed);
   183 
   203 
   184 	const TInt period[8]={31,32,0,0,7,43,19,71};
   204 	const TInt period[8]={31,32,0,0,7,43,19,71};
   185 	for (i=0; i<8; i++)
   205 	for (i=0; i<8; i++)
   186 		{
   206 		{
   187 		TInt p=period[i];
   207 		TInt p=period[i];
   188 		if (p==0)
   208 		if (p==0)
   189 			continue;
   209 			continue;
   190 		SMsTimerInfo& z=info[i];
   210 		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);
   211 		if (unicore)
       
   212 			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;
   213 		TInt count=elapsed/p;
   193 		TInt cdiff=count-z.iCount;
   214 		TInt cdiff=count-z.iCount;
   194 		TEST(cdiff>=0 && cdiff<=2);
   215 		TEST(cdiff>=0 && cdiff<=2);
   195 #ifndef __WINS__
   216 #ifndef __WINS__
   196 		TEST(Abs(z.iMin-1000*p)<1000);
   217 		TEST(Abs(z.iMin-1000*p)<1000);
   197 		TEST(Abs(z.iMax-1000*p)<1000);
   218 		TEST(Abs(z.iMax-1000*p)<1000);
   198 #endif
   219 #endif
   199 		TEST(Abs(z.iAvg-1000*p)<1000);
   220 		TEST(Abs(z.iAvg-1000*p)<1000);
   200 		}
   221 		}
   201 
   222 
   202 	test.Next(_L("Cancel periodic"));
   223 	if (unicore)
       
   224 		test.Next(_L("Cancel periodic"));
   203 	r=mstim.StopPeriodic(7);
   225 	r=mstim.StopPeriodic(7);
   204 	CHECK(r);
   226 	CHECK(r);
   205 	r=mstim.GetInfo(7,info[7]);
   227 	r=mstim.GetInfo(7,info[7]);
   206 	CHECK(r);
   228 	CHECK(r);
   207 	User::After(1000000);
   229 	User::After(1000000);
   208 	r=mstim.GetInfo(7,info[6]);
   230 	r=mstim.GetInfo(7,info[6]);
   209 	CHECK(r);
   231 	CHECK(r);
   210 	TEST(info[6].iCount==info[7].iCount);
   232 	TEST(info[6].iCount==info[7].iCount);
   211 
   233 
   212 	test.Next(_L("Reuse cancelled"));
   234 	if (unicore)
       
   235 		test.Next(_L("Reuse cancelled"));
   213 	mstim.StartOneShotInt(s,7,128);
   236 	mstim.StartOneShotInt(s,7,128);
   214 	User::WaitForRequest(s);
   237 	User::WaitForRequest(s);
   215 	TEST(s==KErrNone);
   238 	TEST(s==KErrNone);
   216 	time=GetOneShotTime(7);
   239 	time=GetOneShotTime(7);
   217 	test.Printf(_L("Took %dms\n"),time);
   240 	if (unicore)
       
   241 		test.Printf(_L("Took %dms\n"),time);
   218 	TESTTIME(time,128,130);
   242 	TESTTIME(time,128,130);
   219 
   243 
   220 	TRequestStatus s2;
   244 	TRequestStatus s2;
   221 	test.Next(_L("Timed Cancel"));
   245 	if (unicore)
       
   246 		test.Next(_L("Timed Cancel"));
   222 	mstim.StartOneShotInt(s,2,128);
   247 	mstim.StartOneShotInt(s,2,128);
   223 	mstim.IntCancel(s2,2,130);
   248 	mstim.IntCancel(s2,2,130);
   224 	User::WaitForRequest(s);
   249 	User::WaitForRequest(s);
   225 	TEST(s==KErrNone);
   250 	TEST(s==KErrNone);
   226 	User::WaitForRequest(s2);
   251 	User::WaitForRequest(s2);
   227 	TEST(s2==KErrNone);
   252 	TEST(s2==KErrNone);
   228 	time=GetOneShotTime(2);
   253 	time=GetOneShotTime(2);
   229 	test.Printf(_L("Took %dms\n"),time);
   254 	if (unicore)
       
   255 		test.Printf(_L("Took %dms\n"),time);
   230 	TESTTIME(time,128,130);
   256 	TESTTIME(time,128,130);
   231 	time=GetOneShotTime(7);
   257 	time=GetOneShotTime(7);
   232 	test.Printf(_L("Cancel Took %dms\n"),time);
   258 	if (unicore)
       
   259 		test.Printf(_L("Cancel Took %dms\n"),time);
   233 	TESTTIME(time,130,132);
   260 	TESTTIME(time,130,132);
   234 
   261 
   235 	mstim.StartOneShotInt(s,2,128);
   262 	mstim.StartOneShotInt(s,2,128);
   236 	mstim.IntCancel(s2,2,126);
   263 	mstim.IntCancel(s2,2,126);
   237 	User::WaitForRequest(s);
   264 	User::WaitForRequest(s);
   238 	TEST(s==KErrAbort);
   265 	TEST(s==KErrAbort);
   239 	User::WaitForRequest(s2);
   266 	User::WaitForRequest(s2);
   240 	TEST(s2==KErrNone);
   267 	TEST(s2==KErrNone);
   241 	time=GetOneShotTime(7);
   268 	time=GetOneShotTime(7);
   242 	test.Printf(_L("Cancel Took %dms\n"),time);
   269 	if (unicore)
       
   270 		test.Printf(_L("Cancel Took %dms\n"),time);
   243 	TESTTIME(time,126,128);
   271 	TESTTIME(time,126,128);
   244 
   272 
   245 	test.Next(_L("Reuse cancelled"));
   273 	if (unicore)
       
   274 		test.Next(_L("Reuse cancelled"));
   246 	mstim.StartOneShotInt(s,2,64);
   275 	mstim.StartOneShotInt(s,2,64);
   247 	User::WaitForRequest(s);
   276 	User::WaitForRequest(s);
   248 	TEST(s==KErrNone);
   277 	TEST(s==KErrNone);
   249 	time=GetOneShotTime(2);
   278 	time=GetOneShotTime(2);
   250 	test.Printf(_L("Took %dms\n"),time);
   279 	if (unicore)
       
   280 		test.Printf(_L("Took %dms\n"),time);
   251 	TESTTIME(time,64,66);
   281 	TESTTIME(time,64,66);
   252 
   282 
   253 #ifdef _DEBUG
   283 #ifdef _DEBUG
   254 	test.Next(_L("Random test"));
   284 	if (unicore)
       
   285 		test.Next(_L("Random test"));
   255 	r=mstim.BeginRandomTest();
   286 	r=mstim.BeginRandomTest();
   256 	CHECK(r);
   287 	CHECK(r);
   257 #endif
   288 #endif
   258 
   289 
   259 	test.Printf(_L("Please wait...\n"));
   290 	if (unicore)
       
   291 		test.Printf(_L("Please wait...\n"));
   260 	User::After(10000000);
   292 	User::After(10000000);
   261 
   293 
   262 #ifdef _DEBUG
   294 #ifdef _DEBUG
   263 	r=mstim.EndRandomTest();
   295 	r=mstim.EndRandomTest();
   264 	CHECK(r);
   296 	CHECK(r);
   265 	SRandomTestInfo rInfo;
   297 	if (unicore)
   266 	r=mstim.GetRandomTestInfo(rInfo);
   298 		{
   267 	test.Printf(_L("min error = %d\n"),rInfo.iMin);
   299 		SRandomTestInfo rInfo;
   268 	test.Printf(_L("max error = %d\n"),rInfo.iMax);
   300 		r=mstim.GetRandomTestInfo(rInfo);
   269 	test.Printf(_L("xfer cancel = %d\n"),rInfo.iXferC);
   301 		test.Printf(_L("min error = %d\n"),rInfo.iMin);
   270 	test.Printf(_L("crit cancel = %d\n"),rInfo.iCritC);
   302 		test.Printf(_L("max error = %d\n"),rInfo.iMax);
   271 	test.Printf(_L("start fails = %d\n"),rInfo.iStartFail);
   303 		test.Printf(_L("xfer cancel = %d\n"),rInfo.iXferC);
   272 	test.Printf(_L("debug calls = %d\n"),rInfo.iCallBacks);
   304 		test.Printf(_L("crit cancel = %d\n"),rInfo.iCritC);
   273 	test.Printf(_L("completions = %d\n"),rInfo.iCompletions);
   305 		test.Printf(_L("start fails = %d\n"),rInfo.iStartFail);
       
   306 		test.Printf(_L("debug calls = %d\n"),rInfo.iCallBacks);
       
   307 		test.Printf(_L("completions = %d\n"),rInfo.iCompletions);
       
   308 		}
   274 #endif
   309 #endif
   275 
   310 
   276 	for (i=0; i<8; i++)
   311 	for (i=0; i<8; i++)
   277 		{
   312 		{
   278 		r=mstim.GetInfo(i,info[i]);
   313 		r=mstim.GetInfo(i,info[i]);
   279 		CHECK(r);
   314 		CHECK(r);
   280 		}
   315 		}
   281 
   316 
   282 	final_count=User::NTickCount();
   317 	final_count=User::NTickCount();
   283 	elapsed=TInt(final_count-init_count);
   318 	elapsed=TInt(final_count-init_count);
   284 	test.Printf(_L("Elapsed time %dms\n"),elapsed);
   319 	if (unicore)
       
   320 		test.Printf(_L("Elapsed time %dms\n"),elapsed);
   285 
   321 
   286 	const TInt period2[8]={31,32,0,0,7,43,19,0};
   322 	const TInt period2[8]={31,32,0,0,7,43,19,0};
   287 	for (i=0; i<8; i++)
   323 	for (i=0; i<8; i++)
   288 		{
   324 		{
   289 		TInt p=period2[i];
   325 		TInt p=period2[i];
   290 		if (p==0)
   326 		if (p==0)
   291 			continue;
   327 			continue;
   292 		r=mstim.StopPeriodic(i);
   328 		r=mstim.StopPeriodic(i);
   293 		CHECK(r);
   329 		CHECK(r);
   294 		SMsTimerInfo& z=info[i];
   330 		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);
   331 		if (unicore)
       
   332 			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;
   333 		TInt count=elapsed/p;
   297 		TInt cdiff=count-z.iCount;
   334 		TInt cdiff=count-z.iCount;
   298 		TEST(cdiff>=0 && cdiff<=2);
   335 		TEST(cdiff>=0 && cdiff<=2);
   299 #ifndef __WINS__
   336 #ifndef __WINS__
   300 		TEST(Abs(z.iMin-1000*p)<=1000);
   337 		TEST(Abs(z.iMin-1000*p)<=1000);