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_interval = the previous
      9  * reload value.
     10  * - set up a timer to expire in TIMERSEC seconds with reload value RELOADVAL
     11  * - set up a new timer
     12  * - ensure ovalue.it_interval = RELOADVAL
     13  *
     14  * For this test, signal SIGCONT will be used so that the test will
     15  * not abort.  Clock CLOCK_REALTIME will be used.
     16  */
     17 
     18 #include <time.h>
     19 #include <signal.h>
     20 #include <stdio.h>
     21 #include <unistd.h>
     22 #include <stdlib.h>
     23 #include "posixtest.h"
     24 
     25 #define TIMERSEC 1
     26 #define RELOADVAL 8
     27 
     28 int main(void)
     29 {
     30 	struct sigevent ev;
     31 	timer_t tid;
     32 	struct itimerspec its, oits;
     33 
     34 	ev.sigev_notify = SIGEV_SIGNAL;
     35 	ev.sigev_signo = SIGCONT;
     36 
     37 	its.it_interval.tv_sec = RELOADVAL;
     38 	its.it_value.tv_sec = TIMERSEC;
     39 	its.it_interval.tv_nsec = 0;
     40 	its.it_value.tv_nsec = 0;
     41 
     42 	if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
     43 		perror("timer_create() did not return success\n");
     44 		return PTS_UNRESOLVED;
     45 	}
     46 
     47 	if (timer_settime(tid, 0, &its, &oits) != 0) {
     48 		perror("timer_settime() did not return success\n");
     49 		return PTS_UNRESOLVED;
     50 	}
     51 
     52 	/*
     53 	 * second call to timer_settime()
     54 	 */
     55 	if (timer_settime(tid, 0, &its, &oits) != 0) {
     56 		perror("timer_settime() did not return success\n");
     57 		return PTS_UNRESOLVED;
     58 	}
     59 
     60 	if (RELOADVAL == oits.it_interval.tv_sec) {
     61 		printf("Test PASSED\n");
     62 		return PTS_PASS;
     63 	}
     64 
     65 	printf("Test FAILED:  correct %d oits.it_interval %d\n",
     66 	       RELOADVAL, (int)oits.it_interval.tv_sec);
     67 	return PTS_FAIL;
     68 }
     69