Home | History | Annotate | Download | only in timer_gettime
      1 /*
      2  * Copyright (c) 2002, Intel Corporation. All rights reserved.
      3  * Created by:  julie.n.fleischer REMOVE-THIS AT intel DOT com
      4  * This file is licensed under the GPL license.  For the full content
      5  * of this license, see the COPYING file at the top level of this
      6  * source tree.
      7  *
      8  * Test that timer_gettime() sets itimerspec.it_value = 0 if
      9  * the timer was previously disarmed because it had just expired with
     10  * no repeating interval.
     11  *
     12  * For this test, signal SIGCONT will be used so that the test will
     13  * not abort.  Clock CLOCK_REALTIME will be used.
     14  */
     15 
     16 #include <time.h>
     17 #include <signal.h>
     18 #include <stdio.h>
     19 #include <unistd.h>
     20 #include <stdlib.h>
     21 #include "posixtest.h"
     22 
     23 #define TIMERSEC 1
     24 #define SLEEPDELTA 1
     25 
     26 int main(void)
     27 {
     28 	struct sigevent ev;
     29 	timer_t tid;
     30 	struct itimerspec itsset, itsget;
     31 
     32 	ev.sigev_notify = SIGEV_SIGNAL;
     33 	ev.sigev_signo = SIGCONT;
     34 
     35 	itsset.it_interval.tv_sec = 0;
     36 	itsset.it_interval.tv_nsec = 0;
     37 	itsset.it_value.tv_sec = TIMERSEC;
     38 	itsset.it_value.tv_nsec = 0;
     39 
     40 	if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
     41 		perror("timer_create() did not return success\n");
     42 		return PTS_UNRESOLVED;
     43 	}
     44 
     45 	/*
     46 	 * set up timer that will expire
     47 	 */
     48 	if (timer_settime(tid, 0, &itsset, NULL) != 0) {
     49 		perror("timer_settime() did not return success\n");
     50 		return PTS_UNRESOLVED;
     51 	}
     52 
     53 	/*
     54 	 * let timer expire (just call sleep())
     55 	 */
     56 	sleep(TIMERSEC + SLEEPDELTA);
     57 
     58 	if (timer_gettime(tid, &itsget) != 0) {
     59 		perror("timer_gettime() did not return success\n");
     60 		return PTS_UNRESOLVED;
     61 	}
     62 
     63 	if (0 == itsget.it_value.tv_sec && 0 == itsget.it_value.tv_nsec) {
     64 		printf("Test PASSED\n");
     65 		return PTS_PASS;
     66 	}
     67 
     68 	printf("Test FAILED:  tv_sec %d tv_nsec %d\n",
     69 	       (int)itsget.it_value.tv_sec,
     70 	       (int)itsget.it_value.tv_nsec);
     71 	return PTS_FAIL;
     72 }
     73