xref: /titanic_44/usr/src/cmd/sendmail/libsm/t-event.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2001-2002, 2004 Sendmail, Inc. and its suppliers.
3*7c478bd9Sstevel@tonic-gate  *      All rights reserved.
4*7c478bd9Sstevel@tonic-gate  *
5*7c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
6*7c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
7*7c478bd9Sstevel@tonic-gate  * the sendmail distribution.
8*7c478bd9Sstevel@tonic-gate  */
9*7c478bd9Sstevel@tonic-gate 
10*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
11*7c478bd9Sstevel@tonic-gate 
12*7c478bd9Sstevel@tonic-gate #include <sm/gen.h>
13*7c478bd9Sstevel@tonic-gate SM_RCSID("@(#)$Id: t-event.c,v 1.12 2004/08/03 20:50:32 ca Exp $")
14*7c478bd9Sstevel@tonic-gate 
15*7c478bd9Sstevel@tonic-gate #include <stdio.h>
16*7c478bd9Sstevel@tonic-gate 
17*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
18*7c478bd9Sstevel@tonic-gate #include <unistd.h>
19*7c478bd9Sstevel@tonic-gate # include <sys/wait.h>
20*7c478bd9Sstevel@tonic-gate #if SM_CONF_SETITIMER
21*7c478bd9Sstevel@tonic-gate # include <sys/time.h>
22*7c478bd9Sstevel@tonic-gate #endif /* SM_CONF_SETITIMER */
23*7c478bd9Sstevel@tonic-gate 
24*7c478bd9Sstevel@tonic-gate #include <sm/clock.h>
25*7c478bd9Sstevel@tonic-gate #include <sm/test.h>
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate static void	evcheck __P((int));
28*7c478bd9Sstevel@tonic-gate static void	ev1 __P((int));
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate static int check;
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate static void
33*7c478bd9Sstevel@tonic-gate evcheck(arg)
34*7c478bd9Sstevel@tonic-gate 	int arg;
35*7c478bd9Sstevel@tonic-gate {
36*7c478bd9Sstevel@tonic-gate 	SM_TEST(arg == 3);
37*7c478bd9Sstevel@tonic-gate 	SM_TEST(check == 0);
38*7c478bd9Sstevel@tonic-gate 	check++;
39*7c478bd9Sstevel@tonic-gate }
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate static void
42*7c478bd9Sstevel@tonic-gate ev1(arg)
43*7c478bd9Sstevel@tonic-gate 	int arg;
44*7c478bd9Sstevel@tonic-gate {
45*7c478bd9Sstevel@tonic-gate 	SM_TEST(arg == 1);
46*7c478bd9Sstevel@tonic-gate }
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate /* define as x if you want debug output */
49*7c478bd9Sstevel@tonic-gate #define DBG_OUT(x)
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate int
52*7c478bd9Sstevel@tonic-gate main(argc, argv)
53*7c478bd9Sstevel@tonic-gate 	int argc;
54*7c478bd9Sstevel@tonic-gate 	char *argv[];
55*7c478bd9Sstevel@tonic-gate {
56*7c478bd9Sstevel@tonic-gate 	SM_EVENT *ev;
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate 	sm_test_begin(argc, argv, "test event handling");
59*7c478bd9Sstevel@tonic-gate 	fprintf(stdout, "This test may hang. If there is no output within twelve seconds, abort it\nand recompile with -DSM_CONF_SETITIMER=%d\n",
60*7c478bd9Sstevel@tonic-gate 		SM_CONF_SETITIMER == 0 ? 1 : 0);
61*7c478bd9Sstevel@tonic-gate 	sleep(1);
62*7c478bd9Sstevel@tonic-gate 	SM_TEST(1 == 1);
63*7c478bd9Sstevel@tonic-gate 	DBG_OUT(fprintf(stdout, "We're back, test 1 seems to work.\n"));
64*7c478bd9Sstevel@tonic-gate 	ev = sm_seteventm(1000, ev1, 1);
65*7c478bd9Sstevel@tonic-gate 	sleep(1);
66*7c478bd9Sstevel@tonic-gate 	SM_TEST(2 == 2);
67*7c478bd9Sstevel@tonic-gate 	DBG_OUT(fprintf(stdout, "We're back, test 2 seems to work.\n"));
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate 	/* schedule an event in 9s */
70*7c478bd9Sstevel@tonic-gate 	ev = sm_seteventm(9000, ev1, 2);
71*7c478bd9Sstevel@tonic-gate 	sleep(1);
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate 	/* clear the event before it can fire */
74*7c478bd9Sstevel@tonic-gate 	sm_clrevent(ev);
75*7c478bd9Sstevel@tonic-gate 	SM_TEST(3 == 3);
76*7c478bd9Sstevel@tonic-gate 	DBG_OUT(fprintf(stdout, "We're back, test 3 seems to work.\n"));
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate 	/* schedule an event in 1s */
79*7c478bd9Sstevel@tonic-gate 	check = 0;
80*7c478bd9Sstevel@tonic-gate 	ev = sm_seteventm(1000, evcheck, 3);
81*7c478bd9Sstevel@tonic-gate 	sleep(2);
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 	/* clear the event */
84*7c478bd9Sstevel@tonic-gate 	sm_clrevent(ev);
85*7c478bd9Sstevel@tonic-gate 	SM_TEST(4 == 4);
86*7c478bd9Sstevel@tonic-gate 	SM_TEST(check == 1);
87*7c478bd9Sstevel@tonic-gate 	DBG_OUT(fprintf(stdout, "We're back, test 4 seems to work.\n"));
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate 	return sm_test_end();
90*7c478bd9Sstevel@tonic-gate }
91