2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright 2021 Lutz Donnerhacke
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials provided
15 * with the distribution.
16 * 3. Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
31 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 ATF_TC_HEAD(basic, conf)
43 atf_tc_set_md_var(conf, "require.user", "root");
46 ATF_TC_BODY(basic, dummy)
56 ng_mkpeer(".", "a", "hub", "a");
58 ng_connect(".", "b", "hub:", "b");
59 ng_connect(".", "c", "hub:", "c");
61 /* do not bounce back */
62 ng_register_data("a", get_data0);
64 ng_send_data("a", msg, sizeof(msg));
65 ng_handle_events(50, r);
69 ng_register_data("b", get_data0);
70 ng_register_data("c", get_data0);
72 ng_send_data("a", msg, sizeof(msg));
73 ng_handle_events(50, r);
77 ng_send_data("b", msg, sizeof(msg));
78 ng_handle_events(50, r);
82 ng_send_data("c", msg, sizeof(msg));
83 ng_handle_events(50, r);
89 ng_send_data("a", msg, sizeof(msg));
90 ng_handle_events(50, r);
97 ATF_TC_HEAD(persistence, conf)
99 atf_tc_set_md_var(conf, "require.user", "root");
102 ATF_TC_BODY(persistence, dummy)
109 ng_mkpeer(".", "a", "hub", "a");
112 ng_send_msg("hub:", "setpersistent");
119 ATF_TC_HEAD(loop, conf)
121 atf_tc_set_md_var(conf, "require.user", "root");
124 ATF_TC_BODY(loop, dummy)
128 char msg[] = "LOOP Alert!";
131 ng_shutdown("hub1:");
132 ng_shutdown("hub2:");
136 ng_mkpeer(".", "a", "hub", "a");
137 ng_name("a", "hub1");
138 ng_mkpeer(".", "b", "hub", "b");
139 ng_name("b", "hub2");
141 ng_register_data("a", get_data0);
142 ng_register_data("b", get_data0);
151 ng_connect("hub1:", "xc1", "hub2:", "xc1");
154 ng_send_data("a", msg, sizeof(msg));
155 ng_handle_events(50, r);
156 ATF_CHECK(r[0] == 1);
159 * Closed loop, DANGEROUS!
165 ng_connect("hub1:", "xc2", "hub2:", "xc2");
168 ng_send_data("a", msg, sizeof(msg));
169 for (i = 0; i < 10; i++) /* don't run forever */
170 if (!ng_handle_event(50, r))
174 ng_shutdown("hub1:");
175 ng_shutdown("hub2:");
179 ATF_TC_HEAD(many_hooks, conf)
181 atf_tc_set_md_var(conf, "require.user", "root");
184 ATF_TC_BODY(many_hooks, dummy)
189 const int HOOKS = 1000;
196 ng_mkpeer(".", "a", "hub", "a");
199 ng_register_data("a", get_data0);
201 for (i = 0; i < HOOKS; i++)
205 snprintf(hook, sizeof(hook), "hook%d", i);
206 ng_connect(".", hook, "hub:", hook);
208 ng_send_data(hook, msg, sizeof(msg));
212 ng_handle_events(50, r);
214 ATF_CHECK(r[0] > 100);
215 atf_tc_expect_fail("Implementation limitation (%d)", i);
216 ATF_CHECK(r[0] == HOOKS);
217 atf_tc_expect_pass();
225 ATF_TP_ADD_TC(hub, basic);
226 ATF_TP_ADD_TC(hub, loop);
227 ATF_TP_ADD_TC(hub, persistence);
228 ATF_TP_ADD_TC(hub, many_hooks);
230 return atf_no_error();