os/ossrv/genericopenlibs/posixrealtimeextensions/test/testclock/src/tclockblocks.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Name        : tclockblocks.cpp
sl@0
    15
// Test cases for blocking signal api's
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include "tclock.h"
sl@0
    20
sl@0
    21
// -----------------------------------------------------------------------------
sl@0
    22
// CTestclock::Testgetclockid1
sl@0
    23
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
    24
// API tested: clock_getcpuclockid()
sl@0
    25
// Description: To access the clock id of CPU time clock with pid = 0. API tested: clock_getcpuclockid()
sl@0
    26
// -----------------------------------------------------------------------------
sl@0
    27
sl@0
    28
TInt CTestclock::Testgetclockid1 (  )
sl@0
    29
	{
sl@0
    30
	int ret, ret1 = KErrGeneral;
sl@0
    31
	clockid_t clockid;
sl@0
    32
	ret = clock_getcpuclockid(0,&clockid);
sl@0
    33
	if (ret != 0)
sl@0
    34
		{
sl@0
    35
	 	ERR_PRINTF2(_L("Failed to retrieve the clock id of the calling process and errno is %d"),errno);
sl@0
    36
	 	goto close;	
sl@0
    37
		}
sl@0
    38
	if (clockid != CLOCK_REALTIME)
sl@0
    39
		{
sl@0
    40
	 	ERR_PRINTF1(_L("Failed to return the right clock id"));
sl@0
    41
	 	goto close;	
sl@0
    42
		}
sl@0
    43
	INFO_PRINTF1(_L("Successfully able to get the calling process's clock id") );
sl@0
    44
	ret1 = KErrNone;
sl@0
    45
	
sl@0
    46
	close:
sl@0
    47
	return ret1;	
sl@0
    48
	}
sl@0
    49
sl@0
    50
// -----------------------------------------------------------------------------
sl@0
    51
// CTestclock::Testgetclockid2
sl@0
    52
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
    53
// API tested: clock_getcpuclockid()
sl@0
    54
// Description:  To access the clock id of CPU time clock of self. API tested: clock_getcpuclockid() 
sl@0
    55
// -----------------------------------------------------------------------------
sl@0
    56
sl@0
    57
TInt CTestclock::Testgetclockid2 (  )
sl@0
    58
	{
sl@0
    59
	int ret, ret1 = KErrGeneral;
sl@0
    60
	clockid_t clockid;
sl@0
    61
	ret = clock_getcpuclockid(getpid(),&clockid);
sl@0
    62
	if ((ret != -1) || (errno !=  ESRCH))
sl@0
    63
		{
sl@0
    64
	 	ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno);
sl@0
    65
	 	goto close;	
sl@0
    66
		}
sl@0
    67
	INFO_PRINTF1(_L("clock_getcpuclockid() is successful on negative test") );
sl@0
    68
	ret1 = KErrNone;
sl@0
    69
	
sl@0
    70
	close:
sl@0
    71
	return ret1;
sl@0
    72
	}
sl@0
    73
sl@0
    74
// -----------------------------------------------------------------------------
sl@0
    75
// CTestclock::Testgetclockid3
sl@0
    76
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
    77
// API tested: clock_getcpuclockid()
sl@0
    78
// Description: To access the clock id of CPU time clock of other process 
sl@0
    79
// -----------------------------------------------------------------------------
sl@0
    80
sl@0
    81
TInt CTestclock::Testgetclockid3 (  )
sl@0
    82
	{
sl@0
    83
	int ret, ret1 = KErrGeneral;
sl@0
    84
	pid_t pid;
sl@0
    85
	clockid_t clockid;
sl@0
    86
	char **argv = (char **)malloc(2*sizeof(char*));
sl@0
    87
	argv[0] = (char *)malloc(30*sizeof(char*));
sl@0
    88
	argv[1] = 0;
sl@0
    89
	strcpy(argv[0],"z:\\sys\\bin\\getclockid.exe");
sl@0
    90
	ret = posix_spawn(&pid, "z:\\sys\\bin\\getclockid.exe", NULL, NULL, argv, (char**)NULL);
sl@0
    91
	if(ret != 0)
sl@0
    92
		{
sl@0
    93
		ERR_PRINTF2(_L("Error in posix spawn and errno is set to %d"),errno);
sl@0
    94
		goto close;
sl@0
    95
		}
sl@0
    96
	ret = clock_getcpuclockid(pid,&clockid);
sl@0
    97
	if ((ret != -1) || (errno !=  ESRCH))
sl@0
    98
		{
sl@0
    99
	 	ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno);
sl@0
   100
	 	goto close;	
sl@0
   101
		}
sl@0
   102
	INFO_PRINTF1(_L("clock_getcpuclockid() is successful on negative test") );
