[PATCH v2 5/6] tests: extend TEST_NLATTR_OBJECT macro

JingPiao Chen chenjingpiao at gmail.com
Sun Jul 23 12:00:32 UTC 2017


* tests/test_nlattr.h (TEST_NLATTR_OBJECT_EX_,
TEST_NLATTR_OBJECT_EX): New macros.
(TEST_NLATTR_OBJECT): Use TEST_NLATTR_OBJECT_EX_.
---
 tests/test_nlattr.h | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/tests/test_nlattr.h b/tests/test_nlattr.h
index 4585893..5df9b92 100644
--- a/tests/test_nlattr.h
+++ b/tests/test_nlattr.h
@@ -96,9 +96,10 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
 		(nla_type_), #nla_type_,				\
 		(nla_data_len_), (src_), (slen_), __VA_ARGS__)
 
-#define TEST_NLATTR_OBJECT(fd_, nlh0_, hdrlen_,				\
-			   init_msg_, print_msg_,			\
-			   nla_type_, pattern_, obj_, ...)		\
+#define TEST_NLATTR_OBJECT_EX_(fd_, nlh0_, hdrlen_,			\
+			       init_msg_, print_msg_,			\
+			       nla_type_, nla_type_str_,		\
+			       pattern_, obj_, fallback_func, ...)	\
 	do {								\
 		const unsigned int plen =				\
 			sizeof(obj_) - 1 > DEFAULT_STRLEN		\
@@ -106,13 +107,13 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
 		/* len < sizeof(obj_) */				\
 		TEST_NLATTR_((fd_), (nlh0_), (hdrlen_),			\
 			(init_msg_), (print_msg_),			\
-			(nla_type_), #nla_type_,			\
+			(nla_type_), (nla_type_str_),			\
 			plen, (pattern_), plen,				\
-			print_quoted_hex((pattern_), plen));		\
+			fallback_func((pattern_), plen));		\
 		/* short read of sizeof(obj_) */			\
 		TEST_NLATTR_((fd_), (nlh0_), (hdrlen_),			\
 			(init_msg_), (print_msg_),			\
-			(nla_type_), #nla_type_,			\
+			(nla_type_), (nla_type_str_),			\
 			sizeof(obj_),					\
 			(pattern_), sizeof(obj_) - 1,			\
 			printf("%p",					\
@@ -120,12 +121,31 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
 		/* sizeof(obj_) */					\
 		TEST_NLATTR_((fd_), (nlh0_), (hdrlen_),			\
 			(init_msg_), (print_msg_),			\
-			(nla_type_), #nla_type_,			\
+			(nla_type_), (nla_type_str_),			\
 			sizeof(obj_),					\
 			&(obj_), sizeof(obj_),				\
 			__VA_ARGS__);					\
 	} while (0)
 
+#define TEST_NLATTR_OBJECT_EX(fd_, nlh0_, hdrlen_,			\
+			      init_msg_, print_msg_,			\
+			      nla_type_,				\
+			      pattern_, obj_, fallback_func, ...)	\
+	TEST_NLATTR_OBJECT_EX_((fd_), (nlh0_), (hdrlen_),		\
+			       (init_msg_), (print_msg_),		\
+			       (nla_type_), #nla_type_,			\
+			       (pattern_), (obj_), (fallback_func),	\
+			       __VA_ARGS__)
+
+#define TEST_NLATTR_OBJECT(fd_, nlh0_, hdrlen_,				\
+			   init_msg_, print_msg_,			\
+			   nla_type_, pattern_, obj_, ...)		\
+	TEST_NLATTR_OBJECT_EX_((fd_), (nlh0_), (hdrlen_),		\
+			       (init_msg_), (print_msg_),		\
+			       (nla_type_), #nla_type_,			\
+			       (pattern_), (obj_), print_quoted_hex,	\
+			       __VA_ARGS__)
+
 #define TEST_NLATTR_ARRAY(fd_, nlh0_, hdrlen_,				\
 			  init_msg_, print_msg_,			\
 			  nla_type_, pattern_, obj_, print_elem_)	\
-- 
2.7.4





More information about the Strace-devel mailing list