os/ossrv/genericopenlibs/posixrealtimeextensions/test/testclock/src/tclockblocks.cpp
Update contrib.
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Name : tclockblocks.cpp
15 // Test cases for blocking signal api's
21 // -----------------------------------------------------------------------------
22 // CTestclock::Testgetclockid1
23 // Test Case ID: OPENENV-LIBC-CIT-5946
24 // API tested: clock_getcpuclockid()
25 // Description: To access the clock id of CPU time clock with pid = 0. API tested: clock_getcpuclockid()
26 // -----------------------------------------------------------------------------
28 TInt CTestclock::Testgetclockid1 ( )
30 int ret, ret1 = KErrGeneral;
32 ret = clock_getcpuclockid(0,&clockid);
35 ERR_PRINTF2(_L("Failed to retrieve the clock id of the calling process and errno is %d"),errno);
38 if (clockid != CLOCK_REALTIME)
40 ERR_PRINTF1(_L("Failed to return the right clock id"));
43 INFO_PRINTF1(_L("Successfully able to get the calling process's clock id") );
50 // -----------------------------------------------------------------------------
51 // CTestclock::Testgetclockid2
52 // Test Case ID: OPENENV-LIBC-CIT-5946
53 // API tested: clock_getcpuclockid()
54 // Description: To access the clock id of CPU time clock of self. API tested: clock_getcpuclockid()
55 // -----------------------------------------------------------------------------
57 TInt CTestclock::Testgetclockid2 ( )
59 int ret, ret1 = KErrGeneral;
61 ret = clock_getcpuclockid(getpid(),&clockid);
62 if ((ret != -1) || (errno != ESRCH))
64 ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno);
67 INFO_PRINTF1(_L("clock_getcpuclockid() is successful on negative test") );
74 // -----------------------------------------------------------------------------
75 // CTestclock::Testgetclockid3
76 // Test Case ID: OPENENV-LIBC-CIT-5946
77 // API tested: clock_getcpuclockid()
78 // Description: To access the clock id of CPU time clock of other process
79 // -----------------------------------------------------------------------------
81 TInt CTestclock::Testgetclockid3 ( )
83 int ret, ret1 = KErrGeneral;
86 char **argv = (char **)malloc(2*sizeof(char*));
87 argv[0] = (char *)malloc(30*sizeof(char*));
89 strcpy(argv[0],"z:\\sys\\bin\\getclockid.exe");
90 ret = posix_spawn(&pid, "z:\\sys\\bin\\getclockid.exe", NULL, NULL, argv, (char**)NULL);
93 ERR_PRINTF2(_L("Error in posix spawn and errno is set to %d"),errno);
96 ret = clock_getcpuclockid(pid,&clockid);
97 if ((ret != -1) || (errno != ESRCH))
99 ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno);
102 INFO_PRINTF1(_L("clock_getcpuclockid() is successful on negative test") );
106 free((void*)argv[0]);
111 // -----------------------------------------------------------------------------
112 // CTestclock::Testgetclockid4
113 // Test Case ID: OPENENV-LIBC-CIT-5946
114 // API tested: clock_getcpuclockid()
115 // Description: To access the clock id of CPU time clock of an invalid process.
116 // -----------------------------------------------------------------------------
118 TInt CTestclock::Testgetclockid4 ( )
120 int ret, ret1 = KErrGeneral;
122 ret = clock_getcpuclockid(-1,&clockid);
123 if ((ret != -1) || (errno != ESRCH))
125 ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno);
128 INFO_PRINTF1(_L("clock_getcpuclockid() has successfully returned ESRCH on negative test") );
135 // -----------------------------------------------------------------------------
136 // CTestclock::Testgetclockid5
137 // Test Case ID: OPENENV-LIBC-CIT-5946
138 // API tested: clock_getcpuclockid()
139 // Description: Trying to access the clock id of an invalid id passing to it.
140 // -----------------------------------------------------------------------------
142 TInt CTestclock::Testgetclockid5 ( )
144 int ret, ret1 = KErrGeneral;
145 ret = clock_getcpuclockid(0,NULL);
146 if ((ret != -1) || (errno != EFAULT))
148 ERR_PRINTF2(_L("clock_getcpuclockid() failed on negative test and errno is %d"),errno);
151 INFO_PRINTF1(_L("clock_getcpuclockid() has successfully returned EFAULT on negative test") );
158 // -----------------------------------------------------------------------------
159 // CTestclock::Testclockresolution1
160 // Test Case ID: OPENENV-LIBC-CIT-5946
161 // API tested: clock_getres()
162 // Description: To get the clock resolution with valid clock id using clock_getres()
163 // -----------------------------------------------------------------------------
165 TInt CTestclock::Testclockresolution1 ( )
167 int ret, ret1 = KErrGeneral;
169 struct timespec tmspec;
170 ret = clock_getcpuclockid(0,&clockid);
173 ERR_PRINTF2(_L("Failed to retrieve the clock id of the calling process and errno is %d"),errno);
176 ret = clock_getres(clockid,&tmspec);
179 ERR_PRINTF2(_L("Failed to retrieve resolution of the clock id specified and errno is %d"),errno);
182 if ((tmspec.tv_nsec != 1000) || (tmspec.tv_sec != 0))
184 ERR_PRINTF1(_L("Resolution of the clock id is not set properly"));
187 INFO_PRINTF1(_L("Successfully able to get the clock resolution of the specified clock id") );
194 // -----------------------------------------------------------------------------
195 // CTestclock::Testclockresolution2
196 // Test Case ID: OPENENV-LIBC-CIT-5946
197 // API tested: clock_getres()
198 // Description: Trying to get the clock resolution using clock_getres() for a clockid other than CLOCK_REALTIME
199 // -----------------------------------------------------------------------------
201 TInt CTestclock::Testclockresolution2 ( )
203 int ret, ret1 = KErrGeneral, Clockid, Error;
204 struct timespec tmspec;
205 ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid);
208 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
211 ret = GetIntFromConfig(ConfigSection(), _L("Error"), Error);
214 ERR_PRINTF1(_L("Unable to read expected error num")) ;
217 ret = clock_getres(Clockid,&tmspec);
218 if ((ret != -1) || (errno != Error))
220 ERR_PRINTF2(_L("The expected and errno are not same and errno is %d"),errno);
223 INFO_PRINTF1(_L("The output and expected value are same for clock_getres()") );
230 // -----------------------------------------------------------------------------
231 // CTestclock::Testclockresolution3
232 // Test Case ID: OPENENV-LIBC-CIT-5946
233 // API tested: clock_getres()
234 // Description: Negative Test: Trying to get the resolution with res = NULL using clock_getres()
235 // -----------------------------------------------------------------------------
237 TInt CTestclock::Testclockresolution3 ( )
239 int ret, ret1 = KErrGeneral, Clockid;
240 ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid);
243 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
246 ret = clock_getres(Clockid,NULL);
249 ERR_PRINTF2(_L("clock_getres() failed on negative test if timespec argument is NULL and errno is %d"),errno);
252 INFO_PRINTF1(_L("clock_getres() successfully returned 0 on negative test") );
259 // -----------------------------------------------------------------------------
260 // CTestclock::Testclocknanosleep1
261 // Test Case ID: OPENENV-LIBC-CIT-5946
262 // API tested: clock_nanosleep()
263 // Description: Trying to suspend the process for the specified time using clock_nanosleep() in the absence of TIMER_ABSTIME
265 // -----------------------------------------------------------------------------
267 TInt CTestclock::Testclocknanosleep1 ( )
269 int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec;
270 struct timespec gettmspec, oldtmpsec, sleeptmspec, sleeptmspec1;
271 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
274 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
277 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
280 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
283 sleeptmspec.tv_sec = Valuesec;
284 sleeptmspec.tv_nsec = Valuenanosec;
285 ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
288 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
291 oldtmpsec = gettmspec;
292 ret = clock_nanosleep(CLOCK_REALTIME,0,&sleeptmspec,&sleeptmspec1);
295 ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno);
298 ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
301 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
304 if (gettmspec.tv_sec != (oldtmpsec.tv_sec + Valuesec))
306 ERR_PRINTF2(_L("clock_nanosleep() has failed to sleep for %d secs"),Valuesec);
309 INFO_PRINTF1(_L("Relative timer"));
310 INFO_PRINTF2(_L("clock_nanosleep() successfully able to sleep for %d secs"),Valuesec );
317 // -----------------------------------------------------------------------------
318 // CTestclock::Testclocknanosleep2
319 // Test Case ID: OPENENV-LIBC-CIT-5946
320 // API tested: clock_nanosleep()
321 // Description: Trying to suspend the process for the specified time using clock_nanosleep()
323 // -----------------------------------------------------------------------------
325 TInt CTestclock::Testclocknanosleep2 ( )
327 int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec;
328 struct timespec gettmspec, oldtmpsec, sleeptmspec, sleeptmspec1;
329 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
332 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
335 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
338 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
341 sleeptmspec.tv_sec = Valuesec;
342 sleeptmspec.tv_nsec = Valuenanosec;
343 ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
346 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
349 oldtmpsec = gettmspec;
350 sleeptmspec.tv_sec = gettmspec.tv_sec + Valuesec;
351 sleeptmspec.tv_nsec = gettmspec.tv_nsec + Valuenanosec;
352 ret = clock_nanosleep(CLOCK_REALTIME,TIMER_ABSTIME,&sleeptmspec,&sleeptmspec1);
355 ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno);
358 ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
361 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
364 if (gettmspec.tv_sec < (oldtmpsec.tv_sec + Valuesec))
366 ERR_PRINTF2(_L("clock_nanosleep() has failed to sleep for %d secs"),Valuesec);
369 INFO_PRINTF1(_L("Absolute timer"));
370 INFO_PRINTF2(_L("clock_nanosleep() successfully able to sleep for %d secs"),Valuesec );
377 // -----------------------------------------------------------------------------
378 // CTestclock::Testclocknanosleep3
379 // Test Case ID: OPENENV-LIBC-CIT-5946
380 // API tested: clock_nanosleep()
381 // Description: Trying to suspend the process for an invalid time using clock_nanosleep() in the absence of TIMER_ABSTIME
382 // -----------------------------------------------------------------------------
384 TInt CTestclock::Testclocknanosleep3 ( )
386 int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec;
387 struct timespec sleeptmspec;
388 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
391 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
394 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
397 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
400 sleeptmspec.tv_sec = Valuesec;
401 sleeptmspec.tv_nsec = Valuenanosec;
402 ret = clock_nanosleep(CLOCK_REALTIME,0,&sleeptmspec,NULL);
403 if ((ret != -1) || (errno != EINVAL))
405 ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno);
408 INFO_PRINTF1(_L("clock_nanosleep() successfully able to sleep for 2 secs") );
415 // -----------------------------------------------------------------------------
416 // CTestclock::Testclocknanosleep4
417 // Test Case ID: OPENENV-LIBC-CIT-5946
418 // API tested: clock_nanosleep()
419 // Description: Trying to suspend the process with an invalid clock id clock_nanosleep()
420 // -----------------------------------------------------------------------------
422 TInt CTestclock::Testclocknanosleep4 ( )
424 int ret, ret1 = KErrGeneral, Invalidid;
425 struct timespec sleeptmspec;
426 ret = GetIntFromConfig(ConfigSection(), _L("Invalidid"), Invalidid);
429 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
432 sleeptmspec.tv_sec = 2;
433 sleeptmspec.tv_nsec = 0;
434 ret = clock_nanosleep(Invalidid,0,&sleeptmspec,NULL);
435 if ((ret != -1) || (errno != EINVAL))
437 ERR_PRINTF2(_L("clock_nanosleep() failed to return EINVAL and errno is %d"),errno);
440 INFO_PRINTF1(_L("clock_nanosleep() successfully able to return EINVAL ") );
447 // -----------------------------------------------------------------------------
448 // CTestclock::Testclocknanosleep5
449 // Test Case ID: OPENENV-LIBC-CIT-5946
450 // API tested: clock_nanosleep()
451 // Description: clock_nanosleep() with an invalid parameter of timespec
452 // -----------------------------------------------------------------------------
454 TInt CTestclock::Testclocknanosleep5 ( )
456 int ret, ret1 = KErrGeneral;
457 ret = clock_nanosleep(CLOCK_REALTIME,0,NULL,NULL);
458 if ((ret != -1) || (errno != EFAULT))
460 ERR_PRINTF2(_L("clock_nanosleep() failed to return EINVAL and errno is %d"),errno);
463 INFO_PRINTF1(_L("clock_nanosleep() successfully able to return EINVAL ") );
470 // -----------------------------------------------------------------------------
471 // CTestclock::Testclocknanosleep6
472 // Test Case ID: OPENENV-LIBC-CIT-5946
473 // API tested: clock_nanosleep()
474 // Description: clock_nanosleep() with a flag other than Absolute value
475 // -----------------------------------------------------------------------------
477 TInt CTestclock::Testclocknanosleep6 ( )
479 int ret, ret1 = KErrGeneral, Valuesec, Valuenanosec;
480 struct timespec gettmspec, oldtmpsec, sleeptmspec, sleeptmspec1;
481 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
484 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
487 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
490 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
493 sleeptmspec.tv_sec = Valuesec;
494 sleeptmspec.tv_nsec = Valuenanosec;
495 ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
498 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
501 oldtmpsec = gettmspec;
502 ret = clock_nanosleep(CLOCK_REALTIME,15,&sleeptmspec,&sleeptmspec1);
505 ERR_PRINTF2(_L("clock_nanosleep() failed and errno is %d"),errno);
508 ret = clock_gettime(CLOCK_REALTIME,&gettmspec);
511 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
514 if (gettmspec.tv_sec != (oldtmpsec.tv_sec + Valuesec))
516 ERR_PRINTF2(_L("clock_nanosleep() has failed to sleep for %d secs"),Valuesec);
519 INFO_PRINTF1(_L("Relative timer"));
520 INFO_PRINTF2(_L("clock_nanosleep() successfully able to sleep for %d secs"),Valuesec );
527 // -----------------------------------------------------------------------------
528 // CTestclock::Testclockgettime1
529 // Test Case ID: OPENENV-LIBC-CIT-5946
530 // API tested: clock_gettime()
531 // Description: To get the current value for the specified valid clock_id<CLOCK_REALTIME>
532 // -----------------------------------------------------------------------------
534 TInt CTestclock::Testclockgettime1 ( )
536 int ret, ret1 = KErrGeneral;
538 struct timespec tmspec, oldtmspec;
539 ret = clock_getcpuclockid(0,&clockid);
542 ERR_PRINTF2(_L("Failed to retrieve the clock id of the calling process and errno is %d"),errno);
545 ret = clock_gettime(clockid,&tmspec);
548 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
553 ret = clock_gettime(clockid,&tmspec);
556 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
559 if (tmspec.tv_sec != (oldtmspec.tv_sec + 2))
561 ERR_PRINTF1(_L("Failed to retrieve resolution of the clock id specified"));
564 INFO_PRINTF1(_L("clock_gettime() successfully able to get the time") );
571 // -----------------------------------------------------------------------------
572 // CTestclock::Testclockgettime2
573 // Test Case ID: OPENENV-LIBC-CIT-5946
574 // API tested: clock_gettime()
575 // Description: Trying to get the current time value for an invalid clock id using clock_gettime()
576 // -----------------------------------------------------------------------------
578 TInt CTestclock::Testclockgettime2 ( )
580 int ret, ret1 = KErrGeneral, Clockid, Error;
581 struct timespec tmspec;
582 ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid);
585 ERR_PRINTF1(_L("Unable to clock id value")) ;
588 ret = GetIntFromConfig(ConfigSection(), _L("Error"), Error);
591 ERR_PRINTF1(_L("Unable to read expected error num")) ;
594 ret = clock_gettime(Clockid,&tmspec);
595 if ((ret != -1) || (errno != Error))
597 ERR_PRINTF2(_L("clock_gettime() failed to return EINVAL for an invalid clock id and errno is %d"),errno);
600 INFO_PRINTF1(_L("clock_gettime() successfully returned EINVAL for an invalid clock id") );
607 // -----------------------------------------------------------------------------
608 // CTestclock::Testclockgettime3
609 // Test Case ID: OPENENV-LIBC-CIT-5946
610 // API tested: clock_gettime()
611 // Description: Trying to get the current time value for a valid clock id with NULL as the timespec using clock_gettime()
612 // -----------------------------------------------------------------------------
614 TInt CTestclock::Testclockgettime3 ( )
616 int ret, ret1 = KErrGeneral, Clockid;
617 ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid);
620 ERR_PRINTF1(_L("Unable to read clock id value")) ;
623 ret = clock_gettime(Clockid,NULL);
624 if ((ret != -1) || (errno != EFAULT))
626 ERR_PRINTF2(_L("clock_gettime() failed to return EFAULT for NULL timespec parameter and errno is %d"),errno);
629 INFO_PRINTF1(_L("clock_gettime() successfully returned EFAULT for NULL timespec parameter ") );
636 // -----------------------------------------------------------------------------
637 // CTestclock::Testclocksettime1
638 // Test Case ID: OPENENV-LIBC-CIT-5946
639 // API tested: clock_settime()
640 // Description: Trying to set the current time value for an invalid clock id using clock_settime()
641 // -----------------------------------------------------------------------------
643 TInt CTestclock::Testclocksettime1 ( )
645 int ret, ret1 = KErrGeneral, Clockid, Error;
646 struct timespec tmspec;
648 tmspec.tv_nsec = 2000;
649 ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid);
652 ERR_PRINTF1(_L("Unable to read clock id value")) ;
655 ret = GetIntFromConfig(ConfigSection(), _L("Error"), Error);
658 ERR_PRINTF1(_L("Unable to read expected error num")) ;
661 ret = clock_settime(Clockid,&tmspec);
662 if ((ret != -1) || (errno != Error))
664 ERR_PRINTF2(_L("clock_settime() failed on negative test and errno is %d"),errno);
667 INFO_PRINTF1(_L("clock_settime() is successfull on negative test") );
674 // -----------------------------------------------------------------------------
675 // CTestclock::Testclocksettime2
676 // Test Case ID: OPENENV-LIBC-CIT-5946
677 // API tested: clock_settime()
678 // Description: clock_settime() with NULL as the timespec parameter
679 // -----------------------------------------------------------------------------
681 TInt CTestclock::Testclocksettime2 ( )
683 int ret, ret1 = KErrGeneral, Clockid;
684 ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid);
687 ERR_PRINTF1(_L("Unable to read clock id value")) ;
690 ret = clock_settime(Clockid,NULL);
691 if ((ret != -1) || (errno != EFAULT))
693 ERR_PRINTF2(_L("clock_settime() failed to return EFAULT on negative test and errno is %d"),errno);
696 INFO_PRINTF1(_L("clock_settime() successfully returned EFAULT on negative test") );
703 // -----------------------------------------------------------------------------
704 // CTestclock::Testclocksettime3
705 // Test Case ID: OPENENV-LIBC-CIT-5946
706 // API tested: clock_settime()
707 // Description: Test case added to set the value of clock id current value to an invalid specified value using clock_settime()
708 // -----------------------------------------------------------------------------
710 TInt CTestclock::Testclocksettime3 ( )
712 int ret, ret1 = KErrGeneral, Clockid, Valuesec, Valuenanosec;
713 struct timespec tmspec;
714 ret = GetIntFromConfig(ConfigSection(), _L("Clockid"), Clockid);
717 ERR_PRINTF1(_L("Unable to read clock id value")) ;
720 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
723 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
726 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
729 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
732 tmspec.tv_sec = Valuesec;
733 tmspec.tv_nsec = Valuenanosec;
734 ret = clock_settime(Clockid,&tmspec);
735 if ((ret != -1) || (errno != EINVAL))
737 ERR_PRINTF2(_L("clock_settime() failed to return EINVAL on negative test and errno is %d"),errno);
740 INFO_PRINTF1(_L("clock_settime() successfully returned EINVAL on negative test") );