Home | History | Annotate | Download | only in timer_settime
      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_settime() will return ovalue.it_value = 0
      9  * and ovalue.it_interval = 0 if the timer was previously disarmed
     10  * because it had just been created.
     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 
     25 int main(void)
     26 {
     27 	struct sigevent ev;
     28 	timer_t tid;
     29 	struct itimerspec its, oits;
     30 
     31 	ev.sigev_notify = SIGEV_SIGNAL;
     32 	ev.sigev_signo = SIGCONT;
     33 
     34 	its.it_interval.tv_sec = 0;
     35 	its.it_interval.tv_nsec = 0;
     36 	its.it_value.tv_sec = TIMERSEC;
     37 	its.it_value.tv_nsec = 0;
     38 
     39 	if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
     40 		perror("timer_create() did not return success\n");
     41 		return PTS_UNRESOLVED;
     42 	}
     43 
     44 	if (timer_settime(tid, 0, &its, &oits) != 0) {
     45 		perror("timer_settime() did not return success\n");
     46 		return PTS_UNRESOLVED;
     47 	}
     48 
     49 	if ((0 == oits.it_value.tv_sec) &&
     50 	    (0 == oits.it_value.tv_nsec) &&
     51 	    (0 == oits.it_interval.tv_sec) && (0 == oits.it_interval.tv_nsec)) {
     52 		printf("Test PASSED\n");
     53 		return PTS_PASS;
     54 	}
     55 
     56 	printf("Test FAILED:  value: tv_sec %d tv_nsec %d\n",
     57 	       (int)oits.it_value.tv_sec, (int)oits.it_value.tv_nsec);
     58 	printf("Test FAILED:  interval: tv_sec %d tv_nsec %d\n",
     59 	       (int)oits.it_interval.tv_sec,
     60 	       (int)oits.it_interval.tv_nsec);
     61 	return PTS_FAIL;
     62 }
     63