os/ossrv/genericopenlibs/posixrealtimeextensions/test/testclock/src/tclockblocks.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/posixrealtimeextensions/test/testclock/src/tclockblocks.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,747 @@
     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        : tclockblocks.cpp
    1.18 +// Test cases for blocking signal api's
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#include "tclock.h"
    1.23 +
    1.24 +// -----------------------------------------------------------------------------
    1.25 +// CTestclock::Testgetclockid1
    1.26 +// Test Case ID: OPENENV-LIBC-CIT-5946
    1.27 +// API tested: clock_getcpuclockid()
    1.28 +// Description: To access the clock id of CPU time clock with pid = 0. API tested: clock_getcpuclockid()
    1.29 +// -----------------------------------------------------------------------------
    1.30 +
    1.31 +TInt CTestclock::Testgetclockid1 (  )
    1.32 +	{
    1.33 +	int ret, ret1 = KErrGeneral;
    1.34 +	clockid_t clockid;
    1.35 +	ret = clock_getcpuclockid(0,&clockid);
    1.36 +	if (ret != 0)
    1.37 +		{
    1.38 +	 	ERR_PRINTF2(_L("Failed to retrieve the clock id of the calling process and errno is %d"),errno);
    1.39 +	 	goto close;	
    1.40 +		}
    1.41 +	if (clockid != CLOCK_REALTIME)
    1.42 +		{
    1.43 +	 	ERR_PRINTF1(_L("Failed to return the right clock id"));
    1.44 +	 	goto close;	
    1.45 +		}
    1.46 +	INFO_PRINTF1(_L("Successfully able to get the calling process's clock id") );
    1.47 +	ret1 = KErrNone;
    1.48 +	
    1.49 +	close:
    1.50 +	return ret1;	
    1.51 +	}
    1.52 +
    1.53 +// -----------------------------------------------------------------------------
    1.54 +// CTestclock::Testgetclockid2
    1.55 +// Test Case ID: OPENENV-LIBC-CIT-5946
    1.56 +// API tested: clock_getcpuclockid()
    1.57 +// Description:  To access the clock id of CPU time clock of self. API tested: clock_getcpuclockid() 
    1.58 +// -----------------------------------------------------------------------------
    1.59 +
    1.60 +TInt CTestclock::Testgetclockid2 (  )
    1.61 +	{
    1.62 +	int ret, ret1 = KErrGeneral;
    1.63 +	clockid_t clockid;
    1.64 +	ret = clock_getcpuclockid(getpid(),&clockid);
    1.65 +	if ((ret != -1) || (errno !=  ESRCH))
    1.66 +		{
    1.67 +	 	ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno);
    1.68 +	 	goto close;	
    1.69 +		}
    1.70 +	INFO_PRINTF1(_L("clock_getcpuclockid() is successful on negative test") );
    1.71 +	ret1 = KErrNone;
    1.72 +	
    1.73 +	close:
    1.74 +	return ret1;
    1.75 +	}
    1.76 +
    1.77 +// -----------------------------------------------------------------------------
    1.78 +// CTestclock::Testgetclockid3
    1.79 +// Test Case ID: OPENENV-LIBC-CIT-5946
    1.80 +// API tested: clock_getcpuclockid()
    1.81 +// Description: To access the clock id of CPU time clock of other process 
    1.82 +// -----------------------------------------------------------------------------
    1.83 +
    1.84 +TInt CTestclock::Testgetclockid3 (  )
    1.85 +	{
    1.86 +	int ret, ret1 = KErrGeneral;
    1.87 +	pid_t pid;
    1.88 +	clockid_t clockid;
    1.89 +	char **argv = (char **)malloc(2*sizeof(char*));
    1.90 +	argv[0] = (char *)malloc(30*sizeof(char*));
    1.91 +	argv[1] = 0;
    1.92 +	strcpy(argv[0],"z:\\sys\\bin\\getclockid.exe");
    1.93 +	ret = posix_spawn(&pid, "z:\\sys\\bin\\getclockid.exe", NULL, NULL, argv, (char**)NULL);
    1.94 +	if(ret != 0)
    1.95 +		{
    1.96 +		ERR_PRINTF2(_L("Error in posix spawn and errno is set to %d"),errno);
    1.97 +		goto close;
    1.98 +		}
    1.99 +	ret = clock_getcpuclockid(pid,&clockid);
   1.100 +	if ((ret != -1) || (errno !=  ESRCH))
   1.101 +		{
   1.102 +	 	ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno);
   1.103 +	 	goto close;	
   1.104 +		}
   1.105 +	INFO_PRINTF1(_L("clock_getcpuclockid() is successful on negative test") );
   1.106 +	ret1 = KErrNone;
   1.107 +	
   1.108 +	close:
   1.109 +	free((void*)argv[0]);
   1.110 +	free((void*)argv);
   1.111 +	return ret1;	
   1.112 +	}
   1.113 +
   1.114 +// -----------------------------------------------------------------------------
   1.115 +// CTestclock::Testgetclockid4
   1.116 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.117 +// API tested: clock_getcpuclockid()
   1.118 +// Description: To access the clock id of CPU time clock of an invalid process. 
   1.119 +// -----------------------------------------------------------------------------
   1.120 +
   1.121 +TInt CTestclock::Testgetclockid4 (  )
   1.122 +	{
   1.123 +	int ret, ret1 = KErrGeneral;
   1.124 +	clockid_t clockid;
   1.125 +	ret = clock_getcpuclockid(-1,&clockid);
   1.126 +	if ((ret != -1) || (errno !=  ESRCH))
   1.127 +		{
   1.128 +	 	ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno);
   1.129 +	 	goto close;	
   1.130 +		}
   1.131 +	INFO_PRINTF1(_L("clock_getcpuclockid() has successfully returned ESRCH on negative test") );
   1.132 +	ret1 = KErrNone;
   1.133 +	
   1.134 +	close:
   1.135 +	return ret1;		
   1.136 +	}
   1.137 +
   1.138 +// -----------------------------------------------------------------------------
   1.139 +// CTestclock::Testgetclockid5
   1.140 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.141 +// API tested: clock_getcpuclockid()
   1.142 +// Description: Trying to access the clock id of an invalid id passing to it.
   1.143 +// -----------------------------------------------------------------------------
   1.144 +
   1.145 +TInt CTestclock::Testgetclockid5 (  )
   1.146 +	{
   1.147 +	int ret, ret1 = KErrGeneral;
   1.148 +	ret = clock_getcpuclockid(0,NULL);
   1.149 +	if ((ret != -1) || (errno !=  EFAULT))
   1.150 +		{
   1.151 +	 	ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno);
   1.152 +	 	goto close;	
   1.153 +		}
   1.154 +	INFO_PRINTF1(_L("clock_getcpuclockid() has successfully returned EFAULT on negative test") );
   1.155 +	ret1 = KErrNone;
   1.156 +	
   1.157 +	close:
   1.158 +	return ret1;			
   1.159 +	}
   1.160 +
   1.161 +// -----------------------------------------------------------------------------
   1.162 +// CTestclock::Testclockresolution1
   1.163 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.164 +// API tested: clock_getres()
   1.165 +// Description: To get the clock resolution with valid clock id using clock_getres() 
   1.166 +// -----------------------------------------------------------------------------
   1.167 +
   1.168 +TInt CTestclock::Testclockresolution1 (  )
   1.169 +	{
   1.170 +	int ret, ret1 = KErrGeneral;
   1.171 +	clockid_t clockid;
   1.172 +	struct timespec tmspec;
   1.173 +	ret = clock_getcpuclockid(0,&clockid);
   1.174 +	if (ret != 0)
   1.175 +		{
   1.176 +	 	ERR_PRINTF2(_L("Failed to retrieve the clock id of the calling process and errno is %d"),errno);
   1.177 +	 	goto close;	
   1.178 +		}
   1.179 +	ret = clock_getres(clockid,&tmspec);
   1.180 +	if (ret != 0)
   1.181 +		{
   1.182 +	 	ERR_PRINTF2(_L("Failed to retrieve resolution of the clock id specified and errno is %d"),errno);
   1.183 +	 	goto close;	
   1.184 +		}	
   1.185 +	if ((tmspec.tv_nsec != 1000) || (tmspec.tv_sec != 0))
   1.186 +		{
   1.187 +	 	ERR_PRINTF1(_L("Resolution of the clock id is not set properly"));
   1.188 +	 	goto close;			
   1.189 +		}
   1.190 +	INFO_PRINTF1(_L("Successfully able to get the clock resolution of the specified clock id") );
   1.191 +	ret1 = KErrNone;
   1.192 +	
   1.193 +	close:
   1.194 +	return ret1;		
   1.195 +	}
   1.196 +
   1.197 +// -----------------------------------------------------------------------------
   1.198 +// CTestclock::Testclockresolution2
   1.199 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.200 +// API tested: clock_getres()
   1.201 +// Description: Trying to get the clock resolution using clock_getres() for a clockid other than CLOCK_REALTIME 
   1.202 +// -----------------------------------------------------------------------------
   1.203 +
   1.204 +TInt CTestclock::Testclockresolution2 (  )
   1.205 +	{
   1.206 +	int ret, ret1 = KErrGeneral, Clockid, Error;
   1.207 +	struct timespec tmspec;
   1.208 +	ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); 
   1.209 +	if(ret == 0)
   1.210 +		{
   1.211 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   1.212 +	 	goto close;
   1.213 +	  	}
   1.214 +	ret = GetIntFromConfig(ConfigSection(), _L("Error"), Error); 
   1.215 +	if(ret == 0)
   1.216 +		{
   1.217 +	 	ERR_PRINTF1(_L("Unable to read expected error num")) ;
   1.218 +	 	goto close;
   1.219 +	  	}
   1.220 +	ret = clock_getres(Clockid,&tmspec);
   1.221 +	if ((ret != -1) || (errno != Error))
   1.222 +		{
   1.223 +	 	ERR_PRINTF2(_L("The expected and errno are not same and errno is %d"),errno);
   1.224 +	 	goto close;			
   1.225 +		}
   1.226 +	INFO_PRINTF1(_L("The output and expected value are same for clock_getres()") );
   1.227 +	ret1 = KErrNone;
   1.228 +	
   1.229 +	close:
   1.230 +	return ret1;
   1.231 +	}
   1.232 +
   1.233 +// -----------------------------------------------------------------------------
   1.234 +// CTestclock::Testclockresolution3
   1.235 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.236 +// API tested: clock_getres()
   1.237 +// Description: Negative Test: Trying to get the resolution with res = NULL using clock_getres() 
   1.238 +// -----------------------------------------------------------------------------
   1.239 +
   1.240 +TInt CTestclock::Testclockresolution3 (  )
   1.241 +	{
   1.242 +	int ret, ret1 = KErrGeneral, Clockid;
   1.243 +	ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); 
   1.244 +	if(ret == 0)
   1.245 +		{
   1.246 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   1.247 +	 	goto close;
   1.248 +	  	}
   1.249 +	ret = clock_getres(Clockid,NULL);
   1.250 +	if (ret != 0) 
   1.251 +		{
   1.252 +	 	ERR_PRINTF2(_L("clock_getres() failed on negative test if timespec argument is NULL and errno is %d"),errno);
   1.253 +	 	goto close;	
   1.254 +		}	
   1.255 +	INFO_PRINTF1(_L("clock_getres() successfully returned 0 on negative test") );
   1.256 +	ret1 = KErrNone;
   1.257 +	
   1.258 +	close:
   1.259 +	return ret1;
   1.260 +	}
   1.261 +
   1.262 +// -----------------------------------------------------------------------------
   1.263 +// CTestclock::Testclocknanosleep1
   1.264 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.265 +// API tested: clock_nanosleep()
   1.266 +// Description: Trying to suspend the process for the specified time using clock_nanosleep() in the absence of TIMER_ABSTIME
   1.267 +// Relative timer
   1.268 +// -----------------------------------------------------------------------------
   1.269 +
   1.270 +TInt CTestclock::Testclocknanosleep1 (  )
   1.271 +	{
   1.272 +	int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec;
   1.273 +	struct timespec gettmspec, oldtmpsec, sleeptmspec, sleeptmspec1;
   1.274 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   1.275 +	if(ret == 0)
   1.276 +		{
   1.277 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   1.278 +	 	goto close;
   1.279 +	  	}
   1.280 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   1.281 +	if(ret == 0)
   1.282 +		{
   1.283 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   1.284 +	 	goto close;
   1.285 +	  	}
   1.286 +	sleeptmspec.tv_sec = Valuesec;
   1.287 +	sleeptmspec.tv_nsec = Valuenanosec;
   1.288 +	ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
   1.289 +	if (ret != 0)
   1.290 +		{
   1.291 +	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
   1.292 +	 	goto close;	
   1.293 +		}	
   1.294 +	oldtmpsec = gettmspec;
   1.295 +	ret = clock_nanosleep(CLOCK_REALTIME,0,&sleeptmspec,&sleeptmspec1);
   1.296 +	if (ret != 0) 
   1.297 +		{
   1.298 +	 	ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno);
   1.299 +	 	goto close;			
   1.300 +		}
   1.301 +	ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
   1.302 +	if (ret != 0)
   1.303 +		{
   1.304 +	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
   1.305 +	 	goto close;	
   1.306 +		}	
   1.307 +	if (gettmspec.tv_sec != (oldtmpsec.tv_sec + Valuesec))
   1.308 +		{
   1.309 +	 	ERR_PRINTF2(_L("clock_nanosleep() has failed to sleep for %d secs"),Valuesec);
   1.310 +	 	goto close;			
   1.311 +		}
   1.312 +	INFO_PRINTF1(_L("Relative timer"));
   1.313 +	INFO_PRINTF2(_L("clock_nanosleep() successfully able to sleep for %d secs"),Valuesec );
   1.314 +	ret1 = KErrNone;
   1.315 +	
   1.316 +	close:
   1.317 +	return ret1;	
   1.318 +	}
   1.319 +
   1.320 +// -----------------------------------------------------------------------------
   1.321 +// CTestclock::Testclocknanosleep2
   1.322 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.323 +// API tested: clock_nanosleep()
   1.324 +// Description: Trying to suspend the process for the specified time using clock_nanosleep()
   1.325 +// Absolute timer
   1.326 +// -----------------------------------------------------------------------------
   1.327 +
   1.328 +TInt CTestclock::Testclocknanosleep2 (  )
   1.329 +	{
   1.330 +	int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec;
   1.331 +	struct timespec gettmspec, oldtmpsec, sleeptmspec, sleeptmspec1;
   1.332 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   1.333 +	if(ret == 0)
   1.334 +		{
   1.335 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   1.336 +	 	goto close;
   1.337 +	  	}
   1.338 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   1.339 +	if(ret == 0)
   1.340 +		{
   1.341 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   1.342 +	 	goto close;
   1.343 +	  	}
   1.344 +	sleeptmspec.tv_sec = Valuesec;
   1.345 +	sleeptmspec.tv_nsec = Valuenanosec;
   1.346 +	ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
   1.347 +	if (ret != 0)
   1.348 +		{
   1.349 +	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
   1.350 +	 	goto close;	
   1.351 +		}	
   1.352 +	oldtmpsec = gettmspec;
   1.353 +	sleeptmspec.tv_sec = gettmspec.tv_sec + Valuesec;
   1.354 +	sleeptmspec.tv_nsec = gettmspec.tv_nsec + Valuenanosec;
   1.355 +	ret = clock_nanosleep(CLOCK_REALTIME,TIMER_ABSTIME,&sleeptmspec,&sleeptmspec1);
   1.356 +	if (ret != 0) 
   1.357 +		{
   1.358 +	 	ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno);
   1.359 +	 	goto close;			
   1.360 +		}
   1.361 +	ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
   1.362 +	if (ret != 0)
   1.363 +		{
   1.364 +	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
   1.365 +	 	goto close;	
   1.366 +		}	
   1.367 +	if (gettmspec.tv_sec < (oldtmpsec.tv_sec + Valuesec))
   1.368 +		{
   1.369 +	 	ERR_PRINTF2(_L("clock_nanosleep() has failed to sleep for %d secs"),Valuesec);
   1.370 +	 	goto close;			
   1.371 +		}
   1.372 +	INFO_PRINTF1(_L("Absolute timer"));
   1.373 +	INFO_PRINTF2(_L("clock_nanosleep() successfully able to sleep for %d secs"),Valuesec );
   1.374 +	ret1 = KErrNone;
   1.375 +	
   1.376 +	close:
   1.377 +	return ret1;	
   1.378 +	}
   1.379 +
   1.380 +// -----------------------------------------------------------------------------
   1.381 +// CTestclock::Testclocknanosleep3
   1.382 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.383 +// API tested: clock_nanosleep()
   1.384 +// Description: Trying to suspend the process for an invalid time using clock_nanosleep() in the absence of TIMER_ABSTIME 
   1.385 +// -----------------------------------------------------------------------------
   1.386 +
   1.387 +TInt CTestclock::Testclocknanosleep3 (  )
   1.388 +	{
   1.389 +	int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec;
   1.390 +	struct timespec sleeptmspec;
   1.391 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   1.392 +	if(ret == 0)
   1.393 +		{
   1.394 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   1.395 +	 	goto close;
   1.396 +	  	}
   1.397 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   1.398 +	if(ret == 0)
   1.399 +		{
   1.400 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   1.401 +	 	goto close;
   1.402 +	  	}
   1.403 +	sleeptmspec.tv_sec = Valuesec;
   1.404 +	sleeptmspec.tv_nsec = Valuenanosec;
   1.405 +	ret = clock_nanosleep(CLOCK_REALTIME,0,&sleeptmspec,NULL);
   1.406 +	if ((ret != -1) || (errno != EINVAL)) 
   1.407 +		{
   1.408 +	 	ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno);
   1.409 +	 	goto close;			
   1.410 +		}
   1.411 +	INFO_PRINTF1(_L("clock_nanosleep() successfully able to sleep for 2 secs") );
   1.412 +	ret1 = KErrNone;
   1.413 +	
   1.414 +	close:
   1.415 +	return ret1;	
   1.416 +	}
   1.417 +
   1.418 +// -----------------------------------------------------------------------------
   1.419 +// CTestclock::Testclocknanosleep4
   1.420 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.421 +// API tested: clock_nanosleep()
   1.422 +// Description: Trying to suspend the process with an invalid clock id clock_nanosleep() 
   1.423 +// -----------------------------------------------------------------------------
   1.424 +
   1.425 +TInt CTestclock::Testclocknanosleep4 (  )
   1.426 +	{
   1.427 +	int ret, ret1 = KErrGeneral, Invalidid;
   1.428 +	struct timespec sleeptmspec;
   1.429 +	ret = GetIntFromConfig(ConfigSection(), _L("Invalidid"), Invalidid);
   1.430 +	if(ret == 0)
   1.431 +		{
   1.432 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   1.433 +	 	goto close;
   1.434 +	  	}
   1.435 +	sleeptmspec.tv_sec = 2;
   1.436 +	sleeptmspec.tv_nsec = 0;
   1.437 +	ret = clock_nanosleep(Invalidid,0,&sleeptmspec,NULL);
   1.438 +	if ((ret != -1) || (errno != EINVAL)) 
   1.439 +		{
   1.440 +	 	ERR_PRINTF2(_L("clock_nanosleep() failed to return EINVAL and errno is %d"),errno);
   1.441 +	 	goto close;			
   1.442 +		}
   1.443 +	INFO_PRINTF1(_L("clock_nanosleep() successfully able to return EINVAL ") );
   1.444 +	ret1 = KErrNone;
   1.445 +	
   1.446 +	close:
   1.447 +	return ret1;	
   1.448 +	}
   1.449 +
   1.450 +// -----------------------------------------------------------------------------
   1.451 +// CTestclock::Testclocknanosleep5
   1.452 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.453 +// API tested: clock_nanosleep()
   1.454 +// Description: clock_nanosleep() with an invalid parameter of timespec 
   1.455 +// -----------------------------------------------------------------------------
   1.456 +
   1.457 +TInt CTestclock::Testclocknanosleep5 (  )
   1.458 +	{
   1.459 +	int ret, ret1 = KErrGeneral;
   1.460 +	ret = clock_nanosleep(CLOCK_REALTIME,0,NULL,NULL);
   1.461 +	if ((ret != -1) || (errno != EFAULT)) 
   1.462 +		{
   1.463 +	 	ERR_PRINTF2(_L("clock_nanosleep() failed to return EINVAL and errno is %d"),errno);
   1.464 +	 	goto close;			
   1.465 +		}
   1.466 +	INFO_PRINTF1(_L("clock_nanosleep() successfully able to return EINVAL ") );
   1.467 +	ret1 = KErrNone;
   1.468 +	
   1.469 +	close:
   1.470 +	return ret1;	
   1.471 +	}
   1.472 +
   1.473 +// -----------------------------------------------------------------------------
   1.474 +// CTestclock::Testclocknanosleep6
   1.475 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.476 +// API tested: clock_nanosleep()
   1.477 +// Description: clock_nanosleep() with a flag other than Absolute value
   1.478 +// -----------------------------------------------------------------------------
   1.479 +
   1.480 +TInt CTestclock::Testclocknanosleep6 (  )
   1.481 +	{
   1.482 +	int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec;
   1.483 +	struct timespec gettmspec, oldtmpsec, sleeptmspec, sleeptmspec1;
   1.484 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
   1.485 +	if(ret == 0)
   1.486 +		{
   1.487 +	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
   1.488 +	 	goto close;
   1.489 +	  	}
   1.490 +	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
   1.491 +	if(ret == 0)
   1.492 +		{
   1.493 +	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
   1.494 +	 	goto close;
   1.495 +	  	}
   1.496 +	sleeptmspec.tv_sec = Valuesec;
   1.497 +	sleeptmspec.tv_nsec = Valuenanosec;
   1.498 +	ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
   1.499 +	if (ret != 0)
   1.500 +		{
   1.501 +	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
   1.502 +	 	goto close;	
   1.503 +		}	
   1.504 +	oldtmpsec = gettmspec;
   1.505 +	ret = clock_nanosleep(CLOCK_REALTIME,15,&sleeptmspec,&sleeptmspec1);
   1.506 +	if (ret != 0) 
   1.507 +		{
   1.508 +	 	ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno);
   1.509 +	 	goto close;			
   1.510 +		}
   1.511 +	ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
   1.512 +	if (ret != 0)
   1.513 +		{
   1.514 +	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
   1.515 +	 	goto close;	
   1.516 +		}	
   1.517 +	if (gettmspec.tv_sec != (oldtmpsec.tv_sec + Valuesec))
   1.518 +		{
   1.519 +	 	ERR_PRINTF2(_L("clock_nanosleep() has failed to sleep for %d secs"),Valuesec);
   1.520 +	 	goto close;			
   1.521 +		}
   1.522 +	INFO_PRINTF1(_L("Relative timer"));
   1.523 +	INFO_PRINTF2(_L("clock_nanosleep() successfully able to sleep for %d secs"),Valuesec );
   1.524 +	ret1 = KErrNone;
   1.525 +	
   1.526 +	close:
   1.527 +	return ret1;	
   1.528 +	}
   1.529 +
   1.530 +// -----------------------------------------------------------------------------
   1.531 +// CTestclock::Testclockgettime1
   1.532 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.533 +// API tested: clock_gettime()
   1.534 +// Description: To get the current value for the specified valid clock_id<CLOCK_REALTIME> 
   1.535 +// -----------------------------------------------------------------------------
   1.536 +
   1.537 +TInt CTestclock::Testclockgettime1 (  )
   1.538 +	{
   1.539 +	int ret, ret1 = KErrGeneral;
   1.540 +	clockid_t clockid;
   1.541 +	struct timespec tmspec, oldtmspec;
   1.542 +	ret = clock_getcpuclockid(0,&clockid);
   1.543 +	if (ret != 0)
   1.544 +		{
   1.545 +	 	ERR_PRINTF2(_L("Failed to retrieve the clock id of the calling process and errno is %d"),errno);
   1.546 +	 	goto close;	
   1.547 +		}
   1.548 +	ret = clock_gettime(clockid,&tmspec);
   1.549 +	if (ret != 0)
   1.550 +		{
   1.551 +	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
   1.552 +	 	goto close;	
   1.553 +		}	
   1.554 +	sleep(2);
   1.555 +	oldtmspec = tmspec;
   1.556 +	ret = clock_gettime(clockid,&tmspec);
   1.557 +	if (ret != 0)
   1.558 +		{
   1.559 +	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
   1.560 +	 	goto close;	
   1.561 +		}
   1.562 +	if (tmspec.tv_sec != (oldtmspec.tv_sec + 2))
   1.563 +		{
   1.564 +	 	ERR_PRINTF1(_L("Failed to retrieve resolution of the clock id specified"));
   1.565 +	 	goto close;			
   1.566 +		}
   1.567 +	INFO_PRINTF1(_L("clock_gettime() successfully able to get the time") );
   1.568 +	ret1 = KErrNone;
   1.569 +	
   1.570 +	close:
   1.571 +	return ret1;	
   1.572 +	}
   1.573 +
   1.574 +// -----------------------------------------------------------------------------
   1.575 +// CTestclock::Testclockgettime2
   1.576 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.577 +// API tested: clock_gettime()
   1.578 +// Description: Trying to get the current time value for an invalid clock id using clock_gettime()  
   1.579 +// -----------------------------------------------------------------------------
   1.580 +
   1.581 +TInt CTestclock::Testclockgettime2 (  )
   1.582 +	{
   1.583 +	int ret, ret1 = KErrGeneral, Clockid, Error;
   1.584 +	struct timespec tmspec;
   1.585 +	ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); 
   1.586 +	if(ret == 0)
   1.587 +		{
   1.588 +	 	ERR_PRINTF1(_L("Unable to clock id value")) ;
   1.589 +	 	goto close;
   1.590 +	  	}
   1.591 +	ret = GetIntFromConfig(ConfigSection(), _L("Error"), Error); 
   1.592 +	if(ret == 0)
   1.593 +		{
   1.594 +	 	ERR_PRINTF1(_L("Unable to read expected error num")) ;
   1.595 +	 	goto close;
   1.596 +	  	}
   1.597 +	ret = clock_gettime(Clockid,&tmspec);
   1.598 +	if ((ret != -1) || (errno != Error)) 
   1.599 +		{
   1.600 +	 	ERR_PRINTF2(_L("clock_gettime() failed to return EINVAL for an invalid clock id and errno is %d"),errno);
   1.601 +	 	goto close;	
   1.602 +		}	
   1.603 +	INFO_PRINTF1(_L("clock_gettime() successfully returned EINVAL for an invalid clock id") );
   1.604 +	ret1 = KErrNone;
   1.605 +	
   1.606 +	close:
   1.607 +	return ret1;	
   1.608 +	}
   1.609 +
   1.610 +// -----------------------------------------------------------------------------
   1.611 +// CTestclock::Testclockgettime3
   1.612 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.613 +// API tested: clock_gettime()
   1.614 +// Description: Trying to get the current time value for a valid clock id with NULL as the timespec using clock_gettime()   
   1.615 +// -----------------------------------------------------------------------------
   1.616 +
   1.617 +TInt CTestclock::Testclockgettime3 (  )
   1.618 +	{
   1.619 +	int ret, ret1 = KErrGeneral, Clockid;
   1.620 +	ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); 
   1.621 +	if(ret == 0)
   1.622 +		{
   1.623 +		ERR_PRINTF1(_L("Unable to read clock id value")) ;
   1.624 +	 	goto close;
   1.625 +	  	}
   1.626 +	ret = clock_gettime(Clockid,NULL);
   1.627 +	if ((ret != -1) || (errno != EFAULT)) 
   1.628 +		{
   1.629 +	 	ERR_PRINTF2(_L("clock_gettime() failed to return EFAULT for NULL timespec parameter and errno is %d"),errno);
   1.630 +	 	goto close;	
   1.631 +		}	
   1.632 +	INFO_PRINTF1(_L("clock_gettime() successfully returned EFAULT for NULL timespec parameter ") );
   1.633 +	ret1 = KErrNone;
   1.634 +		
   1.635 +	close:
   1.636 +	return ret1;	
   1.637 +	}
   1.638 +
   1.639 +// -----------------------------------------------------------------------------
   1.640 +// CTestclock::Testclocksettime1
   1.641 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.642 +// API tested: clock_settime()
   1.643 +// Description: Trying to set the current time value for an invalid clock id using clock_settime()  
   1.644 +// -----------------------------------------------------------------------------
   1.645 +
   1.646 +TInt CTestclock::Testclocksettime1 (  )
   1.647 +	{
   1.648 +	int ret, ret1 = KErrGeneral, Clockid, Error;
   1.649 +	struct timespec tmspec;
   1.650 +	tmspec.tv_sec = 30;
   1.651 +	tmspec.tv_nsec = 2000;
   1.652 +	ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); 
   1.653 +	if(ret == 0)
   1.654 +		{
   1.655 +		ERR_PRINTF1(_L("Unable to read clock id value")) ;
   1.656 +	 	goto close;
   1.657 +	  	}
   1.658 +	ret = GetIntFromConfig(ConfigSection(), _L("Error"), Error); 
   1.659 +	if(ret == 0)
   1.660 +		{
   1.661 +	 	ERR_PRINTF1(_L("Unable to read expected error num")) ;
   1.662 +	 	goto close;
   1.663 +	  	}
   1.664 +	ret = clock_settime(Clockid,&tmspec);
   1.665 +	if ((ret != -1) || (errno != Error)) 
   1.666 +		{
   1.667 +	 	ERR_PRINTF2(_L("clock_settime() failed on negative test and errno is %d"),errno);
   1.668 +	 	goto close;	
   1.669 +		}	
   1.670 +	INFO_PRINTF1(_L("clock_settime() is successfull on negative test") );
   1.671 +	ret1 = KErrNone;
   1.672 +	
   1.673 +	close:
   1.674 +	return ret1;	
   1.675 +	}
   1.676 +
   1.677 +// -----------------------------------------------------------------------------
   1.678 +// CTestclock::Testclocksettime2
   1.679 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.680 +// API tested: clock_settime()
   1.681 +// Description: clock_settime() with NULL as the timespec parameter  
   1.682 +// -----------------------------------------------------------------------------
   1.683 +
   1.684 +TInt CTestclock::Testclocksettime2 (  )
   1.685 +	{
   1.686 +	int ret, ret1 = KErrGeneral, Clockid;
   1.687 +	ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); 
   1.688 +	if(ret == 0)
   1.689 +		{
   1.690 +		ERR_PRINTF1(_L("Unable to read clock id value")) ;
   1.691 +	 	goto close;
   1.692 +	  	}
   1.693 +	ret = clock_settime(Clockid,NULL);
   1.694 +	if ((ret != -1) || (errno != EFAULT)) 
   1.695 +		{
   1.696 +	 	ERR_PRINTF2(_L("clock_settime() failed to return EFAULT on negative test and errno is %d"),errno);
   1.697 +	 	goto close;	
   1.698 +		}	
   1.699 +	INFO_PRINTF1(_L("clock_settime() successfully returned EFAULT on negative test") );
   1.700 +	ret1 = KErrNone;
   1.701 +	
   1.702 +	close:
   1.703 +	return ret1;	
   1.704 +	}
   1.705 +
   1.706 +// -----------------------------------------------------------------------------
   1.707 +// CTestclock::Testclocksettime3
   1.708 +// Test Case ID: OPENENV-LIBC-CIT-5946
   1.709 +// API tested: clock_settime()
   1.710 +// Description: Test case added to set the value of clock id current value to an invalid specified value using clock_settime()
   1.711 +// -----------------------------------------------------------------------------
   1.712 +
   1.713 +TInt CTestclock::Testclocksettime3 (  )
   1.714 +	{
   1.715 +	int ret, ret1 = KErrGeneral, Clockid, Valuesec, Valuenanosec;
   1.716 +	struct timespec tmspec;
   1.717 +	ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); 
   1.718 +	if(ret == 0)
   1.719 +		{
   1.720 +		ERR_PRINTF1(_L("Unable to read clock id value")) ;
   1.721 +	 	goto close;
   1.722 +	  	}
   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 +	 	goto close;
   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 +	 	goto close;
   1.734 +	  	}
   1.735 +	tmspec.tv_sec = Valuesec;
   1.736 +	tmspec.tv_nsec = Valuenanosec;
   1.737 +	ret = clock_settime(Clockid,&tmspec);
   1.738 +	if ((ret != -1) || (errno != EINVAL)) 
   1.739 +		{
   1.740 +	 	ERR_PRINTF2(_L("clock_settime() failed to return EINVAL on negative test and errno is %d"),errno);
   1.741 +	 	goto close;	
   1.742 +		}	
   1.743 +	INFO_PRINTF1(_L("clock_settime() successfully returned EINVAL on negative test") );
   1.744 +	ret1 = KErrNone;
   1.745 +	
   1.746 +	close:
   1.747 +	return ret1;	
   1.748 +	}
   1.749 +
   1.750 +//End of a file