8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sendmail / libsm / t-event.c
blob9eab98b0f8fe64c4a9cf4614337e45495b80d69f
1 /*
2 * Copyright (c) 2001-2002, 2004 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
8 */
10 #pragma ident "%Z%%M% %I% %E% SMI"
12 #include <sm/gen.h>
13 SM_RCSID("@(#)$Id: t-event.c,v 1.13 2005/06/14 23:07:20 ca Exp $")
15 #include <stdio.h>
17 #include <stdlib.h>
18 #include <unistd.h>
19 # include <sys/wait.h>
20 #if SM_CONF_SETITIMER
21 # include <sm/time.h>
22 #endif /* SM_CONF_SETITIMER */
24 #include <sm/clock.h>
25 #include <sm/test.h>
27 static void evcheck __P((int));
28 static void ev1 __P((int));
30 static int check;
32 static void
33 evcheck(arg)
34 int arg;
36 SM_TEST(arg == 3);
37 SM_TEST(check == 0);
38 check++;
41 static void
42 ev1(arg)
43 int arg;
45 SM_TEST(arg == 1);
48 /* define as x if you want debug output */
49 #define DBG_OUT(x)
51 int
52 main(argc, argv)
53 int argc;
54 char *argv[];
56 SM_EVENT *ev;
58 sm_test_begin(argc, argv, "test event handling");
59 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 SM_CONF_SETITIMER == 0 ? 1 : 0);
61 sleep(1);
62 SM_TEST(1 == 1);
63 DBG_OUT(fprintf(stdout, "We're back, test 1 seems to work.\n"));
64 ev = sm_seteventm(1000, ev1, 1);
65 sleep(1);
66 SM_TEST(2 == 2);
67 DBG_OUT(fprintf(stdout, "We're back, test 2 seems to work.\n"));
69 /* schedule an event in 9s */
70 ev = sm_seteventm(9000, ev1, 2);
71 sleep(1);
73 /* clear the event before it can fire */
74 sm_clrevent(ev);
75 SM_TEST(3 == 3);
76 DBG_OUT(fprintf(stdout, "We're back, test 3 seems to work.\n"));
78 /* schedule an event in 1s */
79 check = 0;
80 ev = sm_seteventm(1000, evcheck, 3);
81 sleep(2);
83 /* clear the event */
84 sm_clrevent(ev);
85 SM_TEST(4 == 4);
86 SM_TEST(check == 1);
87 DBG_OUT(fprintf(stdout, "We're back, test 4 seems to work.\n"));
89 return sm_test_end();