Source-Changes-HG archive

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

[src/trunk]: src Run mcast tests on rump kernels



details:   https://anonhg.NetBSD.org/src/rev/07b025e4d9f3
branches:  trunk
changeset: 338462:07b025e4d9f3
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Tue May 26 00:42:07 2015 +0000

description:
Run mcast tests on rump kernels

The tests on anita qemus failed due to that the host network environment
didn't meet the tests.

The change makes the tests independent from host environments
and the tests will pass on any environments including anita qemus.

Discussed on tech-kern and tech-net.

diffstat:

 distrib/sets/lists/debug/mi |    4 +-
 distrib/sets/lists/tests/mi |    9 +-
 tests/net/Makefile          |    8 +-
 tests/net/mcast/Makefile    |    8 +-
 tests/net/mcast/mcast.c     |  497 ++++++++++++++++++++++++++++++++++++++++++++
 tests/net/mcast/t_mcast.c   |  497 --------------------------------------------
 tests/net/mcast/t_mcast.sh  |  109 +++++++++
 7 files changed, 623 insertions(+), 509 deletions(-)

diffs (truncated from 1197 to 300 lines):

diff -r 1ad359b78de2 -r 07b025e4d9f3 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Mon May 25 23:47:01 2015 +0000
+++ b/distrib/sets/lists/debug/mi       Tue May 26 00:42:07 2015 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.113 2015/05/01 14:17:56 christos Exp $
+# $NetBSD: mi,v 1.114 2015/05/26 00:42:07 ozaki-r Exp $
 
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib/i18n/libBIG5_g.a                     comp-c-debuglib         debuglib
@@ -2174,7 +2174,7 @@
 ./usr/libdata/debug/usr/tests/net/if/t_compat.debug            tests-net-debug         debug,atf,rump
 ./usr/libdata/debug/usr/tests/net/if_loop/t_pr.debug           tests-net-debug         debug,atf,rump
 ./usr/libdata/debug/usr/tests/net/in_cksum/in_cksum.debug      tests-net-debug         debug,atf
-./usr/libdata/debug/usr/tests/net/mcast/t_mcast.debug          tests-net-debug         debug,atf
+./usr/libdata/debug/usr/tests/net/mcast/mcast.debug            tests-net-debug         debug,atf,rump
 ./usr/libdata/debug/usr/tests/net/net/t_pktinfo.debug          tests-net-debug         debug,atf
 ./usr/libdata/debug/usr/tests/net/net/t_raw.debug              tests-net-debug         debug,atf,rump
 ./usr/libdata/debug/usr/tests/net/net/t_tcp.debug              tests-net-debug         debug,atf
diff -r 1ad359b78de2 -r 07b025e4d9f3 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Mon May 25 23:47:01 2015 +0000
+++ b/distrib/sets/lists/tests/mi       Tue May 26 00:42:07 2015 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.622 2015/05/18 06:27:04 ozaki-r Exp $
+# $NetBSD: mi,v 1.623 2015/05/26 00:42:07 ozaki-r Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -3151,9 +3151,10 @@
 ./usr/tests/net/in_cksum/t_in_cksum            tests-net-tests         atf
 ./usr/tests/net/in_cksum/in_cksum              tests-net-tests         atf
 ./usr/tests/net/mcast                          tests-net-tests
-./usr/tests/net/mcast/Atffile                  tests-net-tests         atf
-./usr/tests/net/mcast/Kyuafile                 tests-net-tests         atf,kyua
-./usr/tests/net/mcast/t_mcast                  tests-net-tests         atf
+./usr/tests/net/mcast/Atffile                  tests-net-tests         atf,rump
+./usr/tests/net/mcast/Kyuafile                 tests-net-tests         atf,rump,kyua
+./usr/tests/net/mcast/mcast                    tests-net-tests         atf,rump
+./usr/tests/net/mcast/t_mcast                  tests-net-tests         atf,rump
 ./usr/tests/net/mpls                           tests-net-tests
 ./usr/tests/net/mpls/Atffile                   tests-net-tests         atf,rump
 ./usr/tests/net/mpls/Kyuafile                  tests-net-tests         atf,rump,kyua
