2 * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers.
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.
11 SM_RCSID("@(#)$Id: t-shm.c,v 1.18 2002/01/31 04:11:41 ca Exp $")
18 # include <sys/wait.h>
21 # include <sm/string.h>
26 # define SHM_MAX 6400000
31 ** SHMINTER -- interactive testing of shared memory
34 ** owner -- create segment.
41 int shminter __P((bool));
50 shm = (int *) sm_shmstart(T_SHMKEY, SHMSIZE, 0, &shmid, owner);
53 perror("shminit failed");
57 while ((t = getchar()) != EOF)
75 for (i = 0; i < SHM_MAX; i++)
80 if (*shm != SHM_MAX + t)
81 fprintf(stderr, "error: %d != %d\n",
85 printf("shmval: %d\n", *shm);
89 return sm_shmstop((void *) shm, shmid, owner);
94 ** SHMBIG -- testing of shared memory
97 ** owner -- create segment.
98 ** size -- size of segment.
105 int shmbig __P((bool, int));
115 shm = (int *) sm_shmstart(T_SHMKEY, size, 0, &shmid, owner);
116 if (shm == (int *) 0)
118 perror("shminit failed");
122 for (i = 0; i < size / sizeof(int); i++)
124 for (i = 0; i < size / sizeof(int); i++)
128 fprintf(stderr, "failed at %d: %d", i, shm[i]);
132 return sm_shmstop((void *) shm, shmid, owner);
137 ** SHMTEST -- test of shared memory
140 ** owner -- create segment.
156 shm = (int *) sm_shmstart(T_SHMKEY, SHMSIZE, 0, &shmid, owner);
157 if (shm == (int *) 0)
159 perror("shminit failed");
168 while (*shm == 1 && cnt++ < MAX_CNT)
170 SM_TEST(cnt <= MAX_CNT);
172 /* release and re-acquire the segment */
173 r = sm_shmstop((void *) shm, shmid, owner);
175 shm = (int *) sm_shmstart(T_SHMKEY, SHMSIZE, 0, &shmid, owner);
176 SM_TEST(shm != (int *) 0);
180 while (*shm != 1 && cnt++ < MAX_CNT)
182 SM_TEST(cnt <= MAX_CNT);
185 /* wait a momemt so the segment is still in use */
188 return sm_shmstop((void *) shm, shmid, owner);
196 bool interactive = false;
204 # define OPTIONS "b:io"
205 while ((ch = getopt(argc, argv, OPTIONS)) != -1)
229 r = shmbig(true, big);
233 extern int SmTestNumErrors;
235 if ((pid = fork()) < 0)
237 perror("fork failed\n");
241 sm_test_begin(argc, argv, "test shared memory");
244 /* give the parent the chance to setup data */
251 (void) wait(&status);
254 if (SmTestNumErrors > 0)
255 printf("add -DSM_CONF_SHM=0 to confENVDEF in devtools/Site/site.config.m4\nand start over.\n");
256 return sm_test_end();
260 #else /* SM_CONF_SHM */
266 printf("No support for shared memory configured on this machine\n");
269 #endif /* SM_CONF_SHM */