From: JingPiao Chen Date: Sat, 9 Sep 2017 01:30:01 +0000 (+0800) Subject: tests: extend TEST_NESTED_NLATTR_OBJECT macro X-Git-Tag: v4.20~71 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b20432b3238dacc2a8998ae988869cdb439f04d;p=strace 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_. --- diff --git a/tests/test_nlattr.h b/tests/test_nlattr.h index aff32dd5..43f467ff 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_)\