diff -r 1ad359b78de2 -r 07b025e4d9f3 tests/net/Makefile
--- a/tests/net/Makefile        Mon May 25 23:47:01 2015 +0000
+++ b/tests/net/Makefile        Tue May 26 00:42:07 2015 +0000
@@ -1,13 +1,13 @@
-# $NetBSD: Makefile,v 1.21 2015/05/20 17:39:04 christos Exp $
+# $NetBSD: Makefile,v 1.22 2015/05/26 00:42:07 ozaki-r Exp $
 
 .include <bsd.own.mk>
 
 TESTSDIR=      ${TESTSBASE}/net
 
-TESTS_SUBDIRS=         fdpass in_cksum mcast net sys
+TESTS_SUBDIRS=         fdpass in_cksum net sys
 .if (${MKRUMP} != "no")
-TESTS_SUBDIRS+=                bpf bpfilter carp icmp if if_bridge if_loop mpls npf
-TESTS_SUBDIRS+=                route
+TESTS_SUBDIRS+=                bpf bpfilter carp icmp if if_bridge if_loop mcast
+TESTS_SUBDIRS+=                mpls npf route
 .if (${MKSLJIT} != "no")
 TESTS_SUBDIRS+=                bpfjit
 .endif
diff -r 1ad359b78de2 -r 07b025e4d9f3 tests/net/mcast/Makefile
--- a/tests/net/mcast/Makefile  Mon May 25 23:47:01 2015 +0000
+++ b/tests/net/mcast/Makefile  Tue May 26 00:42:07 2015 +0000
@@ -1,10 +1,14 @@
-# $NetBSD: Makefile,v 1.1 2014/10/11 23:04:42 christos Exp $
+# $NetBSD: Makefile,v 1.2 2015/05/26 00:42:07 ozaki-r Exp $
 #
 
 .include <bsd.own.mk>
 
 TESTSDIR=      ${TESTSBASE}/net/mcast
 
-TESTS_C=       t_mcast
+TESTS_SH=      t_mcast
+
+PROGS=         mcast
+MAN.mcast=     # empty
+BINDIR.mcast=  ${TESTSDIR}
 
 .include <bsd.test.mk>
