Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/libc/sys use a pipe instead of sched_yield()
details: https://anonhg.NetBSD.org/src/rev/b1df8365b56a
branches: trunk
changeset: 953830:b1df8365b56a
user: christos <christos%NetBSD.org@localhost>
date: Sun Mar 21 16:58:07 2021 +0000
description:
use a pipe instead of sched_yield()
diffstat:
tests/lib/libc/sys/t_sendrecv.c | 49 +++++++++++++++++++++-------------------
1 files changed, 26 insertions(+), 23 deletions(-)
diffs (129 lines):
diff -r 9097c4adbf19 -r b1df8365b56a tests/lib/libc/sys/t_sendrecv.c
--- a/tests/lib/libc/sys/t_sendrecv.c Sun Mar 21 16:36:32 2021 +0000
+++ b/tests/lib/libc/sys/t_sendrecv.c Sun Mar 21 16:58:07 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_sendrecv.c,v 1.6 2019/02/03 03:19:28 mrg Exp $ */
+/* $NetBSD: t_sendrecv.c,v 1.7 2021/03/21 16:58:07 christos Exp $ */
/*-
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_sendrecv.c,v 1.6 2019/02/03 03:19:28 mrg Exp $");
+__RCSID("$NetBSD: t_sendrecv.c,v 1.7 2021/03/21 16:58:07 christos Exp $");
#include <atf-c.h>
#include <sys/types.h>
@@ -41,7 +41,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include <sched.h>
#include <signal.h>
@@ -62,33 +61,33 @@
}
static void
-sender(int fd)
+sender(int sd)
{
union packet p;
ssize_t n;
p.seq = 0;
for (size_t i = 0; i < COUNT; i++) {
- for (; (n = send(fd, &p, sizeof(p), 0)) == sizeof(p);
+ for (; (n = send(sd, &p, sizeof(p), 0)) == sizeof(p);
p.seq++)
continue;
- printf(">>%zd %d %ju\n", n, errno, p.seq);
+// printf(">>%zd %d %ju\n", n, errno, p.seq);
ATF_REQUIRE_MSG(errno == ENOBUFS, "send %s", strerror(errno));
-// sched_yield();
}
- printf("sender done\n");
+ close(sd);
+// printf("sender done\n");
}
static void
-receiver(int fd)
+receiver(int sd)
{
union packet p;
ssize_t n;
uintmax_t seq = 0;
- do {
+ for (size_t i = 0; i < COUNT; i++) {
if (rdied)
return;
- while ((n = recv(fd, &p, sizeof(p), 0), sizeof(p))
+ while ((n = recv(sd, &p, sizeof(p), 0), sizeof(p))
== sizeof(p))
{
if (rdied)
@@ -97,26 +96,29 @@
printf("%ju != %ju\n", p.seq, seq);
seq = p.seq + 1;
}
- printf("<<%zd %d %ju\n", n, errno, seq);
+// printf("<<%zd %d %ju\n", n, errno, seq);
if (n == 0)
return;
ATF_REQUIRE_EQ(n, -1);
ATF_REQUIRE_MSG(errno == ENOBUFS, "recv %s", strerror(errno));
- } while (p.seq < COUNT);
+ }
+ close(sd);
}
static void
sendrecv(int rerror)
{
- int fd[2], error;
+ int fd[2], sd[2], error;
+ char c = 0;
struct sigaction sa;
- error = socketpair(AF_UNIX, SOCK_DGRAM, 0, fd);
-// error = pipe(fd);
+ error = socketpair(AF_UNIX, SOCK_DGRAM, 0, sd);
ATF_REQUIRE_MSG(error != -1, "socketpair failed (%s)", strerror(errno));
+ error = pipe(fd);
+ ATF_REQUIRE_MSG(error != -1, "pipe failed (%s)", strerror(errno));
- for (size_t i = 0; i < __arraycount(fd); i++) {
- error = setsockopt(fd[i], SOL_SOCKET, SO_RERROR, &rerror,
+ for (size_t i = 0; i < __arraycount(sd); i++) {
+ error = setsockopt(sd[i], SOL_SOCKET, SO_RERROR, &rerror,
sizeof(rerror));
ATF_REQUIRE_MSG(error != -1,
"setsockopt(SO_RERROR) failed (%s)", strerror(errno));
@@ -133,17 +135,18 @@
switch (fork()) {
case -1:
ATF_REQUIRE_MSG(errno == 0,
- "socketpair failed (%s)", strerror(errno));
+ "fork failed (%s)", strerror(errno));
__unreachable();
/*NOTREACHED*/
case 0:
- sched_yield();
- sender(fd[0]);
- close(fd[0]);
+ read(fd[1], &c, sizeof(c));
+ sender(sd[0]);
+ close(sd[0]);
exit(EXIT_SUCCESS);
/*NOTREACHED*/
default:
- receiver(fd[1]);
+ write(fd[0], &c, sizeof(c));
+ receiver(sd[1]);
return;
}
}
Home |
Main Index |
Thread Index |
Old Index