From owner-dev-commits-src-all@freebsd.org Tue Jun 8 17:25:03 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id CC13A63B808; Tue, 8 Jun 2021 17:25:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FzxvM5Sf1z3sjD; Tue, 8 Jun 2021 17:25:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9EBBA4ED9; Tue, 8 Jun 2021 17:25:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 158HP3rF025820; Tue, 8 Jun 2021 17:25:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 158HP33p025819; Tue, 8 Jun 2021 17:25:03 GMT (envelope-from git) Date: Tue, 8 Jun 2021 17:25:03 GMT Message-Id: <202106081725.158HP33p025819@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Lutz Donnerhacke Subject: git: 9021c46603bf - main - tests/netgraph: Attribute errors to the caller MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: donner X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9021c46603bf29b9700f24b8dce8796b434d7c8f Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Jun 2021 17:25:03 -0000 The branch main has been updated by donner: URL: https://cgit.FreeBSD.org/src/commit/?id=9021c46603bf29b9700f24b8dce8796b434d7c8f commit 9021c46603bf29b9700f24b8dce8796b434d7c8f Author: Lutz Donnerhacke AuthorDate: 2021-06-08 17:19:35 +0000 Commit: Lutz Donnerhacke 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 -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__)