diff -r 1ad359b78de2 -r 07b025e4d9f3 tests/net/mcast/mcast.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/net/mcast/mcast.c   Tue May 26 00:42:07 2015 +0000
@@ -0,0 +1,497 @@
+/*     $NetBSD: mcast.c,v 1.1 2015/05/26 00:42:07 ozaki-r Exp $        */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+#ifdef __RCSID
+__RCSID("$NetBSD: mcast.c,v 1.1 2015/05/26 00:42:07 ozaki-r Exp $");
+#else
+extern const char *__progname;
+#define getprogname() __progname
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+
+#include <assert.h>
+#include <netdb.h>
+#include <time.h>
+#include <signal.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <err.h>
+#include <errno.h>
+#include <poll.h>
+#include <stdbool.h>
+
+#ifdef ATF
+#include <atf-c.h>
+
+#define ERRX(ev, msg, ...)     ATF_REQUIRE_MSG(0, msg, __VA_ARGS__)
+
+#define SKIPX(ev, msg, ...)    do {                    \
+       atf_tc_skip(msg, __VA_ARGS__);                  \
+       return;                                         \
+} while(/*CONSTCOND*/0)
+
+#else
+#define ERRX(ev, msg, ...)     errx(ev, msg, __VA_ARGS__)
+#define SKIPX(ev, msg, ...)    errx(ev, msg, __VA_ARGS__)
+#endif
+
+static int debug;
+
+#define TOTAL 10
+#define PORT_V4MAPPED "6666"
+#define HOST_V4MAPPED "::FFFF:239.1.1.1"
+#define PORT_V4 "6666"
+#define HOST_V4 "239.1.1.1"
+#define PORT_V6 "6666"
+#define HOST_V6 "FF05:1:0:0:0:0:0:1"
+
+struct message {
+       size_t seq;
+       struct timespec ts;
+};
+
+static int
+addmc(int s, struct addrinfo *ai, bool bug)
+{
+       struct ip_mreq m4;
+       struct ipv6_mreq m6;
+       struct sockaddr_in *s4;
+       struct sockaddr_in6 *s6;
+       unsigned int ifc;
+
+       switch (ai->ai_family) {
+       case AF_INET:
+               s4 = (void *)ai->ai_addr;
+               assert(sizeof(*s4) == ai->ai_addrlen);
+               m4.imr_multiaddr = s4->sin_addr;
+               m4.imr_interface.s_addr = htonl(INADDR_ANY);
+               return setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP,
+                   &m4, sizeof(m4));
+       case AF_INET6:
+               s6 = (void *)ai->ai_addr;
+               /*
+                * Linux:       Does not support the v6 ioctls on v4 mapped
+                *              sockets but it does support the v4 ones and
+                *              it works.
+                * MacOS/X:     Supports the v6 ioctls on v4 mapped sockets,
+                *              but does not work and also does not support
+                *              the v4 ioctls. So no way to make multicasting
+                *              work with mapped addresses.
+                * NetBSD:      Supports both and works for both.
+                */
+               if (bug && IN6_IS_ADDR_V4MAPPED(&s6->sin6_addr)) {
+                       memcpy(&m4.imr_multiaddr, &s6->sin6_addr.s6_addr[12],
+                           sizeof(m4.imr_multiaddr));
+                       m4.imr_interface.s_addr = htonl(INADDR_ANY);
+                       return setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP,
+                           &m4, sizeof(m4));
+               }
+               assert(sizeof(*s6) == ai->ai_addrlen);
+               memset(&m6, 0, sizeof(m6));
+#if 0
+               ifc = 1;
+               if (setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
+                   &ifc, sizeof(ifc)) == -1)
+                       return -1;
+               ifc = 224;
+               if (setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
+                   &ifc, sizeof(ifc)) == -1)
+                       return -1;
+               ifc = 1; /* XXX should pick a proper interface */
+               if (setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_IF, &ifc,
+                   sizeof(ifc)) == -1)
+                       return -1;
+#else
+               ifc = 0; /* Let pick an appropriate interface */
+#endif
+               m6.ipv6mr_interface = ifc;
+               m6.ipv6mr_multiaddr = s6->sin6_addr;
+               return setsockopt(s, IPPROTO_IPV6, IPV6_JOIN_GROUP,
+                   &m6, sizeof(m6));
+       default:
+               errno = EOPNOTSUPP;
+               return -1;
+       }
+}
+
+static int
+allowv4mapped(int s, struct addrinfo *ai)
+{
+       struct sockaddr_in6 *s6;
+       int zero = 0;
+
+       if (ai->ai_family != AF_INET6)
+               return 0;
+
+       s6 = (void *)ai->ai_addr;
+
+       if (!IN6_IS_ADDR_V4MAPPED(&s6->sin6_addr))
+               return 0;
+       return setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &zero, sizeof(zero));
+}
+
+static struct sockaddr_storage ss;
+static int
+connector(int fd, const struct sockaddr *sa, socklen_t slen)
+{
+       assert(sizeof(ss) > slen);
+       memcpy(&ss, sa, slen);
+       return 0;
+}
+
+static void
+show(const char *prefix, const struct message *msg)
+{
+       printf("%10.10s: %zu [%jd.%ld]\n", prefix, msg->seq, (intmax_t)
+           msg->ts.tv_sec, msg->ts.tv_nsec);
+}
+
+static int
+getsocket(const char *host, const char *port,
+    int (*f)(int, const struct sockaddr *, socklen_t), socklen_t *slen,
+    bool bug)
+{
+       int e, s, lasterrno = 0;
+       struct addrinfo hints, *ai0, *ai;
+       const char *cause = "?";
+
+       memset(&hints, 0, sizeof(hints));
+       hints.ai_family = AF_UNSPEC;
+       hints.ai_socktype = SOCK_DGRAM;
+       e = getaddrinfo(host, port, &hints, &ai0);
+       if (e)
+               ERRX(EXIT_FAILURE, "Can't resolve %s:%s (%s)", host, port,
+                   gai_strerror(e));
+
+       s = -1;
+       for (ai = ai0; ai; ai = ai->ai_next) {
+               s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
+               if (s == -1) {
+                       lasterrno = errno;
+                       cause = "socket";
+                       continue;
+               }
+               if (allowv4mapped(s, ai) == -1) {
+                       cause = "allow v4 mapped";
+                       goto out;
+               }
+               if ((*f)(s, ai->ai_addr, ai->ai_addrlen) == -1) {
+                       cause = f == bind ? "bind" : "connect";



Home | Main Index | Thread Index | Old Index