2 * Copyright (c) 2020 Proofpoint, 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.
13 #if _FFR_DMTRIGGER || _FFR_NOTIFY
18 # include <sm/string.h>
20 # include <sm/notify.h>
24 static int Verbose = 0;
25 #define MAX_CHILDREN 256
27 static pid_t pids[MAX_CHILDREN];
28 static char msgs[MAX_CHILDREN][MAX_MSGS];
31 ** NOTIFY_WR -- test of notify write feature
34 ** pid -- pid of process
35 ** nmsgs -- number of messages to write
50 #define TSTSTR "qf0001"
52 r = sm_notify_start(false, 0);
55 perror("sm_notify_start failed");
59 for (i = 0; i < nmsgs; i++)
61 len = sm_snprintf(buf, sizeof(buf), "%s-%ld_%d", TSTSTR,
63 r = sm_notify_snd(buf, len);
76 for (i = 0; i < nproc; i++)
80 fprintf(stderr, "pid=%ld not found, nproc=%d\n",
86 ** NOTIFY_RD -- test of notify read feature
89 ** nproc -- number of processes started
90 ** nmsgs -- number of messages to read for each process
98 notify_rd(nproc, nmsgs)
105 #define TSTSTR "qf0001"
107 r = sm_notify_start(true, 0);
110 perror("sm_notify_start failed");
114 for (i = 0; i < nmsgs * nproc; i++)
118 r = sm_notify_rcv(buf, sizeof(buf), 5 * SM_MICROS);
123 fprintf(stderr, "pid=%ld, rcv=%d, i=%d\n",
124 (long)getpid(), r, i);
127 if (r > 0 && r < sizeof(buf))
129 buf[sizeof(buf) - 1] = '\0';
132 fprintf(stderr, "pid=%ld, buf=\"%s\", i=%d\n",
133 (long)getpid(), buf, i);
135 SM_TEST(strncmp(buf, TSTSTR, sizeof(TSTSTR) - 1) == 0);
136 SM_TEST(r > sizeof(TSTSTR));
138 r = sscanf(buf + sizeof(TSTSTR), "%ld", &cpid);
140 pidx = validpid(nproc, (pid_t)cpid);
142 SM_TEST(pidx < nproc);
144 p = strchr(buf, '_');
146 if (NULL != p && pidx < nproc && pidx >= 0)
150 r = sscanf(p + 1, "%d", &n);
154 if (1 == r && n < nmsgs && n >= 0)
156 SM_TEST('\0' == msgs[pidx][n]);
175 # define OPTIONS "n:p:V"
176 while ((i = getopt(argc, argv, OPTIONS)) != -1)
181 nmsgs = atoi(optarg);
185 fprintf(stderr, "-%c: must be >0\n", (char) i);
188 if (nmsgs >= MAX_MSGS)
191 fprintf(stderr, "-%c: must be <%d\n", (char) i, MAX_MSGS);
196 nproc = atoi(optarg);
200 fprintf(stderr, "-%c: must be >0\n", (char) i);
203 if (nproc >= MAX_CHILDREN)
206 fprintf(stderr, "-%c: must be <%d\n", (char) i, MAX_CHILDREN);
218 memset(msgs, '\0', sizeof(msgs));
219 sm_test_begin(argc, argv, "test notify");
220 r = sm_notify_init(0);
224 perror("sm_notify_init failed\n");
229 for (i = 0; i < nproc; i++)
231 if ((pid = fork()) < 0)
233 perror("fork failed\n");
239 /* give the parent the chance to set up data */
241 r = notify_wr(getpid(), nmsgs);
248 r = notify_rd(nproc, nmsgs);
250 return sm_test_end();
252 #else /* _FFR_DMTRIGGER */
258 printf("SKIPPED: no _FFR_DMTRIGGER || _FFR_NOTIFY\n");
261 #endif /* _FFR_DMTRIGGER || _FFR_NOTIFY */