Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F112036842
D30633.id90383.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D30633.id90383.diff
View Options
Index: tests/sys/netgraph/Makefile
===================================================================
--- tests/sys/netgraph/Makefile
+++ tests/sys/netgraph/Makefile
@@ -11,8 +11,10 @@
TEST_METADATA.ng_macfilter_test+= required_programs="perl"
ATF_TESTS_C+= basic \
+ hub \
SRCS.basic= basic.c util.c
+SRCS.hub= hub.c util.c
LIBADD+= netgraph
Index: tests/sys/netgraph/hub.c
===================================================================
--- /dev/null
+++ tests/sys/netgraph/hub.c
@@ -0,0 +1,168 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright 2021 Lutz Donnerhacke
+ *
+ * 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.
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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 <atf-c.h>
+#include <errno.h>
+#include <stdio.h>
+
+#include "util.h"
+
+static void get_data(void *data, size_t len, void *ctx);
+
+ATF_TC_WITHOUT_HEAD(basic);
+ATF_TC_BODY(basic, dummy)
+{
+ char msg[] = "test";
+ int received;
+
+ ng_init();
+ ng_mkpeer(".", "a", "hub", "a");
+ ng_name("a", "hub");
+ ng_connect(".", "b", "hub:", "b");
+ ng_connect(".", "c", "hub:", "c");
+
+ /* do not bounce back */
+ ng_register_data("a", get_data);
+ received = 0;
+ ng_send_data("a", msg, sizeof(msg));
+ ng_handle_events(50, &received);
+ ATF_CHECK(received == 0);
+
+ /* send to others */
+ ng_register_data("b", get_data);
+ ng_register_data("c", get_data);
+ received = 0;
+ ng_send_data("a", msg, sizeof(msg));
+ ng_handle_events(50, &received);
+ ATF_CHECK(received == 2);
+
+ received = 0;
+ ng_send_data("b", msg, sizeof(msg));
+ ng_handle_events(50, &received);
+ ATF_CHECK(received == 2);
+
+ received = 0;
+ ng_send_data("c", msg, sizeof(msg));
+ ng_handle_events(50, &received);
+ ATF_CHECK(received == 2);
+
+ /* remove a link */
+ ng_rmhook(".", "b");
+ received = 0;
+ ng_send_data("a", msg, sizeof(msg));
+ ng_handle_events(50, &received);
+ ATF_CHECK(received == 1);
+
+ ng_shutdown("hub:");
+}
+
+ATF_TC_WITHOUT_HEAD(persistence);
+ATF_TC_BODY(persistence, dummy)
+{
+ ng_init();
+ ng_mkpeer(".", "a", "hub", "a");
+ ng_name("a", "hub");
+
+ ng_send_msg("hub:", "setpersistent");
+ ng_rmhook(".", "a");
+
+ ng_shutdown("hub:");
+}
+
+ATF_TC_WITHOUT_HEAD(loop);
+ATF_TC_BODY(loop, dummy)
+{
+ int received, i;
+ char msg[] = "LOOP Alert!";
+
+ ng_init();
+ ng_mkpeer(".", "a", "hub", "a");
+ ng_name("a", "hub1");
+ ng_mkpeer(".", "b", "hub", "b");
+ ng_name("b", "hub2");
+
+ ng_register_data("a", get_data);
+ ng_register_data("b", get_data);
+
+ /*
+ * Open loop
+ *
+ * /-- hub1
+ * . < |
+ * \-- hub2
+ */
+ ng_connect("hub1:", "xc1", "hub2:", "xc1");
+
+ received = 0;
+ ng_send_data("a", msg, sizeof(msg));
+ ng_handle_events(50, &received);
+ ATF_CHECK(received == 1);
+
+ /*
+ * Closed loop, DANGEROUS!
+ *
+ * /-- hub1 -\
+ * . < | |
+ * \-- hub2 -/
+ */
+ ng_connect("hub1:", "xc2", "hub2:", "xc2");
+
+ received = 0;
+ ng_send_data("a", msg, sizeof(msg));
+ for(i = 0; i < 10; i++) /* don't run forever */
+ if (!ng_handle_event(50, &received))
+ break;
+ ATF_CHECK(received > 7);
+
+ ng_shutdown("hub1:");
+ ng_shutdown("hub2:");
+}
+
+ATF_TP_ADD_TCS(basic)
+{
+ ATF_TP_ADD_TC(basic, basic);
+ ATF_TP_ADD_TC(basic, loop);
+ ATF_TP_ADD_TC(basic, persistence);
+
+ return atf_no_error();
+}
+
+static void
+get_data(void *data, size_t len, void *ctx)
+{
+ int *cnt = ctx;
+
+ (void)data;
+ printf("Got %zu bytes of data.\n", len);
+ (*cnt)++;
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Mar 12, 10:04 PM (4 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17126842
Default Alt Text
D30633.id90383.diff (4 KB)
Attached To
Mode
D30633: tests/netgraph: Tests for ng_hub
Attached
Detach File
Event Timeline
Log In to Comment