xref: /titanic_51/usr/src/cmd/sendmail/libsm/t-event.c (revision 49218d4f8e4d84d1c08aeb267bcf6e451f2056dc)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright (c) 2001-2002, 2004 Sendmail, Inc. and its suppliers.
37c478bd9Sstevel@tonic-gate  *      All rights reserved.
47c478bd9Sstevel@tonic-gate  *
57c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
67c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
77c478bd9Sstevel@tonic-gate  * the sendmail distribution.
87c478bd9Sstevel@tonic-gate  */
97c478bd9Sstevel@tonic-gate 
107c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
117c478bd9Sstevel@tonic-gate 
127c478bd9Sstevel@tonic-gate #include <sm/gen.h>
13*49218d4fSjbeck SM_RCSID("@(#)$Id: t-event.c,v 1.13 2005/06/14 23:07:20 ca Exp $")
147c478bd9Sstevel@tonic-gate 
157c478bd9Sstevel@tonic-gate #include <stdio.h>
167c478bd9Sstevel@tonic-gate 
177c478bd9Sstevel@tonic-gate #include <stdlib.h>
187c478bd9Sstevel@tonic-gate #include <unistd.h>
197c478bd9Sstevel@tonic-gate # include <sys/wait.h>
207c478bd9Sstevel@tonic-gate #if SM_CONF_SETITIMER
21*49218d4fSjbeck # include <sm/time.h>
227c478bd9Sstevel@tonic-gate #endif /* SM_CONF_SETITIMER */
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate #include <sm/clock.h>
257c478bd9Sstevel@tonic-gate #include <sm/test.h>
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate static void	evcheck __P((int));
287c478bd9Sstevel@tonic-gate static void	ev1 __P((int));
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate static int check;
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate static void
337c478bd9Sstevel@tonic-gate evcheck(arg)
347c478bd9Sstevel@tonic-gate 	int arg;
357c478bd9Sstevel@tonic-gate {
367c478bd9Sstevel@tonic-gate 	SM_TEST(arg == 3);
377c478bd9Sstevel@tonic-gate 	SM_TEST(check == 0);
387c478bd9Sstevel@tonic-gate 	check++;
397c478bd9Sstevel@tonic-gate }
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate static void
427c478bd9Sstevel@tonic-gate ev1(arg)
437c478bd9Sstevel@tonic-gate 	int arg;
447c478bd9Sstevel@tonic-gate {
457c478bd9Sstevel@tonic-gate 	SM_TEST(arg == 1);
467c478bd9Sstevel@tonic-gate }
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /* define as x if you want debug output */
497c478bd9Sstevel@tonic-gate #define DBG_OUT(x)
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate int
527c478bd9Sstevel@tonic-gate main(argc, argv)
537c478bd9Sstevel@tonic-gate 	int argc;
547c478bd9Sstevel@tonic-gate 	char *argv[];
557c478bd9Sstevel@tonic-gate {
567c478bd9Sstevel@tonic-gate 	SM_EVENT *ev;
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	sm_test_begin(argc, argv, "test event handling");
597c478bd9Sstevel@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",
607c478bd9Sstevel@tonic-gate 		SM_CONF_SETITIMER == 0 ? 1 : 0);
617c478bd9Sstevel@tonic-gate 	sleep(1);
627c478bd9Sstevel@tonic-gate 	SM_TEST(1 == 1);
637c478bd9Sstevel@tonic-gate 	DBG_OUT(fprintf(stdout, "We're back, test 1 seems to work.\n"));
647c478bd9Sstevel@tonic-gate 	ev = sm_seteventm(1000, ev1, 1);
657c478bd9Sstevel@tonic-gate 	sleep(1);
667c478bd9Sstevel@tonic-gate 	SM_TEST(2 == 2);
677c478bd9Sstevel@tonic-gate 	DBG_OUT(fprintf(stdout, "We're back, test 2 seems to work.\n"));
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 	/* schedule an event in 9s */
707c478bd9Sstevel@tonic-gate 	ev = sm_seteventm(9000, ev1, 2);
717c478bd9Sstevel@tonic-gate 	sleep(1);
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	/* clear the event before it can fire */
747c478bd9Sstevel@tonic-gate 	sm_clrevent(ev);
757c478bd9Sstevel@tonic-gate 	SM_TEST(3 == 3);
767c478bd9Sstevel@tonic-gate 	DBG_OUT(fprintf(stdout, "We're back, test 3 seems to work.\n"));
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	/* schedule an event in 1s */
797c478bd9Sstevel@tonic-gate 	check = 0;
807c478bd9Sstevel@tonic-gate 	ev = sm_seteventm(1000, evcheck, 3);
817c478bd9Sstevel@tonic-gate 	sleep(2);
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate 	/* clear the event */
847c478bd9Sstevel@tonic-gate 	sm_clrevent(ev);
857c478bd9Sstevel@tonic-gate 	SM_TEST(4 == 4);
867c478bd9Sstevel@tonic-gate 	SM_TEST(check == 1);
877c478bd9Sstevel@tonic-gate 	DBG_OUT(fprintf(stdout, "We're back, test 4 seems to work.\n"));
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 	return sm_test_end();
907c478bd9Sstevel@tonic-gate }
91