diff options
author | mbuhl <> | 2022-09-11 20:51:44 +0000 |
---|---|---|
committer | mbuhl <> | 2022-09-11 20:51:44 +0000 |
commit | 72fe4eb86ffec1e1c4ed0b0cd502e56dc937eb39 (patch) | |
tree | 62bf34c1df3f817a4f7adbf9104b6ba32db8252f | |
parent | 7e5d2cb927223e2d6b747ecab3022cfb81b37b7f (diff) | |
download | openbsd-72fe4eb86ffec1e1c4ed0b0cd502e56dc937eb39.tar.gz openbsd-72fe4eb86ffec1e1c4ed0b0cd502e56dc937eb39.tar.bz2 openbsd-72fe4eb86ffec1e1c4ed0b0cd502e56dc937eb39.zip |
Add regression tests for the sendmmsg and recvmmsg system calls.
-rw-r--r-- | src/regress/lib/libc/sys/Makefile | 4 | ||||
-rw-r--r-- | src/regress/lib/libc/sys/atf-c.h | 3 | ||||
-rw-r--r-- | src/regress/lib/libc/sys/t_recvmmsg.c | 189 | ||||
-rw-r--r-- | src/regress/lib/libc/sys/t_sendmmsg.c | 216 |
4 files changed, 410 insertions, 2 deletions
diff --git a/src/regress/lib/libc/sys/Makefile b/src/regress/lib/libc/sys/Makefile index 93b977707a..e563279422 100644 --- a/src/regress/lib/libc/sys/Makefile +++ b/src/regress/lib/libc/sys/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.15 2022/01/06 03:30:15 guenther Exp $ | 1 | # $OpenBSD: Makefile,v 1.16 2022/09/11 20:51:44 mbuhl Exp $ |
2 | 2 | ||
3 | # Copyright (c) 2019 Moritz Buhl <openbsd@moritzbuhl.de> | 3 | # Copyright (c) 2019 Moritz Buhl <openbsd@moritzbuhl.de> |
4 | # Copyright (c) 2019 Alexander Bluhm <bluhm@openbsd.org> | 4 | # Copyright (c) 2019 Alexander Bluhm <bluhm@openbsd.org> |
@@ -54,8 +54,10 @@ PROGS += t_pipe2 | |||
54 | PROGS += t_poll | 54 | PROGS += t_poll |
55 | PROGS += t_ppoll | 55 | PROGS += t_ppoll |
56 | PROGS += t_ptrace | 56 | PROGS += t_ptrace |
57 | PROGS += t_recvmmsg | ||
57 | PROGS += t_revoke | 58 | PROGS += t_revoke |
58 | PROGS += t_select | 59 | PROGS += t_select |
60 | PROGS += t_sendmmsg | ||
59 | PROGS += t_sendrecv | 61 | PROGS += t_sendrecv |
60 | PROGS += t_setrlimit | 62 | PROGS += t_setrlimit |
61 | PROGS += t_setuid | 63 | PROGS += t_setuid |
diff --git a/src/regress/lib/libc/sys/atf-c.h b/src/regress/lib/libc/sys/atf-c.h index 1a0f29d673..6670abac0a 100644 --- a/src/regress/lib/libc/sys/atf-c.h +++ b/src/regress/lib/libc/sys/atf-c.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: atf-c.h,v 1.4 2022/05/28 18:39:39 mbuhl Exp $ */ | 1 | /* $OpenBSD: atf-c.h,v 1.5 2022/09/11 20:51:44 mbuhl Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2019 Moritz Buhl <openbsd@moritzbuhl.de> | 3 | * Copyright (c) 2019 Moritz Buhl <openbsd@moritzbuhl.de> |
4 | * | 4 | * |
@@ -76,6 +76,7 @@ ATF_TC_FUNCTIONS(fn) | |||
76 | #define ATF_CHECK ATF_REQUIRE | 76 | #define ATF_CHECK ATF_REQUIRE |
77 | #define ATF_CHECK_MSG ATF_REQUIRE_MSG | 77 | #define ATF_CHECK_MSG ATF_REQUIRE_MSG |
78 | #define ATF_CHECK_EQ ATF_REQUIRE_EQ | 78 | #define ATF_CHECK_EQ ATF_REQUIRE_EQ |
79 | #define ATF_CHECK_EQ_MSG ATF_REQUIRE_EQ_MSG | ||
79 | #define ATF_CHECK_ERRNO ATF_REQUIRE_ERRNO | 80 | #define ATF_CHECK_ERRNO ATF_REQUIRE_ERRNO |
80 | #define ATF_CHECK_STREQ ATF_REQUIRE_STREQ | 81 | #define ATF_CHECK_STREQ ATF_REQUIRE_STREQ |
81 | 82 | ||
diff --git a/src/regress/lib/libc/sys/t_recvmmsg.c b/src/regress/lib/libc/sys/t_recvmmsg.c index e69de29bb2..793692dac1 100644 --- a/src/regress/lib/libc/sys/t_recvmmsg.c +++ b/src/regress/lib/libc/sys/t_recvmmsg.c | |||
@@ -0,0 +1,189 @@ | |||
1 | /* $OpenBSD: t_recvmmsg.c,v 1.2 2022/09/11 20:51:44 mbuhl Exp $ */ | ||
2 | /* $NetBSD: t_recvmmsg.c,v 1.4 2018/08/21 10:39:21 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2012 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Jared McNeill and Christos Zoulas. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * 3. All advertising materials mentioning features or use of this software | ||
20 | * must display the following acknowledgement: | ||
21 | * This product includes software developed by the NetBSD | ||
22 | * Foundation, Inc. and its contributors. | ||
23 | * 4. Neither the name of The NetBSD Foundation nor the names of its | ||
24 | * contributors may be used to endorse or promote products derived | ||
25 | * from this software without specific prior written permission. | ||
26 | * | ||
27 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
28 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
29 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
30 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
31 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
32 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
33 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
34 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
35 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
36 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
37 | * POSSIBILITY OF SUCH DAMAGE. | ||
38 | */ | ||
39 | #include <sys/cdefs.h> | ||
40 | |||
41 | #include "atf-c.h" | ||
42 | #include <sys/types.h> | ||
43 | #include <sys/socket.h> | ||
44 | #include <sys/wait.h> | ||
45 | |||
46 | #include <string.h> | ||
47 | #include <time.h> | ||
48 | #include <stdint.h> | ||
49 | #include <errno.h> | ||
50 | #include <signal.h> | ||
51 | #include <stdio.h> | ||
52 | #include <stdlib.h> | ||
53 | #include <unistd.h> | ||
54 | #include <sched.h> | ||
55 | |||
56 | #define BUFSIZE 65536 | ||
57 | #define NPKTS 50 | ||
58 | |||
59 | #define min(a, b) ((a) < (b) ? (a) : (b)) | ||
60 | static int debug; | ||
61 | static volatile sig_atomic_t rdied; | ||
62 | |||
63 | static void | ||
64 | handle_sigchld(__unused int pid) | ||
65 | { | ||
66 | |||
67 | rdied = 1; | ||
68 | } | ||
69 | |||
70 | ATF_TC(recvmmsg_basic); | ||
71 | ATF_TC_HEAD(recvmmsg_basic, tc) | ||
72 | { | ||
73 | atf_tc_set_md_var(tc, "descr", "A basic test of recvmmsg(2)"); | ||
74 | } | ||
75 | |||
76 | ATF_TC_BODY(recvmmsg_basic, tc) | ||
77 | { | ||
78 | int fd[2], error, i, cnt; | ||
79 | uint8_t *buf; | ||
80 | struct mmsghdr *mmsghdr; | ||
81 | struct iovec *iov; | ||
82 | unsigned int mmsgcnt, n; | ||
83 | int status; | ||
84 | off_t off; | ||
85 | uint8_t DGRAM[1316] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, }; | ||
86 | struct sigaction sa; | ||
87 | ssize_t overf = 0; | ||
88 | |||
89 | error = socketpair(AF_UNIX, SOCK_DGRAM, 0, fd); | ||
90 | ATF_REQUIRE_MSG(error != -1, "socketpair failed (%s)", strerror(errno)); | ||
91 | |||
92 | buf = malloc(BUFSIZE); | ||
93 | ATF_REQUIRE_MSG(buf != NULL, "malloc failed (%s)", strerror(errno)); | ||
94 | |||
95 | mmsgcnt = BUFSIZE / sizeof(DGRAM); | ||
96 | mmsghdr = malloc(sizeof(*mmsghdr) * mmsgcnt); | ||
97 | ATF_REQUIRE_MSG(mmsghdr != NULL, "malloc failed (%s)", strerror(errno)); | ||
98 | iov = malloc(sizeof(*iov) * mmsgcnt); | ||
99 | ATF_REQUIRE_MSG(iov != NULL, "malloc failed (%s)", strerror(errno)); | ||
100 | |||
101 | for (off = 0, n = 0; n < mmsgcnt; n++) { | ||
102 | iov[n].iov_base = buf + off; | ||
103 | iov[n].iov_len = sizeof(DGRAM); | ||
104 | off += iov[n].iov_len; | ||
105 | mmsghdr[n].msg_hdr.msg_iov = &iov[n]; | ||
106 | mmsghdr[n].msg_hdr.msg_iovlen = 1; | ||
107 | mmsghdr[n].msg_hdr.msg_name = NULL; | ||
108 | mmsghdr[n].msg_hdr.msg_namelen = 0; | ||
109 | } | ||
110 | |||
111 | memset(&sa, 0, sizeof(sa)); | ||
112 | sa.sa_flags = SA_RESTART; | ||
113 | sa.sa_handler = &handle_sigchld; | ||
114 | sigemptyset(&sa.sa_mask); | ||
115 | error = sigaction(SIGCHLD, &sa, 0); | ||
116 | ATF_REQUIRE_MSG(error != -1, "sigaction failed (%s)", | ||
117 | strerror(errno)); | ||
118 | |||
119 | switch (fork()) { | ||
120 | case -1: | ||
121 | ATF_REQUIRE_MSG(0, "fork failed (%s)", strerror(errno)); | ||
122 | break; | ||
123 | |||
124 | case 0: | ||
125 | n = NPKTS; | ||
126 | if (debug) | ||
127 | printf("waiting for %u messages (max %u per syscall)\n", n, | ||
128 | mmsgcnt); | ||
129 | while (n > 0) { | ||
130 | struct timespec ts = { 1, 0 }; | ||
131 | cnt = recvmmsg(fd[1], mmsghdr, min(mmsgcnt, n), | ||
132 | MSG_WAITALL, &ts); | ||
133 | if (cnt == -1 && errno == ENOBUFS) { | ||
134 | overf++; | ||
135 | if (debug) | ||
136 | printf("receive buffer overflowed" | ||
137 | " (%zu)\n",overf); | ||
138 | continue; | ||
139 | } | ||
140 | ATF_REQUIRE_MSG(cnt != -1, "recvmmsg failed (%s)", | ||
141 | strerror(errno)); | ||
142 | ATF_REQUIRE_MSG(cnt != 0, "recvmmsg timeout"); | ||
143 | if (debug) | ||
144 | printf("recvmmsg: got %u messages\n", cnt); | ||
145 | for (i = 0; i < cnt; i++) { | ||
146 | ATF_CHECK_EQ_MSG(mmsghdr[i].msg_len, | ||
147 | sizeof(DGRAM), "packet length"); | ||
148 | ATF_CHECK_EQ_MSG( | ||
149 | ((uint8_t *)iov[i].iov_base)[0], | ||
150 | NPKTS - n + i, "packet contents"); | ||
151 | } | ||
152 | n -= cnt; | ||
153 | } | ||
154 | if (debug) | ||
155 | printf("done!\n"); | ||
156 | exit(0); | ||
157 | /*NOTREACHED*/ | ||
158 | default: | ||
159 | sched_yield(); | ||
160 | |||
161 | for (n = 0; n < NPKTS; n++) { | ||
162 | if (debug) | ||
163 | printf("sending packet %u/%u...\n", (n+1), | ||
164 | NPKTS); | ||
165 | do { | ||
166 | if (rdied) | ||
167 | break; | ||
168 | DGRAM[0] = n; | ||
169 | error = send(fd[0], DGRAM, sizeof(DGRAM), 0); | ||
170 | } while (error == -1 && errno == ENOBUFS); | ||
171 | ATF_REQUIRE_MSG(error != -1, "send failed (%s)", | ||
172 | strerror(errno)); | ||
173 | } | ||
174 | error = wait(&status); | ||
175 | ATF_REQUIRE_MSG(error != -1, "wait failed (%s)", | ||
176 | strerror(errno)); | ||
177 | ATF_REQUIRE_MSG(WIFEXITED(status) && WEXITSTATUS(status) == 0, | ||
178 | "receiver died"); | ||
179 | break; | ||
180 | } | ||
181 | } | ||
182 | |||
183 | ATF_TP_ADD_TCS(tp) | ||
184 | { | ||
185 | |||
186 | ATF_TP_ADD_TC(tp, recvmmsg_basic); | ||
187 | |||
188 | return atf_no_error(); | ||
189 | } | ||
diff --git a/src/regress/lib/libc/sys/t_sendmmsg.c b/src/regress/lib/libc/sys/t_sendmmsg.c index e69de29bb2..44e6c001f6 100644 --- a/src/regress/lib/libc/sys/t_sendmmsg.c +++ b/src/regress/lib/libc/sys/t_sendmmsg.c | |||
@@ -0,0 +1,216 @@ | |||
1 | /* $OpenBSD: t_sendmmsg.c,v 1.2 2022/09/11 20:51:44 mbuhl Exp $ */ | ||
2 | /* $NetBSD: t_sendmmsg.c,v 1.3 2019/03/16 21:46:43 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Christos Zoulas. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | * POSSIBILITY OF SUCH DAMAGE. | ||
31 | */ | ||
32 | #include <sys/cdefs.h> | ||
33 | |||
34 | #include "atf-c.h" | ||
35 | #include <sys/types.h> | ||
36 | #include <sys/socket.h> | ||
37 | #include <sys/ioctl.h> | ||
38 | #include <sys/wait.h> | ||
39 | |||
40 | #include <string.h> | ||
41 | #include <time.h> | ||
42 | #include <stdint.h> | ||
43 | #include <errno.h> | ||
44 | #include <signal.h> | ||
45 | #include <stdio.h> | ||
46 | #include <stdlib.h> | ||
47 | #include <unistd.h> | ||
48 | #include <sched.h> | ||
49 | |||
50 | #define BUFSIZE 65536 | ||
51 | |||
52 | #define min(a, b) ((a) < (b) ? (a) : (b)) | ||
53 | static int debug; | ||
54 | static volatile sig_atomic_t rdied; | ||
55 | |||
56 | static void | ||
57 | handle_sigchld(__unused int pid) | ||
58 | { | ||
59 | |||
60 | rdied = 1; | ||
61 | } | ||
62 | |||
63 | ATF_TC(sendmmsg_basic); | ||
64 | ATF_TC_HEAD(sendmmsg_basic, tc) | ||
65 | { | ||
66 | atf_tc_set_md_var(tc, "descr", "A basic test of sendmmsg(2)"); | ||
67 | } | ||
68 | |||
69 | static void | ||
70 | setsock(int fd, int type) | ||
71 | { | ||
72 | int buflen = BUFSIZE; | ||
73 | socklen_t socklen = sizeof(buflen); | ||
74 | |||
75 | ATF_REQUIRE_MSG(setsockopt(fd, SOL_SOCKET, type, | ||
76 | &buflen, socklen) != -1, "%s (%s)", | ||
77 | type == SO_RCVBUF ? "rcv" : "snd", strerror(errno)); | ||
78 | } | ||
79 | |||
80 | ATF_TC_BODY(sendmmsg_basic, tc) | ||
81 | { | ||
82 | int fd[2], error, cnt; | ||
83 | uint8_t *buf; | ||
84 | struct mmsghdr *mmsghdr; | ||
85 | struct iovec *iov; | ||
86 | unsigned int mmsgcnt, n; | ||
87 | int status; | ||
88 | off_t off; | ||
89 | uint8_t DGRAM[1316] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, }; | ||
90 | uint8_t rgram[sizeof(DGRAM)]; | ||
91 | struct sigaction sa; | ||
92 | ssize_t overf = 0; | ||
93 | |||
94 | error = socketpair(AF_UNIX, SOCK_DGRAM, 0, fd); | ||
95 | ATF_REQUIRE_MSG(error != -1, "socketpair failed (%s)", strerror(errno)); | ||
96 | |||
97 | buf = malloc(BUFSIZE); | ||
98 | ATF_REQUIRE_MSG(buf != NULL, "malloc failed (%s)", strerror(errno)); | ||
99 | |||
100 | setsock(fd[1], SO_SNDBUF); | ||
101 | // setsock(fd[0], SO_RCVBUF); | ||
102 | |||
103 | mmsgcnt = BUFSIZE / sizeof(DGRAM); | ||
104 | mmsghdr = calloc(mmsgcnt, sizeof(*mmsghdr)); | ||
105 | ATF_REQUIRE_MSG(mmsghdr != NULL, "malloc failed (%s)", strerror(errno)); | ||
106 | iov = malloc(sizeof(*iov) * mmsgcnt); | ||
107 | ATF_REQUIRE_MSG(iov != NULL, "malloc failed (%s)", strerror(errno)); | ||
108 | |||
109 | for (off = 0, n = 0; n < mmsgcnt; n++) { | ||
110 | iov[n].iov_base = buf + off; | ||
111 | memcpy(iov[n].iov_base, DGRAM, sizeof(DGRAM)); | ||
112 | *(buf + off) = n; | ||
113 | iov[n].iov_len = sizeof(DGRAM); | ||
114 | off += iov[n].iov_len; | ||
115 | mmsghdr[n].msg_hdr.msg_iov = &iov[n]; | ||
116 | mmsghdr[n].msg_hdr.msg_iovlen = 1; | ||
117 | mmsghdr[n].msg_hdr.msg_name = NULL; | ||
118 | mmsghdr[n].msg_hdr.msg_namelen = 0; | ||
119 | } | ||
120 | |||
121 | memset(&sa, 0, sizeof(sa)); | ||
122 | sa.sa_flags = SA_RESTART; | ||
123 | sa.sa_handler = &handle_sigchld; | ||
124 | sigemptyset(&sa.sa_mask); | ||
125 | error = sigaction(SIGCHLD, &sa, 0); | ||
126 | ATF_REQUIRE_MSG(error != -1, "sigaction failed (%s)", | ||
127 | strerror(errno)); | ||
128 | |||
129 | switch (fork()) { | ||
130 | case -1: | ||
131 | ATF_REQUIRE_MSG(0, "fork failed (%s)", strerror(errno)); | ||
132 | break; | ||
133 | case 0: | ||
134 | sched_yield(); | ||
135 | if (debug) | ||
136 | printf("sending %u messages (max %u per syscall)\n", n, | ||
137 | mmsgcnt); | ||
138 | for (n = 0; n < mmsgcnt;) { | ||
139 | if (debug) | ||
140 | printf("sending packet %u/%u...\n", n, | ||
141 | mmsgcnt); | ||
142 | #ifdef __OpenBSD__ | ||
143 | int npkt = min(1024, mmsgcnt - n); | ||
144 | #else | ||
145 | // XXX: ENOBUFS bug, on the receive side!!! | ||
146 | // in npkt = min(mmsgsize, mmsgcnt - n); | ||
147 | int npkt = min(3, mmsgcnt - n), a; | ||
148 | do { | ||
149 | a = 0; | ||
150 | ATF_REQUIRE(ioctl(fd[1], FIONSPACE, &a) != -1); | ||
151 | printf("1 %d\n", a); | ||
152 | ATF_REQUIRE(ioctl(fd[0], FIONSPACE, &a) != -1); | ||
153 | printf("0 %d\n", a); | ||
154 | } while ((size_t)a < sizeof(DGRAM)); | ||
155 | #endif | ||
156 | cnt = sendmmsg(fd[1], mmsghdr + n, npkt, 0); | ||
157 | if (cnt == -1 && errno == ENOBUFS) { | ||
158 | overf++; | ||
159 | if (debug) | ||
160 | printf("send buffer overflowed" | ||
161 | " (%zu)\n",overf); | ||
162 | if (overf > 100) | ||
163 | exit(1); | ||
164 | sched_yield(); | ||
165 | sched_yield(); | ||
166 | sched_yield(); | ||
167 | continue; | ||
168 | } | ||
169 | ATF_REQUIRE_MSG(cnt != -1, "sendmmsg %u failed (%s)", | ||
170 | n, strerror(errno)); | ||
171 | if (debug) | ||
172 | printf("sendmmsg: sent %u messages\n", cnt); | ||
173 | n += cnt; | ||
174 | sched_yield(); | ||
175 | sched_yield(); | ||
176 | sched_yield(); | ||
177 | } | ||
178 | if (debug) | ||
179 | printf("done!\n"); | ||
180 | exit(0); | ||
181 | /*NOTREACHED*/ | ||
182 | default: | ||
183 | for (n = 0; n < mmsgcnt; n++) { | ||
184 | if (debug) | ||
185 | printf("receiving packet %u/%u...\n", n, | ||
186 | mmsgcnt); | ||
187 | do { | ||
188 | if (rdied) | ||
189 | break; | ||
190 | cnt = recv(fd[0], rgram, sizeof(rgram), 0); | ||
191 | ATF_REQUIRE_MSG(cnt != -1 || errno != ENOBUFS, | ||
192 | "recv failed (%s)", strerror(errno)); | ||
193 | ATF_CHECK_EQ_MSG(cnt, sizeof(rgram), | ||
194 | "packet length"); | ||
195 | ATF_CHECK_EQ_MSG(rgram[0], n, | ||
196 | "number %u != %u", rgram[0], n); | ||
197 | ATF_REQUIRE_MSG(memcmp(rgram + 1, DGRAM + 1, | ||
198 | sizeof(rgram) - 1) == 0, "bad data"); | ||
199 | } while (cnt == -1 && errno == ENOBUFS); | ||
200 | } | ||
201 | error = wait(&status); | ||
202 | ATF_REQUIRE_MSG(error != -1, "wait failed (%s)", | ||
203 | strerror(errno)); | ||
204 | ATF_REQUIRE_MSG(WIFEXITED(status) && WEXITSTATUS(status) == 0, | ||
205 | "receiver died"); | ||
206 | break; | ||
207 | } | ||
208 | } | ||
209 | |||
210 | ATF_TP_ADD_TCS(tp) | ||
211 | { | ||
212 | |||
213 | ATF_TP_ADD_TC(tp, sendmmsg_basic); | ||
214 | |||
215 | return atf_no_error(); | ||
216 | } | ||