[PATCH v2 2/4] tests: extend TEST_NESTED_NLATTR_OBJECT macro

JingPiao Chen chenjingpiao at gmail.com
Tue Sep 12 14:54:59 UTC 2017


Extend TEST_NESTED_NLATTR_OBJECT macro for multi-nested netlink attribute.
Such as:
[MDBA_MDB] = {
	[MDBA_MDB_ENTRY] = {
		[MDBA_MDB_ENTRY_INFO] {
			struct br_mdb_entry
			[MDBA_MDB_EATTR attributes]
		}
	}
}

* tests/test_nlattr.h (TEST_NESTED_NLATTR_OBJECT_EX_,
TEST_NESTED_NLATTR_OBJECT_EX): New macros.
(TEST_NESTED_NLATTR_OBJECT): Use TEST_NESTED_NLATTR_OBJECT_EX_.
---
 tests/test_nlattr.h | 60 ++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 43 insertions(+), 17 deletions(-)

diff --git a/tests/test_nlattr.h b/tests/test_nlattr.h
index aff32dd..43f467f 100644
--- a/tests/test_nlattr.h
+++ b/tests/test_nlattr.h
@@ -203,41 +203,67 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
 			printf("]"));					\
 	} while (0)
 
-#define TEST_NESTED_NLATTR_OBJECT(fd_, nlh0_, hdrlen_,			\
-				  init_msg_, print_msg_,		\
-				  nla_type_, pattern_, obj_, ...)	\
+#define TEST_NESTED_NLATTR_OBJECT_EX_(fd_, nlh0_, hdrlen_,		\
+				      init_msg_, print_msg_,		\
+				      nla_type_, nla_type_str_,		\
+				      pattern_, obj_, depth_, ...)	\
 	do {								\
 		const unsigned int plen =				\
 			sizeof(obj_) - 1 > DEFAULT_STRLEN		\
 			? DEFAULT_STRLEN : (int) sizeof(obj_) - 1;	\
 		/* len < sizeof(obj_) */				\
-		TEST_NLATTR_((fd_), (nlh0_) - NLA_HDRLEN,		\
-			(hdrlen_) + NLA_HDRLEN,				\
+		TEST_NLATTR_((fd_), (nlh0_) - NLA_HDRLEN * depth_,	\
+			(hdrlen_) + NLA_HDRLEN * depth_,		\
 			(init_msg_), (print_msg_),			\
-			(nla_type_), #nla_type_,			\
+			(nla_type_), (nla_type_str_),			\
 			plen, (pattern_), plen,				\
 			print_quoted_hex((pattern_), plen);		\
-			printf("}"));					\
+			size_t i;					\
+			for (i = 0; i < depth_; ++i)			\
+				printf("}"));				\
 		/* short read of sizeof(obj_) */			\
-		TEST_NLATTR_((fd_), (nlh0_) - NLA_HDRLEN,		\
-			(hdrlen_) + NLA_HDRLEN,				\
+		TEST_NLATTR_((fd_), (nlh0_) - NLA_HDRLEN * depth_,	\
+			(hdrlen_) + NLA_HDRLEN * depth_,		\
 			(init_msg_), (print_msg_),			\
-			(nla_type_), #nla_type_,			\
+			(nla_type_), (nla_type_str_),			\
 			sizeof(obj_),					\
 			(pattern_), sizeof(obj_) - 1,			\
-			printf("%p}",					\
-			       RTA_DATA(TEST_NLATTR_nla)));		\
+			printf("%p", RTA_DATA(TEST_NLATTR_nla));	\
+			size_t i;					\
+			for (i = 0; i < depth_; ++i)			\
+				printf("}"));				\
 		/* sizeof(obj_) */					\
-		TEST_NLATTR_((fd_), (nlh0_) - NLA_HDRLEN,		\
-			(hdrlen_) + NLA_HDRLEN,				\
+		TEST_NLATTR_((fd_), (nlh0_) - NLA_HDRLEN * depth_,	\
+			(hdrlen_) + NLA_HDRLEN * depth_,		\
 			(init_msg_), (print_msg_),			\
-			(nla_type_), #nla_type_,			\
+			(nla_type_), (nla_type_str_),			\
 			sizeof(obj_),					\
 			&(obj_), sizeof(obj_),				\
-			__VA_ARGS__,					\
-			printf("}"));					\
+			__VA_ARGS__;					\
+			size_t i;					\
+			for (i = 0; i < depth_; ++i)			\
+				printf("}"));				\
 	} while (0)
 
+#define TEST_NESTED_NLATTR_OBJECT_EX(fd_, nlh0_, hdrlen_,		\
+				     init_msg_, print_msg_,		\
+				     nla_type_, pattern_, obj_,		\
+				     depth_, ...)			\
+	TEST_NESTED_NLATTR_OBJECT_EX_((fd_), (nlh0_), (hdrlen_),	\
+				      (init_msg_), (print_msg_),	\
+				      (nla_type_), #nla_type_,		\
+				      (pattern_), (obj_), (depth_),	\
+				      __VA_ARGS__)
+
+#define TEST_NESTED_NLATTR_OBJECT(fd_, nlh0_, hdrlen_,			\
+				  init_msg_, print_msg_,		\
+				  nla_type_, pattern_, obj_, ...)	\
+	TEST_NESTED_NLATTR_OBJECT_EX_((fd_), (nlh0_), (hdrlen_),	\
+				      (init_msg_), (print_msg_),	\
+				      (nla_type_), #nla_type_,		\
+				      (pattern_), (obj_), 1,		\
+				      __VA_ARGS__)
+
 #define TEST_NESTED_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