tests: extend TEST_NESTED_NLATTR_OBJECT macro

Extend TEST_NESTED_NLATTR_OBJECT macro for multi-nested netlink
attributes, 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_.
This commit is contained in:
JingPiao Chen 2017-09-09 09:30:01 +08:00 committed by Dmitry V. Levin
parent 8229db741f
commit 7b20432b32

View File

@ -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_)\