Module Name:    src
Committed By:   pooka
Date:           Mon Aug  9 15:08:43 UTC 2010

Modified Files:
        src/tests/net/icmp: Makefile
Added Files:
        src/tests/net/icmp: t_ping.c

Log Message:
test that kernel reponds to ping


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/icmp/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/icmp/t_ping.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/net/icmp/Makefile
diff -u src/tests/net/icmp/Makefile:1.1 src/tests/net/icmp/Makefile:1.2
--- src/tests/net/icmp/Makefile:1.1	Sun Jul  4 19:30:59 2010
+++ src/tests/net/icmp/Makefile	Mon Aug  9 15:08:43 2010
@@ -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

Added files:

Index: src/tests/net/icmp/t_ping.c
diff -u /dev/null src/tests/net/icmp/t_ping.c:1.1
--- /dev/null	Mon Aug  9 15:08:43 2010
+++ src/tests/net/icmp/t_ping.c	Mon Aug  9 15:08:43 2010
@@ -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();
+}

Reply via email to