]> granicus.if.org Git - strace/commitdiff
tests: extend TEST_NESTED_NLATTR_OBJECT macro
authorJingPiao Chen <chenjingpiao@gmail.com>
Sat, 9 Sep 2017 01:30:01 +0000 (09:30 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 17 Sep 2017 12:04:11 +0000 (12:04 +0000)
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_.

tests/test_nlattr.h

index aff32dd5e376e9b296e66393788f1072f146cea5..43f467ffb6d8e75db165565c2ecf4fc57065bad5 100644 (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_)\