Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Jun 2021 11:34:04 GMT
From:      Lutz Donnerhacke <donner@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 5554abd9cc97 - main - tests/netgraph: Factor out univeral data counter functions
Message-ID:  <202106091134.159BY4e4074092@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by donner:

URL: https://cgit.FreeBSD.org/src/commit/?id=5554abd9cc9702af30af90925b33c5efff4e7d88

commit 5554abd9cc9702af30af90925b33c5efff4e7d88
Author:     Lutz Donnerhacke <donner@FreeBSD.org>
AuthorDate: 2021-06-08 19:45:20 +0000
Commit:     Lutz Donnerhacke <donner@FreeBSD.org>
CommitDate: 2021-06-09 11:32:22 +0000

    tests/netgraph: Factor out univeral data counter functions
    
    Factor out the data counter helpers for other tests to use.
    
    Reviewed by:    kp
    MFC after:      1 week
    Differential Revision: https://reviews.freebsd.org/D30699
---
 tests/sys/netgraph/bridge.c | 104 +++++++++++++++++---------------------------
 tests/sys/netgraph/util.c   |  20 +++++++++
 tests/sys/netgraph/util.h   |  17 ++++++++
 3 files changed, 78 insertions(+), 63 deletions(-)

diff --git a/tests/sys/netgraph/bridge.c b/tests/sys/netgraph/bridge.c
index 41d2346b527b..3e3c0f804278 100644
--- a/tests/sys/netgraph/bridge.c
+++ b/tests/sys/netgraph/bridge.c
@@ -43,11 +43,6 @@
 #include "util.h"
 #include <netgraph/ng_bridge.h>
 