sl@0
   103
	ret1 = KErrNone;
sl@0
   104
	
sl@0
   105
	close:
sl@0
   106
	free((void*)argv[0]);
sl@0
   107
	free((void*)argv);
sl@0
   108
	return ret1;	
sl@0
   109
	}
sl@0
   110
sl@0
   111
// -----------------------------------------------------------------------------
sl@0
   112
// CTestclock::Testgetclockid4
sl@0
   113
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
   114
// API tested: clock_getcpuclockid()
sl@0
   115
// Description: To access the clock id of CPU time clock of an invalid process. 
sl@0
   116
// -----------------------------------------------------------------------------
sl@0
   117
sl@0
   118
TInt CTestclock::Testgetclockid4 (  )
sl@0
   119
	{
sl@0
   120
	int ret, ret1 = KErrGeneral;
sl@0
   121
	clockid_t clockid;
sl@0
   122
	ret = clock_getcpuclockid(-1,&clockid);
sl@0
   123
	if ((ret != -1) || (errno !=  ESRCH))
sl@0
   124
		{
sl@0
   125
	 	ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno);
sl@0
   126
	 	goto close;	
sl@0
   127
		}
sl@0
   128
	INFO_PRINTF1(_L("clock_getcpuclockid() has successfully returned ESRCH on negative test") );
sl@0
   129
	ret1 = KErrNone;
sl@0
   130
	
sl@0
   131
	close:
sl@0
   132
	return ret1;		
sl@0
   133
	}
sl@0
   134
sl@0
   135
// -----------------------------------------------------------------------------
sl@0
   136
// CTestclock::Testgetclockid5
sl@0
   137
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
   138
// API tested: clock_getcpuclockid()
sl@0
   139
// Description: Trying to access the clock id of an invalid id passing to it.
sl@0
   140
// -----------------------------------------------------------------------------
sl@0
   141
sl@0
   142
TInt CTestclock::Testgetclockid5 (  )
sl@0
   143
	{
sl@0
   144
	int ret, ret1 = KErrGeneral;
sl@0
   145
	ret = clock_getcpuclockid(0,NULL);
sl@0
   146
	if ((ret != -1) || (errno !=  EFAULT))
sl@0
   147
		{
sl@0
   148
	 	ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno);
sl@0
   149
	 	goto close;	
sl@0
   150
		}
sl@0
   151
	INFO_PRINTF1(_L("clock_getcpuclockid() has successfully returned EFAULT on negative test") );
sl@0
   152
	ret1 = KErrNone;
sl@0
   153
	
sl@0
   154
	close:
sl@0
   155
	return ret1;			
sl@0
   156
	}
sl@0
   157
sl@0
   158
// -----------------------------------------------------------------------------
sl@0
   159
// CTestclock::Testclockresolution1
sl@0
   160
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
   161
// API tested: clock_getres()
sl@0
   162
// Description: To get the clock resolution with valid clock id using clock_getres() 
sl@0
   163
// -----------------------------------------------------------------------------
sl@0
   164
sl@0
   165
TInt CTestclock::Testclockresolution1 (  )
sl@0
   166
	{
sl@0
   167
	int ret, ret1 = KErrGeneral;
sl@0
   168
	clockid_t clockid;
sl@0
   169
	struct timespec tmspec;
sl@0
   170
	ret = clock_getcpuclockid(0,&clockid);
sl@0
   171
	if (ret != 0)
sl@0
   172
		{
sl@0
   173
	 	ERR_PRINTF2(_L("Failed to retrieve the clock id of the calling process and errno is %d"),errno);
sl@0
   174
	 	goto close;	
sl@0
   175
		}
sl@0
   176
	ret = clock_getres(clockid,&tmspec);
sl@0
   177
	if (ret != 0)
sl@0
   178
		{
sl@0
   179
	 	ERR_PRINTF2(_L("Failed to retrieve resolution of the clock id specified and errno is %d"),errno);
sl@0
   180
	 	goto close;	
sl@0
   181
		}	
sl@0
   182
	if ((tmspec.tv_nsec != 1000) || (tmspec.tv_sec != 0))
sl@0
   183
		{
sl@0
   184
	 	ERR_PRINTF1(_L("Resolution of the clock id is not set properly"));
sl@0
   185
	 	goto close;			
sl@0
   186
		}
sl@0
   187
	INFO_PRINTF1(_L("Successfully able to get the clock resolution of the specified clock id") );
sl@0
   188
	ret1 = KErrNone;
sl@0
   189
	
sl@0
   190
	close:
sl@0
   191
	return ret1;		
sl@0
   192
	}
sl@0
   193
sl@0
   194
// -----------------------------------------------------------------------------
sl@0
   195
