t-event.c revision 90792
190792Sgshapiro/*
290792Sgshapiro * Copyright (c) 2001 Sendmail, 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>
1190792SgshapiroSM_RCSID("@(#)$Id: t-event.c,v 1.7 2001/09/11 04:04:49 gshapiro Exp $")
1290792Sgshapiro
1390792Sgshapiro#include <stdio.h>
1490792Sgshapiro
1590792Sgshapiro#include <stdlib.h>
1690792Sgshapiro#include <unistd.h>
1790792Sgshapiro#include <sys/wait.h>
1890792Sgshapiro#if SM_CONF_SETITIMER
1990792Sgshapiro# include <sys/time.h>
2090792Sgshapiro#endif /* SM_CONF_SETITIMER */
2190792Sgshapiro
2290792Sgshapiro#include <sm/clock.h>
2390792Sgshapiro#include <sm/test.h>
2490792Sgshapiro
2590792Sgshapiroint check;
2690792Sgshapiro
2790792Sgshapirovoid
2890792Sgshapiroevcheck(arg)
2990792Sgshapiro	int arg;
3090792Sgshapiro{
3190792Sgshapiro	SM_TEST(arg == 3);
3290792Sgshapiro	SM_TEST(check == 0);
3390792Sgshapiro	check++;
3490792Sgshapiro}
3590792Sgshapiro
3690792Sgshapirovoid
3790792Sgshapiroev1(arg)
3890792Sgshapiro	int arg;
3990792Sgshapiro{
4090792Sgshapiro	SM_TEST(arg == 1);
4190792Sgshapiro}
4290792Sgshapiro
4390792Sgshapiro/* define as x if you want debug output */
4490792Sgshapiro#define DBG_OUT(x)
4590792Sgshapiro
4690792Sgshapiroint
4790792Sgshapiromain(argc, argv)
4890792Sgshapiro	int argc;
4990792Sgshapiro	char *argv[];
5090792Sgshapiro{
5190792Sgshapiro	SM_EVENT *ev;
5290792Sgshapiro
5390792Sgshapiro	sm_test_begin(argc, argv, "test event handling");
5490792Sgshapiro	fprintf(stdout, "this test may hang. If there is no output within twelve seconds, abort it\nand recompile with -DSM_CONF_SETITIMER=%d\n",
5590792Sgshapiro		SM_CONF_SETITIMER == 0 ? 1 : 0);
5690792Sgshapiro	sleep(1);
5790792Sgshapiro	SM_TEST(1 == 1);
5890792Sgshapiro	DBG_OUT(fprintf(stdout, "We're back, test 1 seems to work.\n"));
5990792Sgshapiro	ev = sm_seteventm(1000, ev1, 1);
6090792Sgshapiro	sleep(1);
6190792Sgshapiro	SM_TEST(2 == 2);
6290792Sgshapiro	DBG_OUT(fprintf(stdout, "We're back, test 2 seems to work.\n"));
6390792Sgshapiro
6490792Sgshapiro	/* schedule an event in 9s */
6590792Sgshapiro	ev = sm_seteventm(9000, ev1, 2);
6690792Sgshapiro	sleep(1);
6790792Sgshapiro
6890792Sgshapiro	/* clear the event before it can fire */
6990792Sgshapiro	sm_clrevent(ev);
7090792Sgshapiro	SM_TEST(3 == 3);
7190792Sgshapiro	DBG_OUT(fprintf(stdout, "We're back, test 3 seems to work.\n"));
7290792Sgshapiro
7390792Sgshapiro	/* schedule an event in 1s */
7490792Sgshapiro	check = 0;
7590792Sgshapiro	ev = sm_seteventm(1000, evcheck, 3);
7690792Sgshapiro	sleep(2);
7790792Sgshapiro
7890792Sgshapiro	/* clear the event */
7990792Sgshapiro	sm_clrevent(ev);
8090792Sgshapiro	SM_TEST(4 == 4);
8190792Sgshapiro	SM_TEST(check == 1);
8290792Sgshapiro	DBG_OUT(fprintf(stdout, "We're back, test 4 seems to work.\n"));
8390792Sgshapiro
8490792Sgshapiro	return sm_test_end();
8590792Sgshapiro}
86