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_delete() deletes a timer. 9 * Steps: 10 * - Create a timer to send SIGTOTEST on expiration and set up a signal 11 * handler to catch it. 12 * - Activate the timer. 13 * - Delete the timer before the timer had a chance to expire. [Potential 14 * false failure here if the timer cannot be deleted in time. However, 15 * the timer expiration will be set large enough that this should not 16 * be likely.] 17 * - Sleep until the timer would have expired. 18 * - If no signal was caught, PASS. Otherwise, FAIL. 19 * 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#define TIMERSEC 3 33 34void handler(int signo) 35{ 36 printf("Should not have caught signal\n"); 37 exit(PTS_FAIL); 38} 39 40int main(int argc, char *argv[]) 41{ 42 struct sigevent ev; 43 struct sigaction act; 44 timer_t tid; 45 struct itimerspec its; 46 47 ev.sigev_notify = SIGEV_SIGNAL; 48 ev.sigev_signo = SIGTOTEST; 49 50 act.sa_handler=handler; 51 act.sa_flags=0; 52 53 its.it_interval.tv_sec = 0; 54 its.it_interval.tv_nsec = 0; 55 its.it_value.tv_sec = TIMERSEC; 56 its.it_value.tv_nsec = 0; 57 58 if (sigemptyset(&act.sa_mask) == -1) { 59 perror("Error calling sigemptyset\n"); 60 return PTS_UNRESOLVED; 61 } 62 if (sigaction(SIGTOTEST, &act, 0) == -1) { 63 perror("Error calling sigaction\n"); 64 return PTS_UNRESOLVED; 65 } 66 67 if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { 68 perror("timer_create() did not return success\n"); 69 return PTS_UNRESOLVED; 70 } 71 72 if (timer_settime(tid, 0, &its, NULL) != 0) { 73 perror("timer_settime() did not return success\n"); 74 return PTS_UNRESOLVED; 75 } 76 77 if (timer_delete(tid) != 0) { 78 perror("timer_delete() did not return success\n"); 79 return PTS_UNRESOLVED; 80 } 81 82 if (sleep(TIMERSEC) != 0) { 83 printf("sleep() did not sleep full time\n"); 84 return PTS_FAIL; 85 } 86 87 printf("Test PASSED\n"); 88 return PTS_PASS; 89} 90