// CTestclock::Testclockresolution2
sl@0
   196
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
   197
// API tested: clock_getres()
sl@0
   198
// Description: Trying to get the clock resolution using clock_getres() for a clockid other than CLOCK_REALTIME 
sl@0
   199
// -----------------------------------------------------------------------------
sl@0
   200
sl@0
   201
TInt CTestclock::Testclockresolution2 (  )
sl@0
   202
	{
sl@0
   203
	int ret, ret1 = KErrGeneral, Clockid, Error;
sl@0
   204
	struct timespec tmspec;
sl@0
   205
	ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); 
sl@0
   206
	if(ret == 0)
sl@0
   207
		{
sl@0
   208
	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
sl@0
   209
	 	goto close;
sl@0
   210
	  	}
sl@0
   211
	ret = GetIntFromConfig(ConfigSection(), _L("Error"), Error); 
sl@0
   212
	if(ret == 0)
sl@0
   213
		{
sl@0
   214
	 	ERR_PRINTF1(_L("Unable to read expected error num")) ;
sl@0
   215
	 	goto close;
sl@0
   216
	  	}
sl@0
   217
	ret = clock_getres(Clockid,&tmspec);
sl@0
   218
	if ((ret != -1) || (errno != Error))
sl@0
   219
		{
sl@0
   220
	 	ERR_PRINTF2(_L("The expected and errno are not same and errno is %d"),errno);
sl@0
   221
	 	goto close;			
sl@0
   222
		}
sl@0
   223
	INFO_PRINTF1(_L("The output and expected value are same for clock_getres()") );
sl@0
   224
	ret1 = KErrNone;
sl@0
   225
	
sl@0
   226
	close:
sl@0
   227
	return ret1;
sl@0
   228
	}
sl@0
   229
sl@0
   230
// -----------------------------------------------------------------------------
sl@0
   231
// CTestclock::Testclockresolution3
sl@0
   232
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
   233
// API tested: clock_getres()
sl@0
   234
// Description: Negative Test: Trying to get the resolution with res = NULL using clock_getres() 
sl@0
   235
// -----------------------------------------------------------------------------
sl@0
   236
sl@0
   237
TInt CTestclock::Testclockresolution3 (  )
sl@0
   238
	{
sl@0
   239
	int ret, ret1 = KErrGeneral, Clockid;
sl@0
   240
	ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); 
sl@0
   241
	if(ret == 0)
sl@0
   242
		{
sl@0
   243
	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
sl@0
   244
	 	goto close;
sl@0
   245
	  	}
sl@0
   246
	ret = clock_getres(Clockid,NULL);
sl@0
   247
	if (ret != 0) 
sl@0
   248
		{
sl@0
   249
	 	ERR_PRINTF2(_L("clock_getres() failed on negative test if timespec argument is NULL and errno is %d"),errno);
sl@0
   250
	 	goto close;	
sl@0
   251
		}	
sl@0
   252
	INFO_PRINTF1(_L("clock_getres() successfully returned 0 on negative test") );
sl@0
   253
	ret1 = KErrNone;
sl@0
   254
	
sl@0
   255
	close:
sl@0
   256
	return ret1;
sl@0
   257
	}
sl@0
   258
sl@0
   259
// -----------------------------------------------------------------------------
sl@0
   260
// CTestclock::Testclocknanosleep1
sl@0
   261
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
   262
// API tested: clock_nanosleep()
sl@0
   263
// Description: Trying to suspend the process for the specified time using clock_nanosleep() in the absence of TIMER_ABSTIME
sl@0
   264
// Relative timer
sl@0
   265
// -----------------------------------------------------------------------------
sl@0
   266
sl@0
   267
TInt CTestclock::Testclocknanosleep1 (  )
sl@0
   268
	{
sl@0
   269
	int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec;
sl@0
   270
	struct timespec gettmspec, oldtmpsec, sleeptmspec, sleeptmspec1;
sl@0
   271
	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
sl@0
   272
	if(ret == 0)
sl@0
   273
		{
sl@0
   274
	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
sl@0
   275
	 	goto close;
sl@0
   276
	  	}
sl@0
   277
	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
sl@0
   278
	if(ret == 0)
sl@0
   279
		{
sl@0
   280
	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
sl@0
   281
	 	goto close;
sl@0
   282
	  	}
sl@0
   283
	sleeptmspec.tv_sec = Valuesec;
sl@0
   284
	sleeptmspec.tv_nsec = Valuenanosec;
sl@0
   285
	ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
sl@0
   286
	if (ret != 0)
sl@0
   287
		{
sl@0
   288
	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
sl@0
   289
	 	goto close;	
sl@0
   290
		}	
sl@0
   291
	oldtmpsec = gettmspec;
sl@0
   292
	ret = clock_nanosleep(CLOCK_REALTIME,0,&sleeptmspec,&sleeptmspec1);
sl@0
   293
	if (ret != 0) 
sl@0
   294
		{
sl@0
   295
	 	ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno);
sl@0
   296
	 	goto close;			
sl@0
   297
		}
