t-event.c revision 261363
1174195Srwatson/* 2174195Srwatson * Copyright (c) 2001-2002, 2004 Proofpoint, Inc. and its suppliers. 3174195Srwatson * All rights reserved. 4174195Srwatson * 5174195Srwatson * By using this file, you agree to the terms and conditions set 6174195Srwatson * forth in the LICENSE file which can be found at the top level of 7174195Srwatson * the sendmail distribution. 8174195Srwatson */ 9174195Srwatson 10174195Srwatson#include <sm/gen.h> 11174195SrwatsonSM_RCSID("@(#)$Id: t-event.c,v 1.14 2013/11/22 20:51:43 ca Exp $") 12174195Srwatson 13174195Srwatson#include <stdio.h> 14174195Srwatson 15174195Srwatson#include <stdlib.h> 16174195Srwatson#include <unistd.h> 17174195Srwatson# include <sys/wait.h> 18174195Srwatson#if SM_CONF_SETITIMER 19174195Srwatson# include <sm/time.h> 20174195Srwatson#endif /* SM_CONF_SETITIMER */ 21174195Srwatson 22174195Srwatson#include <sm/clock.h> 23174195Srwatson#include <sm/test.h> 24174195Srwatson 25174195Srwatsonstatic void evcheck __P((int)); 26174195Srwatsonstatic void ev1 __P((int)); 27174195Srwatson 28174195Srwatsonstatic int check; 29174195Srwatson 30174195Srwatsonstatic void 31174195Srwatsonevcheck(arg) 32174195Srwatson int arg; 33174195Srwatson{ 34174195Srwatson SM_TEST(arg == 3); 35174195Srwatson SM_TEST(check == 0); 36174195Srwatson check++; 37174195Srwatson} 38174195Srwatson 39174195Srwatsonstatic void 40174195Srwatsonev1(arg) 41 int arg; 42{ 43 SM_TEST(arg == 1); 44} 45 46/* define as x if you want debug output */ 47#define DBG_OUT(x) 48 49int 50main(argc, argv) 51 int argc; 52 char *argv[]; 53{ 54 SM_EVENT *ev; 55 56 sm_test_begin(argc, argv, "test event handling"); 57 fprintf(stdout, "This test may hang. If there is no output within twelve seconds, abort it\nand recompile with -DSM_CONF_SETITIMER=%d\n", 58 SM_CONF_SETITIMER == 0 ? 1 : 0); 59 sleep(1); 60 SM_TEST(1 == 1); 61 DBG_OUT(fprintf(stdout, "We're back, test 1 seems to work.\n")); 62 ev = sm_seteventm(1000, ev1, 1); 63 sleep(1); 64 SM_TEST(2 == 2); 65 DBG_OUT(fprintf(stdout, "We're back, test 2 seems to work.\n")); 66 67 /* schedule an event in 9s */ 68 ev = sm_seteventm(9000, ev1, 2); 69 sleep(1); 70 71 /* clear the event before it can fire */ 72 sm_clrevent(ev); 73 SM_TEST(3 == 3); 74 DBG_OUT(fprintf(stdout, "We're back, test 3 seems to work.\n")); 75 76 /* schedule an event in 1s */ 77 check = 0; 78 ev = sm_seteventm(1000, evcheck, 3); 79 sleep(2); 80 81 /* clear the event */ 82 sm_clrevent(ev); 83 SM_TEST(4 == 4); 84 SM_TEST(check == 1); 85 DBG_OUT(fprintf(stdout, "We're back, test 4 seems to work.\n")); 86 87 return sm_test_end(); 88} 89