os/ossrv/genericopenlibs/posixrealtimeextensions/test/testtimer/src/ttimerblocks.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2008-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 "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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Name        : ttimerblocks.cpp
    15 // Test cases for blocking signal api's
    16 //
    17 
    18 
    19 
    20 #include "ttimer.h"
    21 #include "ttimerthread.h"
    22 #define Maxtimerid 512
    23 int timer_value = 0;
    24 
    25 RSemaphore iLock;
    26 void CreateLock()
    27 	{
    28 	iLock.CreateLocal(0);
    29 	}
    30 void ReleaseLock()
    31 	{
    32 	iLock.Signal();
    33 	}
    34 void AcquireLock()
    35 	{
    36 	iLock.Wait();
    37 	}
    38 
    39 //signal handler
    40 void sig_handler(int sig)
    41 	{
    42 	timer_value = sig;
    43 	ReleaseLock();
    44 	}
    45 
    46 //overrun signal handler
    47 void overrun_handler(int sig)
    48 	{
    49 	timer_value = sig;
    50 	sleep(1);
    51 	}
    52 
    53 //notification function
    54 void notifyfunc(union sigval val)
    55 	{
    56 	timer_value = val.sival_int;
    57 	}
    58 
    59 void alarm_handler(int sig)
    60 	{
    61 	timer_value = sig;
    62 	}
    63 
    64 // -----------------------------------------------------------------------------
    65 // CTesttimer::Testtimerapi1
    66 // Test Case ID: OPENENV-LIBC-CIT-5946
    67 // API tested: timer_create(), timer_delete()
    68 // Description: Test case to create a timer with NONE as sigev_notify parameter
    69 // TIMER_ABSTIME not set
    70 // -----------------------------------------------------------------------------
    71 
    72 TInt CTesttimer::Testtimerapi1 (  )
    73 	{
    74 	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
    75 	struct sigevent sigev;
    76 	struct itimerspec timerspec;
    77 	timer_value = 0;
    78 	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
    79 	if(ret == 0)
    80 		{
    81 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
    82 		return ret1;
    83 	  	}
    84 	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
    85 	if(ret == 0)
    86 		{
    87 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
    88 	 	return ret1;
    89 	  	}
    90 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
    91 	if(ret == 0)
    92 		{
    93 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
    94 	 	return ret1;
    95 	  	}
    96 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
    97 	if(ret == 0)
    98 		{
    99 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
   100 	 	return ret1;
   101 	  	}
   102 	sigev.sigev_notify = SIGEV_NONE;
   103 	timer_t timerid;
   104 	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
   105 
   106 	if(ret != 0)
   107 		{
   108 		ERR_PRINTF2(_L("Failed to create a timer and  errno is %d"),errno);
   109      	return -1;		
   110 		}
   111 	INFO_PRINTF1(_L("Successfully able to create a timer") );
   112 	timerspec.it_value.tv_sec = Valuesec;
   113 	timerspec.it_value.tv_nsec = Valuenanosec;
   114 	timerspec.it_interval.tv_sec = Intervalsec;
   115 	timerspec.it_interval.tv_nsec = Intervalnanosec;
   116 	ret = timer_settime(timerid,0,&timerspec,NULL);
   117 	if(ret != 0)
   118 		{
   119 		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
   120      	ret1 = -1;
   121      	goto close;			
   122 		}
   123 	sleep(2);
   124 	INFO_PRINTF1(_L("Successfully able to set the timer") );
   125 	ret = timer_delete(timerid);
   126 	if(ret != 0)
   127 		{
   128 		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
   129      	return -1;				
   130 		}
   131 	INFO_PRINTF1(_L("Successfully able to delete the timer") );
   132 	ret1 = KErrNone;
   133 	return ret1;
   134 	close:
   135 	timer_delete(timerid);
   136 	return ret1;
   137 	}
   138 
   139 // -----------------------------------------------------------------------------
   140 // CTesttimer::Testtimerapi2
   141 // Test Case ID: OPENENV-LIBC-CIT-5946
   142 // API tested: timer_create(), timer_delete()
   143 // Description: Test case to create a timer with NONE as sigev_notify parameter
   144 // TIMER_ABSTIME set
   145 // -----------------------------------------------------------------------------
   146 
   147 TInt CTesttimer::Testtimerapi2 (  )
   148 	{
   149 	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
   150 	struct sigevent sigev;
   151 	struct itimerspec timerspec;
   152 	struct timespec curtmspec;
   153 	timer_value = 0;
   154 	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   155 	if(ret == 0)
   156 		{
   157 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   158 	 	return ret1;
   159 	  	}
   160 	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   161 	if(ret == 0)
   162 		{
   163 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   164 	 	return ret1;
   165 	  	}
   166 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
   167 	if(ret == 0)
   168 		{
   169 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
   170 	 	return ret1;
   171 	  	}
   172 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
   173 	if(ret == 0)
   174 		{
   175 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
   176 	 	return ret1;
   177 	  	}
   178 	sigev.sigev_notify = SIGEV_NONE;
   179 	timer_t timerid;
   180 	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
   181 	if(ret != 0)
   182 		{
   183 		ERR_PRINTF2(_L("Failed to create a timer and  errno is %d"),errno);
   184      	return -1;	
   185 		}
   186 	INFO_PRINTF1(_L("Successfully able to create a timer") );
   187 	ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
   188 	if (ret != 0)
   189 		{
   190 	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
   191 	 	goto close;	
   192 		}
   193 	timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
   194 	timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec; 
   195 	timerspec.it_interval.tv_sec = Intervalsec;
   196 	timerspec.it_interval.tv_nsec = Intervalnanosec;
   197 	ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,NULL);
   198 	if(ret != 0)
   199 		{
   200 		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno);
   201 		ret1 = -1;
   202      	goto close;				
   203 		}
   204 	sleep(2);
   205 	INFO_PRINTF1(_L("Successfully able to set the timer") );
   206 	ret = timer_delete(timerid);
   207 	if(ret != 0)
   208 		{
   209 		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
   210      	return -1;
   211      	}
   212 	INFO_PRINTF1(_L("Successfully able to delete the timer") );
   213 	ret1 = KErrNone;
   214 	return ret1;
   215 	close:
   216 	timer_delete(timerid); 
   217 	return ret1;
   218 	}
   219 
   220 // -----------------------------------------------------------------------------
   221 // CTesttimer::Testtimerapi3
   222 // Test Case ID: OPENENV-LIBC-CIT-5946
   223 // API tested: timer_create(), timer_delete()
   224 // Description: To create a timer with SIGEV_SIGNAL as sigev_notify parameter
   225 // TIMER_ABSTIME not set
   226 // -----------------------------------------------------------------------------
   227 
   228 TInt CTesttimer::Testtimerapi3 (  )
   229 	{
   230 	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec, Signum, Maxsig, Sigval;
   231 	struct sigevent sigev;
   232 	struct itimerspec timerspec;
   233 	timer_t timerid;
   234 	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   235 	if(ret == 0)
   236 		{
   237 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   238 	 	return -1;
   239 	  	}
   240 	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   241 	if(ret == 0)
   242 		{
   243 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   244 	 	return -1;
   245 	  	}
   246 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
   247 	if(ret == 0)
   248 		{
   249 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
   250 	 	return -1;
   251 	  	}
   252 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
   253 	if(ret == 0)
   254 		{
   255 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
   256 	 	return -1;
   257 	  	}
   258 	ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
   259 	if(ret == 0)
   260 		{
   261 	 	ERR_PRINTF1(_L("Unable to read signal number")) ;
   262 	 	return -1;
   263 	  	}
   264 	ret = GetIntFromConfig(ConfigSection(), _L("Maxsig"), Maxsig);
   265 	if(ret == 0)
   266 		{
   267 	 	ERR_PRINTF1(_L("Unable to read maximum signal number")) ;
   268 	 	return -1;
   269 	  	}
   270 	for(Signum=Sigval; Signum <= Maxsig; Signum++)
   271 		{
   272 		if((Signum == SIGSTOP) || (Signum == SIGKILL))
   273 			{
   274 			continue;
   275 			}
   276 		timer_value = 0;
   277 		if(signal(Signum,sig_handler) == SIG_ERR)
   278 			{
   279 		 	ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
   280 		 	return ret1;		
   281 			}
   282 		sigev.sigev_notify = SIGEV_SIGNAL;
   283 		sigev.sigev_signo = Signum;
   284 
   285 		ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
   286 		if(ret != 0)
   287 			{
   288 			ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
   289 	     	return -1;		
   290 			}
   291 		timerspec.it_value.tv_sec = Valuesec;
   292 		timerspec.it_value.tv_nsec = Valuenanosec;
   293 		timerspec.it_interval.tv_sec = Intervalsec;
   294 		timerspec.it_interval.tv_nsec = Intervalnanosec;
   295 		timer_value = 0;
   296 		CreateLock();
   297 		ret = timer_settime(timerid,0,&timerspec,NULL);
   298 		if(ret != 0)
   299 			{
   300 			ERR_PRINTF3(_L("Failed to set the timer for signal %d and errno is %d"),Signum,errno);
   301 			ret1 = -1;
   302 	     	goto close;				
   303 			}
   304 //		sleep(2);
   305 		
   306 		AcquireLock();
   307 		if(timer_value != Signum)
   308 			{
   309 			ERR_PRINTF2(_L("The expected and timer_value are not same for signal %d"),Signum);
   310 			goto close;
   311 			}
   312 		ret = timer_delete(timerid);
   313 		if(ret != 0)
   314 			{
   315 			ERR_PRINTF3(_L("Failed to delete the timer for signal %d and errno is %d"),Signum, errno);
   316 	     	return -1;				
   317 			}
   318 		}
   319 	INFO_PRINTF1(_L("Relative time"));
   320 		INFO_PRINTF1(_L("Successfully able to create a timer with SIGEV_SIGNAL as sigev_notify parameter validated for all signals"));
   321 	ret1 = KErrNone;
   322 	return ret1;
   323 	close:
   324 	timer_delete(timerid);
   325 	return ret1;
   326 	}
   327 
   328 // -----------------------------------------------------------------------------
   329 // CTesttimer::Testtimerapi4
   330 // Test Case ID: OPENENV-LIBC-CIT-5946
   331 // API tested: timer_create(), timer_delete()
   332 // Description: To create a timer with SIGEV_SIGNAL as sigev_notify parameter
   333 // TIMER_ABSTIME set
   334 // -----------------------------------------------------------------------------
   335 
   336 TInt CTesttimer::Testtimerapi4 (  )
   337 	{
   338 	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec, Signum, Maxsig, Sigval;
   339 	struct sigevent sigev;
   340 	struct itimerspec timerspec;
   341 	struct timespec curtmspec;
   342 	timer_t timerid;
   343 	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   344 	if(ret == 0)
   345 		{
   346 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   347 	 	return ret1;
   348 	  	}
   349 	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   350 	if(ret == 0)
   351 		{
   352 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   353 	 	return ret1;
   354 	  	}
   355 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
   356 	if(ret == 0)
   357 		{
   358 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
   359 	 	return ret1;
   360 	  	}
   361 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
   362 	if(ret == 0)
   363 		{
   364 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
   365 	 	return ret1;
   366 	  	}
   367 	ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
   368 	if(ret == 0)
   369 		{
   370 	 	ERR_PRINTF1(_L("Unable to read signal number")) ;
   371 	 	return ret1;
   372 	  	}
   373 	ret = GetIntFromConfig(ConfigSection(), _L("Maxsig"), Maxsig);
   374 	if(ret == 0)
   375 		{
   376 	 	ERR_PRINTF1(_L("Unable to read maximum signal number")) ;
   377 	 	return ret1;
   378 	  	}
   379 	for(Signum=Sigval; Signum <= Maxsig; Signum++)
   380 		{
   381 		if((Signum == SIGSTOP) || (Signum == SIGKILL))
   382 			{
   383 			continue;
   384 			}
   385 		timer_value = 0;
   386 		if(signal(Signum,sig_handler) == SIG_ERR)
   387 			{
   388 		 	ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
   389 		 	return ret1;		
   390 			}
   391 		sigev.sigev_notify = SIGEV_SIGNAL;
   392 		sigev.sigev_signo = Signum;
   393 
   394 		ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
   395 		if(ret != 0)
   396 			{
   397 			ERR_PRINTF3(_L("Failed to create a timer for signal %d and errno is %d"),Signum,errno);
   398 	     	return -1;	
   399 			}
   400 		ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
   401 		if (ret != 0)
   402 			{
   403 		 	ERR_PRINTF3(_L("Failed to get the time of specified clock id for signal %d and errno is %d"),Signum,errno);
   404 		 	goto close;	
   405 			}
   406 		timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
   407 		timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec;
   408 		timerspec.it_interval.tv_sec = Intervalsec;
   409 		timerspec.it_interval.tv_nsec = Intervalnanosec;
   410 		timer_value = 0;
   411 		ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,NULL);
   412 		//sleep(2);
   413 		AcquireLock();
   414 		if(ret != 0)
   415 			{
   416 			ERR_PRINTF3(_L("Failed to set the timer for signal %d and errno is %d"),Signum,errno);
   417 			ret1 = -1;
   418 	     	goto close;				
   419 			}
   420 		if(timer_value != Signum)
   421 			{
   422 			ERR_PRINTF2(_L("The expected and timer_value are not same for signal %d"),Signum);
   423 	     	goto close;				
   424 			}
   425 		ret = timer_delete(timerid);
   426 		if(ret != 0)
   427 			{
   428 			ERR_PRINTF3(_L("Failed to delete the timer for signal %d and errno is %d"),Signum, errno);
   429 	     	return -1;				
   430 			}
   431 		}
   432 	INFO_PRINTF1(_L("Absolute time"));
   433 	INFO_PRINTF1(_L("Successfully able to create a timer with SIGEV_SIGNAL as sigev_notify parameter validated for all signals"));
   434 	ret1 = KErrNone;
   435 	return ret1;
   436 	close:
   437 	timer_delete(timerid);
   438 	return ret1;
   439 	}
   440 
   441 
   442 // -----------------------------------------------------------------------------
   443 // CTesttimer::Testtimerapi5
   444 // Test Case ID: OPENENV-LIBC-CIT-5946
   445 // API tested: timer_create(), timer_delete()
   446 // Description: To create a timer with SIGEV_THREAD as sigev_notify parameter
   447 // TIMER_ABSTIME not set
   448 // -----------------------------------------------------------------------------
   449 
   450 TInt CTesttimer::Testtimerapi5 (  )
   451 	{
   452 	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
   453 	struct sigevent sigev;
   454 	struct sched_param parm;	 
   455 	pthread_attr_t attr;
   456 	struct itimerspec timerspec;
   457 	timer_t timerid;
   458 	pthread_attr_init( &attr );
   459 	parm.sched_priority = 255; //raise the priority..
   460 	pthread_attr_setschedparam(&attr, &parm);
   461 	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   462 	if(ret == 0)
   463 		{
   464 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   465 	 	return ret1;
   466 	  	}
   467 	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   468 	if(ret == 0)
   469 		{
   470 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   471 	 	return ret1;
   472 	  	}
   473 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
   474 	if(ret == 0)
   475 		{
   476 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
   477 	 	return ret1;
   478 	  	}
   479 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
   480 	if(ret == 0)
   481 		{
   482 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
   483 	 	return ret1;
   484 	  	}
   485 	timer_value = 0;
   486 	sigev.sigev_notify = SIGEV_THREAD;
   487 	sigev.sigev_value.sival_int = 100;
   488 	sigev.sigev_notify_function = notifyfunc ;
   489 	sigev.sigev_notify_attributes = &attr;
   490 	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
   491 	if(ret != 0)
   492 		{
   493 		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
   494 		return -1;		
   495 		}
   496 	INFO_PRINTF1(_L("Successfully able to create a timer") );
   497 	timerspec.it_value.tv_sec = Valuesec;
   498 	timerspec.it_value.tv_nsec = Valuenanosec;
   499 	timerspec.it_interval.tv_sec = Intervalsec;
   500 	timerspec.it_interval.tv_nsec = Intervalnanosec;
   501 	ret = timer_settime(timerid,0,&timerspec,NULL);
   502 	if(ret != 0)
   503 		{
   504 		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
   505 		ret1 = -1;
   506 		goto close;				
   507 		}
   508 	sleep(2);
   509 	if(timer_value != 100)
   510 		{
   511 		ERR_PRINTF1(_L("The expected and timer_value are not same"));
   512 		goto close;				
   513 		}
   514 	INFO_PRINTF1(_L("Successfully able to set the timer") );
   515 	ret = timer_delete(timerid);
   516 	if(ret != 0)
   517 		{
   518 		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
   519 		return -1;				
   520 		}
   521 	INFO_PRINTF1(_L("Successfully able to delete the timer") );
   522 	ret1 = KErrNone;
   523 	return ret1;
   524 	close:
   525 	timer_delete(timerid);
   526 	return ret1;
   527 	}
   528 
   529 // -----------------------------------------------------------------------------
   530 // CTesttimer::Testtimerapi6
   531 // Test Case ID: OPENENV-LIBC-CIT-5946
   532 // API tested: timer_create(), timer_delete()
   533 // Description: To create a timer with SIGEV_THREAD as sigev_notify parameter
   534 // TIMER_ABSTIME set
   535 // -----------------------------------------------------------------------------
   536 
   537 TInt CTesttimer::Testtimerapi6 (  )
   538 	{
   539 	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
   540 	struct sigevent sigev;
   541 	struct itimerspec timerspec;
   542 	struct timespec curtmspec;
   543 	timer_t timerid;
   544 	struct sched_param parm;	
   545 	pthread_attr_t attr;
   546 	pthread_attr_init( &attr );
   547 	parm.sched_priority = 255;
   548 	pthread_attr_setschedparam(&attr, &parm);
   549 	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   550 	if(ret == 0)
   551 		{
   552 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   553 	 	return ret1;
   554 	  	}
   555 	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   556 	if(ret == 0)
   557 		{
   558 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   559 	 	return ret1;
   560 	  	}
   561 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
   562 	if(ret == 0)
   563 		{
   564 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
   565 	 	return ret1;
   566 	  	}
   567 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
   568 	if(ret == 0)
   569 		{
   570 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
   571 	 	return ret1;
   572 	  	}
   573 	timer_value = 0;
   574 	sigev.sigev_notify = SIGEV_THREAD;
   575 	sigev.sigev_value.sival_int = 100;
   576 	sigev.sigev_notify_function = notifyfunc ;
   577 	sigev.sigev_notify_attributes = &attr;
   578 	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
   579 	if(ret != 0)
   580 		{
   581 		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
   582 		return -1;		
   583 		}
   584 	INFO_PRINTF1(_L("Successfully able to create a timer") );
   585 	ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
   586 	if (ret != 0)
   587 		{
   588 		ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
   589 		goto close;	
   590 		}
   591 	timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
   592 	timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec; 
   593 	timerspec.it_interval.tv_sec = Intervalsec;
   594 	timerspec.it_interval.tv_nsec = Intervalnanosec;
   595 	ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,NULL);
   596 	if(ret != 0)
   597 		{
   598 		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
   599 		ret1 = -1;
   600 		goto close;				
   601 		}
   602 	sleep(2); 
   603 	if(timer_value != 100)
   604 		{
   605 		ERR_PRINTF1(_L("The expected and timer_value are not same"));
   606 		goto close;				
   607 		}
   608 	INFO_PRINTF1(_L("Successfully able to set the timer") );
   609 	ret = timer_delete(timerid);
   610 	if(ret != 0)
   611 		{
   612 		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
   613 		return -1;				
   614 		}
   615 	INFO_PRINTF1(_L("Successfully able to delete the timer") );
   616 	ret1 = KErrNone;
   617 	return ret1;
   618 	close:
   619 	timer_delete(timerid);
   620 	return ret1;
   621 	}
   622 
   623 // -----------------------------------------------------------------------------
   624 // CTesttimer::Testtimerapi7
   625 // Test Case ID: OPENENV-LIBC-CIT-5946
   626 // API tested: timer_create(), timer_delete()
   627 // Description: To create a timer for CLOCK_REALTIME id using timer_create() with sigevent argument as NULL
   628 // TIMER_ABSTIME not set
   629 // -----------------------------------------------------------------------------
   630 
   631 TInt CTesttimer::Testtimerapi7 (  )
   632 	{
   633 	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
   634 	timer_t timerid;
   635 	struct itimerspec timerspec;
   636 	timer_value = 0;
   637 	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   638 	if(ret == 0)
   639 		{
   640 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   641 	 	return -1;
   642 	  	}
   643 	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   644 	if(ret == 0)
   645 		{
   646 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   647 	 	return -1;
   648 	  	}
   649 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
   650 	if(ret == 0)
   651 		{
   652 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
   653 	 	return -1;
   654 	  	}
   655 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
   656 	if(ret == 0)
   657 		{
   658 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
   659 	 	return -1;
   660 	  	}
   661 	if(signal(SIGALRM, alarm_handler) == SIG_ERR)
   662 		{
   663 	 	ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
   664 	 	return ret1;				
   665 		}
   666 	ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
   667 	if(ret != 0)
   668 		{
   669 		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
   670 		return -1;		
   671 		}
   672 	INFO_PRINTF1(_L("Successfully able to create a timer") );
   673 	timerspec.it_value.tv_sec = Valuesec;
   674 	timerspec.it_value.tv_nsec = Valuenanosec;
   675 	timerspec.it_interval.tv_sec = Intervalsec;
   676 	timerspec.it_interval.tv_nsec = Intervalnanosec;
   677 	ret = timer_settime(timerid,0,&timerspec,NULL);
   678 	if(ret != 0)
   679 		{
   680 		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
   681 		ret1 = -1;
   682 		goto close;				
   683 		}
   684 	sleep(2);
   685 	if(timer_value != SIGALRM)
   686 		{
   687 		ERR_PRINTF1(_L("Error in raising the signal after timer expire"));
   688 		goto close;	
   689 		}
   690 	INFO_PRINTF1(_L("Successfully able to set the timer with the default signal as SIGALRM") );
   691 	ret = timer_delete(timerid);
   692 	if(ret != 0)
   693 		{
   694 		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
   695      	return -1;				
   696 		}
   697 	INFO_PRINTF1(_L("Successfully able to delete the timer") );
   698 	ret1 = KErrNone;
   699 	return ret1;
   700 	close:
   701 	timer_delete(timerid);
   702 	return ret1;
   703 	}
   704 
   705 // -----------------------------------------------------------------------------
   706 // CTesttimer::Testtimerapi8
   707 // Test Case ID: OPENENV-LIBC-CIT-5946
   708 // API tested: timer_create(), timer_delete()
   709 // Description: To create a timer for CLOCK_REALTIME id using timer_create() with sigevent argument as NULL
   710 // TIMER_ABSTIME set
   711 // -----------------------------------------------------------------------------
   712 
   713 TInt CTesttimer::Testtimerapi8 (  )
   714 	{
   715 	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
   716 	timer_t timerid;
   717 	struct itimerspec timerspec;
   718 	struct timespec curtmspec;
   719 	timer_value = 0;
   720 	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   721 	if(ret == 0)
   722 		{
   723 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   724 	 	return ret1;
   725 	  	}
   726 	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   727 	if(ret == 0)
   728 		{
   729 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   730 	 	return ret1;
   731 	  	}
   732 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
   733 	if(ret == 0)
   734 		{
   735 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
   736 	 	return ret1;
   737 	  	}
   738 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
   739 	if(ret == 0)
   740 		{
   741 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
   742 	 	return ret1;
   743 	  	}
   744 	if(signal(SIGALRM, alarm_handler) == SIG_ERR)
   745 		{
   746 	 	ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"),errno) ;
   747 	 	return ret1;				
   748 		}
   749 	ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
   750 	if(ret != 0)
   751 		{
   752 		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
   753 		return -1;		
   754 		}
   755 	INFO_PRINTF1(_L("Successfully able to create a timer") );
   756 	ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
   757 	if (ret != 0)
   758 		{
   759 		ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
   760 		goto close;	
   761 		}
   762 	timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
   763 	timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec; 
   764 	timerspec.it_interval.tv_sec = Intervalsec;
   765 	timerspec.it_interval.tv_nsec = Intervalnanosec;
   766 	ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,NULL);
   767 	if(ret != 0)
   768 		{
   769 		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
   770 		ret1 = -1;
   771 		goto close;				
   772 		}
   773 	sleep(2);
   774 	if(timer_value != SIGALRM)
   775 		{
   776 		ERR_PRINTF1(_L("Error in raising the signal after timer expire"));
   777 		goto close;	
   778 		}
   779 	INFO_PRINTF1(_L("Successfully able to set the timer with the default signal as SIGALRM") );
   780 	ret = timer_delete(timerid);
   781 	if(ret != 0)
   782 		{
   783 		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
   784      	return -1;				
   785 		}
   786 	INFO_PRINTF1(_L("Successfully able to delete the timer") );
   787 	ret1 = KErrNone;
   788 	return ret1;
   789 	close:
   790 	timer_delete(timerid);
   791 	return ret1;
   792 	}
   793 
   794 // -----------------------------------------------------------------------------
   795 // CTesttimer::Testtimerapi9
   796 // Test Case ID: OPENENV-LIBC-CIT-5946
   797 // API tested: timer_create()
   798 // Description: Negative Test-Trying to create the timer for an invalid clock id using timer_create()
   799 // -----------------------------------------------------------------------------
   800 
   801 TInt CTesttimer::Testtimerapi9 (  )
   802 	{
   803 	int ret, ret1 = KErrGeneral, Invalidclockid;
   804 	timer_t timerid;
   805 	ret = GetIntFromConfig(ConfigSection(), _L("Invalidclockid"), Invalidclockid);
   806 	if(ret == 0)
   807 		{
   808 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
   809 	 	return ret1;
   810 	  	}
   811 	ret = timer_create(Invalidclockid,NULL,&timerid);
   812 	if((ret != -1) || (errno != EINVAL))
   813 		{
   814 		ERR_PRINTF2(_L("timer_create() failed to return EINVAL on negative test and errno is %d"),errno);
   815 		goto close;		
   816 		}
   817 	INFO_PRINTF1(_L("timer_create() successfully returned EINVAL on negative test") );
   818 	ret1 = KErrNone;
   819 	
   820 	close:
   821 	return ret1;	
   822 	}
   823 
   824 // -----------------------------------------------------------------------------
   825 // CTesttimer::Testtimerapi10
   826 // Test Case ID: OPENENV-LIBC-CIT-5946
   827 // API tested: timer_create()
   828 // Description: Timer id as NULL in timer_create()
   829 // -----------------------------------------------------------------------------
   830 
   831 TInt CTesttimer::Testtimerapi10 (  )
   832 	{
   833 	int ret, ret1 = KErrGeneral;
   834 	ret = timer_create(CLOCK_REALTIME,NULL,NULL);
   835 	if((ret != -1) || (errno != EFAULT))
   836 		{
   837 		ERR_PRINTF2(_L("timer_create() failed to return EFAULT on negative test and errno is %d"),errno);
   838      	goto close;				
   839 		}
   840 	INFO_PRINTF1(_L("timer_create() successfully returned EFAULT on negative test") );
   841 	ret1 = KErrNone;
   842 	
   843 	close:
   844 	return ret1;	
   845 	}
   846 
   847 // -----------------------------------------------------------------------------
   848 // CTesttimer::Testtimerapi11
   849 // Test Case ID: OPENENV-LIBC-CIT-5946
   850 // API tested: timer_create()
   851 // Description: Timer id as NULL & an invalid clockid in timer_create()
   852 // -----------------------------------------------------------------------------
   853 
   854 TInt CTesttimer::Testtimerapi11 (  )
   855 	{
   856 	int ret, ret1 = KErrGeneral;
   857 	ret = timer_create(CLOCK_MONOTONIC,NULL,NULL);
   858 	if((ret != -1) || (errno != EFAULT))
   859 		{
   860 		ERR_PRINTF2(_L("timer_create() failed to return EFAULT on negative test and errno is %d"),errno);
   861      	goto close;				
   862 		}
   863 	INFO_PRINTF1(_L("timer_create() successfully returned EFAULT on negative test") );
   864 	ret1 = KErrNone;
   865 	
   866 	close:
   867 	return ret1;	
   868 	}
   869 
   870 // -----------------------------------------------------------------------------
   871 // CTesttimer::Testtimerapi12
   872 // Test Case ID: OPENENV-LIBC-CIT-5946
   873 // API tested: timer_create()
   874 // Description: Trying to create more than maximum no. of timer's possible per process using timer_create()
   875 // -----------------------------------------------------------------------------
   876 
   877 TInt CTesttimer::Testtimerapi12 (  )
   878 	{
   879 	int ret, ret1 = KErrGeneral, i, j;
   880 	timer_t timerid[Maxtimerid + 1];
   881 	for (i = 0; i <= Maxtimerid ; i++)
   882 		{
   883 		ret = timer_create(CLOCK_REALTIME,NULL,&timerid[i]);
   884 		if((ret == -1) && (errno == EAGAIN) && (i == Maxtimerid) )
   885 			{
   886 			INFO_PRINTF3(_L("timer_create() has successfully returned EAGAIN on negative test %d %d"),errno,i);
   887 			ret1 = KErrNone;
   888 			break;		
   889 			}
   890 		else if(ret < 0)
   891 			{
   892 			INFO_PRINTF3(_L("timer_create() has failed with error %d %d"),errno,i);
   893 			}
   894 		}
   895 	for(j = 0; j <= Maxtimerid-1; j++)
   896 		{
   897 		ret = timer_delete(timerid[j]);
   898 		if(ret != 0)
   899 			{			
   900 			ERR_PRINTF3(_L("Failed to delete the timer and errno is %d %d"),errno, j);
   901 			ret1 = KErrGeneral;		
   902 			break;
   903 			}
   904 		}
   905 	INFO_PRINTF1(_L("timer_delete() has successfully deleted all the timers negative test"));
   906 	return ret1;
   907 	}
   908 
   909 // -----------------------------------------------------------------------------
   910 // CTesttimer::Testtimerapi13
   911 // Test Case ID: OPENENV-LIBC-CIT-5946
   912 // API tested: timer_delete()
   913 // Description: To delete the timer with an invalid timer id using timer_delete()
   914 // -----------------------------------------------------------------------------
   915 
   916 TInt CTesttimer::Testtimerapi13 (  )
   917 	{
   918 	timer_t timerid;
   919 	int ret, ret1 = KErrGeneral;
   920 	ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
   921 	if(ret != 0)
   922 		{
   923 		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
   924 		return -1;		
   925 		}
   926 	INFO_PRINTF1(_L("Able to create the timer") );
   927 	ret = timer_delete(timerid);
   928 	if(ret != 0)
   929 		{
   930 		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
   931      	return -1;				
   932 		}
   933 	INFO_PRINTF1(_L("Successfully able to delete the timer") );
   934 	/*Deleting a timer id again expected result = -1 and errno = EINVAL  */
   935 	ret = timer_delete(timerid);
   936 	if((ret != -1) || (errno != EINVAL))
   937 		{
   938 		ERR_PRINTF2(_L("timer_delete() failed to return EINVAL on negative test and errno is %d"),errno);
   939      	goto close;				
   940 		}
   941 	INFO_PRINTF1(_L("timer_delete() successfully returned EINVAL on negative test") );
   942 	ret1 = KErrNone;
   943 	
   944 	close:
   945 	return ret1;		
   946 	}
   947 
   948 // -----------------------------------------------------------------------------
   949 // CTesttimer::Testtimerapi14
   950 // Test Case ID: OPENENV-LIBC-CIT-5946
   951 // API tested: timer_delete()
   952 // Description: To delete the timer with NULL using timer_delete()
   953 // -----------------------------------------------------------------------------
   954 
   955 TInt CTesttimer::Testtimerapi14 (  )
   956 	{
   957 	int ret, ret1 = KErrGeneral;
   958 	ret = timer_delete(NULL);
   959 	if((ret != -1) || (errno != EINVAL))
   960 		{
   961 		ERR_PRINTF2(_L("timer_delete() failed to return EFAULT on negative test and errno is %d"),errno);
   962      	goto close;				
   963 		}
   964 	INFO_PRINTF1(_L("timer_delete() successfully returned EFAULT on negative test") );
   965 	ret1 = KErrNone;
   966 	
   967 	close:
   968 	return ret1;	
   969 	}
   970 
   971 // -----------------------------------------------------------------------------
   972 // CTesttimer::Testtimerapi15
   973 // Test Case ID: OPENENV-LIBC-CIT-5946
   974 // API tested: timer_settime()
   975 // Description: Trying to set the timer for an invalid timer id using timer_settime()
   976 // -----------------------------------------------------------------------------
   977 
   978 TInt CTesttimer::Testtimerapi15 (  )
   979 	{
   980 	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec, Timerflag;
   981 	timer_t timerid;
   982 	struct itimerspec timerspec;
   983 	timer_value = 0;
   984 	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   985 	if(ret == 0)
   986 		{
   987 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   988 	 	return ret1;
   989 	  	}
   990 	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   991 	if(ret == 0)
   992 		{
   993 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   994 	 	return ret1;
   995 	  	}
   996 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
   997 	if(ret == 0)
   998 		{
   999 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
  1000 	 	return ret1;
  1001 	  	}
  1002 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
  1003 	if(ret == 0)
  1004 		{
  1005 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
  1006 	 	return ret1;
  1007 	  	}
  1008 	ret = GetIntFromConfig(ConfigSection(), _L("Timerflag"), Timerflag);
  1009 	if(ret == 0)
  1010 		{
  1011 	 	ERR_PRINTF1(_L("Unable to read the timer flag")) ;
  1012 	 	return ret1;
  1013 	  	}
  1014 	if(signal(SIGALRM, alarm_handler) == SIG_ERR)
  1015 		{
  1016 	 	ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
  1017 	 	return ret1;				
  1018 		}
  1019 	ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
  1020 	if(ret != 0)
  1021 		{
  1022 		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
  1023 		return -1;		
  1024 		}
  1025 	INFO_PRINTF1(_L("Successfully able to create a timer") );
  1026 	ret = timer_delete(timerid);
  1027 	if(ret != 0)
  1028 		{
  1029 		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1030      	return -1;				
  1031 		}
  1032 	INFO_PRINTF1(_L("Successfully able to delete the timer") );
  1033 	timerspec.it_value.tv_sec = Valuesec;
  1034 	timerspec.it_value.tv_nsec = Valuenanosec;
  1035 	timerspec.it_interval.tv_sec = Intervalsec;
  1036 	timerspec.it_interval.tv_nsec = Intervalnanosec;
  1037 	ret = timer_settime(timerid,Timerflag,&timerspec,NULL);
  1038 	if((ret != -1) || (errno != EINVAL))
  1039 		{
  1040 		ERR_PRINTF2(_L("timer_settime() failed to return EINVAL on negative test and errno is %d"),errno);
  1041 		goto close;				
  1042 		}
  1043 	INFO_PRINTF1(_L("timer_settime() successfully able to return EINVAL on negative test") );
  1044 	ret1 = KErrNone;
  1045 	
  1046 	close:
  1047 	RThread athr;
  1048 	if(athr.Open(_L("LibrtTimerServ")) == KErrNone)
  1049 		{
  1050 		athr.Close();
  1051 		}
  1052 	
  1053 	return ret1;
  1054 	}
  1055 
  1056 // -----------------------------------------------------------------------------
  1057 // CTesttimer::Testtimerapi16
  1058 // Test Case ID: OPENENV-LIBC-CIT-5946
  1059 // API tested: timer_settime()
  1060 // Description: Trying to set the timer with an invalid tv_nsec parameter using timer_settime()
  1061 // -----------------------------------------------------------------------------
  1062 
  1063 TInt CTesttimer::Testtimerapi16 (  )
  1064 	{
  1065 	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec, Signum, Maxsig, Timerflag, Sigval;
  1066 	struct sigevent sigev;
  1067 	struct itimerspec timerspec;
  1068 	timer_t timerid;
  1069 	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
  1070 	if(ret == 0)
  1071 		{
  1072 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value"));
  1073 	 	return ret1;
  1074 	  	}
  1075 	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
  1076 	if(ret == 0)
  1077 		{
  1078 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
  1079 	 	return ret1;
  1080 	  	}
  1081 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
  1082 	if(ret == 0)
  1083 		{
  1084 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
  1085 	 	return ret1;
  1086 	  	}
  1087 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
  1088 	if(ret == 0)
  1089 		{
  1090 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
  1091 	 	return ret1;
  1092 	  	}
  1093 	ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
  1094 	if(ret == 0)
  1095 		{
  1096 	 	ERR_PRINTF1(_L("Unable to read signal number")) ;
  1097 	 	return ret1;
  1098 	  	}
  1099 	ret = GetIntFromConfig(ConfigSection(), _L("Maxsig"), Maxsig);
  1100 	if(ret == 0)
  1101 		{
  1102 	 	ERR_PRINTF1(_L("Unable to read maximum signal number")) ;
  1103 	 	return ret1;
  1104 	  	}
  1105 	ret = GetIntFromConfig(ConfigSection(), _L("Timerflag"), Timerflag);
  1106 	if(ret == 0)
  1107 		{
  1108 	 	ERR_PRINTF1(_L("Unable to read the timer flag")) ;
  1109 	 	return ret1;
  1110 	  	}
  1111 	for(Signum=Sigval; Signum <= Maxsig; Signum++)
  1112 		{
  1113 		if((Signum == SIGSTOP) || (Signum == SIGKILL))
  1114 			{
  1115 			continue;
  1116 			}
  1117 		timer_value = 0;
  1118 		if(signal(Signum,sig_handler) == SIG_ERR)
  1119 			{
  1120 		 	ERR_PRINTF3(_L("Error in signal trapping function for signal is %d and errno is %d"),Signum, errno) ;
  1121 		 	return ret1;		
  1122 			}
  1123 		sigev.sigev_notify = SIGEV_SIGNAL;
  1124 		sigev.sigev_signo = Signum;
  1125 		ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1126 		if(ret != 0)
  1127 			{
  1128 			ERR_PRINTF3(_L("Failed to create a timer %d and errno is %d"),Signum, errno);
  1129 			return -1;
  1130 			}
  1131 		timerspec.it_value.tv_sec = Valuesec;
  1132 		timerspec.it_value.tv_nsec = Valuenanosec;
  1133 		timerspec.it_interval.tv_sec = Intervalsec; 
  1134 		timerspec.it_interval.tv_nsec = Intervalnanosec; 
  1135 		ret = timer_settime(timerid,Timerflag,&timerspec,NULL);
  1136 		if((ret != -1) || (errno != EINVAL))
  1137 			{
  1138 			ERR_PRINTF2(_L("timer_settime() failed to return EINVAL on negative test and errno is %d"),errno);
  1139 			goto close;
  1140 			}
  1141 		ret = timer_delete(timerid);
  1142 		if(ret != 0)
  1143 			{
  1144 			ERR_PRINTF3(_L("Failed to delete the timer %d and errno is %d"),Signum,errno);
  1145 			return -1;
  1146 			}
  1147 		}
  1148 	INFO_PRINTF1(_L("timer_settime() successfully able to return EINVAL on negative test") );
  1149 	ret1 = KErrNone;
  1150 	return ret1;
  1151 	close:
  1152 	timer_delete(timerid);
  1153 	return ret1;	
  1154 	}
  1155 
  1156 // -----------------------------------------------------------------------------
  1157 // CTesttimer::Testtimerapi17
  1158 // Test Case ID: OPENENV-LIBC-CIT-5946
  1159 // API tested: timer_create(), timer_delete()
  1160 // Description: To create a timer with SIGEV_SIGNAL as sigev_notify parameter
  1161 // TIMER_ABSTIME not set
  1162 // -----------------------------------------------------------------------------
  1163 
  1164 TInt CTesttimer::Testtimerapi17 (  )
  1165 	{
  1166 	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
  1167 	struct sigevent sigev;
  1168 	struct itimerspec timerspec;
  1169 	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
  1170 	if(ret == 0)
  1171 		{
  1172 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
  1173 	 	return ret1;
  1174 	  	}
  1175 	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
  1176 	if(ret == 0)
  1177 		{
  1178 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
  1179 	 	return ret1;
  1180 	  	}
  1181 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
  1182 	if(ret == 0)
  1183 		{
  1184 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
  1185 	 	return ret1;
  1186 	  	}
  1187 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
  1188 	if(ret == 0)
  1189 		{
  1190 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
  1191 	 	return ret1;
  1192 	  	}
  1193 	timer_value = 0;
  1194 	if(signal(SIGUSR1,overrun_handler) == SIG_ERR)
  1195 		{
  1196 		ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
  1197 		return ret1;
  1198 		}
  1199 	sigev.sigev_notify = SIGEV_SIGNAL;
  1200 	sigev.sigev_signo = SIGUSR1;
  1201 	timer_t timerid;
  1202 	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1203 	if(ret != 0)
  1204 		{
  1205 		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
  1206 		return -1;
  1207 		}
  1208 	timerspec.it_value.tv_sec = Valuesec;
  1209 	timerspec.it_value.tv_nsec = Valuenanosec;
  1210 	timerspec.it_interval.tv_sec = Intervalsec;
  1211 	timerspec.it_interval.tv_nsec = Intervalnanosec;
  1212 	timer_value = 0;
  1213 	ret = timer_settime(timerid,0,&timerspec,NULL);
  1214 	if(ret != 0)
  1215 		{
  1216 		ERR_PRINTF2(_L("Failed to set the time of specified clock id and errno is %d "),errno);
  1217 		ret1 = -1;
  1218 		goto close;				
  1219 		}
  1220 	sleep(2);
  1221 	if(timer_value != SIGUSR1)
  1222 		{
  1223 		ERR_PRINTF1(_L("The expected and timer_value are not same for signal"));
  1224 		ret1 = -1;
  1225 		goto close;
  1226 		}
  1227 	ret = timer_getoverrun(timerid);
  1228 	if (ret != 0)
  1229 		{
  1230 		ERR_PRINTF2(_L("Error in timer_getoverrun() and errno is %d"),errno);
  1231 		ret1 = -1;
  1232 		goto close; 			
  1233 		}
  1234 	ret = timer_delete(timerid);
  1235 	if(ret != 0)
  1236 		{
  1237 		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1238 		return -1;				
  1239 		}
  1240 	INFO_PRINTF1(_L("Relative Timer") );
  1241 	INFO_PRINTF1(_L("Successfully able to create a timer with SIGEV_SIGNAL as sigev_notify parameter") );
  1242 	ret1 = KErrNone;
  1243 	return ret1;
  1244 	close:
  1245 	timer_delete(timerid);
  1246 	return ret1;
  1247 	}
  1248 
  1249 // -----------------------------------------------------------------------------
  1250 // CTesttimer::Testtimerapi18
  1251 // Test Case ID: OPENENV-LIBC-CIT-5946
  1252 // API tested: timer_create(), timer_delete()
  1253 // Description: To create a timer with SIGEV_SIGNAL as sigev_notify parameter
  1254 // TIMER_ABSTIME set
  1255 // -----------------------------------------------------------------------------
  1256 
  1257 TInt CTesttimer::Testtimerapi18 (  )
  1258 	{
  1259 	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
  1260 	struct sigevent sigev;
  1261 	struct itimerspec timerspec, oldtimerspec;
  1262 	struct timespec curtmspec;
  1263 	timer_t timerid;
  1264 	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
  1265 	if(ret == 0)
  1266 		{
  1267 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
  1268 	 	return ret1;
  1269 	  	}
  1270 	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
  1271 	if(ret == 0)
  1272 		{
  1273 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
  1274 	 	return ret1;
  1275 	  	}
  1276 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
  1277 	if(ret == 0)
  1278 		{
  1279 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
  1280 	 	return ret1;
  1281 	  	}
  1282 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
  1283 	if(ret == 0)
  1284 		{
  1285 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
  1286 	 	return ret1;
  1287 	  	}
  1288 		timer_value = 0;
  1289 		if(signal(SIGUSR1,overrun_handler) == SIG_ERR)
  1290 			{
  1291 		 	ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
  1292 		 	return ret1;
  1293 			}
  1294 		sigev.sigev_notify = SIGEV_SIGNAL;
  1295 		sigev.sigev_signo = SIGUSR1;
  1296 		ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1297 		if(ret != 0)
  1298 			{
  1299 			ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
  1300 			return -1;
  1301 			}
  1302 		ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
  1303 		if (ret != 0)
  1304 			{
  1305 		 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
  1306 		 	ret1 = -1;
  1307 		 	goto close;	
  1308 			}
  1309 		timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
  1310 		timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec;
  1311 		timerspec.it_interval.tv_sec = Intervalsec;
  1312 		timerspec.it_interval.tv_nsec = Intervalnanosec;
  1313 		timer_value = 0;
  1314 		ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,&oldtimerspec);
  1315 		if(ret != 0)
  1316 			{
  1317 			ERR_PRINTF2(_L("Failed to set the timer for signal and errno is %d"),errno);
  1318 			ret1 = -1;
  1319 	     	goto close;				
  1320 			}
  1321 		sleep(2);
  1322 		if(timer_value != SIGUSR1)
  1323 			{
  1324 			ERR_PRINTF2(_L("The expected and timer_value are not same for signal %d"),errno);
  1325 			goto close;
  1326 			}
  1327 		ret = timer_getoverrun(timerid);
  1328 		if (ret != 0)
  1329 			{
  1330 			ERR_PRINTF2(_L("Error in timer_getoverrun() and errno is %d"),errno);
  1331 			ret1 = -1;
  1332 	     	goto close;				
  1333 			}
  1334 		ret = timer_delete(timerid);
  1335 		if(ret != 0)
  1336 			{
  1337 			ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1338 			ret1 = -1;			
  1339 			}
  1340 	INFO_PRINTF1(_L("Absolute Timer") );
  1341 	INFO_PRINTF1(_L("Successfully able to create a timer with SIGEV_SIGNAL as sigev_notify parameter") );
  1342 	ret1 = KErrNone;
  1343 	return ret1;
  1344 	close:
  1345 	timer_delete(timerid);
  1346 	return ret1;
  1347 	}
  1348 
  1349 // -----------------------------------------------------------------------------
  1350 // CTesttimer::Testtimerapi19
  1351 // Test Case ID: OPENENV-LIBC-CIT-5946
  1352 // API tested: timer_overrun(), timer_gettime()
  1353 // Description: Negative test: timer_overrun(), timer_gettime() with an invalid timerid
  1354 // -----------------------------------------------------------------------------
  1355 
  1356 TInt CTesttimer::Testtimerapi19 (  )
  1357 	{
  1358 	timer_t timerid;
  1359 	int ret, ret1 = KErrGeneral;
  1360 	struct itimerspec timerspec;
  1361 	ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
  1362 	if(ret != 0)
  1363 		{
  1364 		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
  1365 		return -1;		
  1366 		}
  1367 	INFO_PRINTF1(_L("successfully able to create the timer") );
  1368 	ret = timer_delete(timerid);
  1369 	if(ret != 0)
  1370 		{
  1371 		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1372      	return -1;				
  1373 		}
  1374 	INFO_PRINTF1(_L("Successfully able to delete the timer") );
  1375 	ret = timer_gettime(timerid,&timerspec);
  1376 	if((ret != -1) || (errno != EINVAL))
  1377 		{
  1378 		ERR_PRINTF2(_L("timer_gettime() failed to return EINVAL on negative test and errno is %d"),errno);
  1379 		goto close;
  1380 		}
  1381 	INFO_PRINTF1(_L("timer_gettime() successfully returned EINVAL on negative test") );
  1382 	ret = timer_getoverrun(timerid);
  1383 	if((ret != -1) || (errno != EINVAL))
  1384 		{
  1385 		ERR_PRINTF2(_L("timer_getoverrun() failed to return EINVAL on negative test and errno is %d"),errno);
  1386 		goto close;
  1387 		}
  1388 	INFO_PRINTF1(_L("timer_getoverrun() successfully returned EINVAL on negative test") );
  1389 	ret1 = KErrNone;
  1390 	return ret1;
  1391 	close:
  1392 	timer_delete(timerid);
  1393 	return ret1;		
  1394 	}
  1395 
  1396 // -----------------------------------------------------------------------------
  1397 // CTesttimer::Testtimerapi20
  1398 // Test Case ID: OPENENV-LIBC-CIT-5946
  1399 // API tested: timer_create()
  1400 // Description: Negative test: timer_create() with an invalid signal
  1401 // -----------------------------------------------------------------------------
  1402 
  1403 TInt CTesttimer::Testtimerapi20 (  )
  1404 	{
  1405 	timer_t timerid;
  1406 	int ret, ret1 = KErrGeneral, Sigval;
  1407 	struct sigevent sigev;
  1408 	ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
  1409 	if(ret == 0)
  1410 		{
  1411 	 	ERR_PRINTF1(_L("Unable to read signal number")) ;
  1412 	 	return -1;
  1413 	  	}
  1414 	sigev.sigev_notify = SIGEV_SIGNAL;
  1415 	sigev.sigev_signo = Sigval;
  1416 	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);	
  1417 	if((ret != -1) || (errno != EINVAL))
  1418 		{
  1419 		ERR_PRINTF2(_L("timer_create() failed to return EINVAL on negative test and errno is %d"),errno);
  1420 		goto close;				
  1421 		}
  1422 	INFO_PRINTF1(_L("timer_create() with an invalid sigev_signo member") );
  1423 	INFO_PRINTF1(_L("timer_create() successfully returned EINVAL on negative test") );
  1424 	ret1 = KErrNone;
  1425 	
  1426 	close:
  1427 	return ret1;		
  1428 	}
  1429 
  1430 // -----------------------------------------------------------------------------
  1431 // CTesttimer::Testtimerapi21
  1432 // Test Case ID: OPENENV-LIBC-CIT-5946
  1433 // API tested: timer_create()
  1434 // Description: Negative test: timer_create() with an invalid sigev_notify member
  1435 // -----------------------------------------------------------------------------
  1436 
  1437 TInt CTesttimer::Testtimerapi21 (  )
  1438 	{
  1439 	timer_t timerid;
  1440 	int ret, ret1 = KErrGeneral, Sigval, Signum, Maxsig, Notify;
  1441 	struct sigevent sigev;
  1442 	ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
  1443 	if(ret == 0)
  1444 		{
  1445 	 	ERR_PRINTF1(_L("Unable to read signal number")) ;
  1446 	 	return ret1;
  1447 	  	}
  1448 	ret = GetIntFromConfig(ConfigSection(), _L("Maxsig"), Maxsig);
  1449 	if(ret == 0)
  1450 		{
  1451 	 	ERR_PRINTF1(_L("Unable to read maximum signal number")) ;
  1452 	 	return ret1;
  1453 	  	}
  1454 	ret = GetIntFromConfig(ConfigSection(), _L("Notify"), Notify);
  1455 	if(ret == 0)
  1456 		{
  1457 	 	ERR_PRINTF1(_L("Unable to read an invalid notify value")) ;
  1458 	 	return ret1;
  1459 	  	}
  1460 	for(Signum=Sigval; Signum <= Maxsig; Signum++)
  1461 		{
  1462 		if((Signum == SIGSTOP) || (Signum == SIGKILL))
  1463 			{
  1464 			continue;
  1465 			}
  1466 		sigev.sigev_notify = Notify;
  1467 		sigev.sigev_signo = Signum;
  1468 		ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);	
  1469 		if((ret != -1) || (errno != EINVAL))
  1470 			{
  1471 			ERR_PRINTF2(_L("timer_create() failed to return EINVAL on negative test and errno is %d"),errno);
  1472 			goto close;				
  1473 			}
  1474 		}
  1475 	INFO_PRINTF1(_L("timer_create() with an invalid sigev_notify member") );
  1476 	INFO_PRINTF1(_L("timer_create() successfully returned EINVAL on negative test") );
  1477 	ret1 = KErrNone;
  1478 	
  1479 	close:
  1480 	return ret1;		
  1481 	}
  1482 
  1483 // -----------------------------------------------------------------------------
  1484 // CTesttimer::Testtimerapi22
  1485 // Test Case ID: OPENENV-LIBC-CIT-5946
  1486 // API tested: timer_settime()
  1487 // Description: Negative test: timer_settime() with an input itimerspec value as NULL
  1488 // -----------------------------------------------------------------------------
  1489 
  1490 TInt CTesttimer::Testtimerapi22 (  )
  1491 	{
  1492 	int ret, ret1 = KErrGeneral;
  1493 	struct sigevent sigev;
  1494 	struct itimerspec timerspec;
  1495 	timer_t timerid;
  1496 	sigev.sigev_notify = SIGEV_NONE;
  1497 	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1498 	if(ret != 0)
  1499 		{
  1500 		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"), errno );
  1501      	return -1;		
  1502 		}
  1503 	INFO_PRINTF1(_L("Successfully able to create a timer") );
  1504 	ret = timer_settime(timerid,0,NULL,&timerspec);
  1505 	if((ret != -1) || (errno != EINVAL))
  1506 		{
  1507 		ERR_PRINTF2(_L("timer_settime() failed to return EINVAL on negative test and errno is %d"),errno);
  1508 		goto close;				
  1509 		}
  1510 	INFO_PRINTF1(_L("Successfully able to set the timer") );
  1511 	sleep(2);
  1512 	ret = timer_delete(timerid);
  1513 	if(ret != 0)
  1514 		{
  1515 		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1516      	return -1;				
  1517 		}
  1518 	INFO_PRINTF1(_L("timer_settime() with itimerspec input as NULL") );
  1519 	INFO_PRINTF1(_L("timer_settime() successfully returned EINVAL on negative test") );
  1520 	ret1 = KErrNone;
  1521 	return ret1;
  1522 	close:
  1523 	timer_delete(timerid);
  1524 	return ret1;
  1525 	}
  1526 
  1527 // -----------------------------------------------------------------------------
  1528 // CTesttimer::Testtimerapi23
  1529 // Test Case ID: OPENENV-LIBC-CIT-5946
  1530 // API tested: timer_settime()
  1531 // Description: Negative test: timer_settime() with an invalid flag member
  1532 // -----------------------------------------------------------------------------
  1533 
  1534 TInt CTesttimer::Testtimerapi23 (  )
  1535 	{
  1536 	int ret, ret1 = KErrGeneral;
  1537 	struct sigevent sigev;
  1538 	struct itimerspec timerspec;
  1539 	timer_t timerid;
  1540 	sigev.sigev_notify = SIGEV_NONE;
  1541 	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1542 	if(ret != 0)
  1543 		{
  1544 		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno );
  1545      	return -1;		
  1546 		}
  1547 	INFO_PRINTF1(_L("Successfully able to create a timer") );
  1548 	timerspec.it_value.tv_sec = 1;
  1549 	timerspec.it_value.tv_nsec = 0;
  1550 	timerspec.it_interval.tv_sec = 0;
  1551 	timerspec.it_interval.tv_nsec = 0;
  1552 	ret = timer_settime(timerid,-1,NULL,&timerspec);
  1553 	if((ret != -1) || (errno != EINVAL))
  1554 		{
  1555 		ERR_PRINTF2(_L("timer_settime() failed to return EINVAL on negative test and errno is %d"),errno);
  1556 		goto close;				
  1557 		}
  1558 	INFO_PRINTF1(_L("Successfully able to set the timer") );
  1559 	sleep(3);
  1560 	ret = timer_delete(timerid);
  1561 	if(ret != 0)
  1562 		{
  1563 		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1564      	return -1;				
  1565 		}
  1566 	INFO_PRINTF1(_L("timer_settime() with an invalid flag value") );
  1567 	INFO_PRINTF1(_L("timer_settime() successfully returned EINVAL on negative test") );
  1568 	ret1 = KErrNone;
  1569 	return ret1;
  1570 	close:
  1571 	timer_delete(timerid);
  1572 	return ret1;	
  1573 	}
  1574 
  1575 // -----------------------------------------------------------------------------
  1576 // CTesttimer::Testtimerapi24
  1577 // Test Case ID: OPENENV-LIBC-CIT-5946
  1578 // API tested: timer_gettime()
  1579 // Description: Negative test: timer_gettime() with an input itimerspec value as NULL
  1580 // -----------------------------------------------------------------------------
  1581 
  1582 TInt CTesttimer::Testtimerapi24 (  )
  1583 	{
  1584 	int ret, ret1 = KErrGeneral;
  1585 	struct sigevent sigev;
  1586 	struct itimerspec timerspec;
  1587 	timer_t timerid;
  1588 	timer_value = 0;
  1589 	sigev.sigev_notify = SIGEV_NONE;
  1590 	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1591 	if(ret != 0)
  1592 		{
  1593 		ERR_PRINTF1(_L("Failed to create a timer") );
  1594      	return -1;		
  1595 		}
  1596 	INFO_PRINTF1(_L("Successfully able to create a timer") );
  1597 	timerspec.it_value.tv_sec = 1;
  1598 	timerspec.it_value.tv_nsec = 0;
  1599 	timerspec.it_interval.tv_sec = 1;
  1600 	timerspec.it_interval.tv_nsec = 0;
  1601 	ret = timer_settime(timerid,0,&timerspec,NULL);
  1602 	if(ret != 0)
  1603 		{
  1604 		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
  1605      	ret1 = -1;
  1606      	goto close;				
  1607 		}
  1608 	INFO_PRINTF1(_L("Successfully able to set the timer") );
  1609 	ret = timer_gettime(timerid,NULL);
  1610 	if((ret != -1) || (errno != EFAULT))
  1611 		{
  1612 		ERR_PRINTF2(_L("timer_gettime() failed to return EFAULT on negative test and errno is %d"),errno);
  1613 		goto close;				
  1614 		}	
  1615 	ret = timer_delete(timerid);
  1616 	if(ret != 0)
  1617 		{
  1618 		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1619      	ret1 = -1;				
  1620 		}
  1621 	INFO_PRINTF1(_L("Successfully able to delete the timer") );
  1622 	INFO_PRINTF1(_L("timer_gettime() with an input itimerspec value as NULL") );
  1623 	INFO_PRINTF1(_L("timer_gettime() successfully returned EFAULT on negative test") );
  1624 	ret1 = KErrNone;
  1625 	return ret1;
  1626 	close:
  1627 	timer_delete(timerid);
  1628 	return ret1;	
  1629 	}
  1630 
  1631 // -----------------------------------------------------------------------------
  1632 // CTesttimer::Testtimerapi25
  1633 // Test Case ID: OPENENV-LIBC-CIT-5946
  1634 // API tested: timer_settime(),timer_gettime()
  1635 // Description: To retreive the amount of time until the timer expires
  1636 // Relative timer
  1637 // -----------------------------------------------------------------------------
  1638 
  1639 TInt CTesttimer::Testtimerapi25 (  )
  1640 	{
  1641 	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
  1642 	struct sigevent sigev;
  1643 	struct itimerspec timerspec, gettime, oldtimerspec;
  1644 	timer_value = 0;
  1645 	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
  1646 	if(ret == 0)
  1647 		{
  1648 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
  1649 	 	return ret1;
  1650 	  	}
  1651 	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
  1652 	if(ret == 0)
  1653 		{
  1654 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
  1655 	 	return ret1;
  1656 	  	}
  1657 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
  1658 	if(ret == 0)
  1659 		{
  1660 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
  1661 	 	return ret1;
  1662 	  	}
  1663 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
  1664 	if(ret == 0)
  1665 		{
  1666 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
  1667 	 	return ret1;
  1668 	  	}
  1669 	sigev.sigev_notify = SIGEV_NONE;
  1670 	timer_t timerid;
  1671 	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1672 	if(ret != 0)
  1673 		{
  1674 		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"), errno );
  1675      	return -1;	
  1676 		}
  1677 	INFO_PRINTF1(_L("Successfully able to create a timer") );
  1678 	timerspec.it_value.tv_sec = Valuesec;
  1679 	timerspec.it_value.tv_nsec = Valuenanosec;
  1680 	timerspec.it_interval.tv_sec = Intervalsec;
  1681 	timerspec.it_interval.tv_nsec = Intervalnanosec;
  1682 	ret = timer_settime(timerid,0,&timerspec,&oldtimerspec);
  1683 	if(ret != 0)
  1684 		{
  1685 		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno );
  1686      	ret1 = -1;
  1687      	goto close;				
  1688 		}
  1689 	sleep(1);
  1690 	INFO_PRINTF1(_L("Successfully able to set the timer") );
  1691 	ret = timer_gettime(timerid,&gettime);
  1692 	if(ret != 0)
  1693 		{
  1694 		ERR_PRINTF2(_L("Failed to get the timer and the errno is %d"),errno );
  1695      	ret1 = -1;
  1696      	goto close;				
  1697 		}
  1698 	if((gettime.it_value.tv_sec > (timerspec.it_value.tv_sec-1)) || (gettime.it_value.tv_nsec > (timerspec.it_value.tv_nsec))|| (gettime.it_interval.tv_sec != timerspec.it_interval.tv_sec) || (gettime.it_interval.tv_nsec != timerspec.it_interval.tv_nsec))
  1699 		{
  1700 		ERR_PRINTF1(_L("Failed to get the timer value") );
  1701 		ret1 = -1;
  1702      	goto close;
  1703 		}
  1704 	INFO_PRINTF1(_L("Successfully able to get the timer") );	
  1705 	ret = timer_delete(timerid);
  1706 	if(ret != 0)
  1707 		{
  1708 		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1709      	return -1;;				
  1710 		}
  1711 	INFO_PRINTF1(_L("Successfully able to delete the timer") );
  1712 	ret1 = KErrNone;
  1713 	return ret1;
  1714 	close:
  1715 	timer_delete(timerid);
  1716 	return ret1;	
  1717 	}
  1718 
  1719 // -----------------------------------------------------------------------------
  1720 // CTesttimer::Testtimerapi26
  1721 // Test Case ID: OPENENV-LIBC-CIT-5946
  1722 // API tested: timer_settime(),timer_gettime()
  1723 // Description: To retreive the amount of time until the timer expires
  1724 // Absolute timer
  1725 // -----------------------------------------------------------------------------
  1726 
  1727 TInt CTesttimer::Testtimerapi26 (  )
  1728 	{
  1729 	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
  1730 	struct sigevent sigev;
  1731 	struct itimerspec timerspec, gettime, oldtimerspec;
  1732 	struct timespec curtmspec;
  1733 	timer_value = 0;
  1734 	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
  1735 	if(ret == 0)
  1736 		{
  1737 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
  1738 	 	return ret1;
  1739 	  	}
  1740 	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
  1741 	if(ret == 0)
  1742 		{
  1743 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
  1744 	 	return ret1;
  1745 	  	}
  1746 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
  1747 	if(ret == 0)
  1748 		{
  1749 	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
  1750 	 	return ret1;
  1751 	  	}
  1752 	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
  1753 	if(ret == 0)
  1754 		{
  1755 	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
  1756 	 	return ret1;
  1757 	  	}
  1758 	sigev.sigev_notify = SIGEV_NONE;
  1759 	timer_t timerid;
  1760 	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1761 	if(ret != 0)
  1762 		{
  1763 		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"), errno );
  1764      	return -1;		
  1765 		}
  1766 	INFO_PRINTF1(_L("Successfully able to create a timer") );
  1767 	ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
  1768 	if (ret != 0)
  1769 		{
  1770 	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
  1771 	 	ret1 = -1;
  1772 	 	goto close;	
  1773 		}
  1774 	timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
  1775 	timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec; 
  1776 	timerspec.it_interval.tv_sec = Intervalsec;
  1777 	timerspec.it_interval.tv_nsec = Intervalnanosec;
  1778 	ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,&oldtimerspec);
  1779 	if(ret != 0)
  1780 		{
  1781 		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno );
  1782 		ret1 = -1;
  1783      	goto close;				
  1784 		}
  1785 	sleep(1);
  1786 	INFO_PRINTF1(_L("Successfully able to set the timer") );
  1787 	ret = timer_gettime(timerid,&gettime);
  1788 	if(ret != 0)
  1789 		{
  1790 		ERR_PRINTF2(_L("Failed to get the timer and errno is %d"), errno );
  1791      	ret1 = -1;
  1792      	goto close;				
  1793 		}
  1794 	if((gettime.it_value.tv_sec > (Valuesec-1)) || (gettime.it_value.tv_nsec > (Valuenanosec))|| (gettime.it_interval.tv_sec != Intervalsec) || (gettime.it_interval.tv_nsec != Intervalnanosec))
  1795 		{
  1796 		ERR_PRINTF1(_L("Failed to get the timer value") );
  1797 		ret1 = -1;
  1798      	goto close;
  1799 		}
  1800 	INFO_PRINTF1(_L("Successfully able to get the timer") );	
  1801 	ret = timer_delete(timerid);
  1802 	if(ret != 0)
  1803 		{
  1804 		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1805      	return -1;				
  1806 		}
  1807 	INFO_PRINTF1(_L("Successfully able to delete the timer") );
  1808 	ret1 = KErrNone;
  1809 	return ret1;
  1810 	close:
  1811 	timer_delete(timerid);
  1812 	return ret1;	
  1813 	}
  1814 
  1815 // -----------------------------------------------------------------------------
  1816 // CTesttimer::Testtimerapi27
  1817 // Test Case ID: OPENENV-LIBC-CIT-5946
  1818 // API tested: timer_settime(),timer_gettime()
  1819 // Description: To retreive the amount of time until the timer expires using timer_settime()
  1820 // Absolute timer
  1821 // -----------------------------------------------------------------------------
  1822 
  1823 TInt CTesttimer::Testtimerapi27 (  )
  1824 	{
  1825 	int ret, ret1 = KErrGeneral;
  1826 	struct sigevent sigev;
  1827 	struct itimerspec timerspec1, gettime, oldtimerspec;
  1828 	timer_value = 0;
  1829 	sigev.sigev_notify = SIGEV_NONE;
  1830 	timer_t timerid;
  1831 	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1832 	if(ret != 0)
  1833 		{
  1834 		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"), errno );
  1835      	return -1;		
  1836 		}
  1837 	INFO_PRINTF1(_L("Successfully able to create a timer") );
  1838 	timerspec1.it_value.tv_sec = 5;
  1839 	timerspec1.it_value.tv_nsec = 0;
  1840 	timerspec1.it_interval.tv_sec = 0;
  1841 	timerspec1.it_interval.tv_nsec = 0;
  1842 	ret = timer_settime(timerid,0,&timerspec1,NULL);
  1843 	if(ret != 0)
  1844 		{
  1845 		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno );
  1846      	ret1 = -1;				
  1847      	goto close;
  1848 		}
  1849 	INFO_PRINTF1(_L("Successfully able to set the timer for the first time") );
  1850 	sleep(1);
  1851 	timerspec1.it_value.tv_sec = 3;
  1852 	timerspec1.it_value.tv_nsec = 0;
  1853 	timerspec1.it_interval.tv_sec = 0;
  1854 	timerspec1.it_interval.tv_nsec = 0;
  1855 	ret = timer_settime(timerid,0,&timerspec1,&oldtimerspec);
  1856 	if(ret != 0)
  1857 		{
  1858 		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno );
  1859      	ret1 = -1;				
  1860      	goto close;				
  1861 		}
  1862 	INFO_PRINTF1(_L("Successfully able to set the timer for the second time") );
  1863 	if(oldtimerspec.it_value.tv_sec > 4)
  1864 		{
  1865 		ERR_PRINTF1(_L("Failed to set the timer value") );
  1866 		goto close;
  1867 		}
  1868 	sleep(1);
  1869 	timerspec1.it_value.tv_sec = 0;
  1870 	timerspec1.it_value.tv_nsec = 0;
  1871 	timerspec1.it_interval.tv_sec = 0;
  1872 	timerspec1.it_interval.tv_nsec = 0;
  1873 	ret = timer_settime(timerid,0,&timerspec1,&oldtimerspec);
  1874 	if(ret != 0)
  1875 		{
  1876 		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
  1877      	goto close;				
  1878 		}
  1879 	if(oldtimerspec.it_value.tv_sec > 2)
  1880 		{
  1881 		ERR_PRINTF1(_L("Failed to set the timer value") );
  1882 		goto close;
  1883 		}
  1884 	timerspec1.it_value.tv_sec = 2;
  1885 	timerspec1.it_value.tv_nsec = 0;
  1886 	timerspec1.it_interval.tv_sec = 5;
  1887 	timerspec1.it_interval.tv_nsec = 0;
  1888 	ret = timer_settime(timerid,0,&timerspec1,&oldtimerspec);
  1889 	if(ret != 0)
  1890 		{
  1891 		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno);
  1892 		ret1 = -1;
  1893      	goto close;				
  1894 		}
  1895 	if(oldtimerspec.it_value.tv_sec != 0)
  1896 		{
  1897 		ERR_PRINTF1(_L("Failed to set the timer value") );
  1898 		goto close;
  1899 		}
  1900 	ret = timer_gettime(timerid,&gettime);
  1901 	if(ret != 0)
  1902 		{
  1903 		ERR_PRINTF2(_L("Failed to get the timer and errno is %d"),errno);
  1904 		ret1 = -1;
  1905      	goto close;				
  1906 		}
  1907 	
  1908 	if((gettime.it_value.tv_sec > 2) || (gettime.it_interval.tv_sec != timerspec1.it_interval.tv_sec) || (gettime.it_interval.tv_nsec != timerspec1.it_interval.tv_nsec))
  1909 		{
  1910 		ERR_PRINTF1(_L("Failed to get the timer value") );
  1911 		goto close;
  1912 		}
  1913 	INFO_PRINTF1(_L("Successfully able to get the timer") );	
  1914 	ret = timer_delete(timerid);
  1915 	if(ret != 0)
  1916 		{
  1917 		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1918      	return -1;			
  1919 		}
  1920 	INFO_PRINTF1(_L("Successfully able to delete the timer") );
  1921 	ret1 = KErrNone;
  1922 	return ret1;
  1923 	close:
  1924 	timer_delete(timerid);
  1925 	return ret1;	
  1926 	}
  1927 TInt CTesttimer::Testtimerapi28( )
  1928     {
  1929     TInt err;
  1930 
  1931     TRequestStatus timerThreadStatus1;
  1932     RThread timerThread1;
  1933     TTimerTestThreadParams paramsTimerThread1(*this);
  1934 
  1935     TRequestStatus timerThreadStatus2;
  1936     RThread timerThread2;
  1937     TTimerTestThreadParams paramsTimerThread2(*this);
  1938 
  1939     Logger().ShareAuto();
  1940     //Create the Thread to create shared mem and write to it.
  1941     err = timerThread1.Create(_L("TimerThread1"), (TThreadFunction)CTimerTestThread::OEEntry, KDefaultStackSize, KMinHeapSize, 1024*1024,&paramsTimerThread1);
  1942     if(err != KErrNone)
  1943     {
  1944         ERR_PRINTF2(_L("Timer Thread1 Not created - %d"), err);
  1945         SetTestStepResult(EFail);
  1946         return EFail;
  1947 
  1948     }
  1949     INFO_PRINTF1(_L("Timer Thread1 created "));
  1950     //Create the thread to open shared mem and read from it.
  1951     err = timerThread2.Create(_L("TimerThread2"), (TThreadFunction)CTimerTestThread::OEEntry, KDefaultStackSize, KMinHeapSize, 1024*1024,&paramsTimerThread2);
  1952     if(err != KErrNone)
  1953     {
  1954         ERR_PRINTF2(_L("Timer Thread 2 Not created - %d"), err);
  1955         SetTestStepResult(EFail);
  1956         //Close the Write Thread created previously
  1957         timerThread1.Close();
  1958         return EFail;
  1959 
  1960     }
  1961     INFO_PRINTF1(_L("Timer Thread created "));
  1962 
  1963     timerThread1.SetPriority(EPriorityNormal);
  1964     timerThread2.SetPriority(EPriorityNormal);
  1965 
  1966     timerThread1.Logon(timerThreadStatus1);
  1967     timerThread2.Logon(timerThreadStatus2);
  1968 
  1969     timerThread1.Resume();
  1970     timerThread2.Resume();
  1971 
  1972     User::WaitForRequest(timerThreadStatus1);
  1973    User::WaitForRequest(timerThreadStatus2);
  1974 
  1975     timerThread1.Close();
  1976     timerThread2.Close();
  1977 
  1978     //Check the status of the threads..
  1979    if(!paramsTimerThread1.iTestResult )
  1980         {
  1981          ERR_PRINTF1(_L("Timer Thread 1 Not successful"));
  1982          SetTestStepResult(EFail);
  1983         }
  1984    if(!paramsTimerThread2.iTestResult )
  1985         {
  1986           ERR_PRINTF1(_L("Timer Thread 2 Not successful"));
  1987           SetTestStepResult(EFail);
  1988         }
  1989 
  1990     return TestStepResult();
  1991 
  1992 
  1993     }
  1994 //End of a file
  1995 
  1996 
  1997 
  1998