sl@0
   298
	ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
sl@0
   299
	if (ret != 0)
sl@0
   300
		{
sl@0
   301
	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
sl@0
   302
	 	goto close;	
sl@0
   303
		}	
sl@0
   304
	if (gettmspec.tv_sec != (oldtmpsec.tv_sec + Valuesec))
sl@0
   305
		{
sl@0
   306
	 	ERR_PRINTF2(_L("clock_nanosleep() has failed to sleep for %d secs"),Valuesec);
sl@0
   307
	 	goto close;			
sl@0
   308
		}
sl@0
   309
	INFO_PRINTF1(_L("Relative timer"));
sl@0
   310
	INFO_PRINTF2(_L("clock_nanosleep() successfully able to sleep for %d secs"),Valuesec );
sl@0
   311
	ret1 = KErrNone;
sl@0
   312
	
sl@0
   313
	close:
sl@0
   314
	return ret1;	
sl@0
   315
	}
sl@0
   316
sl@0
   317
// -----------------------------------------------------------------------------
sl@0
   318
// CTestclock::Testclocknanosleep2
sl@0
   319
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
   320
// API tested: clock_nanosleep()
sl@0
   321
// Description: Trying to suspend the process for the specified time using clock_nanosleep()
sl@0
   322
// Absolute timer
sl@0
   323
// -----------------------------------------------------------------------------
sl@0
   324
sl@0
   325
TInt CTestclock::Testclocknanosleep2 (  )
sl@0
   326
	{
sl@0
   327
	int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec;
sl@0
   328
	struct timespec gettmspec, oldtmpsec, sleeptmspec, sleeptmspec1;
sl@0
   329
	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
sl@0
   330
	if(ret == 0)
sl@0
   331
		{
sl@0
   332
	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
sl@0
   333
	 	goto close;
sl@0
   334
	  	}
sl@0
   335
	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
sl@0
   336
	if(ret == 0)
sl@0
   337
		{
sl@0
   338
	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
sl@0
   339
	 	goto close;
sl@0
   340
	  	}
sl@0
   341
	sleeptmspec.tv_sec = Valuesec;
sl@0
   342
	sleeptmspec.tv_nsec = Valuenanosec;
sl@0
   343
	ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
sl@0
   344
	if (ret != 0)
sl@0
   345
		{
sl@0
   346
	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
sl@0
   347
	 	goto close;	
sl@0
   348
		}	
sl@0
   349
	oldtmpsec = gettmspec;
sl@0
   350
	sleeptmspec.tv_sec = gettmspec.tv_sec + Valuesec;
sl@0
   351
	sleeptmspec.tv_nsec = gettmspec.tv_nsec + Valuenanosec;
sl@0
   352
	ret = clock_nanosleep(CLOCK_REALTIME,TIMER_ABSTIME,&sleeptmspec,&sleeptmspec1);
sl@0
   353
	if (ret != 0) 
sl@0
   354
		{
sl@0
   355
	 	ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno);
sl@0
   356
	 	goto close;			
sl@0
   357
		}
sl@0
   358
	ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
sl@0
   359
	if (ret != 0)
sl@0
   360
		{
sl@0
   361
	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
sl@0
   362
	 	goto close;	
sl@0
   363
		}	
sl@0
   364
	if (gettmspec.tv_sec < (oldtmpsec.tv_sec + Valuesec))
sl@0
   365
		{
sl@0
   366
	 	ERR_PRINTF2(_L("clock_nanosleep() has failed to sleep for %d secs"),Valuesec);
sl@0
   367
	 	goto close;			
sl@0
   368
		}
sl@0
   369
	INFO_PRINTF1(_L("Absolute timer"));
sl@0
   370
	INFO_PRINTF2(_L("clock_nanosleep() successfully able to sleep for %d secs"),Valuesec );
sl@0
   371
	ret1 = KErrNone;
sl@0
   372
	
sl@0
   373
	close:
sl@0
   374
	return ret1;	
sl@0
   375
	}
sl@0
   376
sl@0
   377
// -----------------------------------------------------------------------------
sl@0
   378
// CTestclock::Testclocknanosleep3
sl@0
   379
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
   380
// API tested: clock_nanosleep()
sl@0
   381
// Description: Trying to suspend the process for an invalid time using clock_nanosleep() in the absence of TIMER_ABSTIME 
sl@0
   382
