should terminate and does with ktrace, but it does not normally.
This commit is contained in:
parent
fd6a62a9fd
commit
1cd154f24d
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: t_sendrecv.c,v 1.1 2018/08/21 10:41:00 christos Exp $ */
|
||||
/* $NetBSD: t_sendrecv.c,v 1.2 2018/08/21 11:03:27 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2018 The NetBSD Foundation, Inc.
|
||||
|
@ -15,13 +15,6 @@
|
|||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
|
@ -36,7 +29,7 @@
|
|||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: t_sendrecv.c,v 1.1 2018/08/21 10:41:00 christos Exp $");
|
||||
__RCSID("$NetBSD: t_sendrecv.c,v 1.2 2018/08/21 11:03:27 christos Exp $");
|
||||
|
||||
#include <atf-c.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -49,6 +42,7 @@ __RCSID("$NetBSD: t_sendrecv.c,v 1.1 2018/08/21 10:41:00 christos Exp $");
|
|||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sched.h>
|
||||
#include <signal.h>
|
||||
|
||||
ATF_TC(sendrecv_basic);
|
||||
ATF_TC_HEAD(sendrecv_basic, tc)
|
||||
|
@ -56,13 +50,22 @@ ATF_TC_HEAD(sendrecv_basic, tc)
|
|||
atf_tc_set_md_var(tc, "descr", "A basic test of sendrecv(2)");
|
||||
}
|
||||
|
||||
#define COUNT 1000
|
||||
#define COUNT 100
|
||||
|
||||
union packet {
|
||||
uint8_t buf[1316];
|
||||
uintmax_t seq;
|
||||
};
|
||||
|
||||
static volatile sig_atomic_t rdied;
|
||||
|
||||
static void
|
||||
handle_sigchld(__unused int pid)
|
||||
{
|
||||
|
||||
rdied = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
sender(int fd)
|
||||
{
|
||||
|
@ -73,9 +76,11 @@ sender(int fd)
|
|||
for (; (n = send(fd, &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");
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -85,12 +90,16 @@ receiver(int fd)
|
|||
ssize_t n;
|
||||
uintmax_t seq = 0;
|
||||
|
||||
for (size_t i = 0; i < COUNT; i++) {
|
||||
do {
|
||||
if (rdied)
|
||||
return;
|
||||
while ((n = recv(fd, &p, sizeof(p), 0), sizeof(p))
|
||||
== sizeof(p))
|
||||
{
|
||||
// if (p.seq != seq)
|
||||
// printf("%ju != %ju\n", p.seq, seq);
|
||||
if (rdied)
|
||||
return;
|
||||
if (p.seq != seq)
|
||||
printf("%ju != %ju\n", p.seq, seq);
|
||||
seq = p.seq + 1;
|
||||
}
|
||||
printf("<<%zd %d %ju\n", n, errno, seq);
|
||||
|
@ -98,17 +107,26 @@ receiver(int fd)
|
|||
return;
|
||||
ATF_REQUIRE_EQ(n, -1);
|
||||
ATF_REQUIRE_MSG(errno == ENOBUFS, "recv %s", strerror(errno));
|
||||
}
|
||||
} while (p.seq < COUNT);
|
||||
}
|
||||
|
||||
ATF_TC_BODY(sendrecv_basic, tc)
|
||||
{
|
||||
int fd[2], error;
|
||||
struct sigaction sa;
|
||||
|
||||
error = socketpair(AF_UNIX, SOCK_DGRAM, 0, fd);
|
||||
// error = pipe(fd);
|
||||
ATF_REQUIRE_MSG(error != -1, "socketpair failed (%s)", strerror(errno));
|
||||
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_flags = SA_RESTART;
|
||||
sa.sa_handler = &handle_sigchld;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
error = sigaction(SIGCHLD, &sa, 0);
|
||||
ATF_REQUIRE_MSG(error != -1, "sigaction failed (%s)",
|
||||
strerror(errno));
|
||||
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
ATF_REQUIRE_MSG(errno == 0,
|
||||
|
|
Loading…
Reference in New Issue