Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Jun 2021 17:25:03 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: 9021c46603bf - main - tests/netgraph: Attribute errors to the caller
Message-ID:  <202106081725.158HP33p025819@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=9021c46603bf29b9700f24b8dce8796b434d7c8f

commit 9021c46603bf29b9700f24b8dce8796b434d7c8f
Author:     Lutz Donnerhacke <donner@FreeBSD.org>
AuthorDate: 2021-06-08 17:19:35 +0000
Commit:     Lutz Donnerhacke <donner@FreeBSD.org>
CommitDate: 2021-06-08 17:23:50 +0000

    tests/netgraph: Attribute errors to the caller
    
    Errors raised in the common util functions should raise the location
    of their caller to be useful and include the errno description.
    
    Reviewed by:    kp
    MFC after:      1 week
    Differential Revision: https://reviews.freebsd.org/D30671
---
 tests/sys/netgraph/util.c | 43 +++++++++++++++++++++++++-----------------
 tests/sys/netgraph/util.h | 48 +++++++++++++++++++++++++++++++++++++----------
 2 files changed, 64 insertions(+), 27 deletions(-)

diff --git a/tests/sys/netgraph/util.c b/tests/sys/netgraph/util.c
index 450a176971a7..dbf62599aa04 100644
--- a/tests/sys/netgraph/util.c
+++ b/tests/sys/netgraph/util.c
@@ -45,11 +45,13 @@
 static int cs = -1, ds = -1;
 static ng_error_t error_handling = FAIL;
 
