Source-Changes-HG archive

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

[src/trunk]: src/tests/net/bpf Add an xfail test for the mbuf leak described ...



details:   https://anonhg.NetBSD.org/src/rev/23b698d34c09
branches:  trunk
changeset: 759343:23b698d34c09
user:      pooka <pooka%NetBSD.org@localhost>
date:      Mon Dec 06 11:32:01 2010 +0000

description:
Add an xfail test for the mbuf leak described in PR kern/44196.

This is yet another example of a simple test which would be much
trickier to execute against the host kernel.  You would either need
to put networking in a complete lockdown, or do some "statistical"
methods where you trigger the bug many many times and attempt to
ascertain a rising trend in mbuf count.  And, of course, the leaked
mbufs don't go away from the host kernel once the test ends.  In
contrast, we *know* that there is no other networking activity in
a rump kernel, so we can execute the operation exactly once, plus
the leaked mbuf "disappears" when the test is done.

diffstat:

 tests/net/bpf/Makefile |    6 +-
 tests/net/bpf/t_bpf.c  |  101 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 2 deletions(-)

diffs (125 lines):

diff -r ede01b8f7ed1 -r 23b698d34c09 tests/net/bpf/Makefile
--- a/tests/net/bpf/Makefile    Mon Dec 06 10:48:18 2010 +0000
+++ b/tests/net/bpf/Makefile    Mon Dec 06 11:32:01 2010 +0000
@@ -1,12 +1,14 @@
-# $NetBSD: Makefile,v 1.1 2010/04/21 11:07:34 pooka Exp $
+# $NetBSD: Makefile,v 1.2 2010/12/06 11:32:01 pooka Exp $
 #
 
 .include <bsd.own.mk>
 
 TESTSDIR=      ${TESTSBASE}/net/bpf
 
-TESTS_C=       t_div-by-zero
+TESTS_C=       t_bpf
+TESTS_C+=      t_div-by-zero
 
+LDADD+=                -lrumpnet_shmif
 LDADD+=                -lrumpdev_bpf -lrumpdev -lrumpnet_net -lrumpnet -lrumpvfs
 LDADD+=                -lrump -lrumpuser -lpthread
 
diff -r ede01b8f7ed1 -r 23b698d34c09 tests/net/bpf/t_bpf.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/net/bpf/t_bpf.c     Mon Dec 06 11:32:01 2010 +0000
@@ -0,0 +1,101 @@
+/*     $NetBSD: t_bpf.c,v 1.1 2010/12/06 11:32:01 pooka Exp $  */
+
+/*-
+ * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
+ *
+ * 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 AUTHOR ``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 AUTHOR 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/param.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/mbuf.h>
+#include <sys/sysctl.h>
+
+#include <net/if.h>
+#include <net/bpf.h>
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+/* XXX: atf-c.h has collisions with mbuf */
+#undef m_type
+#undef m_data
+#include <atf-c.h>
+
+#include "../../h_macros.h"
+
+ATF_TC(bpfwriteleak);
+ATF_TC_HEAD(bpfwriteleak, tc)
+{
+
+       atf_tc_set_md_var(tc, "descr", "Checks that writing to /dev/bpf "
+           "does not leak mbufs");
+}
+
+static int
+getmtdata(void)
+{
+       struct mbstat mbstat;
+       size_t mbstatlen = sizeof(mbstat);
+       const int mbstat_mib[] = { CTL_KERN, KERN_MBUF, MBUF_STATS };
+
+       RL(rump_sys___sysctl(mbstat_mib, __arraycount(mbstat_mib),
+           &mbstat, &mbstatlen, NULL, 0));
+       return mbstat.m_mtypes[MT_DATA];
+}
+
+ATF_TC_BODY(bpfwriteleak, tc)
+{
+       char buf[28]; /* sizeof(garbage) > etherhdrlen */
+       struct ifreq ifr;
+       int ifnum, bpfd;
+       u_int x;
+
+       RZ(rump_init());
+       RZ(rump_pub_shmif_create(NULL, &ifnum));
+       sprintf(ifr.ifr_name, "shmif%d", ifnum);
+
+       RL(bpfd = rump_sys_open("/dev/bpf", O_RDWR));
+       RL(rump_sys_ioctl(bpfd, BIOCSETIF, &ifr));
+        x = 1;
+       RL(rump_sys_ioctl(bpfd, BIOCSFEEDBACK, &ifr));
+
+       if (getmtdata() != 0)
+               atf_tc_fail("test precondition failed: MT_DATA mbufs != 0");
+
+       ATF_REQUIRE_ERRNO(ENETDOWN, rump_sys_write(bpfd, buf, sizeof(buf))==-1);
+
+       atf_tc_expect_fail("PR kern/44196");
+       ATF_REQUIRE_EQ(getmtdata(), 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, bpfwriteleak);
+       return atf_no_error();
+}



Home | Main Index | Thread Index | Old Index