Source-Changes-HG archive

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

[src/trunk]: src/tests/net/icmp test that kernel reponds to ping



details:   https://anonhg.NetBSD.org/src/rev/dfb3dba95b66
branches:  trunk
changeset: 756984:dfb3dba95b66
user:      pooka <pooka%NetBSD.org@localhost>
date:      Mon Aug 09 15:08:43 2010 +0000

description:
test that kernel reponds to ping

diffstat:

 tests/net/icmp/Makefile |    3 +-
 tests/net/icmp/t_ping.c |  101 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 103 insertions(+), 1 deletions(-)

diffs (122 lines):

diff -r 91baa3091c61 -r dfb3dba95b66 tests/net/icmp/Makefile
--- a/tests/net/icmp/Makefile   Mon Aug 09 15:07:51 2010 +0000
+++ b/tests/net/icmp/Makefile   Mon Aug 09 15:08:43 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2010/07/04 19:30:59 pooka Exp $
+# $NetBSD: Makefile,v 1.2 2010/08/09 15:08:43 pooka Exp $
 #
 
 .include <bsd.own.mk>
@@ -6,6 +6,7 @@
 TESTSDIR=      ${TESTSBASE}/net/icmp
 
 TESTS_C=       t_forward
+TESTS_C+=      t_ping
 
 LDADD+=                -lrumpnet_shmif -lrumpnet_netinet -lrumpnet_net -lrumpnet
 LDADD+=                -lrump -lrumpuser -lpthread
diff -r 91baa3091c61 -r dfb3dba95b66 tests/net/icmp/t_ping.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/net/icmp/t_ping.c   Mon Aug 09 15:08:43 2010 +0000
@@ -0,0 +1,101 @@
+/*     $NetBSD: t_ping.c,v 1.1 2010/08/09 15:08:43 pooka Exp $ */
+
+/*-
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * 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 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>
+#ifndef lint
+__RCSID("$NetBSD: t_ping.c,v 1.1 2010/08/09 15:08:43 pooka Exp $");
+#endif /* not lint */
+
+#include <sys/types.h>
+
+#include <atf-c.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <rump/rump.h>
+
+#include "../../h_macros.h"
+#include "../config/netconfig.c"
+
+ATF_TC(simpleping);
+ATF_TC_HEAD(simpleping, tc)
+{
+
+       atf_tc_set_md_var(tc, "descr", "check that kernel responds to ping");
+       atf_tc_set_md_var(tc, "use.fs", "true");
+       atf_tc_set_md_var(tc, "timeout", "2");
+}
+
+ATF_TC_BODY(simpleping, tc)
+{
+       char ifname[IFNAMSIZ];
+       pid_t cpid;
+       int status;
+       bool win, win2;
+
+       cpid = fork();
+       rump_init();
+       netcfg_rump_makeshmif("but-can-i-buy-your-ether-bus", ifname);
+
+       switch (cpid) {
+       case -1:
+               atf_tc_fail_errno("fork failed");
+       case 0:
+               netcfg_rump_if(ifname, "1.1.1.10", "255.255.255.0");
+               pause();
+               break;
+       default:
+               break;
+       }
+
+       netcfg_rump_if(ifname, "1.1.1.20", "255.255.255.0");
+
+       /*
+        * The beauty of shmif is that we don't have races here.
+        */
+       win = netcfg_rump_pingtest("1.1.1.10", 500);
+       win2 = netcfg_rump_pingtest("1.1.1.30", 500);
+
+       kill(cpid, SIGKILL);
+
+       if (!win)
+               atf_tc_fail("ping failed");
+       if (win2)
+               atf_tc_fail("non-existent host responded");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, simpleping);
+
+       return atf_no_error();
+}



Home | Main Index | Thread Index | Old Index