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 if timer_settime() is using an absolute clock and the 9 * time has already taken place when the test is running that 10 * timer_settime() succeeds and the expiration notification is made. 11 * 12 * Steps: 13 * - Setup and then call timer_settime() with date in past. 14 * - If timer_settime() returns -1 fail. 15 * - If signal handler is not called after a sufficient amount of sleeping, 16 * fail. 17 * *** There is a potential false failure if timer_settime() does not 18 * return before the signal is sent. TBD if this _should_ happen in 19 * reality, though. 20 * For this test, signal SIGTOTEST will be used, clock CLOCK_REALTIME 21 * will be used. 22 */ 23 24 #include <time.h> 25 #include <signal.h> 26 #include <stdio.h> 27 #include <unistd.h> 28 #include <stdlib.h> 29 #include "posixtest.h" 30 31 #define SIGTOTEST SIGALRM 32 33 #define DATEINPAST 1037128358 //Nov 13, 2002 ~11:13am 34 35 #define LONGSLEEPTIME 10 36 37 void handler(int signo) 38 { 39 printf("Caught signal\n"); 40 printf("Test PASSED\n"); 41 exit(PTS_PASS); 42 } 43 44 int main(void) 45 { 46 struct sigevent ev; 47 struct sigaction act; 48 timer_t tid; 49 struct itimerspec its; 50 int flags = 0; 51 52 ev.sigev_notify = SIGEV_SIGNAL; 53 ev.sigev_signo = SIGTOTEST; 54 55 act.sa_handler = handler; 56 act.sa_flags = 0; 57 58 its.it_interval.tv_sec = 0; 59 its.it_interval.tv_nsec = 0; 60 its.it_value.tv_sec = DATEINPAST; 61 its.it_value.tv_nsec = 0; 62 63 if (sigemptyset(&act.sa_mask) == -1) { 64 perror("Error calling sigemptyset\n"); 65 return PTS_UNRESOLVED; 66 } 67 if (sigaction(SIGTOTEST, &act, 0) == -1) { 68 perror("Error calling sigaction\n"); 69 return PTS_UNRESOLVED; 70 } 71 72 if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { 73 perror("timer_create() did not return success\n"); 74 return PTS_UNRESOLVED; 75 } 76 77 flags |= TIMER_ABSTIME; 78 if (timer_settime(tid, flags, &its, NULL) != 0) { 79 perror("timer_settime() did not return success\n"); 80 return PTS_FAIL; 81 } 82 83 sleep(LONGSLEEPTIME); 84 85 printf("signal was not sent\n"); 86 return PTS_FAIL; 87 } 88