-static void	get_data0(void *data, size_t len, void *ctx);
-static void	get_data1(void *data, size_t len, void *ctx);
-static void	get_data2(void *data, size_t len, void *ctx);
-static void	get_data3(void *data, size_t len, void *ctx);
-
 static void	get_tablesize(char const *source, struct ng_mesg *msg, void *ctx);
 struct gettable
 {
@@ -90,7 +85,7 @@ ATF_TC_HEAD(basic, conf)
 
 ATF_TC_BODY(basic, dummy)
 {
-	int		r[4];
+	ng_counter_t	r;
 	struct gettable	rm;
 
 	ng_init();
@@ -105,7 +100,7 @@ ATF_TC_BODY(basic, dummy)
 
 	/* do not bounce back */
 	ng_register_data("a", get_data0);
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 1;
 	ng_send_data("a", &msg4, sizeof(msg4));
 	ng_handle_events(50, &r);
@@ -114,26 +109,26 @@ ATF_TC_BODY(basic, dummy)
 	/* send to others */
 	ng_register_data("b", get_data1);
 	ng_register_data("c", get_data2);
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 1;
 	ng_send_data("a", &msg4, sizeof(msg4));
 	ng_handle_events(50, &r);
 	ATF_CHECK(r[0] == 0 && r[1] == 1 && r[2] == 1);
 
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 2;
 	ng_send_data("b", &msg4, sizeof(msg4));
 	ng_handle_events(50, &r);
 	ATF_CHECK(r[0] == 1 && r[1] == 0 && r[2] == 1);
 
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 3;
 	ng_send_data("c", &msg4, sizeof(msg4));
 	ng_handle_events(50, &r);
 	ATF_CHECK(r[0] == 1 && r[1] == 1 && r[2] == 0);
 
 	/* send to learned unicast */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 1;
 	msg4.eh.ether_dhost[5] = 3;
 	ng_send_data("a", &msg4, sizeof(msg4));
@@ -149,7 +144,7 @@ ATF_TC_BODY(basic, dummy)
 
 	/* remove a link */
 	ng_rmhook(".", "b");
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 1;
 	msg4.eh.ether_dhost[5] = 0;
 	ng_send_data("a", &msg4, sizeof(msg4));
@@ -196,7 +191,8 @@ ATF_TC_HEAD(loop, conf)
 
 ATF_TC_BODY(loop, dummy)
 {
-	int		r[4], i;
+	ng_counter_t	r;
+	int		i;
 
 	ng_init();
 	ng_errors(PASS);
@@ -221,7 +217,7 @@ ATF_TC_BODY(loop, dummy)
 	 */
 	ng_connect("bridge1:", "link11", "bridge2:", "link11");
 
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 1;
 	ng_send_data("a", &msg4, sizeof(msg4));
 	ng_handle_events(50, &r);
@@ -236,7 +232,7 @@ ATF_TC_BODY(loop, dummy)
 	 */
 	ng_connect("bridge1:", "link12", "bridge2:", "link12");
 
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 1;
 	ng_errors(PASS);
 	ng_send_data("a", &msg4, sizeof(msg4));
@@ -259,7 +255,8 @@ ATF_TC_HEAD(many_unicasts, conf)
 
 ATF_TC_BODY(many_unicasts, dummy)
 {
-	int		r[4], i;
+	ng_counter_t	r;
+	int		i;
 	const int	HOOKS = 1000;
 	struct gettable	rm;
 
@@ -273,7 +270,7 @@ ATF_TC_BODY(many_unicasts, dummy)
 	ng_register_data("a", get_data0);
 
 	/* learn MAC */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[3] = 0xff;
 	ng_send_data("a", &msg4, sizeof(msg4));
 	ng_handle_events(50, &r);
@@ -284,7 +281,7 @@ ATF_TC_BODY(many_unicasts, dummy)
 	msg4.eh.ether_dhost[3] = 0xff;
 
 	/* now send */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	for (i = 1; i <= HOOKS; i++)
 	{
 		char		hook[20];
@@ -330,7 +327,8 @@ ATF_TC_HEAD(many_broadcasts, conf)
 
 ATF_TC_BODY(many_broadcasts, dummy)
 {
-	int		r[4], i;
+	ng_counter_t	r;
+	int		i;
 	const int	HOOKS = 1000;
 
 	ng_init();
@@ -343,7 +341,7 @@ ATF_TC_BODY(many_broadcasts, dummy)
 	ng_register_data("a", get_data0);
 
 	/* learn MAC */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[3] = 0xff;
 	ng_send_data("a", &msg4, sizeof(msg4));
 	ng_handle_events(50, &r);
@@ -354,7 +352,7 @@ ATF_TC_BODY(many_broadcasts, dummy)
 	memset(msg4.eh.ether_dhost, 0xff, sizeof(msg4.eh.ether_dhost));
 
 	/* now send */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	for (i = 1; i <= HOOKS; i++)
 	{
 		char		hook[20];
@@ -389,7 +387,7 @@ ATF_TC_HEAD(uplink_private, conf)
 
 ATF_TC_BODY(uplink_private, dummy)
 {
-	int		r[4];
+	ng_counter_t	r;
 	struct gettable	rm;
 
 	ng_init();
@@ -410,14 +408,14 @@ ATF_TC_BODY(uplink_private, dummy)
 	ng_register_data("l3", get_data3);
 
 	/* unknown unicast 0 from uplink1 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 1;
 	ng_send_data("u1", &msg4, sizeof(msg4));
 	ng_handle_events(50, &r);
 	ATF_CHECK(r[0] == 0 && r[1] == 0 && r[2] == 1 && r[3] == 0);
 
 	/* unknown unicast 2 from link0 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 0;
 	msg4.eh.ether_dhost[5] = 2;
 	ng_send_data("l0", &msg4, sizeof(msg4));
@@ -425,7 +423,7 @@ ATF_TC_BODY(uplink_private, dummy)
 	ATF_CHECK(r[0] == 0 && r[1] == 1 && r[2] == 1 && r[3] == 0);
 
 	/* known unicast 0 from uplink2 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 2;
 	msg4.eh.ether_dhost[5] = 0;
 	ng_send_data("u2", &msg4, sizeof(msg4));
@@ -433,7 +431,7 @@ ATF_TC_BODY(uplink_private, dummy)
 	ATF_CHECK(r[0] == 1 && r[1] == 0 && r[2] == 0 && r[3] == 0);
 
 	/* known unicast 0 from link3 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 3;
 	msg4.eh.ether_dhost[5] = 0;
 	ng_send_data("l3", &msg4, sizeof(msg4));
@@ -441,7 +439,7 @@ ATF_TC_BODY(uplink_private, dummy)
 	ATF_CHECK(r[0] == 1 && r[1] == 0 && r[2] == 0 && r[3] == 0);
 
 	/* (un)known unicast 2 from uplink1 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 1;
 	msg4.eh.ether_dhost[5] = 2;
 	ng_send_data("u1", &msg4, sizeof(msg4));
@@ -449,14 +447,14 @@ ATF_TC_BODY(uplink_private, dummy)
 	ATF_CHECK(r[0] == 0 && r[1] == 0 && r[2] == 1 && r[3] == 0);
 
 	/* (un)known unicast 2 from link0 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 0;
 	ng_send_data("l0", &msg4, sizeof(msg4));
 	ng_handle_events(50, &r);
 	ATF_CHECK(r[0] == 0 && r[1] == 1 && r[2] == 1 && r[3] == 0);
 
 	/* unknown multicast 2 from uplink1 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 1;
 	msg4.eh.ether_dhost[0] = 0xff;
 	ng_send_data("u1", &msg4, sizeof(msg4));
@@ -464,14 +462,14 @@ ATF_TC_BODY(uplink_private, dummy)
 	ATF_CHECK(r[0] == 1 && r[1] == 0 && r[2] == 1 && r[3] == 1);
 
 	/* unknown multicast 2 from link0 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 0;
 	ng_send_data("l0", &msg4, sizeof(msg4));
 	ng_handle_events(50, &r);
 	ATF_CHECK(r[0] == 0 && r[1] == 1 && r[2] == 1 && r[3] == 1);
 
 	/* broadcast from uplink1 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 1;
 	memset(msg4.eh.ether_dhost, 0xff, sizeof(msg4.eh.ether_dhost));
 	ng_send_data("u1", &msg4, sizeof(msg4));
@@ -479,7 +477,7 @@ ATF_TC_BODY(uplink_private, dummy)
 	ATF_CHECK(r[0] == 1 && r[1] == 0 && r[2] == 1 && r[3] == 1);
 
 	/* broadcast from link0 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 0;
 	ng_send_data("l0", &msg4, sizeof(msg4));
 	ng_handle_events(50, &r);
@@ -503,7 +501,7 @@ ATF_TC_HEAD(uplink_classic, conf)
 
 ATF_TC_BODY(uplink_classic, dummy)
 {
-	int		r[4];
+	ng_counter_t	r;
 	struct gettable	rm;
 
 	ng_init();
@@ -524,14 +522,14 @@ ATF_TC_BODY(uplink_classic, dummy)
 	ng_register_data("l3", get_data3);
 
 	/* unknown unicast 0 from uplink1 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 1;
 	ng_send_data("u1", &msg4, sizeof(msg4));
 	ng_handle_events(50, &r);
 	ATF_CHECK(r[0] == 1 && r[1] == 0 && r[2] == 1 && r[3] == 1);
 
 	/* unknown unicast 2 from link0 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 0;
 	msg4.eh.ether_dhost[5] = 2;
 	ng_send_data("l0", &msg4, sizeof(msg4));
@@ -539,7 +537,7 @@ ATF_TC_BODY(uplink_classic, dummy)
 	ATF_CHECK(r[0] == 0 && r[1] == 1 && r[2] == 1 && r[3] == 1);
 
 	/* known unicast 0 from uplink2 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 2;
 	msg4.eh.ether_dhost[5] = 0;
 	ng_send_data("u2", &msg4, sizeof(msg4));
@@ -547,7 +545,7 @@ ATF_TC_BODY(uplink_classic, dummy)
 	ATF_CHECK(r[0] == 1 && r[1] == 0 && r[2] == 0 && r[3] == 0);
 
 	/* known unicast 0 from link3 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 3;
 	msg4.eh.ether_dhost[5] = 0;
 	ng_send_data("l3", &msg4, sizeof(msg4));
@@ -555,7 +553,7 @@ ATF_TC_BODY(uplink_classic, dummy)
 	ATF_CHECK(r[0] == 1 && r[1] == 0 && r[2] == 0 && r[3] == 0);
 
 	/* (un)known unicast 2 from uplink1 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 1;
 	msg4.eh.ether_dhost[5] = 2;
 	ng_send_data("u1", &msg4, sizeof(msg4));
@@ -563,14 +561,14 @@ ATF_TC_BODY(uplink_classic, dummy)
 	ATF_CHECK(r[0] == 1 && r[1] == 0 && r[2] == 1 && r[3] == 1);
 
 	/* (un)known unicast 2 from link0 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 0;
 	ng_send_data("l0", &msg4, sizeof(msg4));
 	ng_handle_events(50, &r);
 	ATF_CHECK(r[0] == 0 && r[1] == 1 && r[2] == 1 && r[3] == 1);
 
 	/* unknown multicast 2 from uplink1 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 1;
 	msg4.eh.ether_dhost[0] = 0xff;
 	ng_send_data("u1", &msg4, sizeof(msg4));
@@ -578,14 +576,14 @@ ATF_TC_BODY(uplink_classic, dummy)
 	ATF_CHECK(r[0] == 1 && r[1] == 0 && r[2] == 1 && r[3] == 1);
 
 	/* unknown multicast 2 from link0 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 0;
 	ng_send_data("l0", &msg4, sizeof(msg4));
 	ng_handle_events(50, &r);
 	ATF_CHECK(r[0] == 0 && r[1] == 1 && r[2] == 1 && r[3] == 1);
 
 	/* broadcast from uplink1 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 1;
 	memset(msg4.eh.ether_dhost, 0xff, sizeof(msg4.eh.ether_dhost));
 	ng_send_data("u1", &msg4, sizeof(msg4));
@@ -593,7 +591,7 @@ ATF_TC_BODY(uplink_classic, dummy)
 	ATF_CHECK(r[0] == 1 && r[1] == 0 && r[2] == 1 && r[3] == 1);
 
 	/* broadcast from link0 */
-	bzero(r, sizeof(r));
+	ng_counter_clear(r);
 	msg4.eh.ether_shost[5] = 0;
 	ng_send_data("l0", &msg4, sizeof(msg4));
 	ng_handle_events(50, &r);
@@ -622,26 +620,6 @@ ATF_TP_ADD_TCS(bridge)
 	return atf_no_error();
 }
 
-static inline void
-_get_data(void *data, size_t len, void *ctx, int i)
-{
-	int	       *cnt = ctx;
-
-	(void)data;
-	fprintf(stderr, "[%d] Got %zu bytes of data.\n", i, len);
-	cnt[i]++;
-}
-
-#define GD(x) static void			\
-get_data##x(void *data, size_t len, void *ctx) {\
-	_get_data(data, len, ctx, x);		\
-}
-
-GD(0)
-GD(1)
-GD(2)
-GD(3)
-
 static void
 get_tablesize(char const *source, struct ng_mesg *msg, void *ctx)
 {
diff --git a/tests/sys/netgraph/util.c b/tests/sys/netgraph/util.c
index 307bacfa8cc6..b25e63dfa76d 100644
--- a/tests/sys/netgraph/util.c
+++ b/tests/sys/netgraph/util.c
@@ -255,3 +255,23 @@ _ng_init(char const *file, size_t line)
 	CHECK(, 0 == NgMkSockNode(NULL, &cs, &ds));
 	NgSetDebug(3);
 }
+
+#define GD(x) void				\
+get_data##x(void *data, size_t len, void *ctx) {\
+	int	       *cnt = ctx;		\
+						\
+	(void)data;				\
+	(void)len;				\
+	cnt[x]++;				\
+}
+
+GD(0)
+GD(1)
+GD(2)
+GD(3)
+GD(4)
+GD(5)
+GD(6)
+GD(7)
+GD(8)
+GD(9)
diff --git a/tests/sys/netgraph/util.h b/tests/sys/netgraph/util.h
index 21ecc68459ea..44c9f3a360a7 100644
--- a/tests/sys/netgraph/util.h
+++ b/tests/sys/netgraph/util.h
@@ -95,3 +95,20 @@ ng_error_t	ng_errors(ng_error_t);
 void		_ng_init(char const *file, size_t line);
 #define ng_init()	\
    _ng_init(__FILE__,__LINE__)
+
+/* Helper function to count received data */
+
+typedef int ng_counter_t[10];
+#define ng_counter_clear(x)\
+   bzero((x), sizeof(x))
+
+void		get_data0(void *data, size_t len, void *ctx);
+void		get_data1(void *data, size_t len, void *ctx);
+void		get_data2(void *data, size_t len, void *ctx);
+void		get_data3(void *data, size_t len, void *ctx);
+void		get_data4(void *data, size_t len, void *ctx);
+void		get_data5(void *data, size_t len, void *ctx);
+void		get_data6(void *data, size_t len, void *ctx);
+void		get_data7(void *data, size_t len, void *ctx);
+void		get_data8(void *data, size_t len, void *ctx);
+void		get_data9(void *data, size_t len, void *ctx);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202106091134.159BY4e4074092>