os/ossrv/genericopenlibs/posixrealtimeextensions/test/testtimer/src/ttimerblocks.cpp
First public contribution.
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Name : ttimerblocks.cpp
15 // Test cases for blocking signal api's
21 #include "ttimerthread.h"
22 #define Maxtimerid 512
40 void sig_handler(int sig)
46 //overrun signal handler
47 void overrun_handler(int sig)
53 //notification function
54 void notifyfunc(union sigval val)
56 timer_value = val.sival_int;
59 void alarm_handler(int sig)
64 // -----------------------------------------------------------------------------
65 // CTesttimer::Testtimerapi1
66 // Test Case ID: OPENENV-LIBC-CIT-5946
67 // API tested: timer_create(), timer_delete()
68 // Description: Test case to create a timer with NONE as sigev_notify parameter
69 // TIMER_ABSTIME not set
70 // -----------------------------------------------------------------------------
72 TInt CTesttimer::Testtimerapi1 ( )
74 int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
75 struct sigevent sigev;
76 struct itimerspec timerspec;
78 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
81 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
84 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
87 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
90 ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
93 ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
96 ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
99 ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
102 sigev.sigev_notify = SIGEV_NONE;
104 ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
108 ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
111 INFO_PRINTF1(_L("Successfully able to create a timer") );
112 timerspec.it_value.tv_sec = Valuesec;
113 timerspec.it_value.tv_nsec = Valuenanosec;
114 timerspec.it_interval.tv_sec = Intervalsec;
115 timerspec.it_interval.tv_nsec = Intervalnanosec;
116 ret = timer_settime(timerid,0,&timerspec,NULL);
119 ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
124 INFO_PRINTF1(_L("Successfully able to set the timer") );
125 ret = timer_delete(timerid);
128 ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
131 INFO_PRINTF1(_L("Successfully able to delete the timer") );
135 timer_delete(timerid);
139 // -----------------------------------------------------------------------------
140 // CTesttimer::Testtimerapi2
141 // Test Case ID: OPENENV-LIBC-CIT-5946
142 // API tested: timer_create(), timer_delete()
143 // Description: Test case to create a timer with NONE as sigev_notify parameter
145 // -----------------------------------------------------------------------------
147 TInt CTesttimer::Testtimerapi2 ( )
149 int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
150 struct sigevent sigev;
151 struct itimerspec timerspec;
152 struct timespec curtmspec;
154 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
157 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
160 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
163 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
166 ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
169 ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
172 ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
175 ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
178 sigev.sigev_notify = SIGEV_NONE;
180 ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
183 ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
186 INFO_PRINTF1(_L("Successfully able to create a timer") );
187 ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
190 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
193 timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
194 timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec;
195 timerspec.it_interval.tv_sec = Intervalsec;
196 timerspec.it_interval.tv_nsec = Intervalnanosec;
197 ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,NULL);
200 ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno);
205 INFO_PRINTF1(_L("Successfully able to set the timer") );
206 ret = timer_delete(timerid);
209 ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
212 INFO_PRINTF1(_L("Successfully able to delete the timer") );
216 timer_delete(timerid);
220 // -----------------------------------------------------------------------------
221 // CTesttimer::Testtimerapi3
222 // Test Case ID: OPENENV-LIBC-CIT-5946
223 // API tested: timer_create(), timer_delete()
224 // Description: To create a timer with SIGEV_SIGNAL as sigev_notify parameter
225 // TIMER_ABSTIME not set
226 // -----------------------------------------------------------------------------
228 TInt CTesttimer::Testtimerapi3 ( )
230 int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec, Signum, Maxsig, Sigval;
231 struct sigevent sigev;
232 struct itimerspec timerspec;
234 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
237 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
240 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
243 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
246 ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
249 ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
252 ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
255 ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
258 ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
261 ERR_PRINTF1(_L("Unable to read signal number")) ;
264 ret = GetIntFromConfig(ConfigSection(), _L("Maxsig"), Maxsig);
267 ERR_PRINTF1(_L("Unable to read maximum signal number")) ;
270 for(Signum=Sigval; Signum <= Maxsig; Signum++)
272 if((Signum == SIGSTOP) || (Signum == SIGKILL))
277 if(signal(Signum,sig_handler) == SIG_ERR)
279 ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
282 sigev.sigev_notify = SIGEV_SIGNAL;
283 sigev.sigev_signo = Signum;
285 ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
288 ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
291 timerspec.it_value.tv_sec = Valuesec;
292 timerspec.it_value.tv_nsec = Valuenanosec;
293 timerspec.it_interval.tv_sec = Intervalsec;
294 timerspec.it_interval.tv_nsec = Intervalnanosec;
297 ret = timer_settime(timerid,0,&timerspec,NULL);
300 ERR_PRINTF3(_L("Failed to set the timer for signal %d and errno is %d"),Signum,errno);
307 if(timer_value != Signum)
309 ERR_PRINTF2(_L("The expected and timer_value are not same for signal %d"),Signum);
312 ret = timer_delete(timerid);
315 ERR_PRINTF3(_L("Failed to delete the timer for signal %d and errno is %d"),Signum, errno);
319 INFO_PRINTF1(_L("Relative time"));
320 INFO_PRINTF1(_L("Successfully able to create a timer with SIGEV_SIGNAL as sigev_notify parameter validated for all signals"));
324 timer_delete(timerid);
328 // -----------------------------------------------------------------------------
329 // CTesttimer::Testtimerapi4
330 // Test Case ID: OPENENV-LIBC-CIT-5946
331 // API tested: timer_create(), timer_delete()
332 // Description: To create a timer with SIGEV_SIGNAL as sigev_notify parameter
334 // -----------------------------------------------------------------------------
336 TInt CTesttimer::Testtimerapi4 ( )
338 int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec, Signum, Maxsig, Sigval;
339 struct sigevent sigev;
340 struct itimerspec timerspec;
341 struct timespec curtmspec;
343 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
346 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
349 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
352 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
355 ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
358 ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
361 ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
364 ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
367 ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
370 ERR_PRINTF1(_L("Unable to read signal number")) ;
373 ret = GetIntFromConfig(ConfigSection(), _L("Maxsig"), Maxsig);
376 ERR_PRINTF1(_L("Unable to read maximum signal number")) ;
379 for(Signum=Sigval; Signum <= Maxsig; Signum++)
381 if((Signum == SIGSTOP) || (Signum == SIGKILL))
386 if(signal(Signum,sig_handler) == SIG_ERR)
388 ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
391 sigev.sigev_notify = SIGEV_SIGNAL;
392 sigev.sigev_signo = Signum;
394 ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
397 ERR_PRINTF3(_L("Failed to create a timer for signal %d and errno is %d"),Signum,errno);
400 ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
403 ERR_PRINTF3(_L("Failed to get the time of specified clock id for signal %d and errno is %d"),Signum,errno);
406 timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
407 timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec;
408 timerspec.it_interval.tv_sec = Intervalsec;
409 timerspec.it_interval.tv_nsec = Intervalnanosec;
411 ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,NULL);
416 ERR_PRINTF3(_L("Failed to set the timer for signal %d and errno is %d"),Signum,errno);
420 if(timer_value != Signum)
422 ERR_PRINTF2(_L("The expected and timer_value are not same for signal %d"),Signum);
425 ret = timer_delete(timerid);
428 ERR_PRINTF3(_L("Failed to delete the timer for signal %d and errno is %d"),Signum, errno);
432 INFO_PRINTF1(_L("Absolute time"));
433 INFO_PRINTF1(_L("Successfully able to create a timer with SIGEV_SIGNAL as sigev_notify parameter validated for all signals"));
437 timer_delete(timerid);
442 // -----------------------------------------------------------------------------
443 // CTesttimer::Testtimerapi5
444 // Test Case ID: OPENENV-LIBC-CIT-5946
445 // API tested: timer_create(), timer_delete()
446 // Description: To create a timer with SIGEV_THREAD as sigev_notify parameter
447 // TIMER_ABSTIME not set
448 // -----------------------------------------------------------------------------
450 TInt CTesttimer::Testtimerapi5 ( )
452 int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
453 struct sigevent sigev;
454 struct sched_param parm;
456 struct itimerspec timerspec;
458 pthread_attr_init( &attr );
459 parm.sched_priority = 255; //raise the priority..
460 pthread_attr_setschedparam(&attr, &parm);
461 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
464 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
467 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
470 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
473 ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
476 ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
479 ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
482 ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
486 sigev.sigev_notify = SIGEV_THREAD;
487 sigev.sigev_value.sival_int = 100;
488 sigev.sigev_notify_function = notifyfunc ;
489 sigev.sigev_notify_attributes = &attr;
490 ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
493 ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
496 INFO_PRINTF1(_L("Successfully able to create a timer") );
497 timerspec.it_value.tv_sec = Valuesec;
498 timerspec.it_value.tv_nsec = Valuenanosec;
499 timerspec.it_interval.tv_sec = Intervalsec;
500 timerspec.it_interval.tv_nsec = Intervalnanosec;
501 ret = timer_settime(timerid,0,&timerspec,NULL);
504 ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
509 if(timer_value != 100)
511 ERR_PRINTF1(_L("The expected and timer_value are not same"));
514 INFO_PRINTF1(_L("Successfully able to set the timer") );
515 ret = timer_delete(timerid);
518 ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
521 INFO_PRINTF1(_L("Successfully able to delete the timer") );
525 timer_delete(timerid);
529 // -----------------------------------------------------------------------------
530 // CTesttimer::Testtimerapi6
531 // Test Case ID: OPENENV-LIBC-CIT-5946
532 // API tested: timer_create(), timer_delete()
533 // Description: To create a timer with SIGEV_THREAD as sigev_notify parameter
535 // -----------------------------------------------------------------------------
537 TInt CTesttimer::Testtimerapi6 ( )
539 int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
540 struct sigevent sigev;
541 struct itimerspec timerspec;
542 struct timespec curtmspec;
544 struct sched_param parm;
546 pthread_attr_init( &attr );
547 parm.sched_priority = 255;
548 pthread_attr_setschedparam(&attr, &parm);
549 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
552 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
555 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
558 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
561 ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
564 ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
567 ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
570 ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
574 sigev.sigev_notify = SIGEV_THREAD;
575 sigev.sigev_value.sival_int = 100;
576 sigev.sigev_notify_function = notifyfunc ;
577 sigev.sigev_notify_attributes = &attr;
578 ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
581 ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
584 INFO_PRINTF1(_L("Successfully able to create a timer") );
585 ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
588 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
591 timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
592 timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec;
593 timerspec.it_interval.tv_sec = Intervalsec;
594 timerspec.it_interval.tv_nsec = Intervalnanosec;
595 ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,NULL);
598 ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
603 if(timer_value != 100)
605 ERR_PRINTF1(_L("The expected and timer_value are not same"));
608 INFO_PRINTF1(_L("Successfully able to set the timer") );
609 ret = timer_delete(timerid);
612 ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
615 INFO_PRINTF1(_L("Successfully able to delete the timer") );
619 timer_delete(timerid);
623 // -----------------------------------------------------------------------------
624 // CTesttimer::Testtimerapi7
625 // Test Case ID: OPENENV-LIBC-CIT-5946
626 // API tested: timer_create(), timer_delete()
627 // Description: To create a timer for CLOCK_REALTIME id using timer_create() with sigevent argument as NULL
628 // TIMER_ABSTIME not set
629 // -----------------------------------------------------------------------------
631 TInt CTesttimer::Testtimerapi7 ( )
633 int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
635 struct itimerspec timerspec;
637 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
640 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
643 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
646 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
649 ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
652 ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
655 ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
658 ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
661 if(signal(SIGALRM, alarm_handler) == SIG_ERR)
663 ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
666 ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
669 ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
672 INFO_PRINTF1(_L("Successfully able to create a timer") );
673 timerspec.it_value.tv_sec = Valuesec;
674 timerspec.it_value.tv_nsec = Valuenanosec;
675 timerspec.it_interval.tv_sec = Intervalsec;
676 timerspec.it_interval.tv_nsec = Intervalnanosec;
677 ret = timer_settime(timerid,0,&timerspec,NULL);
680 ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
685 if(timer_value != SIGALRM)
687 ERR_PRINTF1(_L("Error in raising the signal after timer expire"));
690 INFO_PRINTF1(_L("Successfully able to set the timer with the default signal as SIGALRM") );
691 ret = timer_delete(timerid);
694 ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
697 INFO_PRINTF1(_L("Successfully able to delete the timer") );
701 timer_delete(timerid);
705 // -----------------------------------------------------------------------------
706 // CTesttimer::Testtimerapi8
707 // Test Case ID: OPENENV-LIBC-CIT-5946
708 // API tested: timer_create(), timer_delete()
709 // Description: To create a timer for CLOCK_REALTIME id using timer_create() with sigevent argument as NULL
711 // -----------------------------------------------------------------------------
713 TInt CTesttimer::Testtimerapi8 ( )
715 int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
717 struct itimerspec timerspec;
718 struct timespec curtmspec;
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 ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
735 ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
738 ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
741 ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
744 if(signal(SIGALRM, alarm_handler) == SIG_ERR)
746 ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"),errno) ;
749 ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
752 ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
755 INFO_PRINTF1(_L("Successfully able to create a timer") );
756 ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
759 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
762 timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
763 timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec;
764 timerspec.it_interval.tv_sec = Intervalsec;
765 timerspec.it_interval.tv_nsec = Intervalnanosec;
766 ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,NULL);
769 ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
774 if(timer_value != SIGALRM)
776 ERR_PRINTF1(_L("Error in raising the signal after timer expire"));
779 INFO_PRINTF1(_L("Successfully able to set the timer with the default signal as SIGALRM") );
780 ret = timer_delete(timerid);
783 ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
786 INFO_PRINTF1(_L("Successfully able to delete the timer") );
790 timer_delete(timerid);
794 // -----------------------------------------------------------------------------
795 // CTesttimer::Testtimerapi9
796 // Test Case ID: OPENENV-LIBC-CIT-5946
797 // API tested: timer_create()
798 // Description: Negative Test-Trying to create the timer for an invalid clock id using timer_create()
799 // -----------------------------------------------------------------------------
801 TInt CTesttimer::Testtimerapi9 ( )
803 int ret, ret1 = KErrGeneral, Invalidclockid;
805 ret = GetIntFromConfig(ConfigSection(), _L("Invalidclockid"), Invalidclockid);
808 ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
811 ret = timer_create(Invalidclockid,NULL,&timerid);
812 if((ret != -1) || (errno != EINVAL))
814 ERR_PRINTF2(_L("timer_create() failed to return EINVAL on negative test and errno is %d"),errno);
817 INFO_PRINTF1(_L("timer_create() successfully returned EINVAL on negative test") );
824 // -----------------------------------------------------------------------------
825 // CTesttimer::Testtimerapi10
826 // Test Case ID: OPENENV-LIBC-CIT-5946
827 // API tested: timer_create()
828 // Description: Timer id as NULL in timer_create()
829 // -----------------------------------------------------------------------------
831 TInt CTesttimer::Testtimerapi10 ( )
833 int ret, ret1 = KErrGeneral;
834 ret = timer_create(CLOCK_REALTIME,NULL,NULL);
835 if((ret != -1) || (errno != EFAULT))
837 ERR_PRINTF2(_L("timer_create() failed to return EFAULT on negative test and errno is %d"),errno);
840 INFO_PRINTF1(_L("timer_create() successfully returned EFAULT on negative test") );
847 // -----------------------------------------------------------------------------
848 // CTesttimer::Testtimerapi11
849 // Test Case ID: OPENENV-LIBC-CIT-5946
850 // API tested: timer_create()
851 // Description: Timer id as NULL & an invalid clockid in timer_create()
852 // -----------------------------------------------------------------------------
854 TInt CTesttimer::Testtimerapi11 ( )
856 int ret, ret1 = KErrGeneral;
857 ret = timer_create(CLOCK_MONOTONIC,NULL,NULL);
858 if((ret != -1) || (errno != EFAULT))
860 ERR_PRINTF2(_L("timer_create() failed to return EFAULT on negative test and errno is %d"),errno);
863 INFO_PRINTF1(_L("timer_create() successfully returned EFAULT on negative test") );
870 // -----------------------------------------------------------------------------
871 // CTesttimer::Testtimerapi12
872 // Test Case ID: OPENENV-LIBC-CIT-5946
873 // API tested: timer_create()
874 // Description: Trying to create more than maximum no. of timer's possible per process using timer_create()
875 // -----------------------------------------------------------------------------
877 TInt CTesttimer::Testtimerapi12 ( )
879 int ret, ret1 = KErrGeneral, i, j;
880 timer_t timerid[Maxtimerid + 1];
881 for (i = 0; i <= Maxtimerid ; i++)
883 ret = timer_create(CLOCK_REALTIME,NULL,&timerid[i]);
884 if((ret == -1) && (errno == EAGAIN) && (i == Maxtimerid) )
886 INFO_PRINTF3(_L("timer_create() has successfully returned EAGAIN on negative test %d %d"),errno,i);
892 INFO_PRINTF3(_L("timer_create() has failed with error %d %d"),errno,i);
895 for(j = 0; j <= Maxtimerid-1; j++)
897 ret = timer_delete(timerid[j]);
900 ERR_PRINTF3(_L("Failed to delete the timer and errno is %d %d"),errno, j);
905 INFO_PRINTF1(_L("timer_delete() has successfully deleted all the timers negative test"));
909 // -----------------------------------------------------------------------------
910 // CTesttimer::Testtimerapi13
911 // Test Case ID: OPENENV-LIBC-CIT-5946
912 // API tested: timer_delete()
913 // Description: To delete the timer with an invalid timer id using timer_delete()
914 // -----------------------------------------------------------------------------
916 TInt CTesttimer::Testtimerapi13 ( )
919 int ret, ret1 = KErrGeneral;
920 ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
923 ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
926 INFO_PRINTF1(_L("Able to create the timer") );
927 ret = timer_delete(timerid);
930 ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
933 INFO_PRINTF1(_L("Successfully able to delete the timer") );
934 /*Deleting a timer id again expected result = -1 and errno = EINVAL */
935 ret = timer_delete(timerid);
936 if((ret != -1) || (errno != EINVAL))
938 ERR_PRINTF2(_L("timer_delete() failed to return EINVAL on negative test and errno is %d"),errno);
941 INFO_PRINTF1(_L("timer_delete() successfully returned EINVAL on negative test") );
948 // -----------------------------------------------------------------------------
949 // CTesttimer::Testtimerapi14
950 // Test Case ID: OPENENV-LIBC-CIT-5946
951 // API tested: timer_delete()
952 // Description: To delete the timer with NULL using timer_delete()
953 // -----------------------------------------------------------------------------
955 TInt CTesttimer::Testtimerapi14 ( )
957 int ret, ret1 = KErrGeneral;
958 ret = timer_delete(NULL);
959 if((ret != -1) || (errno != EINVAL))
961 ERR_PRINTF2(_L("timer_delete() failed to return EFAULT on negative test and errno is %d"),errno);
964 INFO_PRINTF1(_L("timer_delete() successfully returned EFAULT on negative test") );
971 // -----------------------------------------------------------------------------
972 // CTesttimer::Testtimerapi15
973 // Test Case ID: OPENENV-LIBC-CIT-5946
974 // API tested: timer_settime()
975 // Description: Trying to set the timer for an invalid timer id using timer_settime()
976 // -----------------------------------------------------------------------------
978 TInt CTesttimer::Testtimerapi15 ( )
980 int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec, Timerflag;
982 struct itimerspec timerspec;
984 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
987 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
990 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
993 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
996 ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
999 ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
1002 ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
1005 ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
1008 ret = GetIntFromConfig(ConfigSection(), _L("Timerflag"), Timerflag);
1011 ERR_PRINTF1(_L("Unable to read the timer flag")) ;
1014 if(signal(SIGALRM, alarm_handler) == SIG_ERR)
1016 ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
1019 ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
1022 ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
1025 INFO_PRINTF1(_L("Successfully able to create a timer") );
1026 ret = timer_delete(timerid);
1029 ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
1032 INFO_PRINTF1(_L("Successfully able to delete the timer") );
1033 timerspec.it_value.tv_sec = Valuesec;
1034 timerspec.it_value.tv_nsec = Valuenanosec;
1035 timerspec.it_interval.tv_sec = Intervalsec;
1036 timerspec.it_interval.tv_nsec = Intervalnanosec;
1037 ret = timer_settime(timerid,Timerflag,&timerspec,NULL);
1038 if((ret != -1) || (errno != EINVAL))
1040 ERR_PRINTF2(_L("timer_settime() failed to return EINVAL on negative test and errno is %d"),errno);
1043 INFO_PRINTF1(_L("timer_settime() successfully able to return EINVAL on negative test") );
1048 if(athr.Open(_L("LibrtTimerServ")) == KErrNone)
1056 // -----------------------------------------------------------------------------
1057 // CTesttimer::Testtimerapi16
1058 // Test Case ID: OPENENV-LIBC-CIT-5946
1059 // API tested: timer_settime()
1060 // Description: Trying to set the timer with an invalid tv_nsec parameter using timer_settime()
1061 // -----------------------------------------------------------------------------
1063 TInt CTesttimer::Testtimerapi16 ( )
1065 int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec, Signum, Maxsig, Timerflag, Sigval;
1066 struct sigevent sigev;
1067 struct itimerspec timerspec;
1069 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
1072 ERR_PRINTF1(_L("Unable to read seconds value of it_value"));
1075 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
1078 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
1081 ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
1084 ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
1087 ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
1090 ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
1093 ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
1096 ERR_PRINTF1(_L("Unable to read signal number")) ;
1099 ret = GetIntFromConfig(ConfigSection(), _L("Maxsig"), Maxsig);
1102 ERR_PRINTF1(_L("Unable to read maximum signal number")) ;
1105 ret = GetIntFromConfig(ConfigSection(), _L("Timerflag"), Timerflag);
1108 ERR_PRINTF1(_L("Unable to read the timer flag")) ;
1111 for(Signum=Sigval; Signum <= Maxsig; Signum++)
1113 if((Signum == SIGSTOP) || (Signum == SIGKILL))
1118 if(signal(Signum,sig_handler) == SIG_ERR)
1120 ERR_PRINTF3(_L("Error in signal trapping function for signal is %d and errno is %d"),Signum, errno) ;
1123 sigev.sigev_notify = SIGEV_SIGNAL;
1124 sigev.sigev_signo = Signum;
1125 ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
1128 ERR_PRINTF3(_L("Failed to create a timer %d and errno is %d"),Signum, errno);
1131 timerspec.it_value.tv_sec = Valuesec;
1132 timerspec.it_value.tv_nsec = Valuenanosec;
1133 timerspec.it_interval.tv_sec = Intervalsec;
1134 timerspec.it_interval.tv_nsec = Intervalnanosec;
1135 ret = timer_settime(timerid,Timerflag,&timerspec,NULL);
1136 if((ret != -1) || (errno != EINVAL))
1138 ERR_PRINTF2(_L("timer_settime() failed to return EINVAL on negative test and errno is %d"),errno);
1141 ret = timer_delete(timerid);
1144 ERR_PRINTF3(_L("Failed to delete the timer %d and errno is %d"),Signum,errno);
1148 INFO_PRINTF1(_L("timer_settime() successfully able to return EINVAL on negative test") );
1152 timer_delete(timerid);
1156 // -----------------------------------------------------------------------------
1157 // CTesttimer::Testtimerapi17
1158 // Test Case ID: OPENENV-LIBC-CIT-5946
1159 // API tested: timer_create(), timer_delete()
1160 // Description: To create a timer with SIGEV_SIGNAL as sigev_notify parameter
1161 // TIMER_ABSTIME not set
1162 // -----------------------------------------------------------------------------
1164 TInt CTesttimer::Testtimerapi17 ( )
1166 int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
1167 struct sigevent sigev;
1168 struct itimerspec timerspec;
1169 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
1172 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
1175 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
1178 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
1181 ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
1184 ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
1187 ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
1190 ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
1194 if(signal(SIGUSR1,overrun_handler) == SIG_ERR)
1196 ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
1199 sigev.sigev_notify = SIGEV_SIGNAL;
1200 sigev.sigev_signo = SIGUSR1;
1202 ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
1205 ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
1208 timerspec.it_value.tv_sec = Valuesec;
1209 timerspec.it_value.tv_nsec = Valuenanosec;
1210 timerspec.it_interval.tv_sec = Intervalsec;
1211 timerspec.it_interval.tv_nsec = Intervalnanosec;
1213 ret = timer_settime(timerid,0,&timerspec,NULL);
1216 ERR_PRINTF2(_L("Failed to set the time of specified clock id and errno is %d "),errno);
1221 if(timer_value != SIGUSR1)
1223 ERR_PRINTF1(_L("The expected and timer_value are not same for signal"));
1227 ret = timer_getoverrun(timerid);
1230 ERR_PRINTF2(_L("Error in timer_getoverrun() and errno is %d"),errno);
1234 ret = timer_delete(timerid);
1237 ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
1240 INFO_PRINTF1(_L("Relative Timer") );
1241 INFO_PRINTF1(_L("Successfully able to create a timer with SIGEV_SIGNAL as sigev_notify parameter") );
1245 timer_delete(timerid);
1249 // -----------------------------------------------------------------------------
1250 // CTesttimer::Testtimerapi18
1251 // Test Case ID: OPENENV-LIBC-CIT-5946
1252 // API tested: timer_create(), timer_delete()
1253 // Description: To create a timer with SIGEV_SIGNAL as sigev_notify parameter
1254 // TIMER_ABSTIME set
1255 // -----------------------------------------------------------------------------
1257 TInt CTesttimer::Testtimerapi18 ( )
1259 int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
1260 struct sigevent sigev;
1261 struct itimerspec timerspec, oldtimerspec;
1262 struct timespec curtmspec;
1264 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
1267 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
1270 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
1273 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
1276 ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
1279 ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
1282 ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
1285 ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
1289 if(signal(SIGUSR1,overrun_handler) == SIG_ERR)
1291 ERR_PRINTF2(_L("Error in signal trapping function and errno is %d"), errno) ;
1294 sigev.sigev_notify = SIGEV_SIGNAL;
1295 sigev.sigev_signo = SIGUSR1;
1296 ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
1299 ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
1302 ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
1305 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
1309 timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
1310 timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec;
1311 timerspec.it_interval.tv_sec = Intervalsec;
1312 timerspec.it_interval.tv_nsec = Intervalnanosec;
1314 ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,&oldtimerspec);
1317 ERR_PRINTF2(_L("Failed to set the timer for signal and errno is %d"),errno);
1322 if(timer_value != SIGUSR1)
1324 ERR_PRINTF2(_L("The expected and timer_value are not same for signal %d"),errno);
1327 ret = timer_getoverrun(timerid);
1330 ERR_PRINTF2(_L("Error in timer_getoverrun() and errno is %d"),errno);
1334 ret = timer_delete(timerid);
1337 ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
1340 INFO_PRINTF1(_L("Absolute Timer") );
1341 INFO_PRINTF1(_L("Successfully able to create a timer with SIGEV_SIGNAL as sigev_notify parameter") );
1345 timer_delete(timerid);
1349 // -----------------------------------------------------------------------------
1350 // CTesttimer::Testtimerapi19
1351 // Test Case ID: OPENENV-LIBC-CIT-5946
1352 // API tested: timer_overrun(), timer_gettime()
1353 // Description: Negative test: timer_overrun(), timer_gettime() with an invalid timerid
1354 // -----------------------------------------------------------------------------
1356 TInt CTesttimer::Testtimerapi19 ( )
1359 int ret, ret1 = KErrGeneral;
1360 struct itimerspec timerspec;
1361 ret = timer_create(CLOCK_REALTIME,NULL,&timerid);
1364 ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno);
1367 INFO_PRINTF1(_L("successfully able to create the timer") );
1368 ret = timer_delete(timerid);
1371 ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
1374 INFO_PRINTF1(_L("Successfully able to delete the timer") );
1375 ret = timer_gettime(timerid,&timerspec);
1376 if((ret != -1) || (errno != EINVAL))
1378 ERR_PRINTF2(_L("timer_gettime() failed to return EINVAL on negative test and errno is %d"),errno);
1381 INFO_PRINTF1(_L("timer_gettime() successfully returned EINVAL on negative test") );
1382 ret = timer_getoverrun(timerid);
1383 if((ret != -1) || (errno != EINVAL))
1385 ERR_PRINTF2(_L("timer_getoverrun() failed to return EINVAL on negative test and errno is %d"),errno);
1388 INFO_PRINTF1(_L("timer_getoverrun() successfully returned EINVAL on negative test") );
1392 timer_delete(timerid);
1396 // -----------------------------------------------------------------------------
1397 // CTesttimer::Testtimerapi20
1398 // Test Case ID: OPENENV-LIBC-CIT-5946
1399 // API tested: timer_create()
1400 // Description: Negative test: timer_create() with an invalid signal
1401 // -----------------------------------------------------------------------------
1403 TInt CTesttimer::Testtimerapi20 ( )
1406 int ret, ret1 = KErrGeneral, Sigval;
1407 struct sigevent sigev;
1408 ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
1411 ERR_PRINTF1(_L("Unable to read signal number")) ;
1414 sigev.sigev_notify = SIGEV_SIGNAL;
1415 sigev.sigev_signo = Sigval;
1416 ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
1417 if((ret != -1) || (errno != EINVAL))
1419 ERR_PRINTF2(_L("timer_create() failed to return EINVAL on negative test and errno is %d"),errno);
1422 INFO_PRINTF1(_L("timer_create() with an invalid sigev_signo member") );
1423 INFO_PRINTF1(_L("timer_create() successfully returned EINVAL on negative test") );
1430 // -----------------------------------------------------------------------------
1431 // CTesttimer::Testtimerapi21
1432 // Test Case ID: OPENENV-LIBC-CIT-5946
1433 // API tested: timer_create()
1434 // Description: Negative test: timer_create() with an invalid sigev_notify member
1435 // -----------------------------------------------------------------------------
1437 TInt CTesttimer::Testtimerapi21 ( )
1440 int ret, ret1 = KErrGeneral, Sigval, Signum, Maxsig, Notify;
1441 struct sigevent sigev;
1442 ret = GetIntFromConfig(ConfigSection(), _L("Sigval"), Sigval);
1445 ERR_PRINTF1(_L("Unable to read signal number")) ;
1448 ret = GetIntFromConfig(ConfigSection(), _L("Maxsig"), Maxsig);
1451 ERR_PRINTF1(_L("Unable to read maximum signal number")) ;
1454 ret = GetIntFromConfig(ConfigSection(), _L("Notify"), Notify);
1457 ERR_PRINTF1(_L("Unable to read an invalid notify value")) ;
1460 for(Signum=Sigval; Signum <= Maxsig; Signum++)
1462 if((Signum == SIGSTOP) || (Signum == SIGKILL))
1466 sigev.sigev_notify = Notify;
1467 sigev.sigev_signo = Signum;
1468 ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
1469 if((ret != -1) || (errno != EINVAL))
1471 ERR_PRINTF2(_L("timer_create() failed to return EINVAL on negative test and errno is %d"),errno);
1475 INFO_PRINTF1(_L("timer_create() with an invalid sigev_notify member") );
1476 INFO_PRINTF1(_L("timer_create() successfully returned EINVAL on negative test") );
1483 // -----------------------------------------------------------------------------
1484 // CTesttimer::Testtimerapi22
1485 // Test Case ID: OPENENV-LIBC-CIT-5946
1486 // API tested: timer_settime()
1487 // Description: Negative test: timer_settime() with an input itimerspec value as NULL
1488 // -----------------------------------------------------------------------------
1490 TInt CTesttimer::Testtimerapi22 ( )
1492 int ret, ret1 = KErrGeneral;
1493 struct sigevent sigev;
1494 struct itimerspec timerspec;
1496 sigev.sigev_notify = SIGEV_NONE;
1497 ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
1500 ERR_PRINTF2(_L("Failed to create a timer and errno is %d"), errno );
1503 INFO_PRINTF1(_L("Successfully able to create a timer") );
1504 ret = timer_settime(timerid,0,NULL,&timerspec);
1505 if((ret != -1) || (errno != EINVAL))
1507 ERR_PRINTF2(_L("timer_settime() failed to return EINVAL on negative test and errno is %d"),errno);
1510 INFO_PRINTF1(_L("Successfully able to set the timer") );
1512 ret = timer_delete(timerid);
1515 ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
1518 INFO_PRINTF1(_L("timer_settime() with itimerspec input as NULL") );
1519 INFO_PRINTF1(_L("timer_settime() successfully returned EINVAL on negative test") );
1523 timer_delete(timerid);
1527 // -----------------------------------------------------------------------------
1528 // CTesttimer::Testtimerapi23
1529 // Test Case ID: OPENENV-LIBC-CIT-5946
1530 // API tested: timer_settime()
1531 // Description: Negative test: timer_settime() with an invalid flag member
1532 // -----------------------------------------------------------------------------
1534 TInt CTesttimer::Testtimerapi23 ( )
1536 int ret, ret1 = KErrGeneral;
1537 struct sigevent sigev;
1538 struct itimerspec timerspec;
1540 sigev.sigev_notify = SIGEV_NONE;
1541 ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
1544 ERR_PRINTF2(_L("Failed to create a timer and errno is %d"),errno );
1547 INFO_PRINTF1(_L("Successfully able to create a timer") );
1548 timerspec.it_value.tv_sec = 1;
1549 timerspec.it_value.tv_nsec = 0;
1550 timerspec.it_interval.tv_sec = 0;
1551 timerspec.it_interval.tv_nsec = 0;
1552 ret = timer_settime(timerid,-1,NULL,&timerspec);
1553 if((ret != -1) || (errno != EINVAL))
1555 ERR_PRINTF2(_L("timer_settime() failed to return EINVAL on negative test and errno is %d"),errno);
1558 INFO_PRINTF1(_L("Successfully able to set the timer") );
1560 ret = timer_delete(timerid);
1563 ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
1566 INFO_PRINTF1(_L("timer_settime() with an invalid flag value") );
1567 INFO_PRINTF1(_L("timer_settime() successfully returned EINVAL on negative test") );
1571 timer_delete(timerid);
1575 // -----------------------------------------------------------------------------
1576 // CTesttimer::Testtimerapi24
1577 // Test Case ID: OPENENV-LIBC-CIT-5946
1578 // API tested: timer_gettime()
1579 // Description: Negative test: timer_gettime() with an input itimerspec value as NULL
1580 // -----------------------------------------------------------------------------
1582 TInt CTesttimer::Testtimerapi24 ( )
1584 int ret, ret1 = KErrGeneral;
1585 struct sigevent sigev;
1586 struct itimerspec timerspec;
1589 sigev.sigev_notify = SIGEV_NONE;
1590 ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
1593 ERR_PRINTF1(_L("Failed to create a timer") );
1596 INFO_PRINTF1(_L("Successfully able to create a timer") );
1597 timerspec.it_value.tv_sec = 1;
1598 timerspec.it_value.tv_nsec = 0;
1599 timerspec.it_interval.tv_sec = 1;
1600 timerspec.it_interval.tv_nsec = 0;
1601 ret = timer_settime(timerid,0,&timerspec,NULL);
1604 ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
1608 INFO_PRINTF1(_L("Successfully able to set the timer") );
1609 ret = timer_gettime(timerid,NULL);
1610 if((ret != -1) || (errno != EFAULT))
1612 ERR_PRINTF2(_L("timer_gettime() failed to return EFAULT on negative test and errno is %d"),errno);
1615 ret = timer_delete(timerid);
1618 ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
1621 INFO_PRINTF1(_L("Successfully able to delete the timer") );
1622 INFO_PRINTF1(_L("timer_gettime() with an input itimerspec value as NULL") );
1623 INFO_PRINTF1(_L("timer_gettime() successfully returned EFAULT on negative test") );
1627 timer_delete(timerid);
1631 // -----------------------------------------------------------------------------
1632 // CTesttimer::Testtimerapi25
1633 // Test Case ID: OPENENV-LIBC-CIT-5946
1634 // API tested: timer_settime(),timer_gettime()
1635 // Description: To retreive the amount of time until the timer expires
1637 // -----------------------------------------------------------------------------
1639 TInt CTesttimer::Testtimerapi25 ( )
1641 int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
1642 struct sigevent sigev;
1643 struct itimerspec timerspec, gettime, oldtimerspec;
1645 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
1648 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
1651 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
1654 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
1657 ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
1660 ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
1663 ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
1666 ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
1669 sigev.sigev_notify = SIGEV_NONE;
1671 ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
1674 ERR_PRINTF2(_L("Failed to create a timer and errno is %d"), errno );
1677 INFO_PRINTF1(_L("Successfully able to create a timer") );
1678 timerspec.it_value.tv_sec = Valuesec;
1679 timerspec.it_value.tv_nsec = Valuenanosec;
1680 timerspec.it_interval.tv_sec = Intervalsec;
1681 timerspec.it_interval.tv_nsec = Intervalnanosec;
1682 ret = timer_settime(timerid,0,&timerspec,&oldtimerspec);
1685 ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno );
1690 INFO_PRINTF1(_L("Successfully able to set the timer") );
1691 ret = timer_gettime(timerid,&gettime);
1694 ERR_PRINTF2(_L("Failed to get the timer and the errno is %d"),errno );
1698 if((gettime.it_value.tv_sec > (timerspec.it_value.tv_sec-1)) || (gettime.it_value.tv_nsec > (timerspec.it_value.tv_nsec))|| (gettime.it_interval.tv_sec != timerspec.it_interval.tv_sec) || (gettime.it_interval.tv_nsec != timerspec.it_interval.tv_nsec))
1700 ERR_PRINTF1(_L("Failed to get the timer value") );
1704 INFO_PRINTF1(_L("Successfully able to get the timer") );
1705 ret = timer_delete(timerid);
1708 ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
1711 INFO_PRINTF1(_L("Successfully able to delete the timer") );
1715 timer_delete(timerid);
1719 // -----------------------------------------------------------------------------
1720 // CTesttimer::Testtimerapi26
1721 // Test Case ID: OPENENV-LIBC-CIT-5946
1722 // API tested: timer_settime(),timer_gettime()
1723 // Description: To retreive the amount of time until the timer expires
1725 // -----------------------------------------------------------------------------
1727 TInt CTesttimer::Testtimerapi26 ( )
1729 int ret, ret1 = KErrGeneral, Intervalsec, Intervalnanosec, Valuesec, Valuenanosec;
1730 struct sigevent sigev;
1731 struct itimerspec timerspec, gettime, oldtimerspec;
1732 struct timespec curtmspec;
1734 ret = GetIntFromConfig(ConfigSection(), _L("Valuesec"), Valuesec);
1737 ERR_PRINTF1(_L("Unable to read seconds value of it_value")) ;
1740 ret = GetIntFromConfig(ConfigSection(), _L("Valuenanosec"), Valuenanosec);
1743 ERR_PRINTF1(_L("Unable to read nano seconds value of it_value")) ;
1746 ret = GetIntFromConfig(ConfigSection(), _L("Intervalsec"), Intervalsec);
1749 ERR_PRINTF1(_L("Unable to read seconds value of it_interval")) ;
1752 ret = GetIntFromConfig(ConfigSection(), _L("Intervalnanosec"), Intervalnanosec);
1755 ERR_PRINTF1(_L("Unable to read nano seconds value of it_interval")) ;
1758 sigev.sigev_notify = SIGEV_NONE;
1760 ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
1763 ERR_PRINTF2(_L("Failed to create a timer and errno is %d"), errno );
1766 INFO_PRINTF1(_L("Successfully able to create a timer") );
1767 ret = clock_gettime(CLOCK_REALTIME,&curtmspec);
1770 ERR_PRINTF2(_L("Failed to get the time of specified clock id and errno is %d"),errno);
1774 timerspec.it_value.tv_sec = curtmspec.tv_sec + Valuesec;
1775 timerspec.it_value.tv_nsec = curtmspec.tv_nsec + Valuenanosec;
1776 timerspec.it_interval.tv_sec = Intervalsec;
1777 timerspec.it_interval.tv_nsec = Intervalnanosec;
1778 ret = timer_settime(timerid,TIMER_ABSTIME,&timerspec,&oldtimerspec);
1781 ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno );
1786 INFO_PRINTF1(_L("Successfully able to set the timer") );
1787 ret = timer_gettime(timerid,&gettime);
1790 ERR_PRINTF2(_L("Failed to get the timer and errno is %d"), errno );
1794 if((gettime.it_value.tv_sec > (Valuesec-1)) || (gettime.it_value.tv_nsec > (Valuenanosec))|| (gettime.it_interval.tv_sec != Intervalsec) || (gettime.it_interval.tv_nsec != Intervalnanosec))
1796 ERR_PRINTF1(_L("Failed to get the timer value") );
1800 INFO_PRINTF1(_L("Successfully able to get the timer") );
1801 ret = timer_delete(timerid);
1804 ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
1807 INFO_PRINTF1(_L("Successfully able to delete the timer") );
1811 timer_delete(timerid);
1815 // -----------------------------------------------------------------------------
1816 // CTesttimer::Testtimerapi27
1817 // Test Case ID: OPENENV-LIBC-CIT-5946
1818 // API tested: timer_settime(),timer_gettime()
1819 // Description: To retreive the amount of time until the timer expires using timer_settime()
1821 // -----------------------------------------------------------------------------
1823 TInt CTesttimer::Testtimerapi27 ( )
1825 int ret, ret1 = KErrGeneral;
1826 struct sigevent sigev;
1827 struct itimerspec timerspec1, gettime, oldtimerspec;
1829 sigev.sigev_notify = SIGEV_NONE;
1831 ret = timer_create(CLOCK_REALTIME,&sigev,&timerid);
1834 ERR_PRINTF2(_L("Failed to create a timer and errno is %d"), errno );
1837 INFO_PRINTF1(_L("Successfully able to create a timer") );
1838 timerspec1.it_value.tv_sec = 5;
1839 timerspec1.it_value.tv_nsec = 0;
1840 timerspec1.it_interval.tv_sec = 0;
1841 timerspec1.it_interval.tv_nsec = 0;
1842 ret = timer_settime(timerid,0,&timerspec1,NULL);
1845 ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno );
1849 INFO_PRINTF1(_L("Successfully able to set the timer for the first time") );
1851 timerspec1.it_value.tv_sec = 3;
1852 timerspec1.it_value.tv_nsec = 0;
1853 timerspec1.it_interval.tv_sec = 0;
1854 timerspec1.it_interval.tv_nsec = 0;
1855 ret = timer_settime(timerid,0,&timerspec1,&oldtimerspec);
1858 ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno );
1862 INFO_PRINTF1(_L("Successfully able to set the timer for the second time") );
1863 if(oldtimerspec.it_value.tv_sec > 4)
1865 ERR_PRINTF1(_L("Failed to set the timer value") );
1869 timerspec1.it_value.tv_sec = 0;
1870 timerspec1.it_value.tv_nsec = 0;
1871 timerspec1.it_interval.tv_sec = 0;
1872 timerspec1.it_interval.tv_nsec = 0;
1873 ret = timer_settime(timerid,0,&timerspec1,&oldtimerspec);
1876 ERR_PRINTF2(_L("Failed to set the timer and errno is %d"),errno);
1879 if(oldtimerspec.it_value.tv_sec > 2)
1881 ERR_PRINTF1(_L("Failed to set the timer value") );
1884 timerspec1.it_value.tv_sec = 2;
1885 timerspec1.it_value.tv_nsec = 0;
1886 timerspec1.it_interval.tv_sec = 5;
1887 timerspec1.it_interval.tv_nsec = 0;
1888 ret = timer_settime(timerid,0,&timerspec1,&oldtimerspec);
1891 ERR_PRINTF2(_L("Failed to set the timer and errno is %d"), errno);
1895 if(oldtimerspec.it_value.tv_sec != 0)
1897 ERR_PRINTF1(_L("Failed to set the timer value") );
1900 ret = timer_gettime(timerid,&gettime);
1903 ERR_PRINTF2(_L("Failed to get the timer and errno is %d"),errno);
1908 if((gettime.it_value.tv_sec > 2) || (gettime.it_interval.tv_sec != timerspec1.it_interval.tv_sec) || (gettime.it_interval.tv_nsec != timerspec1.it_interval.tv_nsec))
1910 ERR_PRINTF1(_L("Failed to get the timer value") );
1913 INFO_PRINTF1(_L("Successfully able to get the timer") );
1914 ret = timer_delete(timerid);
1917 ERR_PRINTF2(_L("Failed to delete the timer and errno is %d"),errno);
1920 INFO_PRINTF1(_L("Successfully able to delete the timer") );
1924 timer_delete(timerid);
1927 TInt CTesttimer::Testtimerapi28( )
1931 TRequestStatus timerThreadStatus1;
1932 RThread timerThread1;
1933 TTimerTestThreadParams paramsTimerThread1(*this);
1935 TRequestStatus timerThreadStatus2;
1936 RThread timerThread2;
1937 TTimerTestThreadParams paramsTimerThread2(*this);
1939 Logger().ShareAuto();
1940 //Create the Thread to create shared mem and write to it.
1941 err = timerThread1.Create(_L("TimerThread1"), (TThreadFunction)CTimerTestThread::OEEntry, KDefaultStackSize, KMinHeapSize, 1024*1024,¶msTimerThread1);
1944 ERR_PRINTF2(_L("Timer Thread1 Not created - %d"), err);
1945 SetTestStepResult(EFail);
1949 INFO_PRINTF1(_L("Timer Thread1 created "));
1950 //Create the thread to open shared mem and read from it.
1951 err = timerThread2.Create(_L("TimerThread2"), (TThreadFunction)CTimerTestThread::OEEntry, KDefaultStackSize, KMinHeapSize, 1024*1024,¶msTimerThread2);
1954 ERR_PRINTF2(_L("Timer Thread 2 Not created - %d"), err);
1955 SetTestStepResult(EFail);
1956 //Close the Write Thread created previously
1957 timerThread1.Close();
1961 INFO_PRINTF1(_L("Timer Thread created "));
1963 timerThread1.SetPriority(EPriorityNormal);
1964 timerThread2.SetPriority(EPriorityNormal);
1966 timerThread1.Logon(timerThreadStatus1);
1967 timerThread2.Logon(timerThreadStatus2);
1969 timerThread1.Resume();
1970 timerThread2.Resume();
1972 User::WaitForRequest(timerThreadStatus1);
1973 User::WaitForRequest(timerThreadStatus2);
1975 timerThread1.Close();
1976 timerThread2.Close();
1978 //Check the status of the threads..
1979 if(!paramsTimerThread1.iTestResult )
1981 ERR_PRINTF1(_L("Timer Thread 1 Not successful"));
1982 SetTestStepResult(EFail);
1984 if(!paramsTimerThread2.iTestResult )
1986 ERR_PRINTF1(_L("Timer Thread 2 Not successful"));
1987 SetTestStepResult(EFail);
1990 return TestStepResult();