diff options
Diffstat (limited to 'tests-mx32/test_nlattr.h')
-rw-r--r-- | tests-mx32/test_nlattr.h | 103 |
1 files changed, 95 insertions, 8 deletions
diff --git a/tests-mx32/test_nlattr.h b/tests-mx32/test_nlattr.h index 048d54758..43f467ffb 100644 --- a/tests-mx32/test_nlattr.h +++ b/tests-mx32/test_nlattr.h @@ -203,14 +203,75 @@ 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 * depth_, \ + (hdrlen_) + NLA_HDRLEN * depth_, \ + (init_msg_), (print_msg_), \ + (nla_type_), (nla_type_str_), \ + plen, (pattern_), plen, \ + print_quoted_hex((pattern_), plen); \ + size_t i; \ + for (i = 0; i < depth_; ++i) \ + printf("}")); \ + /* short read of sizeof(obj_) */ \ + TEST_NLATTR_((fd_), (nlh0_) - NLA_HDRLEN * depth_, \ + (hdrlen_) + NLA_HDRLEN * depth_, \ + (init_msg_), (print_msg_), \ + (nla_type_), (nla_type_str_), \ + sizeof(obj_), \ + (pattern_), sizeof(obj_) - 1, \ + 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 * depth_, \ + (hdrlen_) + NLA_HDRLEN * depth_, \ + (init_msg_), (print_msg_), \ + (nla_type_), (nla_type_str_), \ + sizeof(obj_), \ + &(obj_), sizeof(obj_), \ + __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_)\ + do { \ + const unsigned int plen = \ + sizeof((obj_)[0]) - 1 > DEFAULT_STRLEN \ + ? DEFAULT_STRLEN : (int) sizeof((obj_)[0]) - 1; \ + /* len < sizeof((obj_)[0]) */ \ TEST_NLATTR_((fd_), (nlh0_) - NLA_HDRLEN, \ (hdrlen_) + NLA_HDRLEN, \ (init_msg_), (print_msg_), \ @@ -218,15 +279,36 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type) plen, (pattern_), plen, \ print_quoted_hex((pattern_), plen); \ printf("}")); \ + /* sizeof((obj_)[0]) < len < sizeof(obj_) */ \ + TEST_NLATTR_((fd_), (nlh0_) - NLA_HDRLEN, \ + (hdrlen_) + NLA_HDRLEN, \ + (init_msg_), (print_msg_), \ + (nla_type_), #nla_type_, \ + sizeof(obj_) - 1, \ + &(obj_), sizeof(obj_) - 1, \ + printf("["); \ + size_t i; \ + for (i = 0; i < ARRAY_SIZE(obj_) - 1; ++i) { \ + if (i) printf(", "); \ + (print_elem_)(&(obj_)[i]); \ + } \ + printf("]}")); \ /* short read of sizeof(obj_) */ \ TEST_NLATTR_((fd_), (nlh0_) - NLA_HDRLEN, \ (hdrlen_) + NLA_HDRLEN, \ (init_msg_), (print_msg_), \ (nla_type_), #nla_type_, \ sizeof(obj_), \ - (pattern_), sizeof(obj_) - 1, \ - printf("%p}", \ - RTA_DATA(TEST_NLATTR_nla))); \ + &(obj_), sizeof(obj_) - 1, \ + printf("["); \ + size_t i; \ + for (i = 0; i < ARRAY_SIZE(obj_) - 1; ++i) { \ + if (i) printf(", "); \ + (print_elem_)(&(obj_)[i]); \ + } \ + printf(", %p]}", \ + RTA_DATA(TEST_NLATTR_nla) \ + + sizeof((obj_)[0]))); \ /* sizeof(obj_) */ \ TEST_NLATTR_((fd_), (nlh0_) - NLA_HDRLEN, \ (hdrlen_) + NLA_HDRLEN, \ @@ -234,6 +316,11 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type) (nla_type_), #nla_type_, \ sizeof(obj_), \ &(obj_), sizeof(obj_), \ - __VA_ARGS__, \ - printf("}")); \ + printf("["); \ + size_t i; \ + for (i = 0; i < ARRAY_SIZE(obj_); ++i) { \ + if (i) printf(", "); \ + (print_elem_)(&(obj_)[i]); \ + } \ + printf("]}")); \ } while (0) |