140266059SGregory Neil Shapiro /*
25dd76dd0SGregory Neil Shapiro * Copyright (c) 2001-2002, 2004 Proofpoint, Inc. and its suppliers.
340266059SGregory Neil Shapiro * All rights reserved.
440266059SGregory Neil Shapiro *
540266059SGregory Neil Shapiro * By using this file, you agree to the terms and conditions set
640266059SGregory Neil Shapiro * forth in the LICENSE file which can be found at the top level of
740266059SGregory Neil Shapiro * the sendmail distribution.
840266059SGregory Neil Shapiro */
940266059SGregory Neil Shapiro
1040266059SGregory Neil Shapiro #include <sm/gen.h>
114313cc83SGregory Neil Shapiro SM_RCSID("@(#)$Id: t-event.c,v 1.14 2013-11-22 20:51:43 ca Exp $")
1240266059SGregory Neil Shapiro
1340266059SGregory Neil Shapiro #include <stdio.h>
1440266059SGregory Neil Shapiro
1540266059SGregory Neil Shapiro #include <stdlib.h>
1640266059SGregory Neil Shapiro #include <unistd.h>
1740266059SGregory Neil Shapiro # include <sys/wait.h>
1840266059SGregory Neil Shapiro #if SM_CONF_SETITIMER
194e4196cbSGregory Neil Shapiro # include <sm/time.h>
20*5b0945b5SGregory Neil Shapiro #endif
2140266059SGregory Neil Shapiro
2240266059SGregory Neil Shapiro #include <sm/clock.h>
2340266059SGregory Neil Shapiro #include <sm/test.h>
2440266059SGregory Neil Shapiro
25b6bacd31SGregory Neil Shapiro static void evcheck __P((int));
26b6bacd31SGregory Neil Shapiro static void ev1 __P((int));
2740266059SGregory Neil Shapiro
28b6bacd31SGregory Neil Shapiro static int check;
29b6bacd31SGregory Neil Shapiro
30b6bacd31SGregory Neil Shapiro static void
evcheck(arg)3140266059SGregory Neil Shapiro evcheck(arg)
3240266059SGregory Neil Shapiro int arg;
3340266059SGregory Neil Shapiro {
3440266059SGregory Neil Shapiro SM_TEST(arg == 3);
3540266059SGregory Neil Shapiro SM_TEST(check == 0);
3640266059SGregory Neil Shapiro check++;
3740266059SGregory Neil Shapiro }
3840266059SGregory Neil Shapiro
39b6bacd31SGregory Neil Shapiro static void
ev1(arg)4040266059SGregory Neil Shapiro ev1(arg)
4140266059SGregory Neil Shapiro int arg;
4240266059SGregory Neil Shapiro {
4340266059SGregory Neil Shapiro SM_TEST(arg == 1);
4440266059SGregory Neil Shapiro }
4540266059SGregory Neil Shapiro
4640266059SGregory Neil Shapiro /* define as x if you want debug output */
4740266059SGregory Neil Shapiro #define DBG_OUT(x)
4840266059SGregory Neil Shapiro
4940266059SGregory Neil Shapiro int
main(argc,argv)5040266059SGregory Neil Shapiro main(argc, argv)
5140266059SGregory Neil Shapiro int argc;
5240266059SGregory Neil Shapiro char *argv[];
5340266059SGregory Neil Shapiro {
5440266059SGregory Neil Shapiro SM_EVENT *ev;
5540266059SGregory Neil Shapiro
5640266059SGregory Neil Shapiro sm_test_begin(argc, argv, "test event handling");
57605302a5SGregory Neil Shapiro fprintf(stdout, "This test may hang. If there is no output within twelve seconds, abort it\nand recompile with -DSM_CONF_SETITIMER=%d\n",
5840266059SGregory Neil Shapiro SM_CONF_SETITIMER == 0 ? 1 : 0);
5940266059SGregory Neil Shapiro sleep(1);
6040266059SGregory Neil Shapiro SM_TEST(1 == 1);
6140266059SGregory Neil Shapiro DBG_OUT(fprintf(stdout, "We're back, test 1 seems to work.\n"));
6240266059SGregory Neil Shapiro ev = sm_seteventm(1000, ev1, 1);
6340266059SGregory Neil Shapiro sleep(1);
6440266059SGregory Neil Shapiro SM_TEST(2 == 2);
6540266059SGregory Neil Shapiro DBG_OUT(fprintf(stdout, "We're back, test 2 seems to work.\n"));
6640266059SGregory Neil Shapiro
6740266059SGregory Neil Shapiro /* schedule an event in 9s */
6840266059SGregory Neil Shapiro ev = sm_seteventm(9000, ev1, 2);
6940266059SGregory Neil Shapiro sleep(1);
7040266059SGregory Neil Shapiro
7140266059SGregory Neil Shapiro /* clear the event before it can fire */
7240266059SGregory Neil Shapiro sm_clrevent(ev);
7340266059SGregory Neil Shapiro SM_TEST(3 == 3);
7440266059SGregory Neil Shapiro DBG_OUT(fprintf(stdout, "We're back, test 3 seems to work.\n"));
7540266059SGregory Neil Shapiro
7640266059SGregory Neil Shapiro /* schedule an event in 1s */
7740266059SGregory Neil Shapiro check = 0;
7840266059SGregory Neil Shapiro ev = sm_seteventm(1000, evcheck, 3);
7940266059SGregory Neil Shapiro sleep(2);
8040266059SGregory Neil Shapiro
8140266059SGregory Neil Shapiro /* clear the event */
8240266059SGregory Neil Shapiro sm_clrevent(ev);
8340266059SGregory Neil Shapiro SM_TEST(4 == 4);
8440266059SGregory Neil Shapiro SM_TEST(check == 1);
8540266059SGregory Neil Shapiro DBG_OUT(fprintf(stdout, "We're back, test 4 seems to work.\n"));
8640266059SGregory Neil Shapiro
8740266059SGregory Neil Shapiro return sm_test_end();
8840266059SGregory Neil Shapiro }
89