-#define CHECK(r, x)	do {		\
-	if (error_handling == FAIL)	\
-	    ATF_REQUIRE(x);		\
-	else if(!(x))			\
-	    return r;			\
+#define CHECK(r, x)	do {			\
+	if (!(x)) {				\
+		if (error_handling == PASS)	\
+		    return r;			\
+		atf_tc_fail_requirement(file, line, "%s (%s)", \
+		    #x " not met", strerror(errno));\
+	}					\
 } while(0)
 
 struct data_handler {
@@ -64,8 +66,9 @@ static void handle_data(void *ctx);
 static void handle_msg(void *ctx);
 
 void
-ng_connect(char const *path1, char const *hook1,
-	   char const *path2, char const *hook2)
+_ng_connect(char const *path1, char const *hook1,
+	    char const *path2, char const *hook2,
+	    char const *file, size_t line)
 {
 	struct ngm_connect c;
 
@@ -79,8 +82,9 @@ ng_connect(char const *path1, char const *hook1,
 }
 
 void
-ng_mkpeer(char const *path1, char const *hook1,
-	  char const *type,  char const *hook2)
+_ng_mkpeer(char const *path1, char const *hook1,
+	   char const *type,  char const *hook2,
+	   char const *file, size_t line)
 {
 	struct ngm_mkpeer p;
 
@@ -94,7 +98,8 @@ ng_mkpeer(char const *path1, char const *hook1,
 }
 
 void
-ng_rmhook(char const *path, char const *hook)
+_ng_rmhook(char const *path, char const *hook,
+	   char const *file, size_t line)
 {
 	struct ngm_rmhook h;
 
@@ -106,7 +111,8 @@ ng_rmhook(char const *path, char const *hook)
 }
 
 void
-ng_name(char const *path, char const *name)
+_ng_name(char const *path, char const *name,
+	 char const *file, size_t line)
 {
 	struct ngm_name n;
 
@@ -118,7 +124,8 @@ ng_name(char const *path, char const *name)
 }
 
 void
-ng_shutdown(char const *path)
+_ng_shutdown(char const *path,
+	     char const *file, size_t line)
 {
 	CHECK(, -1 != NgSendMsg(cs, path,
 	    NGM_GENERIC_COOKIE, NGM_SHUTDOWN,
@@ -137,8 +144,9 @@ ng_register_data(char const *hook, ng_data_handler_t proc)
 }
 
 void
-ng_send_data(char const *hook,
-	     void const *data, size_t len)
+_ng_send_data(char const *hook,
+	      void const *data, size_t len,
+	      char const *file, size_t line)
 {
 	CHECK(, -1 != NgSendData(ds, hook, data, len));
 }
@@ -213,7 +221,8 @@ ng_handle_events(unsigned int ms, void *context)
 }
 
 int
-ng_send_msg(char const *path, char const *msg)
+_ng_send_msg(char const *path, char const *msg,
+	     char const *file, size_t line)
 {
 	int res;
 
@@ -231,10 +240,10 @@ ng_errors(ng_error_t n)
 }
 
 void
-ng_init(void) {
+_ng_init(char const *file, size_t line) {
 	if (cs >= 0)		       /* prevent reinit */
 		return;
 
-	ATF_REQUIRE(0 == NgMkSockNode(NULL, &cs, &ds));
+	CHECK(, 0 == NgMkSockNode(NULL, &cs, &ds));
 	NgSetDebug(3);
 }
diff --git a/tests/sys/netgraph/util.h b/tests/sys/netgraph/util.h
index 93ddc91f79bc..41243e15fb10 100644
--- a/tests/sys/netgraph/util.h
+++ b/tests/sys/netgraph/util.h
@@ -34,21 +34,47 @@
 
 #include <netgraph.h>
 
-void ng_connect (char const *path1, char const *hook1,
-		 char const *path2, char const *hook2);
-void ng_mkpeer  (char const *path1, char const *hook1,
-		 char const *type,  char const *hook2);
-void ng_shutdown(char const *path);
-void ng_rmhook  (char const *path,  char const *hook);
-void ng_name    (char const *path,  char const *name);
+void _ng_connect (char const *path1, char const *hook1,
+		  char const *path2, char const *hook2,
+		  char const *file,  size_t line);
+#define ng_connect(p1,h1,p2,h2)	\
+   _ng_connect(p1,h1,p2,h2,__FILE__,__LINE__)
+
+void _ng_mkpeer  (char const *path1, char const *hook1,
+		  char const *type,  char const *hook2,
+		  char const *file,  size_t line);
+#define ng_mkpeer(p1,h1,t,h2)	\
+   _ng_mkpeer(p1,h1,t,h2,__FILE__,__LINE__)
+
+void _ng_shutdown(char const *path,
+		  char const *file,  size_t line);
+#define ng_shutdown(p)	\
+   _ng_shutdown(p,__FILE__,__LINE__)
+
+void _ng_rmhook  (char const *path,  char const *hook,
+		  char const *file,  size_t line);
+#define ng_rmhook(p,h)	\
+   _ng_rmhook(p,h,__FILE__,__LINE__)
+
+void _ng_name    (char const *path,  char const *name,
+		  char const *file,  size_t line);
+#define ng_name(p,n)	\
+   _ng_name(p,n,__FILE__,__LINE__)
+
 
 typedef void (*ng_data_handler_t)(void *, size_t, void *ctx);
 void ng_register_data(char const *hook, ng_data_handler_t proc);
-void ng_send_data(char const *hook, void const *, size_t);
+void _ng_send_data(char const *hook, void const *, size_t,
+		   char const *file,  size_t line);
+#define ng_send_data(h,d,l)	\
+   _ng_send_data(h,d,l,__FILE__,__LINE__)
 
 typedef void (*ng_msg_handler_t)(char const *, struct ng_mesg *, void *);
 void ng_register_msg(ng_msg_handler_t proc);
-int  ng_send_msg(char const *path, char const *msg);
+int  _ng_send_msg(char const *path, char const *msg,
+		  char const *file,  size_t line);
+#define ng_send_msg(p,m)	\
+   _ng_send_msg(p,m,__FILE__,__LINE__)
 
 int  ng_handle_event (unsigned int ms, void *ctx);
 void ng_handle_events(unsigned int ms, void *ctx);
@@ -56,4 +82,6 @@ void ng_handle_events(unsigned int ms, void *ctx);
 typedef enum { FAIL, PASS } ng_error_t;
 ng_error_t ng_errors(ng_error_t);
 
-void ng_init(void);
+void _ng_init(char const *file,  size_t line);
+#define ng_init()	\
+   _ng_init(__FILE__,__LINE__)



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