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 to see if timer_delete() returns -1 and sets errno==EINVAL when 9 * trying to delete a timer that has already been deleted or not. 10 * Since this is a "may" assertion, either option is a pass. 11 * Steps: 12 * - Run test case 1-1.c and then try to delete the timer again. 13 * 14 * For this test, signal SIGTOTEST will be used, clock CLOCK_REALTIME 15 * 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 <errno.h> 24 #include "posixtest.h" 25 26 #define SIGTOTEST SIGALRM 27 #define TIMERSEC 3 28 29 void handler(int signo) 30 { 31 printf("Should not have caught signal\n"); 32 exit(PTS_FAIL); 33 } 34 35 int main(void) 36 { 37 struct sigevent ev; 38 struct sigaction act; 39 timer_t tid; 40 struct itimerspec its; 41 42 ev.sigev_notify = SIGEV_SIGNAL; 43 ev.sigev_signo = SIGTOTEST; 44 45 act.sa_handler = handler; 46 act.sa_flags = 0; 47 48 its.it_interval.tv_sec = 0; 49 its.it_interval.tv_nsec = 0; 50 its.it_value.tv_sec = TIMERSEC; 51 its.it_value.tv_nsec = 0; 52 53 if (sigemptyset(&act.sa_mask) == -1) { 54 perror("Error calling sigemptyset\n"); 55 return PTS_UNRESOLVED; 56 } 57 if (sigaction(SIGTOTEST, &act, 0) == -1) { 58 perror("Error calling sigaction\n"); 59 return PTS_UNRESOLVED; 60 } 61 62 if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { 63 perror("timer_create() did not return success\n"); 64 return PTS_UNRESOLVED; 65 } 66 67 if (timer_settime(tid, 0, &its, NULL) != 0) { 68 perror("timer_settime() did not return success\n"); 69 return PTS_UNRESOLVED; 70 } 71 72 if (timer_delete(tid) != 0) { 73 perror("timer_delete() did not return success\n"); 74 return PTS_UNRESOLVED; 75 } 76 77 if (sleep(TIMERSEC) != 0) { 78 printf("sleep() did not sleep full time\n"); 79 return PTS_UNRESOLVED; 80 } 81 82 if (timer_delete(tid) == -1) { 83 if (errno == EINVAL) { 84 printf("fcn returned -1 and set errno=EINVAL\n"); 85 return PTS_PASS; 86 } else { 87 printf("errno!=EINVAL, but fcn returned -1\n"); 88 return PTS_FAIL; 89 } 90 } 91 92 printf("fcn did not return -1\n"); 93 return PTS_PASS; 94 } 95