190792Sgshapiro/* 2261363Sgshapiro * Copyright (c) 2001-2002, 2004 Proofpoint, Inc. and its suppliers. 390792Sgshapiro * All rights reserved. 490792Sgshapiro * 590792Sgshapiro * By using this file, you agree to the terms and conditions set 690792Sgshapiro * forth in the LICENSE file which can be found at the top level of 790792Sgshapiro * the sendmail distribution. 890792Sgshapiro */ 990792Sgshapiro 1090792Sgshapiro#include <sm/gen.h> 11266692SgshapiroSM_RCSID("@(#)$Id: t-event.c,v 1.14 2013-11-22 20:51:43 ca Exp $") 1290792Sgshapiro 1390792Sgshapiro#include <stdio.h> 1490792Sgshapiro 1590792Sgshapiro#include <stdlib.h> 1690792Sgshapiro#include <unistd.h> 1794334Sgshapiro# include <sys/wait.h> 1890792Sgshapiro#if SM_CONF_SETITIMER 19157001Sgshapiro# include <sm/time.h> 2090792Sgshapiro#endif /* SM_CONF_SETITIMER */ 2190792Sgshapiro 2290792Sgshapiro#include <sm/clock.h> 2390792Sgshapiro#include <sm/test.h> 2490792Sgshapiro 25141858Sgshapirostatic void evcheck __P((int)); 26141858Sgshapirostatic void ev1 __P((int)); 2790792Sgshapiro 28141858Sgshapirostatic int check; 29141858Sgshapiro 30141858Sgshapirostatic void 3190792Sgshapiroevcheck(arg) 3290792Sgshapiro int arg; 3390792Sgshapiro{ 3490792Sgshapiro SM_TEST(arg == 3); 3590792Sgshapiro SM_TEST(check == 0); 3690792Sgshapiro check++; 3790792Sgshapiro} 3890792Sgshapiro 39141858Sgshapirostatic void 4090792Sgshapiroev1(arg) 4190792Sgshapiro int arg; 4290792Sgshapiro{ 4390792Sgshapiro SM_TEST(arg == 1); 4490792Sgshapiro} 4590792Sgshapiro 4690792Sgshapiro/* define as x if you want debug output */ 4790792Sgshapiro#define DBG_OUT(x) 4890792Sgshapiro 4990792Sgshapiroint 5090792Sgshapiromain(argc, argv) 5190792Sgshapiro int argc; 5290792Sgshapiro char *argv[]; 5390792Sgshapiro{ 5490792Sgshapiro SM_EVENT *ev; 5590792Sgshapiro 5690792Sgshapiro sm_test_begin(argc, argv, "test event handling"); 5794334Sgshapiro fprintf(stdout, "This test may hang. If there is no output within twelve seconds, abort it\nand recompile with -DSM_CONF_SETITIMER=%d\n", 5890792Sgshapiro SM_CONF_SETITIMER == 0 ? 1 : 0); 5990792Sgshapiro sleep(1); 6090792Sgshapiro SM_TEST(1 == 1); 6190792Sgshapiro DBG_OUT(fprintf(stdout, "We're back, test 1 seems to work.\n")); 6290792Sgshapiro ev = sm_seteventm(1000, ev1, 1); 6390792Sgshapiro sleep(1); 6490792Sgshapiro SM_TEST(2 == 2); 6590792Sgshapiro DBG_OUT(fprintf(stdout, "We're back, test 2 seems to work.\n")); 6690792Sgshapiro 6790792Sgshapiro /* schedule an event in 9s */ 6890792Sgshapiro ev = sm_seteventm(9000, ev1, 2); 6990792Sgshapiro sleep(1); 7090792Sgshapiro 7190792Sgshapiro /* clear the event before it can fire */ 7290792Sgshapiro sm_clrevent(ev); 7390792Sgshapiro SM_TEST(3 == 3); 7490792Sgshapiro DBG_OUT(fprintf(stdout, "We're back, test 3 seems to work.\n")); 7590792Sgshapiro 7690792Sgshapiro /* schedule an event in 1s */ 7790792Sgshapiro check = 0; 7890792Sgshapiro ev = sm_seteventm(1000, evcheck, 3); 7990792Sgshapiro sleep(2); 8090792Sgshapiro 8190792Sgshapiro /* clear the event */ 8290792Sgshapiro sm_clrevent(ev); 8390792Sgshapiro SM_TEST(4 == 4); 8490792Sgshapiro SM_TEST(check == 1); 8590792Sgshapiro DBG_OUT(fprintf(stdout, "We're back, test 4 seems to work.\n")); 8690792Sgshapiro 8790792Sgshapiro return sm_test_end(); 8890792Sgshapiro} 89