// -----------------------------------------------------------------------------
sl@0
   383
sl@0
   384
TInt CTestclock::Testclocknanosleep3 (  )
sl@0
   385
	{
sl@0
   386
	int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec;
sl@0
   387
	struct timespec sleeptmspec;
sl@0
   388
	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
sl@0
   389
	if(ret == 0)
sl@0
   390
		{
sl@0
   391
	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
sl@0
   392
	 	goto close;
sl@0
   393
	  	}
sl@0
   394
	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
sl@0
   395
	if(ret == 0)
sl@0
   396
		{
sl@0
   397
	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
sl@0
   398
	 	goto close;
sl@0
   399
	  	}
sl@0
   400
	sleeptmspec.tv_sec = Valuesec;
sl@0
   401
	sleeptmspec.tv_nsec = Valuenanosec;
sl@0
   402
	ret = clock_nanosleep(CLOCK_REALTIME,0,&sleeptmspec,NULL);
sl@0
   403
	if ((ret != -1) || (errno != EINVAL)) 
sl@0
   404
		{
sl@0
   405
	 	ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno);
sl@0
   406
	 	goto close;			
sl@0
   407
		}
sl@0
   408
	INFO_PRINTF1(_L("clock_nanosleep() successfully able to sleep for 2 secs") );
sl@0
   409
	ret1 = KErrNone;
sl@0
   410
	
sl@0
   411
	close:
sl@0
   412
	return ret1;	
sl@0
   413
	}
sl@0
   414
sl@0
   415
// -----------------------------------------------------------------------------
sl@0
   416
// CTestclock::Testclocknanosleep4
sl@0
   417
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
   418
// API tested: clock_nanosleep()
sl@0
   419
// Description: Trying to suspend the process with an invalid clock id clock_nanosleep() 
sl@0
   420
// -----------------------------------------------------------------------------
sl@0
   421
sl@0
   422
TInt CTestclock::Testclocknanosleep4 (  )
sl@0
   423
	{
sl@0
   424
	int ret, ret1 = KErrGeneral, Invalidid;
sl@0
   425
	struct timespec sleeptmspec;
sl@0
   426
	ret = GetIntFromConfig(ConfigSection(), _L("Invalidid"), Invalidid);
sl@0
   427
	if(ret == 0)
sl@0
   428
		{
sl@0
   429
	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
sl@0
   430
	 	goto close;
sl@0
   431
	  	}
sl@0
   432
	sleeptmspec.tv_sec = 2;
sl@0
   433
	sleeptmspec.tv_nsec = 0;
sl@0
   434
	ret = clock_nanosleep(Invalidid,0,&sleeptmspec,NULL);
sl@0
   435
	if ((ret != -1) || (errno != EINVAL)) 
sl@0
   436
		{
sl@0
   437
	 	ERR_PRINTF2(_L("clock_nanosleep() failed to return EINVAL and errno is %d"),errno);
sl@0
   438
	 	goto close;			
sl@0
   439
		}
sl@0
   440
	INFO_PRINTF1(_L("clock_nanosleep() successfully able to return EINVAL ") );
sl@0
   441
	ret1 = KErrNone;
sl@0
   442
	
sl@0
   443
	close:
sl@0
   444
	return ret1;	
sl@0
   445
	}
sl@0
   446
sl@0
   447
// -----------------------------------------------------------------------------
sl@0
   448
// CTestclock::Testclocknanosleep5
sl@0
   449
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
   450
// API tested: clock_nanosleep()
sl@0
   451
// Description: clock_nanosleep() with an invalid parameter of timespec 
sl@0
   452
// -----------------------------------------------------------------------------
sl@0
   453
sl@0
   454
TInt CTestclock::Testclocknanosleep5 (  )
sl@0
   455
	{
sl@0
   456
	int ret, ret1 = KErrGeneral;
sl@0
   457
	ret = clock_nanosleep(CLOCK_REALTIME,0,NULL,NULL);
sl@0
   458
	if ((ret != -1) || (errno != EFAULT)) 
sl@0
   459
		{
sl@0
   460
	 	ERR_PRINTF2(_L("clock_nanosleep() failed to return EINVAL and errno is %d"),errno);
sl@0
   461
	 	goto close;			
sl@0
   462
		}
sl@0
   463
	INFO_PRINTF1(_L("clock_nanosleep() successfully able to return EINVAL ") );
sl@0
   464
	ret1 = KErrNone;
sl@0
   465
	
sl@0
   466
	close:
sl@0
   467
	return ret1;	
sl@0
   468
	}
sl@0
   469
sl@0
   470
// -----------------------------------------------------------------------------
sl@0
   471
// CTestclock::Testclocknanosleep6
sl@0
   472
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
   473
