Home | History | Annotate | Download | only in timer_create
      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 timers are disarmed and deleted by an exec.
      9  *
     10  * Steps:
     11  * 1.  Set up a timer
     12  * 2.  Call execl to sleep for a few seconds
     13  * 3.  If timer does not interrupt the execl, it will return success.
     14  *     If it does interrupt, or if execl fails, return failure.
     15  *
     16  * For this test, signal SIGTOTEST will be used, clock CLOCK_REALTIME
     17  * will be used.
     18  */
     19 
     20 #include <time.h>
     21 #include <signal.h>
     22 #include <stdio.h>
     23 #include <unistd.h>
     24 #include <stdlib.h>
     25 #include "posixtest.h"
     26 
     27 #define SIGTOTEST SIGALRM
     28 #define TIMERSEC 2
     29 #define SLEEPDELTA 3
     30 #define ACCEPTABLEDELTA 1
     31 
     32 void handler(int signo)
     33 {
     34 	printf("Caught signal\n");
     35 }
     36 
     37 int main(void)
     38 {
     39 	struct sigevent ev;
     40 	struct sigaction act;
     41 	timer_t tid;
     42 	struct itimerspec its;
     43 
     44 	ev.sigev_notify = SIGEV_SIGNAL;
     45 	ev.sigev_signo = SIGTOTEST;
     46 
     47 	act.sa_handler = handler;
     48 	act.sa_flags = 0;
     49 
     50 	its.it_interval.tv_sec = 0;
     51 	its.it_interval.tv_nsec = 0;
     52 	its.it_value.tv_sec = TIMERSEC;
     53 	its.it_value.tv_nsec = 0;
     54 
     55 	if (sigemptyset(&act.sa_mask) == -1) {
     56 		perror("Error calling sigemptyset\n");
     57 		return PTS_UNRESOLVED;
     58 	}
     59 	if (sigaction(SIGTOTEST, &act, 0) == -1) {
     60 		perror("Error calling sigaction\n");
     61 		return PTS_UNRESOLVED;
     62 	}
     63 
     64 	if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
     65 		perror("timer_create() did not return success\n");
     66 		return PTS_UNRESOLVED;
     67 	}
     68 
     69 	if (timer_settime(tid, 0, &its, NULL) != 0) {
     70 		perror("timer_settime() did not return success\n");
     71 		return PTS_UNRESOLVED;
     72 	}
     73 
     74 	if (execl("/bin/sleep", "sleep", "3", NULL) == -1) {
     75 		printf("Test FAILED\n");
     76 		return PTS_FAIL;
     77 	}
     78 
     79 	return PTS_FAIL;
     80 }
     81