Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/net/net tests: make t_socket_afinet.c run on rump kernel



details:   https://anonhg.NetBSD.org/src/rev/92236fcd0866
branches:  trunk
changeset: 372343:92236fcd0866
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Thu Nov 17 08:34:39 2022 +0000

description:
tests: make t_socket_afinet.c run on rump kernel

diffstat:

 tests/net/net/t_socket_afinet.c |  42 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)

diffs (120 lines):

diff -r 79e7eda26de1 -r 92236fcd0866 tests/net/net/t_socket_afinet.c
--- a/tests/net/net/t_socket_afinet.c   Thu Nov 17 08:33:27 2022 +0000
+++ b/tests/net/net/t_socket_afinet.c   Thu Nov 17 08:34:39 2022 +0000
@@ -1,3 +1,5 @@
+/*     $NetBSD: t_socket_afinet.c,v 1.2 2022/11/17 08:34:39 ozaki-r Exp $      */
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
@@ -26,7 +28,12 @@
  */
 
 #include <sys/cdefs.h>
+#ifdef __NetBSD__
+__RCSID("$NetBSD: t_socket_afinet.c,v 1.2 2022/11/17 08:34:39 ozaki-r Exp $");
+#define USE_RUMPKERNEL 1
+#else
 __FBSDID("$FreeBSD$");
+#endif
 
 #include <sys/errno.h>
 #include <sys/socket.h>
@@ -35,11 +42,30 @@
 
 #include <atf-c.h>
 
+#ifdef USE_RUMPKERNEL
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#define socket rump_sys_socket
+#define bind   rump_sys_bind
+#define listen rump_sys_listen
+#define connect        rump_sys_connect
+#define write  rump_sys_write
+#define poll   rump_sys_poll
+#define close  rump_sys_close
+
+#define RUMP_INIT()    rump_init()
+#else
+#define RUMP_INIT()    do { } while (0)
+#endif
+
 ATF_TC_WITHOUT_HEAD(socket_afinet);
 ATF_TC_BODY(socket_afinet, tc)
 {
        int sd;
 
+       RUMP_INIT();
+
        sd = socket(PF_INET, SOCK_DGRAM, 0);
        ATF_CHECK(sd >= 0);
 
@@ -52,6 +78,12 @@
        int sd, rc;
        struct sockaddr_in sin;
 
+       RUMP_INIT();
+
+#ifdef __NetBSD__
+       atf_tc_expect_fail("NetBSD doesn't allow sin_family == 0 (sin_len == 0 too)");
+#endif
+
        if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false))
                atf_tc_skip("doesn't work when mac_portacl(4) loaded (https://bugs.freebsd.org/238781)");
 
@@ -76,6 +108,8 @@
        int sd, rc;
        struct sockaddr_in sin;
 
+       RUMP_INIT();
+
        sd = socket(PF_INET, SOCK_DGRAM, 0);
        ATF_CHECK(sd >= 0);
 
@@ -90,6 +124,7 @@
        close(sd);
 }
 
+#ifdef POLLRDHUP
 ATF_TC_WITHOUT_HEAD(socket_afinet_poll_no_rdhup);
 ATF_TC_BODY(socket_afinet_poll_no_rdhup, tc)
 {
@@ -98,6 +133,8 @@
        struct pollfd pfd;
        int one = 1;
 
+       RUMP_INIT();
+
        /* Verify that we don't expose POLLRDHUP if not requested. */
 
        /* Server setup. */
@@ -158,6 +195,8 @@
        char buffer;
        int one = 1;
 
+       RUMP_INIT();
+
        /* Verify that server sees POLLRDHUP if it asks for it. */
 
        /* Server setup. */
@@ -227,6 +266,7 @@
        close(ss2);
        close(ss);
 }
+#endif /* POLLRDHUP */
 
 ATF_TP_ADD_TCS(tp)
 {
@@ -234,8 +274,10 @@
        ATF_TP_ADD_TC(tp, socket_afinet);
        ATF_TP_ADD_TC(tp, socket_afinet_bind_zero);
        ATF_TP_ADD_TC(tp, socket_afinet_bind_ok);
+#ifdef POLLRDHUP
        ATF_TP_ADD_TC(tp, socket_afinet_poll_no_rdhup);
        ATF_TP_ADD_TC(tp, socket_afinet_poll_rdhup);
+#endif
 
        return atf_no_error();
 }



Home | Main Index | Thread Index | Old Index