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 10 * the timer was previously disarmed because it had just expired with 11 * no repeating interval. 12 * 13 * For this test, signal SIGCONT will be used so that the test will 14 * not abort. Clock CLOCK_REALTIME will be used. 15 */ 16 17 #include <time.h> 18 #include <signal.h> 19 #include <stdio.h> 20 #include <unistd.h> 21 #include <stdlib.h> 22 #include "posixtest.h" 23 24 #define TIMERSEC 1 25 #define SLEEPDELTA 1 26 27 int main(void) 28 { 29 struct sigevent ev; 30 timer_t tid; 31 struct itimerspec its, oits; 32 33 ev.sigev_notify = SIGEV_SIGNAL; 34 ev.sigev_signo = SIGCONT; 35 36 its.it_interval.tv_sec = 0; 37 its.it_interval.tv_nsec = 0; 38 its.it_value.tv_sec = TIMERSEC; 39 its.it_value.tv_nsec = 0; 40 41 if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { 42 perror("timer_create() did not return success\n"); 43 return PTS_UNRESOLVED; 44 } 45 46 /* 47 * set up timer that will expire 48 */ 49 if (timer_settime(tid, 0, &its, &oits) != 0) { 50 perror("timer_settime() did not return success\n"); 51 return PTS_UNRESOLVED; 52 } 53 54 /* 55 * let timer expire (just call sleep()) 56 */ 57 sleep(TIMERSEC + SLEEPDELTA); 58 59 /* 60 * assign oits parameters so they _must_ be reset 61 */ 62 oits.it_value.tv_sec = 1000; 63 oits.it_value.tv_nsec = 1000; 64 oits.it_interval.tv_sec = 1000; 65 oits.it_interval.tv_nsec = 1000; 66 67 if (timer_settime(tid, 0, &its, &oits) != 0) { 68 perror("timer_settime() did not return success\n"); 69 return PTS_UNRESOLVED; 70 } 71 72 if ((0 == oits.it_value.tv_sec) && 73 (0 == oits.it_value.tv_nsec) && 74 (0 == oits.it_interval.tv_sec) && (0 == oits.it_interval.tv_nsec)) { 75 printf("Test PASSED\n"); 76 return PTS_PASS; 77 } 78 79 printf("Test FAILED: value: tv_sec %d tv_nsec %d\n", 80 (int)oits.it_value.tv_sec, (int)oits.it_value.tv_nsec); 81 82 printf("Test FAILED: interval: tv_sec %d tv_nsec %d\n", 83 (int)oits.it_interval.tv_sec, 84 (int)oits.it_interval.tv_nsec); 85 return PTS_FAIL; 86 } 87