// API tested: clock_nanosleep()
sl@0
   474
// Description: clock_nanosleep() with a flag other than Absolute value
sl@0
   475
// -----------------------------------------------------------------------------
sl@0
   476
sl@0
   477
TInt CTestclock::Testclocknanosleep6 (  )
sl@0
   478
	{
sl@0
   479
	int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec;
sl@0
   480
	struct timespec gettmspec, oldtmpsec, sleeptmspec, sleeptmspec1;
sl@0
   481
	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
sl@0
   482
	if(ret == 0)
sl@0
   483
		{
sl@0
   484
	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
sl@0
   485
	 	goto close;
sl@0
   486
	  	}
sl@0
   487
	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
sl@0
   488
	if(ret == 0)
sl@0
   489
		{
sl@0
   490
	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
sl@0
   491
	 	goto close;
sl@0
   492
	  	}
sl@0
   493
	sleeptmspec.tv_sec = Valuesec;
sl@0
   494
	sleeptmspec.tv_nsec = Valuenanosec;
sl@0
   495
	ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
sl@0
   496
	if (ret != 0)
sl@0
   497
		{
sl@0
   498
	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
sl@0
   499
	 	goto close;	
sl@0
   500
		}	
sl@0
   501
	oldtmpsec = gettmspec;
sl@0
   502
	ret = clock_nanosleep(CLOCK_REALTIME,15,&sleeptmspec,&sleeptmspec1);
sl@0
   503
	if (ret != 0) 
sl@0
   504
		{
sl@0
   505
	 	ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno);
sl@0
   506
	 	goto close;			
sl@0
   507
		}
sl@0
   508
	ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
sl@0
   509
	if (ret != 0)
sl@0
   510
		{
sl@0
   511
	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
sl@0
   512
	 	goto close;	
sl@0
   513
		}	
sl@0
   514
	if (gettmspec.tv_sec != (oldtmpsec.tv_sec + Valuesec))
sl@0
   515
		{
sl@0
   516
	 	ERR_PRINTF2(_L("clock_nanosleep() has failed to sleep for %d secs"),Valuesec);
sl@0
   517
	 	goto close;			
sl@0
   518
		}
sl@0
   519
	INFO_PRINTF1(_L("Relative timer"));
sl@0
   520
	INFO_PRINTF2(_L("clock_nanosleep() successfully able to sleep for %d secs"),Valuesec );
sl@0
   521
	ret1 = KErrNone;
sl@0
   522
	
sl@0
   523
	close:
sl@0
   524
	return ret1;	
sl@0
   525
	}
sl@0
   526
sl@0
   527
// -----------------------------------------------------------------------------
sl@0
   528
// CTestclock::Testclockgettime1
sl@0
   529
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
   530
// API tested: clock_gettime()
sl@0
   531
// Description: To get the current value for the specified valid clock_id<CLOCK_REALTIME> 
sl@0
   532
// -----------------------------------------------------------------------------
sl@0
   533
sl@0
   534
TInt CTestclock::Testclockgettime1 (  )
sl@0
   535
	{
sl@0
   536
	int ret, ret1 = KErrGeneral;
sl@0
   537
	clockid_t clockid;
sl@0
   538
	struct timespec tmspec, oldtmspec;
sl@0
   539
	ret = clock_getcpuclockid(0,&clockid);
sl@0
   540
	if (ret != 0)
sl@0
   541
		{
sl@0
   542
	 	ERR_PRINTF2(_L("Failed to retrieve the clock id of the calling process and errno is %d"),errno);
sl@0
   543
	 	goto close;	
sl@0
   544
		}
sl@0
   545
	ret = clock_gettime(clockid,&tmspec);
sl@0
   546
	if (ret != 0)
sl@0
   547
		{
sl@0
   548
	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
sl@0
   549
	 	goto close;	
sl@0
   550
		}	
sl@0
   551
	sleep(2);
sl@0
   552
	oldtmspec = tmspec;
sl@0
   553
	ret = clock_gettime(clockid,&tmspec);
sl@0
   554
	if (ret != 0)
sl@0
   555
		{
sl@0
   556
	 	ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
sl@0
   557
	 	goto close;	
sl@0
   558
		}
sl@0
   559
	if (tmspec.tv_sec != (oldtmspec.tv_sec + 2))
sl@0
   560
		{
sl@0
   561
	 	ERR_PRINTF1(_L("Failed to retrieve resolution of the clock id specified"));
sl@0
   562
	 	goto close;			
sl@0
   563
		}
sl@0
   564
	INFO_PRINTF1(_L("clock_gettime() successfully able to get the time") );
sl@0
   565
	ret1 = KErrNone;
sl@0
   566
	
sl@0
   567
	close:
sl@0
   568
	return ret1;	
sl@0
   569
	}
