]> granicus.if.org Git - strace/commitdiff
tests/test_nlattr.h: add ability to provide additional nlattr payload
authorEugene Syromyatnikov <evgsyr@gmail.com>
Sun, 10 Jun 2018 10:46:19 +0000 (12:46 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 11 Jun 2018 14:02:06 +0000 (14:02 +0000)
* tests/test_nlattr.h (print_nlattr): Add add_data argument, print
opening square bracket if add_data is set to true.
(TEST_NLATTR_EX_): Rename from TEST_NLATTR_, add nla_total_len_
argument, use it for msg_len calculation, print square brackets
if nla_total_len_ is greater than nla_data_len_.
(TEST_NLATTR_): New macro, a wrapper for TEST_NLATTR_EX_.

tests/test_nlattr.h

index 6c3f63acc97e18993956660541283f6c21eced29..f5ee8cbd2c9bcb738b4ae35233ae74558ec6c5c5 100644 (file)
@@ -51,15 +51,17 @@ init_nlattr(struct nlattr *const nla,
 }
 
 static void
-print_nlattr(const unsigned int nla_len, const char *const nla_type)
+print_nlattr(const unsigned int nla_len, const char *const nla_type, bool add_data)
 {
-       printf(", {{nla_len=%u, nla_type=%s}, ", nla_len, nla_type);
+       printf(", %s{{nla_len=%u, nla_type=%s}, ",
+              add_data ? "[" : "", nla_len, nla_type);
 }
 
-#define TEST_NLATTR_(fd_, nlh0_, hdrlen_,                              \
+#define TEST_NLATTR_EX_(fd_, nlh0_, hdrlen_,                           \
                     init_msg_, print_msg_,                             \
                     nla_type_, nla_type_str_,                          \
-                    nla_data_len_, src_, slen_, ...)                   \
+                    nla_data_len_, nla_total_len_,                     \
+                    src_, slen_, ...)                                  \
        do {                                                            \
                struct nlmsghdr *const nlh =                            \
                        (nlh0_) - (NLA_HDRLEN + (slen_));               \
@@ -68,7 +70,7 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
                const unsigned int nla_len =                            \
                        NLA_HDRLEN + (nla_data_len_);                   \
                const unsigned int msg_len =                            \
-                       NLMSG_SPACE(hdrlen_) + nla_len;                 \
+                       NLMSG_SPACE(hdrlen_) + NLA_HDRLEN + (nla_total_len_); \
                                                                        \
                (init_msg_)(nlh, msg_len);                              \
                init_nlattr(TEST_NLATTR_nla, nla_len, (nla_type_),      \
@@ -80,14 +82,28 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
                                                                        \
                printf("sendto(%d, {", (fd_));                          \
                (print_msg_)(msg_len);                                  \
-               print_nlattr(nla_len, (nla_type_str_));                 \
+               print_nlattr(nla_len, (nla_type_str_),                  \
+                            (nla_total_len_) > (nla_data_len_));       \
                                                                        \
                { __VA_ARGS__; }                                        \
                                                                        \
+               if ((nla_total_len_) > (nla_data_len_))                 \
+                       printf("]");                                    \
+                                                                       \
                printf("}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",         \
                       msg_len, errstr);                                \
        } while (0)
 
+#define TEST_NLATTR_(fd_, nlh0_, hdrlen_,                              \
+                    init_msg_, print_msg_,                             \
+                    nla_type_, nla_type_str_,                          \
+                    nla_data_len_, src_, slen_, ...)                   \
+       TEST_NLATTR_EX_((fd_), (nlh0_), (hdrlen_),                      \
+                       (init_msg_), (print_msg_),                      \
+                       (nla_type_), (nla_type_str_),                   \
+                       (nla_data_len_), (nla_data_len_),               \
+                       (src_), (slen_), __VA_ARGS__)
+
 #define TEST_NLATTR(fd_, nlh0_, hdrlen_,                               \
                    init_msg_, print_msg_,                              \
                    nla_type_,                                          \