os/ossrv/genericopenlibs/posixrealtimeextensions/test/testtimer/src/ttimerblocks.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/posixrealtimeextensions/test/testtimer/src/ttimerblocks.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1998 @@
     1.4 +// Copyright (c) 2008-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 "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 +// Name        : ttimerblocks.cpp
    1.18 +// Test cases for blocking signal api's
    1.19 +//
    1.20 +
    1.21 +
    1.22 +
    1.23 +#include "ttimer.h"
    1.24 +#include "ttimerthread.h"
    1.25 +#define Maxtimerid 512
    1.26 +int timer_value = 0;
    1.27 +
    1.28 +RSemaphore iLock;
    1.29 +void CreateLock()
    1.30 +	{
    1.31 +	iLock.CreateLocal(0);
    1.32 +	}
    1.33 +void ReleaseLock()
    1.34 +	{
    1.35 +	iLock.Signal();
    1.36 +	}
    1.37 +void AcquireLock()
    1.38 +	{
    1.39 +	iLock.Wait();
    1.40 +	}
    1.41 +
    1.42 +//signal handler
    1.43 +void sig_handler(int sig)
    1.44 +	{
    1.45 +	timer_value = sig;
    1.46 +	ReleaseLock();
    1.47 +	}
    1.48 +
    1.49 +//overrun signal handler
    1.50 +void overrun_handler(int sig)
    1.51 +	{
    1.52 +	timer_value = sig;
    1.53 +	sleep(1);
    1.54 +	}
    1.55 +
    1.56 +//notification function
    1.57 +void notifyfunc(union sigval val)
    1.58 +	{
    1.59 +	timer_value = val.sival_int;
    1.60 +	}
    1.61 +
    1.62 +void alarm_handler(int sig)
    1.63 +	{
    1.64 +	timer_value = sig;
    1.65 +	}
    1.66 +
    1.67 +// -----------------------------------------------------------------------------
    1.68 +// CTesttimer::Testtimerapi1
    1.69 +// Test Case ID: OPENENV-LIBC-CIT-5946
    1.70 +// API tested: timer_create(), timer_delete()
    1.71 +// Description: Test case to create a timer with NONE as sigev_notify parameter
    1.72 +// TIMER_ABSTIME not set
    1.73 +// -----------------------------------------------------------------------------
    1.74 +
    1.75 +TInt CTesttimer::Testtimerapi1 (  )
    1.76 +	{
    1.77 +	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
    1.78 +	struct sigevent sigev;
    1.79 +	struct itimerspec timerspec;
    1.80 +	timer_value = 0;
    1.81 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
    1.82 +	if(ret == 0)
    1.83 +		{
    1.84 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
    1.85 +		return ret1;
    1.86 +	  	}
    1.87 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
    1.88 +	if(ret == 0)
    1.89 +		{
    1.90 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
    1.91 +	 	return ret1;
    1.92 +	  	}
    1.93 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
    1.94 +	if(ret == 0)
    1.95 +		{
    1.96 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
    1.97 +	 	return ret1;
    1.98 +	  	}
    1.99 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
   1.100 +	if(ret == 0)
   1.101 +		{
   1.102 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
   1.103 +	 	return ret1;
   1.104 +	  	}
   1.105 +	sigev.sigev_notify = SIGEV_NONE;
   1.106 +	timer_t timerid;
   1.107 +	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
   1.108 +
   1.109 +	if(ret != 0)
   1.110 +		{
   1.111 +		ERR_PRINTF2(_L("Failed to create a timer and  errno is %d"),errno);
   1.112 +     	return -1;		
   1.113 +		}
   1.114 +	INFO_PRINTF1(_L("Successfully able to create a timer") );
   1.115 +	timerspec.it_value.tv_sec = Valuesec;
   1.116 +	timerspec.it_value.tv_nsec = Valuenanosec;
   1.117 +	timerspec.it_interval.tv_sec = Intervalsec;
   1.118 +	timerspec.it_interval.tv_nsec = Intervalnanosec;
   1.119 +	ret = timer_settime(timerid,0,&timerspec,NULL);
   1.120 +	if(ret != 0)
   1.121 +		{
   1.122 +		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
   1.123 +     	ret1 = -1;
   1.124 +     	goto close;			
   1.125 +		}
   1.126 +	sleep(2);
   1.127 +	INFO_PRINTF1(_L("Successfully able to set the timer") );
   1.128 +	ret = timer_delete(timerid);
   1.129 +	if(ret != 0)
   1.130 +		{
   1.131 +		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
   1.132 +     	return -1;				
   1.133 +		}
   1.134 +	INFO_PRINTF1(_L("Successfully able to delete the timer") );
   1.135 +	ret1 = KErrNone;
   1.136 +	return ret1;
   1.137 +	close:
   1.138 +	timer_delete(timerid);
   1.139 +	return ret1;
   1.140 +	}
   1.141 +
   1.142 +// -----------------------------------------------------------------------------
   1.143 +// CTesttimer::Testtimerapi2
   1.144 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.145 +// API tested: timer_create(), timer_delete()
   1.146 +// Description: Test case to create a timer with NONE as sigev_notify parameter
   1.147 +// TIMER_ABSTIME set
   1.148 +// -----------------------------------------------------------------------------
   1.149 +
   1.150 +TInt CTesttimer::Testtimerapi2 (  )
   1.151 +	{
   1.152 +	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
   1.153 +	struct sigevent sigev;
   1.154 +	struct itimerspec timerspec;
   1.155 +	struct timespec curtmspec;
   1.156 +	timer_value = 0;
   1.157 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   1.158 +	if(ret == 0)
   1.159 +		{
   1.160 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   1.161 +	 	return ret1;
   1.162 +	  	}
   1.163 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   1.164 +	if(ret == 0)
   1.165 +		{
   1.166 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   1.167 +	 	return ret1;
   1.168 +	  	}
   1.169 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
   1.170 +	if(ret == 0)
   1.171 +		{
   1.172 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
   1.173 +	 	return ret1;
   1.174 +	  	}
   1.175 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
   1.176 +	if(ret == 0)
   1.177 +		{
   1.178 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
   1.179 +	 	return ret1;
   1.180 +	  	}
   1.181 +	sigev.sigev_notify = SIGEV_NONE;
   1.182 +	timer_t timerid;
   1.183 +	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
   1.184 +	if(ret != 0)
   1.185 +		{
   1.186 +		ERR_PRINTF2(_L("Failed to create a timer and  errno is %d"),errno);
   1.187 +     	return -1;	
   1.188 +		}
   1.189 +	INFO_PRINTF1(_L("Successfully able to create a timer") );
   1.190 +	ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
   1.191 +	if (ret != 0)
   1.192 +		{
   1.193 +	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
   1.194 +	 	goto close;	
   1.195 +		}
   1.196 +	timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
   1.197 +	timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec; 
   1.198 +	timerspec.it_interval.tv_sec = Intervalsec;
   1.199 +	timerspec.it_interval.tv_nsec = Intervalnanosec;
   1.200 +	ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,NULL);
   1.201 +	if(ret != 0)
   1.202 +		{
   1.203 +		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno);
   1.204 +		ret1 = -1;
   1.205 +     	goto close;				
   1.206 +		}
   1.207 +	sleep(2);
   1.208 +	INFO_PRINTF1(_L("Successfully able to set the timer") );
   1.209 +	ret = timer_delete(timerid);
   1.210 +	if(ret != 0)
   1.211 +		{
   1.212 +		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
   1.213 +     	return -1;
   1.214 +     	}
   1.215 +	INFO_PRINTF1(_L("Successfully able to delete the timer") );
   1.216 +	ret1 = KErrNone;
   1.217 +	return ret1;
   1.218 +	close:
   1.219 +	timer_delete(timerid); 
   1.220 +	return ret1;
   1.221 +	}
   1.222 +
   1.223 +// -----------------------------------------------------------------------------
   1.224 +// CTesttimer::Testtimerapi3
   1.225 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.226 +// API tested: timer_create(), timer_delete()
   1.227 +// Description: To create a timer with SIGEV_SIGNAL as sigev_notify parameter
   1.228 +// TIMER_ABSTIME not set
   1.229 +// -----------------------------------------------------------------------------
   1.230 +
   1.231 +TInt CTesttimer::Testtimerapi3 (  )
   1.232 +	{
   1.233 +	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec, Signum, Maxsig, Sigval;
   1.234 +	struct sigevent sigev;
   1.235 +	struct itimerspec timerspec;
   1.236 +	timer_t timerid;
   1.237 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   1.238 +	if(ret == 0)
   1.239 +		{
   1.240 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   1.241 +	 	return -1;
   1.242 +	  	}
   1.243 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   1.244 +	if(ret == 0)
   1.245 +		{
   1.246 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   1.247 +	 	return -1;
   1.248 +	  	}
   1.249 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
   1.250 +	if(ret == 0)
   1.251 +		{
   1.252 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
   1.253 +	 	return -1;
   1.254 +	  	}
   1.255 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
   1.256 +	if(ret == 0)
   1.257 +		{
   1.258 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
   1.259 +	 	return -1;
   1.260 +	  	}
   1.261 +	ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
   1.262 +	if(ret == 0)
   1.263 +		{
   1.264 +	 	ERR_PRINTF1(_L("Unable to read signal number")) ;
   1.265 +	 	return -1;
   1.266 +	  	}
   1.267 +	ret = GetIntFromConfig(ConfigSection(), _L("Maxsig"), Maxsig);
   1.268 +	if(ret == 0)
   1.269 +		{
   1.270 +	 	ERR_PRINTF1(_L("Unable to read maximum signal number")) ;
   1.271 +	 	return -1;
   1.272 +	  	}
   1.273 +	for(Signum=Sigval; Signum <= Maxsig; Signum++)
   1.274 +		{
   1.275 +		if((Signum == SIGSTOP) || (Signum == SIGKILL))
   1.276 +			{
   1.277 +			continue;
   1.278 +			}
   1.279 +		timer_value = 0;
   1.280 +		if(signal(Signum,sig_handler) == SIG_ERR)
   1.281 +			{
   1.282 +		 	ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
   1.283 +		 	return ret1;		
   1.284 +			}
   1.285 +		sigev.sigev_notify = SIGEV_SIGNAL;
   1.286 +		sigev.sigev_signo = Signum;
   1.287 +
   1.288 +		ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
   1.289 +		if(ret != 0)
   1.290 +			{
   1.291 +			ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
   1.292 +	     	return -1;		
   1.293 +			}
   1.294 +		timerspec.it_value.tv_sec = Valuesec;
   1.295 +		timerspec.it_value.tv_nsec = Valuenanosec;
   1.296 +		timerspec.it_interval.tv_sec = Intervalsec;
   1.297 +		timerspec.it_interval.tv_nsec = Intervalnanosec;
   1.298 +		timer_value = 0;
   1.299 +		CreateLock();
   1.300 +		ret = timer_settime(timerid,0,&timerspec,NULL);
   1.301 +		if(ret != 0)
   1.302 +			{
   1.303 +			ERR_PRINTF3(_L("Failed to set the timer for signal %d and errno is %d"),Signum,errno);
   1.304 +			ret1 = -1;
   1.305 +	     	goto close;				
   1.306 +			}
   1.307 +//		sleep(2);
   1.308 +		
   1.309 +		AcquireLock();
   1.310 +		if(timer_value != Signum)
   1.311 +			{
   1.312 +			ERR_PRINTF2(_L("The expected and timer_value are not same for signal %d"),Signum);
   1.313 +			goto close;
   1.314 +			}
   1.315 +		ret = timer_delete(timerid);
   1.316 +		if(ret != 0)
   1.317 +			{
   1.318 +			ERR_PRINTF3(_L("Failed to delete the timer for signal %d and errno is %d"),Signum, errno);
   1.319 +	     	return -1;				
   1.320 +			}
   1.321 +		}
   1.322 +	INFO_PRINTF1(_L("Relative time"));
   1.323 +		INFO_PRINTF1(_L("Successfully able to create a timer with SIGEV_SIGNAL as sigev_notify parameter validated for all signals"));
   1.324 +	ret1 = KErrNone;
   1.325 +	return ret1;
   1.326 +	close:
   1.327 +	timer_delete(timerid);
   1.328 +	return ret1;
   1.329 +	}
   1.330 +
   1.331 +// -----------------------------------------------------------------------------
   1.332 +// CTesttimer::Testtimerapi4
   1.333 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.334 +// API tested: timer_create(), timer_delete()
   1.335 +// Description: To create a timer with SIGEV_SIGNAL as sigev_notify parameter
   1.336 +// TIMER_ABSTIME set
   1.337 +// -----------------------------------------------------------------------------
   1.338 +
   1.339 +TInt CTesttimer::Testtimerapi4 (  )
   1.340 +	{
   1.341 +	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec, Signum, Maxsig, Sigval;
   1.342 +	struct sigevent sigev;
   1.343 +	struct itimerspec timerspec;
   1.344 +	struct timespec curtmspec;
   1.345 +	timer_t timerid;
   1.346 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   1.347 +	if(ret == 0)
   1.348 +		{
   1.349 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   1.350 +	 	return ret1;
   1.351 +	  	}
   1.352 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   1.353 +	if(ret == 0)
   1.354 +		{
   1.355 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   1.356 +	 	return ret1;
   1.357 +	  	}
   1.358 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
   1.359 +	if(ret == 0)
   1.360 +		{
   1.361 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
   1.362 +	 	return ret1;
   1.363 +	  	}
   1.364 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
   1.365 +	if(ret == 0)
   1.366 +		{
   1.367 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
   1.368 +	 	return ret1;
   1.369 +	  	}
   1.370 +	ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
   1.371 +	if(ret == 0)
   1.372 +		{
   1.373 +	 	ERR_PRINTF1(_L("Unable to read signal number")) ;
   1.374 +	 	return ret1;
   1.375 +	  	}
   1.376 +	ret = GetIntFromConfig(ConfigSection(), _L("Maxsig"), Maxsig);
   1.377 +	if(ret == 0)
   1.378 +		{
   1.379 +	 	ERR_PRINTF1(_L("Unable to read maximum signal number")) ;
   1.380 +	 	return ret1;
   1.381 +	  	}
   1.382 +	for(Signum=Sigval; Signum <= Maxsig; Signum++)
   1.383 +		{
   1.384 +		if((Signum == SIGSTOP) || (Signum == SIGKILL))
   1.385 +			{
   1.386 +			continue;
   1.387 +			}
   1.388 +		timer_value = 0;
   1.389 +		if(signal(Signum,sig_handler) == SIG_ERR)
   1.390 +			{
   1.391 +		 	ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
   1.392 +		 	return ret1;		
   1.393 +			}
   1.394 +		sigev.sigev_notify = SIGEV_SIGNAL;
   1.395 +		sigev.sigev_signo = Signum;
   1.396 +
   1.397 +		ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
   1.398 +		if(ret != 0)
   1.399 +			{
   1.400 +			ERR_PRINTF3(_L("Failed to create a timer for signal %d and errno is %d"),Signum,errno);
   1.401 +	     	return -1;	
   1.402 +			}
   1.403 +		ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
   1.404 +		if (ret != 0)
   1.405 +			{
   1.406 +		 	ERR_PRINTF3(_L("Failed to get the time of specified clock id for signal %d and errno is %d"),Signum,errno);
   1.407 +		 	goto close;	
   1.408 +			}
   1.409 +		timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
   1.410 +		timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec;
   1.411 +		timerspec.it_interval.tv_sec = Intervalsec;
   1.412 +		timerspec.it_interval.tv_nsec = Intervalnanosec;
   1.413 +		timer_value = 0;
   1.414 +		ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,NULL);
   1.415 +		//sleep(2);
   1.416 +		AcquireLock();
   1.417 +		if(ret != 0)
   1.418 +			{
   1.419 +			ERR_PRINTF3(_L("Failed to set the timer for signal %d and errno is %d"),Signum,errno);
   1.420 +			ret1 = -1;
   1.421 +	     	goto close;				
   1.422 +			}
   1.423 +		if(timer_value != Signum)
   1.424 +			{
   1.425 +			ERR_PRINTF2(_L("The expected and timer_value are not same for signal %d"),Signum);
   1.426 +	     	goto close;				
   1.427 +			}
   1.428 +		ret = timer_delete(timerid);
   1.429 +		if(ret != 0)
   1.430 +			{
   1.431 +			ERR_PRINTF3(_L("Failed to delete the timer for signal %d and errno is %d"),Signum, errno);
   1.432 +	     	return -1;				
   1.433 +			}
   1.434 +		}
   1.435 +	INFO_PRINTF1(_L("Absolute time"));
   1.436 +	INFO_PRINTF1(_L("Successfully able to create a timer with SIGEV_SIGNAL as sigev_notify parameter validated for all signals"));
   1.437 +	ret1 = KErrNone;
   1.438 +	return ret1;
   1.439 +	close:
   1.440 +	timer_delete(timerid);
   1.441 +	return ret1;
   1.442 +	}
   1.443 +
   1.444 +
   1.445 +// -----------------------------------------------------------------------------
   1.446 +// CTesttimer::Testtimerapi5
   1.447 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.448 +// API tested: timer_create(), timer_delete()
   1.449 +// Description: To create a timer with SIGEV_THREAD as sigev_notify parameter
   1.450 +// TIMER_ABSTIME not set
   1.451 +// -----------------------------------------------------------------------------
   1.452 +
   1.453 +TInt CTesttimer::Testtimerapi5 (  )
   1.454 +	{
   1.455 +	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
   1.456 +	struct sigevent sigev;
   1.457 +	struct sched_param parm;	 
   1.458 +	pthread_attr_t attr;
   1.459 +	struct itimerspec timerspec;
   1.460 +	timer_t timerid;
   1.461 +	pthread_attr_init( &attr );
   1.462 +	parm.sched_priority = 255; //raise the priority..
   1.463 +	pthread_attr_setschedparam(&attr, &parm);
   1.464 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   1.465 +	if(ret == 0)
   1.466 +		{
   1.467 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   1.468 +	 	return ret1;
   1.469 +	  	}
   1.470 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   1.471 +	if(ret == 0)
   1.472 +		{
   1.473 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   1.474 +	 	return ret1;
   1.475 +	  	}
   1.476 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
   1.477 +	if(ret == 0)
   1.478 +		{
   1.479 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
   1.480 +	 	return ret1;
   1.481 +	  	}
   1.482 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
   1.483 +	if(ret == 0)
   1.484 +		{
   1.485 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
   1.486 +	 	return ret1;
   1.487 +	  	}
   1.488 +	timer_value = 0;
   1.489 +	sigev.sigev_notify = SIGEV_THREAD;
   1.490 +	sigev.sigev_value.sival_int = 100;
   1.491 +	sigev.sigev_notify_function = notifyfunc ;
   1.492 +	sigev.sigev_notify_attributes = &attr;
   1.493 +	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
   1.494 +	if(ret != 0)
   1.495 +		{
   1.496 +		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
   1.497 +		return -1;		
   1.498 +		}
   1.499 +	INFO_PRINTF1(_L("Successfully able to create a timer") );
   1.500 +	timerspec.it_value.tv_sec = Valuesec;
   1.501 +	timerspec.it_value.tv_nsec = Valuenanosec;
   1.502 +	timerspec.it_interval.tv_sec = Intervalsec;
   1.503 +	timerspec.it_interval.tv_nsec = Intervalnanosec;
   1.504 +	ret = timer_settime(timerid,0,&timerspec,NULL);
   1.505 +	if(ret != 0)
   1.506 +		{
   1.507 +		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
   1.508 +		ret1 = -1;
   1.509 +		goto close;				
   1.510 +		}
   1.511 +	sleep(2);
   1.512 +	if(timer_value != 100)
   1.513 +		{
   1.514 +		ERR_PRINTF1(_L("The expected and timer_value are not same"));
   1.515 +		goto close;				
   1.516 +		}
   1.517 +	INFO_PRINTF1(_L("Successfully able to set the timer") );
   1.518 +	ret = timer_delete(timerid);
   1.519 +	if(ret != 0)
   1.520 +		{
   1.521 +		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
   1.522 +		return -1;				
   1.523 +		}
   1.524 +	INFO_PRINTF1(_L("Successfully able to delete the timer") );
   1.525 +	ret1 = KErrNone;
   1.526 +	return ret1;
   1.527 +	close:
   1.528 +	timer_delete(timerid);
   1.529 +	return ret1;
   1.530 +	}
   1.531 +
   1.532 +// -----------------------------------------------------------------------------
   1.533 +// CTesttimer::Testtimerapi6
   1.534 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.535 +// API tested: timer_create(), timer_delete()
   1.536 +// Description: To create a timer with SIGEV_THREAD as sigev_notify parameter
   1.537 +// TIMER_ABSTIME set
   1.538 +// -----------------------------------------------------------------------------
   1.539 +
   1.540 +TInt CTesttimer::Testtimerapi6 (  )
   1.541 +	{
   1.542 +	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
   1.543 +	struct sigevent sigev;
   1.544 +	struct itimerspec timerspec;
   1.545 +	struct timespec curtmspec;
   1.546 +	timer_t timerid;
   1.547 +	struct sched_param parm;	
   1.548 +	pthread_attr_t attr;
   1.549 +	pthread_attr_init( &attr );
   1.550 +	parm.sched_priority = 255;
   1.551 +	pthread_attr_setschedparam(&attr, &parm);
   1.552 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   1.553 +	if(ret == 0)
   1.554 +		{
   1.555 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   1.556 +	 	return ret1;
   1.557 +	  	}
   1.558 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   1.559 +	if(ret == 0)
   1.560 +		{
   1.561 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   1.562 +	 	return ret1;
   1.563 +	  	}
   1.564 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
   1.565 +	if(ret == 0)
   1.566 +		{
   1.567 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
   1.568 +	 	return ret1;
   1.569 +	  	}
   1.570 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
   1.571 +	if(ret == 0)
   1.572 +		{
   1.573 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
   1.574 +	 	return ret1;
   1.575 +	  	}
   1.576 +	timer_value = 0;
   1.577 +	sigev.sigev_notify = SIGEV_THREAD;
   1.578 +	sigev.sigev_value.sival_int = 100;
   1.579 +	sigev.sigev_notify_function = notifyfunc ;
   1.580 +	sigev.sigev_notify_attributes = &attr;
   1.581 +	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
   1.582 +	if(ret != 0)
   1.583 +		{
   1.584 +		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
   1.585 +		return -1;		
   1.586 +		}
   1.587 +	INFO_PRINTF1(_L("Successfully able to create a timer") );
   1.588 +	ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
   1.589 +	if (ret != 0)
   1.590 +		{
   1.591 +		ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
   1.592 +		goto close;	
   1.593 +		}
   1.594 +	timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
   1.595 +	timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec; 
   1.596 +	timerspec.it_interval.tv_sec = Intervalsec;
   1.597 +	timerspec.it_interval.tv_nsec = Intervalnanosec;
   1.598 +	ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,NULL);
   1.599 +	if(ret != 0)
   1.600 +		{
   1.601 +		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
   1.602 +		ret1 = -1;
   1.603 +		goto close;				
   1.604 +		}
   1.605 +	sleep(2); 
   1.606 +	if(timer_value != 100)
   1.607 +		{
   1.608 +		ERR_PRINTF1(_L("The expected and timer_value are not same"));
   1.609 +		goto close;				
   1.610 +		}
   1.611 +	INFO_PRINTF1(_L("Successfully able to set the timer") );
   1.612 +	ret = timer_delete(timerid);
   1.613 +	if(ret != 0)
   1.614 +		{
   1.615 +		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
   1.616 +		return -1;				
   1.617 +		}
   1.618 +	INFO_PRINTF1(_L("Successfully able to delete the timer") );
   1.619 +	ret1 = KErrNone;
   1.620 +	return ret1;
   1.621 +	close:
   1.622 +	timer_delete(timerid);
   1.623 +	return ret1;
   1.624 +	}
   1.625 +
   1.626 +// -----------------------------------------------------------------------------
   1.627 +// CTesttimer::Testtimerapi7
   1.628 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.629 +// API tested: timer_create(), timer_delete()
   1.630 +// Description: To create a timer for CLOCK_REALTIME id using timer_create() with sigevent argument as NULL
   1.631 +// TIMER_ABSTIME not set
   1.632 +// -----------------------------------------------------------------------------
   1.633 +
   1.634 +TInt CTesttimer::Testtimerapi7 (  )
   1.635 +	{
   1.636 +	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
   1.637 +	timer_t timerid;
   1.638 +	struct itimerspec timerspec;
   1.639 +	timer_value = 0;
   1.640 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   1.641 +	if(ret == 0)
   1.642 +		{
   1.643 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   1.644 +	 	return -1;
   1.645 +	  	}
   1.646 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   1.647 +	if(ret == 0)
   1.648 +		{
   1.649 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   1.650 +	 	return -1;
   1.651 +	  	}
   1.652 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
   1.653 +	if(ret == 0)
   1.654 +		{
   1.655 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
   1.656 +	 	return -1;
   1.657 +	  	}
   1.658 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
   1.659 +	if(ret == 0)
   1.660 +		{
   1.661 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
   1.662 +	 	return -1;
   1.663 +	  	}
   1.664 +	if(signal(SIGALRM, alarm_handler) == SIG_ERR)
   1.665 +		{
   1.666 +	 	ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
   1.667 +	 	return ret1;				
   1.668 +		}
   1.669 +	ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
   1.670 +	if(ret != 0)
   1.671 +		{
   1.672 +		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
   1.673 +		return -1;		
   1.674 +		}
   1.675 +	INFO_PRINTF1(_L("Successfully able to create a timer") );
   1.676 +	timerspec.it_value.tv_sec = Valuesec;
   1.677 +	timerspec.it_value.tv_nsec = Valuenanosec;
   1.678 +	timerspec.it_interval.tv_sec = Intervalsec;
   1.679 +	timerspec.it_interval.tv_nsec = Intervalnanosec;
   1.680 +	ret = timer_settime(timerid,0,&timerspec,NULL);
   1.681 +	if(ret != 0)
   1.682 +		{
   1.683 +		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
   1.684 +		ret1 = -1;
   1.685 +		goto close;				
   1.686 +		}
   1.687 +	sleep(2);
   1.688 +	if(timer_value != SIGALRM)
   1.689 +		{
   1.690 +		ERR_PRINTF1(_L("Error in raising the signal after timer expire"));
   1.691 +		goto close;	
   1.692 +		}
   1.693 +	INFO_PRINTF1(_L("Successfully able to set the timer with the default signal as SIGALRM") );
   1.694 +	ret = timer_delete(timerid);
   1.695 +	if(ret != 0)
   1.696 +		{
   1.697 +		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
   1.698 +     	return -1;				
   1.699 +		}
   1.700 +	INFO_PRINTF1(_L("Successfully able to delete the timer") );
   1.701 +	ret1 = KErrNone;
   1.702 +	return ret1;
   1.703 +	close:
   1.704 +	timer_delete(timerid);
   1.705 +	return ret1;
   1.706 +	}
   1.707 +
   1.708 +// -----------------------------------------------------------------------------
   1.709 +// CTesttimer::Testtimerapi8
   1.710 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.711 +// API tested: timer_create(), timer_delete()
   1.712 +// Description: To create a timer for CLOCK_REALTIME id using timer_create() with sigevent argument as NULL
   1.713 +// TIMER_ABSTIME set
   1.714 +// -----------------------------------------------------------------------------
   1.715 +
   1.716 +TInt CTesttimer::Testtimerapi8 (  )
   1.717 +	{
   1.718 +	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
   1.719 +	timer_t timerid;
   1.720 +	struct itimerspec timerspec;
   1.721 +	struct timespec curtmspec;
   1.722 +	timer_value = 0;
   1.723 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   1.724 +	if(ret == 0)
   1.725 +		{
   1.726 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   1.727 +	 	return ret1;
   1.728 +	  	}
   1.729 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   1.730 +	if(ret == 0)
   1.731 +		{
   1.732 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   1.733 +	 	return ret1;
   1.734 +	  	}
   1.735 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
   1.736 +	if(ret == 0)
   1.737 +		{
   1.738 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
   1.739 +	 	return ret1;
   1.740 +	  	}
   1.741 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
   1.742 +	if(ret == 0)
   1.743 +		{
   1.744 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
   1.745 +	 	return ret1;
   1.746 +	  	}
   1.747 +	if(signal(SIGALRM, alarm_handler) == SIG_ERR)
   1.748 +		{
   1.749 +	 	ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"),errno) ;
   1.750 +	 	return ret1;				
   1.751 +		}
   1.752 +	ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
   1.753 +	if(ret != 0)
   1.754 +		{
   1.755 +		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
   1.756 +		return -1;		
   1.757 +		}
   1.758 +	INFO_PRINTF1(_L("Successfully able to create a timer") );
   1.759 +	ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
   1.760 +	if (ret != 0)
   1.761 +		{
   1.762 +		ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
   1.763 +		goto close;	
   1.764 +		}
   1.765 +	timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
   1.766 +	timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec; 
   1.767 +	timerspec.it_interval.tv_sec = Intervalsec;
   1.768 +	timerspec.it_interval.tv_nsec = Intervalnanosec;
   1.769 +	ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,NULL);
   1.770 +	if(ret != 0)
   1.771 +		{
   1.772 +		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
   1.773 +		ret1 = -1;
   1.774 +		goto close;				
   1.775 +		}
   1.776 +	sleep(2);
   1.777 +	if(timer_value != SIGALRM)
   1.778 +		{
   1.779 +		ERR_PRINTF1(_L("Error in raising the signal after timer expire"));
   1.780 +		goto close;	
   1.781 +		}
   1.782 +	INFO_PRINTF1(_L("Successfully able to set the timer with the default signal as SIGALRM") );
   1.783 +	ret = timer_delete(timerid);
   1.784 +	if(ret != 0)
   1.785 +		{
   1.786 +		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
   1.787 +     	return -1;				
   1.788 +		}
   1.789 +	INFO_PRINTF1(_L("Successfully able to delete the timer") );
   1.790 +	ret1 = KErrNone;
   1.791 +	return ret1;
   1.792 +	close:
   1.793 +	timer_delete(timerid);
   1.794 +	return ret1;
   1.795 +	}
   1.796 +
   1.797 +// -----------------------------------------------------------------------------
   1.798 +// CTesttimer::Testtimerapi9
   1.799 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.800 +// API tested: timer_create()
   1.801 +// Description: Negative Test-Trying to create the timer for an invalid clock id using timer_create()
   1.802 +// -----------------------------------------------------------------------------
   1.803 +
   1.804 +TInt CTesttimer::Testtimerapi9 (  )
   1.805 +	{
   1.806 +	int ret, ret1 = KErrGeneral, Invalidclockid;
   1.807 +	timer_t timerid;
   1.808 +	ret = GetIntFromConfig(ConfigSection(), _L("Invalidclockid"), Invalidclockid);
   1.809 +	if(ret == 0)
   1.810 +		{
   1.811 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
   1.812 +	 	return ret1;
   1.813 +	  	}
   1.814 +	ret = timer_create(Invalidclockid,NULL,&timerid);
   1.815 +	if((ret != -1) || (errno != EINVAL))
   1.816 +		{
   1.817 +		ERR_PRINTF2(_L("timer_create() failed to return EINVAL on negative test and errno is %d"),errno);
   1.818 +		goto close;		
   1.819 +		}
   1.820 +	INFO_PRINTF1(_L("timer_create() successfully returned EINVAL on negative test") );
   1.821 +	ret1 = KErrNone;
   1.822 +	
   1.823 +	close:
   1.824 +	return ret1;	
   1.825 +	}
   1.826 +
   1.827 +// -----------------------------------------------------------------------------
   1.828 +// CTesttimer::Testtimerapi10
   1.829 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.830 +// API tested: timer_create()
   1.831 +// Description: Timer id as NULL in timer_create()
   1.832 +// -----------------------------------------------------------------------------
   1.833 +
   1.834 +TInt CTesttimer::Testtimerapi10 (  )
   1.835 +	{
   1.836 +	int ret, ret1 = KErrGeneral;
   1.837 +	ret = timer_create(CLOCK_REALTIME,NULL,NULL);
   1.838 +	if((ret != -1) || (errno != EFAULT))
   1.839 +		{
   1.840 +		ERR_PRINTF2(_L("timer_create() failed to return EFAULT on negative test and errno is %d"),errno);
   1.841 +     	goto close;				
   1.842 +		}
   1.843 +	INFO_PRINTF1(_L("timer_create() successfully returned EFAULT on negative test") );
   1.844 +	ret1 = KErrNone;
   1.845 +	
   1.846 +	close:
   1.847 +	return ret1;	
   1.848 +	}
   1.849 +
   1.850 +// -----------------------------------------------------------------------------
   1.851 +// CTesttimer::Testtimerapi11
   1.852 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.853 +// API tested: timer_create()
   1.854 +// Description: Timer id as NULL & an invalid clockid in timer_create()
   1.855 +// -----------------------------------------------------------------------------
   1.856 +
   1.857 +TInt CTesttimer::Testtimerapi11 (  )
   1.858 +	{
   1.859 +	int ret, ret1 = KErrGeneral;
   1.860 +	ret = timer_create(CLOCK_MONOTONIC,NULL,NULL);
   1.861 +	if((ret != -1) || (errno != EFAULT))
   1.862 +		{
   1.863 +		ERR_PRINTF2(_L("timer_create() failed to return EFAULT on negative test and errno is %d"),errno);
   1.864 +     	goto close;				
   1.865 +		}
   1.866 +	INFO_PRINTF1(_L("timer_create() successfully returned EFAULT on negative test") );
   1.867 +	ret1 = KErrNone;
   1.868 +	
   1.869 +	close:
   1.870 +	return ret1;	
   1.871 +	}
   1.872 +
   1.873 +// -----------------------------------------------------------------------------
   1.874 +// CTesttimer::Testtimerapi12
   1.875 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.876 +// API tested: timer_create()
   1.877 +// Description: Trying to create more than maximum no. of timer's possible per process using timer_create()
   1.878 +// -----------------------------------------------------------------------------
   1.879 +
   1.880 +TInt CTesttimer::Testtimerapi12 (  )
   1.881 +	{
   1.882 +	int ret, ret1 = KErrGeneral, i, j;
   1.883 +	timer_t timerid[Maxtimerid + 1];
   1.884 +	for (i = 0; i <= Maxtimerid ; i++)
   1.885 +		{
   1.886 +		ret = timer_create(CLOCK_REALTIME,NULL,&timerid[i]);
   1.887 +		if((ret == -1) && (errno == EAGAIN) && (i == Maxtimerid) )
   1.888 +			{
   1.889 +			INFO_PRINTF3(_L("timer_create() has successfully returned EAGAIN on negative test %d %d"),errno,i);
   1.890 +			ret1 = KErrNone;
   1.891 +			break;		
   1.892 +			}
   1.893 +		else if(ret < 0)
   1.894 +			{
   1.895 +			INFO_PRINTF3(_L("timer_create() has failed with error %d %d"),errno,i);
   1.896 +			}
   1.897 +		}
   1.898 +	for(j = 0; j <= Maxtimerid-1; j++)
   1.899 +		{
   1.900 +		ret = timer_delete(timerid[j]);
   1.901 +		if(ret != 0)
   1.902 +			{			
   1.903 +			ERR_PRINTF3(_L("Failed to delete the timer and errno is %d %d"),errno, j);
   1.904 +			ret1 = KErrGeneral;		
   1.905 +			break;
   1.906 +			}
   1.907 +		}
   1.908 +	INFO_PRINTF1(_L("timer_delete() has successfully deleted all the timers negative test"));
   1.909 +	return ret1;
   1.910 +	}
   1.911 +
   1.912 +// -----------------------------------------------------------------------------
   1.913 +// CTesttimer::Testtimerapi13
   1.914 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.915 +// API tested: timer_delete()
   1.916 +// Description: To delete the timer with an invalid timer id using timer_delete()
   1.917 +// -----------------------------------------------------------------------------
   1.918 +
   1.919 +TInt CTesttimer::Testtimerapi13 (  )
   1.920 +	{
   1.921 +	timer_t timerid;
   1.922 +	int ret, ret1 = KErrGeneral;
   1.923 +	ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
   1.924 +	if(ret != 0)
   1.925 +		{
   1.926 +		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
   1.927 +		return -1;		
   1.928 +		}
   1.929 +	INFO_PRINTF1(_L("Able to create the timer") );
   1.930 +	ret = timer_delete(timerid);
   1.931 +	if(ret != 0)
   1.932 +		{
   1.933 +		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
   1.934 +     	return -1;				
   1.935 +		}
   1.936 +	INFO_PRINTF1(_L("Successfully able to delete the timer") );
   1.937 +	/*Deleting a timer id again expected result = -1 and errno = EINVAL  */
   1.938 +	ret = timer_delete(timerid);
   1.939 +	if((ret != -1) || (errno != EINVAL))
   1.940 +		{
   1.941 +		ERR_PRINTF2(_L("timer_delete() failed to return EINVAL on negative test and errno is %d"),errno);
   1.942 +     	goto close;				
   1.943 +		}
   1.944 +	INFO_PRINTF1(_L("timer_delete() successfully returned EINVAL on negative test") );
   1.945 +	ret1 = KErrNone;
   1.946 +	
   1.947 +	close:
   1.948 +	return ret1;		
   1.949 +	}
   1.950 +
   1.951 +// -----------------------------------------------------------------------------
   1.952 +// CTesttimer::Testtimerapi14
   1.953 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.954 +// API tested: timer_delete()
   1.955 +// Description: To delete the timer with NULL using timer_delete()
   1.956 +// -----------------------------------------------------------------------------
   1.957 +
   1.958 +TInt CTesttimer::Testtimerapi14 (  )
   1.959 +	{
   1.960 +	int ret, ret1 = KErrGeneral;
   1.961 +	ret = timer_delete(NULL);
   1.962 +	if((ret != -1) || (errno != EINVAL))
   1.963 +		{
   1.964 +		ERR_PRINTF2(_L("timer_delete() failed to return EFAULT on negative test and errno is %d"),errno);
   1.965 +     	goto close;				
   1.966 +		}
   1.967 +	INFO_PRINTF1(_L("timer_delete() successfully returned EFAULT on negative test") );
   1.968 +	ret1 = KErrNone;
   1.969 +	
   1.970 +	close:
   1.971 +	return ret1;	
   1.972 +	}
   1.973 +
   1.974 +// -----------------------------------------------------------------------------
   1.975 +// CTesttimer::Testtimerapi15
   1.976 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.977 +// API tested: timer_settime()
   1.978 +// Description: Trying to set the timer for an invalid timer id using timer_settime()
   1.979 +// -----------------------------------------------------------------------------
   1.980 +
   1.981 +TInt CTesttimer::Testtimerapi15 (  )
   1.982 +	{
   1.983 +	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec, Timerflag;
   1.984 +	timer_t timerid;
   1.985 +	struct itimerspec timerspec;
   1.986 +	timer_value = 0;
   1.987 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   1.988 +	if(ret == 0)
   1.989 +		{
   1.990 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   1.991 +	 	return ret1;
   1.992 +	  	}
   1.993 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   1.994 +	if(ret == 0)
   1.995 +		{
   1.996 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   1.997 +	 	return ret1;
   1.998 +	  	}
   1.999 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
  1.1000 +	if(ret == 0)
  1.1001 +		{
  1.1002 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
  1.1003 +	 	return ret1;
  1.1004 +	  	}
  1.1005 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
  1.1006 +	if(ret == 0)
  1.1007 +		{
  1.1008 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
  1.1009 +	 	return ret1;
  1.1010 +	  	}
  1.1011 +	ret = GetIntFromConfig(ConfigSection(), _L("Timerflag"), Timerflag);
  1.1012 +	if(ret == 0)
  1.1013 +		{
  1.1014 +	 	ERR_PRINTF1(_L("Unable to read the timer flag")) ;
  1.1015 +	 	return ret1;
  1.1016 +	  	}
  1.1017 +	if(signal(SIGALRM, alarm_handler) == SIG_ERR)
  1.1018 +		{
  1.1019 +	 	ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
  1.1020 +	 	return ret1;				
  1.1021 +		}
  1.1022 +	ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
  1.1023 +	if(ret != 0)
  1.1024 +		{
  1.1025 +		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
  1.1026 +		return -1;		
  1.1027 +		}
  1.1028 +	INFO_PRINTF1(_L("Successfully able to create a timer") );
  1.1029 +	ret = timer_delete(timerid);
  1.1030 +	if(ret != 0)
  1.1031 +		{
  1.1032 +		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1.1033 +     	return -1;				
  1.1034 +		}
  1.1035 +	INFO_PRINTF1(_L("Successfully able to delete the timer") );
  1.1036 +	timerspec.it_value.tv_sec = Valuesec;
  1.1037 +	timerspec.it_value.tv_nsec = Valuenanosec;
  1.1038 +	timerspec.it_interval.tv_sec = Intervalsec;
  1.1039 +	timerspec.it_interval.tv_nsec = Intervalnanosec;
  1.1040 +	ret = timer_settime(timerid,Timerflag,&timerspec,NULL);
  1.1041 +	if((ret != -1) || (errno != EINVAL))
  1.1042 +		{
  1.1043 +		ERR_PRINTF2(_L("timer_settime() failed to return EINVAL on negative test and errno is %d"),errno);
  1.1044 +		goto close;				
  1.1045 +		}
  1.1046 +	INFO_PRINTF1(_L("timer_settime() successfully able to return EINVAL on negative test") );
  1.1047 +	ret1 = KErrNone;
  1.1048 +	
  1.1049 +	close:
  1.1050 +	RThread athr;
  1.1051 +	if(athr.Open(_L("LibrtTimerServ")) == KErrNone)
  1.1052 +		{
  1.1053 +		athr.Close();
  1.1054 +		}
  1.1055 +	
  1.1056 +	return ret1;
  1.1057 +	}
  1.1058 +
  1.1059 +// -----------------------------------------------------------------------------
  1.1060 +// CTesttimer::Testtimerapi16
  1.1061 +// Test Case ID: OPENENV-LIBC-CIT-5946
  1.1062 +// API tested: timer_settime()
  1.1063 +// Description: Trying to set the timer with an invalid tv_nsec parameter using timer_settime()
  1.1064 +// -----------------------------------------------------------------------------
  1.1065 +
  1.1066 +TInt CTesttimer::Testtimerapi16 (  )
  1.1067 +	{
  1.1068 +	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec, Signum, Maxsig, Timerflag, Sigval;
  1.1069 +	struct sigevent sigev;
  1.1070 +	struct itimerspec timerspec;
  1.1071 +	timer_t timerid;
  1.1072 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
  1.1073 +	if(ret == 0)
  1.1074 +		{
  1.1075 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value"));
  1.1076 +	 	return ret1;
  1.1077 +	  	}
  1.1078 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
  1.1079 +	if(ret == 0)
  1.1080 +		{
  1.1081 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
  1.1082 +	 	return ret1;
  1.1083 +	  	}
  1.1084 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
  1.1085 +	if(ret == 0)
  1.1086 +		{
  1.1087 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
  1.1088 +	 	return ret1;
  1.1089 +	  	}
  1.1090 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
  1.1091 +	if(ret == 0)
  1.1092 +		{
  1.1093 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
  1.1094 +	 	return ret1;
  1.1095 +	  	}
  1.1096 +	ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
  1.1097 +	if(ret == 0)
  1.1098 +		{
  1.1099 +	 	ERR_PRINTF1(_L("Unable to read signal number")) ;
  1.1100 +	 	return ret1;
  1.1101 +	  	}
  1.1102 +	ret = GetIntFromConfig(ConfigSection(), _L("Maxsig"), Maxsig);
  1.1103 +	if(ret == 0)
  1.1104 +		{
  1.1105 +	 	ERR_PRINTF1(_L("Unable to read maximum signal number")) ;
  1.1106 +	 	return ret1;
  1.1107 +	  	}
  1.1108 +	ret = GetIntFromConfig(ConfigSection(), _L("Timerflag"), Timerflag);
  1.1109 +	if(ret == 0)
  1.1110 +		{
  1.1111 +	 	ERR_PRINTF1(_L("Unable to read the timer flag")) ;
  1.1112 +	 	return ret1;
  1.1113 +	  	}
  1.1114 +	for(Signum=Sigval; Signum <= Maxsig; Signum++)
  1.1115 +		{
  1.1116 +		if((Signum == SIGSTOP) || (Signum == SIGKILL))
  1.1117 +			{
  1.1118 +			continue;
  1.1119 +			}
  1.1120 +		timer_value = 0;
  1.1121 +		if(signal(Signum,sig_handler) == SIG_ERR)
  1.1122 +			{
  1.1123 +		 	ERR_PRINTF3(_L("Error in signal trapping function for signal is %d and errno is %d"),Signum, errno) ;
  1.1124 +		 	return ret1;		
  1.1125 +			}
  1.1126 +		sigev.sigev_notify = SIGEV_SIGNAL;
  1.1127 +		sigev.sigev_signo = Signum;
  1.1128 +		ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1.1129 +		if(ret != 0)
  1.1130 +			{
  1.1131 +			ERR_PRINTF3(_L("Failed to create a timer %d and errno is %d"),Signum, errno);
  1.1132 +			return -1;
  1.1133 +			}
  1.1134 +		timerspec.it_value.tv_sec = Valuesec;
  1.1135 +		timerspec.it_value.tv_nsec = Valuenanosec;
  1.1136 +		timerspec.it_interval.tv_sec = Intervalsec; 
  1.1137 +		timerspec.it_interval.tv_nsec = Intervalnanosec; 
  1.1138 +		ret = timer_settime(timerid,Timerflag,&timerspec,NULL);
  1.1139 +		if((ret != -1) || (errno != EINVAL))
  1.1140 +			{
  1.1141 +			ERR_PRINTF2(_L("timer_settime() failed to return EINVAL on negative test and errno is %d"),errno);
  1.1142 +			goto close;
  1.1143 +			}
  1.1144 +		ret = timer_delete(timerid);
  1.1145 +		if(ret != 0)
  1.1146 +			{
  1.1147 +			ERR_PRINTF3(_L("Failed to delete the timer %d and errno is %d"),Signum,errno);
  1.1148 +			return -1;
  1.1149 +			}
  1.1150 +		}
  1.1151 +	INFO_PRINTF1(_L("timer_settime() successfully able to return EINVAL on negative test") );
  1.1152 +	ret1 = KErrNone;
  1.1153 +	return ret1;
  1.1154 +	close:
  1.1155 +	timer_delete(timerid);
  1.1156 +	return ret1;	
  1.1157 +	}
  1.1158 +
  1.1159 +// -----------------------------------------------------------------------------
  1.1160 +// CTesttimer::Testtimerapi17
  1.1161 +// Test Case ID: OPENENV-LIBC-CIT-5946
  1.1162 +// API tested: timer_create(), timer_delete()
  1.1163 +// Description: To create a timer with SIGEV_SIGNAL as sigev_notify parameter
  1.1164 +// TIMER_ABSTIME not set
  1.1165 +// -----------------------------------------------------------------------------
  1.1166 +
  1.1167 +TInt CTesttimer::Testtimerapi17 (  )
  1.1168 +	{
  1.1169 +	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
  1.1170 +	struct sigevent sigev;
  1.1171 +	struct itimerspec timerspec;
  1.1172 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
  1.1173 +	if(ret == 0)
  1.1174 +		{
  1.1175 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
  1.1176 +	 	return ret1;
  1.1177 +	  	}
  1.1178 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
  1.1179 +	if(ret == 0)
  1.1180 +		{
  1.1181 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
  1.1182 +	 	return ret1;
  1.1183 +	  	}
  1.1184 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
  1.1185 +	if(ret == 0)
  1.1186 +		{
  1.1187 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
  1.1188 +	 	return ret1;
  1.1189 +	  	}
  1.1190 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
  1.1191 +	if(ret == 0)
  1.1192 +		{
  1.1193 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
  1.1194 +	 	return ret1;
  1.1195 +	  	}
  1.1196 +	timer_value = 0;
  1.1197 +	if(signal(SIGUSR1,overrun_handler) == SIG_ERR)
  1.1198 +		{
  1.1199 +		ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
  1.1200 +		return ret1;
  1.1201 +		}
  1.1202 +	sigev.sigev_notify = SIGEV_SIGNAL;
  1.1203 +	sigev.sigev_signo = SIGUSR1;
  1.1204 +	timer_t timerid;
  1.1205 +	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1.1206 +	if(ret != 0)
  1.1207 +		{
  1.1208 +		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
  1.1209 +		return -1;
  1.1210 +		}
  1.1211 +	timerspec.it_value.tv_sec = Valuesec;
  1.1212 +	timerspec.it_value.tv_nsec = Valuenanosec;
  1.1213 +	timerspec.it_interval.tv_sec = Intervalsec;
  1.1214 +	timerspec.it_interval.tv_nsec = Intervalnanosec;
  1.1215 +	timer_value = 0;
  1.1216 +	ret = timer_settime(timerid,0,&timerspec,NULL);
  1.1217 +	if(ret != 0)
  1.1218 +		{
  1.1219 +		ERR_PRINTF2(_L("Failed to set the time of specified clock id and errno is %d "),errno);
  1.1220 +		ret1 = -1;
  1.1221 +		goto close;				
  1.1222 +		}
  1.1223 +	sleep(2);
  1.1224 +	if(timer_value != SIGUSR1)
  1.1225 +		{
  1.1226 +		ERR_PRINTF1(_L("The expected and timer_value are not same for signal"));
  1.1227 +		ret1 = -1;
  1.1228 +		goto close;
  1.1229 +		}
  1.1230 +	ret = timer_getoverrun(timerid);
  1.1231 +	if (ret != 0)
  1.1232 +		{
  1.1233 +		ERR_PRINTF2(_L("Error in timer_getoverrun() and errno is %d"),errno);
  1.1234 +		ret1 = -1;
  1.1235 +		goto close; 			
  1.1236 +		}
  1.1237 +	ret = timer_delete(timerid);
  1.1238 +	if(ret != 0)
  1.1239 +		{
  1.1240 +		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1.1241 +		return -1;				
  1.1242 +		}
  1.1243 +	INFO_PRINTF1(_L("Relative Timer") );
  1.1244 +	INFO_PRINTF1(_L("Successfully able to create a timer with SIGEV_SIGNAL as sigev_notify parameter") );
  1.1245 +	ret1 = KErrNone;
  1.1246 +	return ret1;
  1.1247 +	close:
  1.1248 +	timer_delete(timerid);
  1.1249 +	return ret1;
  1.1250 +	}
  1.1251 +
  1.1252 +// -----------------------------------------------------------------------------
  1.1253 +// CTesttimer::Testtimerapi18
  1.1254 +// Test Case ID: OPENENV-LIBC-CIT-5946
  1.1255 +// API tested: timer_create(), timer_delete()
  1.1256 +// Description: To create a timer with SIGEV_SIGNAL as sigev_notify parameter
  1.1257 +// TIMER_ABSTIME set
  1.1258 +// -----------------------------------------------------------------------------
  1.1259 +
  1.1260 +TInt CTesttimer::Testtimerapi18 (  )
  1.1261 +	{
  1.1262 +	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
  1.1263 +	struct sigevent sigev;
  1.1264 +	struct itimerspec timerspec, oldtimerspec;
  1.1265 +	struct timespec curtmspec;
  1.1266 +	timer_t timerid;
  1.1267 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
  1.1268 +	if(ret == 0)
  1.1269 +		{
  1.1270 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
  1.1271 +	 	return ret1;
  1.1272 +	  	}
  1.1273 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
  1.1274 +	if(ret == 0)
  1.1275 +		{
  1.1276 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
  1.1277 +	 	return ret1;
  1.1278 +	  	}
  1.1279 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
  1.1280 +	if(ret == 0)
  1.1281 +		{
  1.1282 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
  1.1283 +	 	return ret1;
  1.1284 +	  	}
  1.1285 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
  1.1286 +	if(ret == 0)
  1.1287 +		{
  1.1288 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
  1.1289 +	 	return ret1;
  1.1290 +	  	}
  1.1291 +		timer_value = 0;
  1.1292 +		if(signal(SIGUSR1,overrun_handler) == SIG_ERR)
  1.1293 +			{
  1.1294 +		 	ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
  1.1295 +		 	return ret1;
  1.1296 +			}
  1.1297 +		sigev.sigev_notify = SIGEV_SIGNAL;
  1.1298 +		sigev.sigev_signo = SIGUSR1;
  1.1299 +		ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1.1300 +		if(ret != 0)
  1.1301 +			{
  1.1302 +			ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
  1.1303 +			return -1;
  1.1304 +			}
  1.1305 +		ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
  1.1306 +		if (ret != 0)
  1.1307 +			{
  1.1308 +		 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
  1.1309 +		 	ret1 = -1;
  1.1310 +		 	goto close;	
  1.1311 +			}
  1.1312 +		timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
  1.1313 +		timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec;
  1.1314 +		timerspec.it_interval.tv_sec = Intervalsec;
  1.1315 +		timerspec.it_interval.tv_nsec = Intervalnanosec;
  1.1316 +		timer_value = 0;
  1.1317 +		ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,&oldtimerspec);
  1.1318 +		if(ret != 0)
  1.1319 +			{
  1.1320 +			ERR_PRINTF2(_L("Failed to set the timer for signal and errno is %d"),errno);
  1.1321 +			ret1 = -1;
  1.1322 +	     	goto close;				
  1.1323 +			}
  1.1324 +		sleep(2);
  1.1325 +		if(timer_value != SIGUSR1)
  1.1326 +			{
  1.1327 +			ERR_PRINTF2(_L("The expected and timer_value are not same for signal %d"),errno);
  1.1328 +			goto close;
  1.1329 +			}
  1.1330 +		ret = timer_getoverrun(timerid);
  1.1331 +		if (ret != 0)
  1.1332 +			{
  1.1333 +			ERR_PRINTF2(_L("Error in timer_getoverrun() and errno is %d"),errno);
  1.1334 +			ret1 = -1;
  1.1335 +	     	goto close;				
  1.1336 +			}
  1.1337 +		ret = timer_delete(timerid);
  1.1338 +		if(ret != 0)
  1.1339 +			{
  1.1340 +			ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1.1341 +			ret1 = -1;			
  1.1342 +			}
  1.1343 +	INFO_PRINTF1(_L("Absolute Timer") );
  1.1344 +	INFO_PRINTF1(_L("Successfully able to create a timer with SIGEV_SIGNAL as sigev_notify parameter") );
  1.1345 +	ret1 = KErrNone;
  1.1346 +	return ret1;
  1.1347 +	close:
  1.1348 +	timer_delete(timerid);
  1.1349 +	return ret1;
  1.1350 +	}
  1.1351 +
  1.1352 +// -----------------------------------------------------------------------------
  1.1353 +// CTesttimer::Testtimerapi19
  1.1354 +// Test Case ID: OPENENV-LIBC-CIT-5946
  1.1355 +// API tested: timer_overrun(), timer_gettime()
  1.1356 +// Description: Negative test: timer_overrun(), timer_gettime() with an invalid timerid
  1.1357 +// -----------------------------------------------------------------------------
  1.1358 +
  1.1359 +TInt CTesttimer::Testtimerapi19 (  )
  1.1360 +	{
  1.1361 +	timer_t timerid;
  1.1362 +	int ret, ret1 = KErrGeneral;
  1.1363 +	struct itimerspec timerspec;
  1.1364 +	ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
  1.1365 +	if(ret != 0)
  1.1366 +		{
  1.1367 +		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
  1.1368 +		return -1;		
  1.1369 +		}
  1.1370 +	INFO_PRINTF1(_L("successfully able to create the timer") );
  1.1371 +	ret = timer_delete(timerid);
  1.1372 +	if(ret != 0)
  1.1373 +		{
  1.1374 +		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1.1375 +     	return -1;				
  1.1376 +		}
  1.1377 +	INFO_PRINTF1(_L("Successfully able to delete the timer") );
  1.1378 +	ret = timer_gettime(timerid,&timerspec);
  1.1379 +	if((ret != -1) || (errno != EINVAL))
  1.1380 +		{
  1.1381 +		ERR_PRINTF2(_L("timer_gettime() failed to return EINVAL on negative test and errno is %d"),errno);
  1.1382 +		goto close;
  1.1383 +		}
  1.1384 +	INFO_PRINTF1(_L("timer_gettime() successfully returned EINVAL on negative test") );
  1.1385 +	ret = timer_getoverrun(timerid);
  1.1386 +	if((ret != -1) || (errno != EINVAL))
  1.1387 +		{
  1.1388 +		ERR_PRINTF2(_L("timer_getoverrun() failed to return EINVAL on negative test and errno is %d"),errno);
  1.1389 +		goto close;
  1.1390 +		}
  1.1391 +	INFO_PRINTF1(_L("timer_getoverrun() successfully returned EINVAL on negative test") );
  1.1392 +	ret1 = KErrNone;
  1.1393 +	return ret1;
  1.1394 +	close:
  1.1395 +	timer_delete(timerid);
  1.1396 +	return ret1;		
  1.1397 +	}
  1.1398 +
  1.1399 +// -----------------------------------------------------------------------------
  1.1400 +// CTesttimer::Testtimerapi20
  1.1401 +// Test Case ID: OPENENV-LIBC-CIT-5946
  1.1402 +// API tested: timer_create()
  1.1403 +// Description: Negative test: timer_create() with an invalid signal
  1.1404 +// -----------------------------------------------------------------------------
  1.1405 +
  1.1406 +TInt CTesttimer::Testtimerapi20 (  )
  1.1407 +	{
  1.1408 +	timer_t timerid;
  1.1409 +	int ret, ret1 = KErrGeneral, Sigval;
  1.1410 +	struct sigevent sigev;
  1.1411 +	ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
  1.1412 +	if(ret == 0)
  1.1413 +		{
  1.1414 +	 	ERR_PRINTF1(_L("Unable to read signal number")) ;
  1.1415 +	 	return -1;
  1.1416 +	  	}
  1.1417 +	sigev.sigev_notify = SIGEV_SIGNAL;
  1.1418 +	sigev.sigev_signo = Sigval;
  1.1419 +	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);	
  1.1420 +	if((ret != -1) || (errno != EINVAL))
  1.1421 +		{
  1.1422 +		ERR_PRINTF2(_L("timer_create() failed to return EINVAL on negative test and errno is %d"),errno);
  1.1423 +		goto close;				
  1.1424 +		}
  1.1425 +	INFO_PRINTF1(_L("timer_create() with an invalid sigev_signo member") );
  1.1426 +	INFO_PRINTF1(_L("timer_create() successfully returned EINVAL on negative test") );
  1.1427 +	ret1 = KErrNone;
  1.1428 +	
  1.1429 +	close:
  1.1430 +	return ret1;		
  1.1431 +	}
  1.1432 +
  1.1433 +// -----------------------------------------------------------------------------
  1.1434 +// CTesttimer::Testtimerapi21
  1.1435 +// Test Case ID: OPENENV-LIBC-CIT-5946
  1.1436 +// API tested: timer_create()
  1.1437 +// Description: Negative test: timer_create() with an invalid sigev_notify member
  1.1438 +// -----------------------------------------------------------------------------
  1.1439 +
  1.1440 +TInt CTesttimer::Testtimerapi21 (  )
  1.1441 +	{
  1.1442 +	timer_t timerid;
  1.1443 +	int ret, ret1 = KErrGeneral, Sigval, Signum, Maxsig, Notify;
  1.1444 +	struct sigevent sigev;
  1.1445 +	ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
  1.1446 +	if(ret == 0)
  1.1447 +		{
  1.1448 +	 	ERR_PRINTF1(_L("Unable to read signal number")) ;
  1.1449 +	 	return ret1;
  1.1450 +	  	}
  1.1451 +	ret = GetIntFromConfig(ConfigSection(), _L("Maxsig"), Maxsig);
  1.1452 +	if(ret == 0)
  1.1453 +		{
  1.1454 +	 	ERR_PRINTF1(_L("Unable to read maximum signal number")) ;
  1.1455 +	 	return ret1;
  1.1456 +	  	}
  1.1457 +	ret = GetIntFromConfig(ConfigSection(), _L("Notify"), Notify);
  1.1458 +	if(ret == 0)
  1.1459 +		{
  1.1460 +	 	ERR_PRINTF1(_L("Unable to read an invalid notify value")) ;
  1.1461 +	 	return ret1;
  1.1462 +	  	}
  1.1463 +	for(Signum=Sigval; Signum <= Maxsig; Signum++)
  1.1464 +		{
  1.1465 +		if((Signum == SIGSTOP) || (Signum == SIGKILL))
  1.1466 +			{
  1.1467 +			continue;
  1.1468 +			}
  1.1469 +		sigev.sigev_notify = Notify;
  1.1470 +		sigev.sigev_signo = Signum;
  1.1471 +		ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);	
  1.1472 +		if((ret != -1) || (errno != EINVAL))
  1.1473 +			{
  1.1474 +			ERR_PRINTF2(_L("timer_create() failed to return EINVAL on negative test and errno is %d"),errno);
  1.1475 +			goto close;				
  1.1476 +			}
  1.1477 +		}
  1.1478 +	INFO_PRINTF1(_L("timer_create() with an invalid sigev_notify member") );
  1.1479 +	INFO_PRINTF1(_L("timer_create() successfully returned EINVAL on negative test") );
  1.1480 +	ret1 = KErrNone;
  1.1481 +	
  1.1482 +	close:
  1.1483 +	return ret1;		
  1.1484 +	}
  1.1485 +
  1.1486 +// -----------------------------------------------------------------------------
  1.1487 +// CTesttimer::Testtimerapi22
  1.1488 +// Test Case ID: OPENENV-LIBC-CIT-5946
  1.1489 +// API tested: timer_settime()
  1.1490 +// Description: Negative test: timer_settime() with an input itimerspec value as NULL
  1.1491 +// -----------------------------------------------------------------------------
  1.1492 +
  1.1493 +TInt CTesttimer::Testtimerapi22 (  )
  1.1494 +	{
  1.1495 +	int ret, ret1 = KErrGeneral;
  1.1496 +	struct sigevent sigev;
  1.1497 +	struct itimerspec timerspec;
  1.1498 +	timer_t timerid;
  1.1499 +	sigev.sigev_notify = SIGEV_NONE;
  1.1500 +	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1.1501 +	if(ret != 0)
  1.1502 +		{
  1.1503 +		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"), errno );
  1.1504 +     	return -1;		
  1.1505 +		}
  1.1506 +	INFO_PRINTF1(_L("Successfully able to create a timer") );
  1.1507 +	ret = timer_settime(timerid,0,NULL,&timerspec);
  1.1508 +	if((ret != -1) || (errno != EINVAL))
  1.1509 +		{
  1.1510 +		ERR_PRINTF2(_L("timer_settime() failed to return EINVAL on negative test and errno is %d"),errno);
  1.1511 +		goto close;				
  1.1512 +		}
  1.1513 +	INFO_PRINTF1(_L("Successfully able to set the timer") );
  1.1514 +	sleep(2);
  1.1515 +	ret = timer_delete(timerid);
  1.1516 +	if(ret != 0)
  1.1517 +		{
  1.1518 +		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1.1519 +     	return -1;				
  1.1520 +		}
  1.1521 +	INFO_PRINTF1(_L("timer_settime() with itimerspec input as NULL") );
  1.1522 +	INFO_PRINTF1(_L("timer_settime() successfully returned EINVAL on negative test") );
  1.1523 +	ret1 = KErrNone;
  1.1524 +	return ret1;
  1.1525 +	close:
  1.1526 +	timer_delete(timerid);
  1.1527 +	return ret1;
  1.1528 +	}
  1.1529 +
  1.1530 +// -----------------------------------------------------------------------------
  1.1531 +// CTesttimer::Testtimerapi23
  1.1532 +// Test Case ID: OPENENV-LIBC-CIT-5946
  1.1533 +// API tested: timer_settime()
  1.1534 +// Description: Negative test: timer_settime() with an invalid flag member
  1.1535 +// -----------------------------------------------------------------------------
  1.1536 +
  1.1537 +TInt CTesttimer::Testtimerapi23 (  )
  1.1538 +	{
  1.1539 +	int ret, ret1 = KErrGeneral;
  1.1540 +	struct sigevent sigev;
  1.1541 +	struct itimerspec timerspec;
  1.1542 +	timer_t timerid;
  1.1543 +	sigev.sigev_notify = SIGEV_NONE;
  1.1544 +	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1.1545 +	if(ret != 0)
  1.1546 +		{
  1.1547 +		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno );
  1.1548 +     	return -1;		
  1.1549 +		}
  1.1550 +	INFO_PRINTF1(_L("Successfully able to create a timer") );
  1.1551 +	timerspec.it_value.tv_sec = 1;
  1.1552 +	timerspec.it_value.tv_nsec = 0;
  1.1553 +	timerspec.it_interval.tv_sec = 0;
  1.1554 +	timerspec.it_interval.tv_nsec = 0;
  1.1555 +	ret = timer_settime(timerid,-1,NULL,&timerspec);
  1.1556 +	if((ret != -1) || (errno != EINVAL))
  1.1557 +		{
  1.1558 +		ERR_PRINTF2(_L("timer_settime() failed to return EINVAL on negative test and errno is %d"),errno);
  1.1559 +		goto close;				
  1.1560 +		}
  1.1561 +	INFO_PRINTF1(_L("Successfully able to set the timer") );
  1.1562 +	sleep(3);
  1.1563 +	ret = timer_delete(timerid);
  1.1564 +	if(ret != 0)
  1.1565 +		{
  1.1566 +		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1.1567 +     	return -1;				
  1.1568 +		}
  1.1569 +	INFO_PRINTF1(_L("timer_settime() with an invalid flag value") );
  1.1570 +	INFO_PRINTF1(_L("timer_settime() successfully returned EINVAL on negative test") );
  1.1571 +	ret1 = KErrNone;
  1.1572 +	return ret1;
  1.1573 +	close:
  1.1574 +	timer_delete(timerid);
  1.1575 +	return ret1;	
  1.1576 +	}
  1.1577 +
  1.1578 +// -----------------------------------------------------------------------------
  1.1579 +// CTesttimer::Testtimerapi24
  1.1580 +// Test Case ID: OPENENV-LIBC-CIT-5946
  1.1581 +// API tested: timer_gettime()
  1.1582 +// Description: Negative test: timer_gettime() with an input itimerspec value as NULL
  1.1583 +// -----------------------------------------------------------------------------
  1.1584 +
  1.1585 +TInt CTesttimer::Testtimerapi24 (  )
  1.1586 +	{
  1.1587 +	int ret, ret1 = KErrGeneral;
  1.1588 +	struct sigevent sigev;
  1.1589 +	struct itimerspec timerspec;
  1.1590 +	timer_t timerid;
  1.1591 +	timer_value = 0;
  1.1592 +	sigev.sigev_notify = SIGEV_NONE;
  1.1593 +	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1.1594 +	if(ret != 0)
  1.1595 +		{
  1.1596 +		ERR_PRINTF1(_L("Failed to create a timer") );
  1.1597 +     	return -1;		
  1.1598 +		}
  1.1599 +	INFO_PRINTF1(_L("Successfully able to create a timer") );
  1.1600 +	timerspec.it_value.tv_sec = 1;
  1.1601 +	timerspec.it_value.tv_nsec = 0;
  1.1602 +	timerspec.it_interval.tv_sec = 1;
  1.1603 +	timerspec.it_interval.tv_nsec = 0;
  1.1604 +	ret = timer_settime(timerid,0,&timerspec,NULL);
  1.1605 +	if(ret != 0)
  1.1606 +		{
  1.1607 +		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
  1.1608 +     	ret1 = -1;
  1.1609 +     	goto close;				
  1.1610 +		}
  1.1611 +	INFO_PRINTF1(_L("Successfully able to set the timer") );
  1.1612 +	ret = timer_gettime(timerid,NULL);
  1.1613 +	if((ret != -1) || (errno != EFAULT))
  1.1614 +		{
  1.1615 +		ERR_PRINTF2(_L("timer_gettime() failed to return EFAULT on negative test and errno is %d"),errno);
  1.1616 +		goto close;				
  1.1617 +		}	
  1.1618 +	ret = timer_delete(timerid);
  1.1619 +	if(ret != 0)
  1.1620 +		{
  1.1621 +		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1.1622 +     	ret1 = -1;				
  1.1623 +		}
  1.1624 +	INFO_PRINTF1(_L("Successfully able to delete the timer") );
  1.1625 +	INFO_PRINTF1(_L("timer_gettime() with an input itimerspec value as NULL") );
  1.1626 +	INFO_PRINTF1(_L("timer_gettime() successfully returned EFAULT on negative test") );
  1.1627 +	ret1 = KErrNone;
  1.1628 +	return ret1;
  1.1629 +	close:
  1.1630 +	timer_delete(timerid);
  1.1631 +	return ret1;	
  1.1632 +	}
  1.1633 +
  1.1634 +// -----------------------------------------------------------------------------
  1.1635 +// CTesttimer::Testtimerapi25
  1.1636 +// Test Case ID: OPENENV-LIBC-CIT-5946
  1.1637 +// API tested: timer_settime(),timer_gettime()
  1.1638 +// Description: To retreive the amount of time until the timer expires
  1.1639 +// Relative timer
  1.1640 +// -----------------------------------------------------------------------------
  1.1641 +
  1.1642 +TInt CTesttimer::Testtimerapi25 (  )
  1.1643 +	{
  1.1644 +	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
  1.1645 +	struct sigevent sigev;
  1.1646 +	struct itimerspec timerspec, gettime, oldtimerspec;
  1.1647 +	timer_value = 0;
  1.1648 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
  1.1649 +	if(ret == 0)
  1.1650 +		{
  1.1651 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
  1.1652 +	 	return ret1;
  1.1653 +	  	}
  1.1654 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
  1.1655 +	if(ret == 0)
  1.1656 +		{
  1.1657 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
  1.1658 +	 	return ret1;
  1.1659 +	  	}
  1.1660 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
  1.1661 +	if(ret == 0)
  1.1662 +		{
  1.1663 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
  1.1664 +	 	return ret1;
  1.1665 +	  	}
  1.1666 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
  1.1667 +	if(ret == 0)
  1.1668 +		{
  1.1669 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
  1.1670 +	 	return ret1;
  1.1671 +	  	}
  1.1672 +	sigev.sigev_notify = SIGEV_NONE;
  1.1673 +	timer_t timerid;
  1.1674 +	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1.1675 +	if(ret != 0)
  1.1676 +		{
  1.1677 +		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"), errno );
  1.1678 +     	return -1;	
  1.1679 +		}
  1.1680 +	INFO_PRINTF1(_L("Successfully able to create a timer") );
  1.1681 +	timerspec.it_value.tv_sec = Valuesec;
  1.1682 +	timerspec.it_value.tv_nsec = Valuenanosec;
  1.1683 +	timerspec.it_interval.tv_sec = Intervalsec;
  1.1684 +	timerspec.it_interval.tv_nsec = Intervalnanosec;
  1.1685 +	ret = timer_settime(timerid,0,&timerspec,&oldtimerspec);
  1.1686 +	if(ret != 0)
  1.1687 +		{
  1.1688 +		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno );
  1.1689 +     	ret1 = -1;
  1.1690 +     	goto close;				
  1.1691 +		}
  1.1692 +	sleep(1);
  1.1693 +	INFO_PRINTF1(_L("Successfully able to set the timer") );
  1.1694 +	ret = timer_gettime(timerid,&gettime);
  1.1695 +	if(ret != 0)
  1.1696 +		{
  1.1697 +		ERR_PRINTF2(_L("Failed to get the timer and the errno is %d"),errno );
  1.1698 +     	ret1 = -1;
  1.1699 +     	goto close;				
  1.1700 +		}
  1.1701 +	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))
  1.1702 +		{
  1.1703 +		ERR_PRINTF1(_L("Failed to get the timer value") );
  1.1704 +		ret1 = -1;
  1.1705 +     	goto close;
  1.1706 +		}
  1.1707 +	INFO_PRINTF1(_L("Successfully able to get the timer") );	
  1.1708 +	ret = timer_delete(timerid);
  1.1709 +	if(ret != 0)
  1.1710 +		{
  1.1711 +		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1.1712 +     	return -1;;				
  1.1713 +		}
  1.1714 +	INFO_PRINTF1(_L("Successfully able to delete the timer") );
  1.1715 +	ret1 = KErrNone;
  1.1716 +	return ret1;
  1.1717 +	close:
  1.1718 +	timer_delete(timerid);
  1.1719 +	return ret1;	
  1.1720 +	}
  1.1721 +
  1.1722 +// -----------------------------------------------------------------------------
  1.1723 +// CTesttimer::Testtimerapi26
  1.1724 +// Test Case ID: OPENENV-LIBC-CIT-5946
  1.1725 +// API tested: timer_settime(),timer_gettime()
  1.1726 +// Description: To retreive the amount of time until the timer expires
  1.1727 +// Absolute timer
  1.1728 +// -----------------------------------------------------------------------------
  1.1729 +
  1.1730 +TInt CTesttimer::Testtimerapi26 (  )
  1.1731 +	{
  1.1732 +	int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
  1.1733 +	struct sigevent sigev;
  1.1734 +	struct itimerspec timerspec, gettime, oldtimerspec;
  1.1735 +	struct timespec curtmspec;
  1.1736 +	timer_value = 0;
  1.1737 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
  1.1738 +	if(ret == 0)
  1.1739 +		{
  1.1740 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
  1.1741 +	 	return ret1;
  1.1742 +	  	}
  1.1743 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
  1.1744 +	if(ret == 0)
  1.1745 +		{
  1.1746 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
  1.1747 +	 	return ret1;
  1.1748 +	  	}
  1.1749 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
  1.1750 +	if(ret == 0)
  1.1751 +		{
  1.1752 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
  1.1753 +	 	return ret1;
  1.1754 +	  	}
  1.1755 +	ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
  1.1756 +	if(ret == 0)
  1.1757 +		{
  1.1758 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
  1.1759 +	 	return ret1;
  1.1760 +	  	}
  1.1761 +	sigev.sigev_notify = SIGEV_NONE;
  1.1762 +	timer_t timerid;
  1.1763 +	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1.1764 +	if(ret != 0)
  1.1765 +		{
  1.1766 +		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"), errno );
  1.1767 +     	return -1;		
  1.1768 +		}
  1.1769 +	INFO_PRINTF1(_L("Successfully able to create a timer") );
  1.1770 +	ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
  1.1771 +	if (ret != 0)
  1.1772 +		{
  1.1773 +	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
  1.1774 +	 	ret1 = -1;
  1.1775 +	 	goto close;	
  1.1776 +		}
  1.1777 +	timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
  1.1778 +	timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec; 
  1.1779 +	timerspec.it_interval.tv_sec = Intervalsec;
  1.1780 +	timerspec.it_interval.tv_nsec = Intervalnanosec;
  1.1781 +	ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,&oldtimerspec);
  1.1782 +	if(ret != 0)
  1.1783 +		{
  1.1784 +		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno );
  1.1785 +		ret1 = -1;
  1.1786 +     	goto close;				
  1.1787 +		}
  1.1788 +	sleep(1);
  1.1789 +	INFO_PRINTF1(_L("Successfully able to set the timer") );
  1.1790 +	ret = timer_gettime(timerid,&gettime);
  1.1791 +	if(ret != 0)
  1.1792 +		{
  1.1793 +		ERR_PRINTF2(_L("Failed to get the timer and errno is %d"), errno );
  1.1794 +     	ret1 = -1;
  1.1795 +     	goto close;				
  1.1796 +		}
  1.1797 +	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))
  1.1798 +		{
  1.1799 +		ERR_PRINTF1(_L("Failed to get the timer value") );
  1.1800 +		ret1 = -1;
  1.1801 +     	goto close;
  1.1802 +		}
  1.1803 +	INFO_PRINTF1(_L("Successfully able to get the timer") );	
  1.1804 +	ret = timer_delete(timerid);
  1.1805 +	if(ret != 0)
  1.1806 +		{
  1.1807 +		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1.1808 +     	return -1;				
  1.1809 +		}
  1.1810 +	INFO_PRINTF1(_L("Successfully able to delete the timer") );
  1.1811 +	ret1 = KErrNone;
  1.1812 +	return ret1;
  1.1813 +	close:
  1.1814 +	timer_delete(timerid);
  1.1815 +	return ret1;	
  1.1816 +	}
  1.1817 +
  1.1818 +// -----------------------------------------------------------------------------
  1.1819 +// CTesttimer::Testtimerapi27
  1.1820 +// Test Case ID: OPENENV-LIBC-CIT-5946
  1.1821 +// API tested: timer_settime(),timer_gettime()
  1.1822 +// Description: To retreive the amount of time until the timer expires using timer_settime()
  1.1823 +// Absolute timer
  1.1824 +// -----------------------------------------------------------------------------
  1.1825 +
  1.1826 +TInt CTesttimer::Testtimerapi27 (  )
  1.1827 +	{
  1.1828 +	int ret, ret1 = KErrGeneral;
  1.1829 +	struct sigevent sigev;
  1.1830 +	struct itimerspec timerspec1, gettime, oldtimerspec;
  1.1831 +	timer_value = 0;
  1.1832 +	sigev.sigev_notify = SIGEV_NONE;
  1.1833 +	timer_t timerid;
  1.1834 +	ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
  1.1835 +	if(ret != 0)
  1.1836 +		{
  1.1837 +		ERR_PRINTF2(_L("Failed to create a timer and errno is %d"), errno );
  1.1838 +     	return -1;		
  1.1839 +		}
  1.1840 +	INFO_PRINTF1(_L("Successfully able to create a timer") );
  1.1841 +	timerspec1.it_value.tv_sec = 5;
  1.1842 +	timerspec1.it_value.tv_nsec = 0;
  1.1843 +	timerspec1.it_interval.tv_sec = 0;
  1.1844 +	timerspec1.it_interval.tv_nsec = 0;
  1.1845 +	ret = timer_settime(timerid,0,&timerspec1,NULL);
  1.1846 +	if(ret != 0)
  1.1847 +		{
  1.1848 +		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno );
  1.1849 +     	ret1 = -1;				
  1.1850 +     	goto close;
  1.1851 +		}
  1.1852 +	INFO_PRINTF1(_L("Successfully able to set the timer for the first time") );
  1.1853 +	sleep(1);
  1.1854 +	timerspec1.it_value.tv_sec = 3;
  1.1855 +	timerspec1.it_value.tv_nsec = 0;
  1.1856 +	timerspec1.it_interval.tv_sec = 0;
  1.1857 +	timerspec1.it_interval.tv_nsec = 0;
  1.1858 +	ret = timer_settime(timerid,0,&timerspec1,&oldtimerspec);
  1.1859 +	if(ret != 0)
  1.1860 +		{
  1.1861 +		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno );
  1.1862 +     	ret1 = -1;				
  1.1863 +     	goto close;				
  1.1864 +		}
  1.1865 +	INFO_PRINTF1(_L("Successfully able to set the timer for the second time") );
  1.1866 +	if(oldtimerspec.it_value.tv_sec > 4)
  1.1867 +		{
  1.1868 +		ERR_PRINTF1(_L("Failed to set the timer value") );
  1.1869 +		goto close;
  1.1870 +		}
  1.1871 +	sleep(1);
  1.1872 +	timerspec1.it_value.tv_sec = 0;
  1.1873 +	timerspec1.it_value.tv_nsec = 0;
  1.1874 +	timerspec1.it_interval.tv_sec = 0;
  1.1875 +	timerspec1.it_interval.tv_nsec = 0;
  1.1876 +	ret = timer_settime(timerid,0,&timerspec1,&oldtimerspec);
  1.1877 +	if(ret != 0)
  1.1878 +		{
  1.1879 +		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
  1.1880 +     	goto close;				
  1.1881 +		}
  1.1882 +	if(oldtimerspec.it_value.tv_sec > 2)
  1.1883 +		{
  1.1884 +		ERR_PRINTF1(_L("Failed to set the timer value") );
  1.1885 +		goto close;
  1.1886 +		}
  1.1887 +	timerspec1.it_value.tv_sec = 2;
  1.1888 +	timerspec1.it_value.tv_nsec = 0;
  1.1889 +	timerspec1.it_interval.tv_sec = 5;
  1.1890 +	timerspec1.it_interval.tv_nsec = 0;
  1.1891 +	ret = timer_settime(timerid,0,&timerspec1,&oldtimerspec);
  1.1892 +	if(ret != 0)
  1.1893 +		{
  1.1894 +		ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno);
  1.1895 +		ret1 = -1;
  1.1896 +     	goto close;				
  1.1897 +		}
  1.1898 +	if(oldtimerspec.it_value.tv_sec != 0)
  1.1899 +		{
  1.1900 +		ERR_PRINTF1(_L("Failed to set the timer value") );
  1.1901 +		goto close;
  1.1902 +		}
  1.1903 +	ret = timer_gettime(timerid,&gettime);
  1.1904 +	if(ret != 0)
  1.1905 +		{
  1.1906 +		ERR_PRINTF2(_L("Failed to get the timer and errno is %d"),errno);
  1.1907 +		ret1 = -1;
  1.1908 +     	goto close;				
  1.1909 +		}
  1.1910 +	
  1.1911 +	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))
  1.1912 +		{
  1.1913 +		ERR_PRINTF1(_L("Failed to get the timer value") );
  1.1914 +		goto close;
  1.1915 +		}
  1.1916 +	INFO_PRINTF1(_L("Successfully able to get the timer") );	
  1.1917 +	ret = timer_delete(timerid);
  1.1918 +	if(ret != 0)
  1.1919 +		{
  1.1920 +		ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
  1.1921 +     	return -1;			
  1.1922 +		}
  1.1923 +	INFO_PRINTF1(_L("Successfully able to delete the timer") );
  1.1924 +	ret1 = KErrNone;
  1.1925 +	return ret1;
  1.1926 +	close:
  1.1927 +	timer_delete(timerid);
  1.1928 +	return ret1;	
  1.1929 +	}
  1.1930 +TInt CTesttimer::Testtimerapi28( )
  1.1931 +    {
  1.1932 +    TInt err;
  1.1933 +
  1.1934 +    TRequestStatus timerThreadStatus1;
  1.1935 +    RThread timerThread1;
  1.1936 +    TTimerTestThreadParams paramsTimerThread1(*this);
  1.1937 +
  1.1938 +    TRequestStatus timerThreadStatus2;
  1.1939 +    RThread timerThread2;
  1.1940 +    TTimerTestThreadParams paramsTimerThread2(*this);
  1.1941 +
  1.1942 +    Logger().ShareAuto();
  1.1943 +    //Create the Thread to create shared mem and write to it.
  1.1944 +    err = timerThread1.Create(_L("TimerThread1"), (TThreadFunction)CTimerTestThread::OEEntry, KDefaultStackSize, KMinHeapSize, 1024*1024,&paramsTimerThread1);
  1.1945 +    if(err != KErrNone)
  1.1946 +    {
  1.1947 +        ERR_PRINTF2(_L("Timer Thread1 Not created - %d"), err);
  1.1948 +        SetTestStepResult(EFail);
  1.1949 +        return EFail;
  1.1950 +
  1.1951 +    }
  1.1952 +    INFO_PRINTF1(_L("Timer Thread1 created "));
  1.1953 +    //Create the thread to open shared mem and read from it.
  1.1954 +    err = timerThread2.Create(_L("TimerThread2"), (TThreadFunction)CTimerTestThread::OEEntry, KDefaultStackSize, KMinHeapSize, 1024*1024,&paramsTimerThread2);
  1.1955 +    if(err != KErrNone)
  1.1956 +    {
  1.1957 +        ERR_PRINTF2(_L("Timer Thread 2 Not created - %d"), err);
  1.1958 +        SetTestStepResult(EFail);
  1.1959 +        //Close the Write Thread created previously
  1.1960 +        timerThread1.Close();
  1.1961 +        return EFail;
  1.1962 +
  1.1963 +    }
  1.1964 +    INFO_PRINTF1(_L("Timer Thread created "));
  1.1965 +
  1.1966 +    timerThread1.SetPriority(EPriorityNormal);
  1.1967 +    timerThread2.SetPriority(EPriorityNormal);
  1.1968 +
  1.1969 +    timerThread1.Logon(timerThreadStatus1);
  1.1970 +    timerThread2.Logon(timerThreadStatus2);
  1.1971 +
  1.1972 +    timerThread1.Resume();
  1.1973 +    timerThread2.Resume();
  1.1974 +
  1.1975 +    User::WaitForRequest(timerThreadStatus1);
  1.1976 +   User::WaitForRequest(timerThreadStatus2);
  1.1977 +
  1.1978 +    timerThread1.Close();
  1.1979 +    timerThread2.Close();
  1.1980 +
  1.1981 +    //Check the status of the threads..
  1.1982 +   if(!paramsTimerThread1.iTestResult )
  1.1983 +        {
  1.1984 +         ERR_PRINTF1(_L("Timer Thread 1 Not successful"));
  1.1985 +         SetTestStepResult(EFail);
  1.1986 +        }
  1.1987 +   if(!paramsTimerThread2.iTestResult )
  1.1988 +        {
  1.1989 +          ERR_PRINTF1(_L("Timer Thread 2 Not successful"));
  1.1990 +          SetTestStepResult(EFail);
  1.1991 +        }
  1.1992 +
  1.1993 +    return TestStepResult();
  1.1994 +
  1.1995 +
  1.1996 +    }
  1.1997 +//End of a file
  1.1998 +
  1.1999 +
  1.2000 +
  1.2001 +