Module Name: src
Committed By: martin
Date: Sat Aug 24 16:53:09 UTC 2024
Modified Files:
src/tests/kernel/kqueue [netbsd-10]: t_empty.c
src/tests/net/net [netbsd-10]: t_tcp.c
Log Message:
Pull up following revision(s) (requested by rin in ticket #813):
tests/kernel/kqueue/t_empty.c: revision 1.2
tests/net/net/t_tcp.c: revision 1.13
tests: Fix false positives due to race b/w connect(2) and accept(2)
For kernel/kqueue/t_empty and net/net/t_tcp, there were no sync ops
b/w connect(2) and accept(2) for non-blocking socket pair on host
(rump is not used).
As a result, accept(2) can fail immediately with EAGAIN, when
kernel-side routines for connect(2) and accept(2) are processed in
different CPU cores.
1-sec sleep(3) between two syscalls seems to mitigate this problem
as far as I can see, although this should not be a perfect solution...
Thanks ozaki-r@ for discussion.
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.1.2.1 src/tests/kernel/kqueue/t_empty.c
cvs rdiff -u -r1.12 -r1.12.2.1 src/tests/net/net/t_tcp.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/kernel/kqueue/t_empty.c
diff -u src/tests/kernel/kqueue/t_empty.c:1.1 src/tests/kernel/kqueue/t_empty.c:1.1.2.1
--- src/tests/kernel/kqueue/t_empty.c:1.1 Sat Oct 23 01:28:33 2021
+++ src/tests/kernel/kqueue/t_empty.c Sat Aug 24 16:53:09 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_empty.c,v 1.1 2021/10/23 01:28:33 thorpej Exp $ */
+/* $NetBSD: t_empty.c,v 1.1.2.1 2024/08/24 16:53:09 martin Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_empty.c,v 1.1 2021/10/23 01:28:33 thorpej Exp $");
+__RCSID("$NetBSD: t_empty.c,v 1.1.2.1 2024/08/24 16:53:09 martin Exp $");
#include <sys/event.h>
#include <sys/socket.h>
@@ -163,6 +163,9 @@ ATF_TC_BODY(sock_tcp, tc)
ATF_REQUIRE_ERRNO(EINPROGRESS,
connect(writesock, (struct sockaddr *)&sin, sizeof(sin)) == -1);
+ /* XXX Avoid race between connect(2) and accept(2). */
+ sleep(1);
+
slen = sizeof(sin);
ATF_REQUIRE((readsock = accept(readsock, (struct sockaddr *)&sin,
&slen)) != -1);
Index: src/tests/net/net/t_tcp.c
diff -u src/tests/net/net/t_tcp.c:1.12 src/tests/net/net/t_tcp.c:1.12.2.1
--- src/tests/net/net/t_tcp.c:1.12 Mon Nov 8 10:57:09 2021
+++ src/tests/net/net/t_tcp.c Sat Aug 24 16:53:09 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_tcp.c,v 1.12 2021/11/08 10:57:09 rin Exp $ */
+/* $NetBSD: t_tcp.c,v 1.12.2.1 2024/08/24 16:53:09 martin Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#ifdef __RCSID
-__RCSID("$Id: t_tcp.c,v 1.12 2021/11/08 10:57:09 rin Exp $");
+__RCSID("$Id: t_tcp.c,v 1.12.2.1 2024/08/24 16:53:09 martin Exp $");
#endif
/* Example code. Should block; does with accept not accept4_. */
@@ -159,6 +159,10 @@ accept_test(sa_family_t sfamily, sa_fami
if (ok != -1 || errno != EINPROGRESS)
FAIL("expected connect to fail");
#endif
+
+ /* XXX avoid race between connect(2) and accept(2). */
+ sleep(1);
+
if (useaccept) {
acpt = accept(srvr, NULL, NULL);
} else {