sl@0
   570
sl@0
   571
// -----------------------------------------------------------------------------
sl@0
   572
// CTestclock::Testclockgettime2
sl@0
   573
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
   574
// API tested: clock_gettime()
sl@0
   575
// Description: Trying to get the current time value for an invalid clock id using clock_gettime()  
sl@0
   576
// -----------------------------------------------------------------------------
sl@0
   577
sl@0
   578
TInt CTestclock::Testclockgettime2 (  )
sl@0
   579
	{
sl@0
   580
	int ret, ret1 = KErrGeneral, Clockid, Error;
sl@0
   581
	struct timespec tmspec;
sl@0
   582
	ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); 
sl@0
   583
	if(ret == 0)
sl@0
   584
		{
sl@0
   585
	 	ERR_PRINTF1(_L("Unable to clock id value")) ;
sl@0
   586
	 	goto close;
sl@0
   587
	  	}
sl@0
   588
	ret = GetIntFromConfig(ConfigSection(), _L("Error"), Error); 
sl@0
   589
	if(ret == 0)
sl@0
   590
		{
sl@0
   591
	 	ERR_PRINTF1(_L("Unable to read expected error num")) ;
sl@0
   592
	 	goto close;
sl@0
   593
	  	}
sl@0
   594
	ret = clock_gettime(Clockid,&tmspec);
sl@0
   595
	if ((ret != -1) || (errno != Error)) 
sl@0
   596
		{
sl@0
   597
	 	ERR_PRINTF2(_L("clock_gettime() failed to return EINVAL for an invalid clock id and errno is %d"),errno);
sl@0
   598
	 	goto close;	
sl@0
   599
		}	
sl@0
   600
	INFO_PRINTF1(_L("clock_gettime() successfully returned EINVAL for an invalid clock id") );
sl@0
   601
	ret1 = KErrNone;
sl@0
   602
	
sl@0
   603
	close:
sl@0
   604
	return ret1;	
sl@0
   605
	}
sl@0
   606
sl@0
   607
// -----------------------------------------------------------------------------
sl@0
   608
// CTestclock::Testclockgettime3
sl@0
   609
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
   610
// API tested: clock_gettime()
sl@0
   611
// Description: Trying to get the current time value for a valid clock id with NULL as the timespec using clock_gettime()   
sl@0
   612
// -----------------------------------------------------------------------------
sl@0
   613
sl@0
   614
TInt CTestclock::Testclockgettime3 (  )
sl@0
   615
	{
sl@0
   616
	int ret, ret1 = KErrGeneral, Clockid;
sl@0
   617
	ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); 
sl@0
   618
	if(ret == 0)
sl@0
   619
		{
sl@0
   620
		ERR_PRINTF1(_L("Unable to read clock id value")) ;
sl@0
   621
	 	goto close;
sl@0
   622
	  	}
sl@0
   623
	ret = clock_gettime(Clockid,NULL);
sl@0
   624
	if ((ret != -1) || (errno != EFAULT)) 
sl@0
   625
		{
sl@0
   626
	 	ERR_PRINTF2(_L("clock_gettime() failed to return EFAULT for NULL timespec parameter and errno is %d"),errno);
sl@0
   627
	 	goto close;	
sl@0
   628
		}	
sl@0
   629
	INFO_PRINTF1(_L("clock_gettime() successfully returned EFAULT for NULL timespec parameter ") );
sl@0
   630
	ret1 = KErrNone;
sl@0
   631
		
sl@0
   632
	close:
sl@0
   633
	return ret1;	
sl@0
   634
	}
sl@0
   635
sl@0
   636
// -----------------------------------------------------------------------------
sl@0
   637
// CTestclock::Testclocksettime1
sl@0
   638
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
   639
// API tested: clock_settime()
sl@0
   640
// Description: Trying to set the current time value for an invalid clock id using clock_settime()  
sl@0
   641
// -----------------------------------------------------------------------------
sl@0
   642
sl@0
   643
TInt CTestclock::Testclocksettime1 (  )
sl@0
   644
	{
sl@0
   645
	int ret, ret1 = KErrGeneral, Clockid, Error;
sl@0
   646
	struct timespec tmspec;
sl@0
   647
	tmspec.tv_sec = 30;
sl@0
   648
	tmspec.tv_nsec = 2000;
sl@0
   649
	ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); 
sl@0
   650
	if(ret == 0)
sl@0
   651
		{
sl@0
   652
		ERR_PRINTF1(_L("Unable to read clock id value")) ;
sl@0
   653
	 	goto close;
sl@0
   654
	  	}
sl@0
   655
	ret = GetIntFromConfig(ConfigSection(), _L("Error"), Error); 
