1 /* 2 * Copyright (c) 2009-2011, The Regents of the University of California, 3 * through Lawrence Berkeley National Laboratory (subject to receipt of any 4 * required approvals from the U.S. Dept. of Energy). All rights reserved. 5 * 6 * This code is distributed under a BSD style license, see the LICENSE file 7 * for complete information. 8 */ 9 10 #include <stdio.h> 11 #include <stdlib.h> 12 #include <unistd.h> 13 #include <sys/time.h> 14 15 #include "timer.h" 16 17 18 static int flag; 19 20 21 static void 22 timer_proc( TimerClientData client_data, struct timeval* nowP ) 23 { 24 flag = 1; 25 } 26 27 28 int 29 main(int argc, char **argv) 30 { 31 Timer *tp; 32 33 flag = 0; 34 tp = tmr_create((struct timeval*) 0, timer_proc, JunkClientData, 3000000, 0); 35 if (!tp) 36 { 37 printf("failed to create timer\n"); 38 exit(-1); 39 } 40 41 sleep(2); 42 43 tmr_run((struct timeval*) 0); 44 if (flag) 45 { 46 printf("timer should not have expired\n"); 47 exit(-1); 48 } 49 sleep(1); 50 51 tmr_run((struct timeval*) 0); 52 if (!flag) 53 { 54 printf("timer should have expired\n"); 55 exit(-2); 56 } 57 58 tmr_destroy(); 59 exit(0); 60 } 61