2 * Copyright (c) 2000-2002, 2004, 2005 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.22 2005/01/14 02:14:10 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++)
79 if (*shm != SHM_MAX + t)
80 fprintf(stderr, "error: %d != %d\n",
84 printf("shmval: %d\n", *shm);
87 i = sm_shmsetowner(shmid, getuid(), getgid(), 0644);
88 printf("sm_shmsetowner=%d\n", i);
92 return sm_shmstop((void *) shm, shmid, owner);
97 ** SHMBIG -- testing of shared memory
100 ** owner -- create segment.
101 ** size -- size of segment.
108 int shmbig __P((bool, int));
118 shm = (int *) sm_shmstart(T_SHMKEY, size, 0, &shmid, owner);
119 if (shm == (int *) 0)
121 perror("shminit failed");
125 for (i = 0; i < size / sizeof(int); i++)
127 for (i = 0; i < size / sizeof(int); i++)
131 fprintf(stderr, "failed at %d: %d", i, shm[i]);
135 return sm_shmstop((void *) shm, shmid, owner);
140 ** SHMTEST -- test of shared memory
143 ** owner -- create segment.
152 int shmtest __P((int));
161 shm = (int *) sm_shmstart(T_SHMKEY, SHMSIZE, 0, &shmid, owner);
162 if (shm == (int *) 0)
164 perror("shminit failed");
172 r = sm_shmsetowner(shmid, getuid(), getgid(), 0660);
175 while (*shm == 1 && cnt++ < MAX_CNT)
177 SM_TEST(cnt <= MAX_CNT);
179 /* release and re-acquire the segment */
180 r = sm_shmstop((void *) shm, shmid, owner);
182 shm = (int *) sm_shmstart(T_SHMKEY, SHMSIZE, 0, &shmid, owner);
183 SM_TEST(shm != (int *) 0);
187 while (*shm != 1 && cnt++ < MAX_CNT)
189 SM_TEST(cnt <= MAX_CNT);
192 /* wait a momemt so the segment is still in use */
195 return sm_shmstop((void *) shm, shmid, owner);
203 bool interactive = false;
211 # define OPTIONS "b:io"
212 while ((ch = getopt(argc, argv, OPTIONS)) != -1)
236 r = shmbig(true, big);
240 extern int SmTestNumErrors;
242 if ((pid = fork()) < 0)
244 perror("fork failed\n");
248 sm_test_begin(argc, argv, "test shared memory");
251 /* give the parent the chance to setup data */
258 (void) wait(&status);
261 if (SmTestNumErrors > 0)
262 printf("add -DSM_CONF_SHM=0 to confENVDEF in devtools/Site/site.config.m4\nand start over.\n");
263 return sm_test_end();
267 #else /* SM_CONF_SHM */
273 printf("No support for shared memory configured on this machine\n");
276 #endif /* SM_CONF_SHM */