sl@0
   656
	if(ret == 0)
sl@0
   657
		{
sl@0
   658
	 	ERR_PRINTF1(_L("Unable to read expected error num")) ;
sl@0
   659
	 	goto close;
sl@0
   660
	  	}
sl@0
   661
	ret = clock_settime(Clockid,&tmspec);
sl@0
   662
	if ((ret != -1) || (errno != Error)) 
sl@0
   663
		{
sl@0
   664
	 	ERR_PRINTF2(_L("clock_settime() failed on negative test and errno is %d"),errno);
sl@0
   665
	 	goto close;	
sl@0
   666
		}	
sl@0
   667
	INFO_PRINTF1(_L("clock_settime() is successfull on negative test") );
sl@0
   668
	ret1 = KErrNone;
sl@0
   669
	
sl@0
   670
	close:
sl@0
   671
	return ret1;	
sl@0
   672
	}
sl@0
   673
sl@0
   674
// -----------------------------------------------------------------------------
sl@0
   675
// CTestclock::Testclocksettime2
sl@0
   676
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
   677
// API tested: clock_settime()
sl@0
   678
// Description: clock_settime() with NULL as the timespec parameter  
sl@0
   679
// -----------------------------------------------------------------------------
sl@0
   680
sl@0
   681
TInt CTestclock::Testclocksettime2 (  )
sl@0
   682
	{
sl@0
   683
	int ret, ret1 = KErrGeneral, Clockid;
sl@0
   684
	ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); 
sl@0
   685
	if(ret == 0)
sl@0
   686
		{
sl@0
   687
		ERR_PRINTF1(_L("Unable to read clock id value")) ;
sl@0
   688
	 	goto close;
sl@0
   689
	  	}
sl@0
   690
	ret = clock_settime(Clockid,NULL);
sl@0
   691
	if ((ret != -1) || (errno != EFAULT)) 
sl@0
   692
		{
sl@0
   693
	 	ERR_PRINTF2(_L("clock_settime() failed to return EFAULT on negative test and errno is %d"),errno);
sl@0
   694
	 	goto close;	
sl@0
   695
		}	
sl@0
   696
	INFO_PRINTF1(_L("clock_settime() successfully returned EFAULT on negative test") );
sl@0
   697
	ret1 = KErrNone;
sl@0
   698
	
sl@0
   699
	close:
sl@0
   700
	return ret1;	
sl@0
   701
	}
sl@0
   702
sl@0
   703
// -----------------------------------------------------------------------------
sl@0
   704
// CTestclock::Testclocksettime3
sl@0
   705
// Test Case ID: OPENENV-LIBC-CIT-5946
sl@0
   706
// API tested: clock_settime()
sl@0
   707
// Description: Test case added to set the value of clock id current value to an invalid specified value using clock_settime()
sl@0
   708
// -----------------------------------------------------------------------------
sl@0
   709
sl@0
   710
TInt CTestclock::Testclocksettime3 (  )
sl@0
   711
	{
sl@0
   712
	int ret, ret1 = KErrGeneral, Clockid, Valuesec, Valuenanosec;
sl@0
   713
	struct timespec tmspec;
sl@0
   714
	ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid); 
sl@0
   715
	if(ret == 0)
sl@0
   716
		{
sl@0
   717
		ERR_PRINTF1(_L("Unable to read clock id value")) ;
sl@0
   718
	 	goto close;
sl@0
   719
	  	}
sl@0
   720
	ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
sl@0
   721
	if(ret == 0)
sl@0
   722
		{
sl@0
   723
	 	ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
sl@0
   724
	 	goto close;
sl@0
   725
	  	}
sl@0
   726
	ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
sl@0
   727
	if(ret == 0)
sl@0
   728
		{
sl@0
   729
	 	ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
sl@0
   730
	 	goto close;
sl@0
   731
	  	}
sl@0
   732
	tmspec.tv_sec = Valuesec;
sl@0
   733
	tmspec.tv_nsec = Valuenanosec;
sl@0
   734
	ret = clock_settime(Clockid,&tmspec);
sl@0
   735
	if ((ret != -1) || (errno != EINVAL)) 
sl@0
   736
		{
sl@0
   737
	 	ERR_PRINTF2(_L("clock_settime() failed to return EINVAL on negative test and errno is %d"),errno);
sl@0
   738
	 	goto close;	
sl@0
   739
		}	
sl@0
   740
	INFO_PRINTF1(_L("clock_settime() successfully returned EINVAL on negative test") );
sl@0
   741
	ret1 = KErrNone;
sl@0
   742
	
sl@0
   743
	close:
sl@0
   744
	return ret1;	
sl@0
   745
	}
sl@0
   746
sl@0
   747
//End of a file