tests: add TEST_NESTED_NLATTR_ARRAY_EX to test_nlattr.h
An ability to specify custom depth is going to be needed later to check IFLA_AF_SPEC decoding. * configure.ac (AC_CHECK_DECLS): Check for TCA_STAB_DATA in <linux/pkt_sched.h>. * tests/test_nlattr.h (TEST_NESTED_NLATTR_ARRAY_EX): Rename from TEST_NESTED_NLATTR_ARRAY, add depth_ argument, perform padding and output accordingly. (TEST_NESTED_NLATTR_ARRAY): New macro, a thin wrapper around TEST_NESTED_NLATTR_ARRAY_EX. * tests/nlattr_tca_stab.c [!HAVE_DECL_TCA_STAB_DATA] (TCA_STAB_DATA): New enumeration declaration. Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
This commit is contained in:
parent
ce3bddf6c4
commit
6229d93cb2
@ -531,6 +531,8 @@ AC_CHECK_TYPES(m4_normalize([
|
||||
]),,, [#include <linux/gen_stats.h>])
|
||||
|
||||
AC_CHECK_TYPES([struct tc_sizespec],,, [#include <linux/pkt_sched.h>])
|
||||
AC_CHECK_DECLS([TCA_STAB_DATA],,, [#include <linux/types.h>
|
||||
#include <linux/pkt_sched.h>])
|
||||
|
||||
AC_CHECK_TYPES(m4_normalize([
|
||||
struct fib_rule_uid_range,
|
||||
|
@ -36,8 +36,8 @@
|
||||
#ifndef TCA_STAB
|
||||
# define TCA_STAB 8
|
||||
#endif
|
||||
#ifndef TCA_STAB_DATA
|
||||
# define TCA_STAB_DATA 2
|
||||
#if !HAVE_DECL_TCA_STAB_DATA
|
||||
enum { TCA_STAB_DATA = 2 };
|
||||
#endif
|
||||
|
||||
const unsigned int hdrlen = sizeof(struct tcmsg);
|
||||
|
@ -266,24 +266,26 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
|
||||
(pattern_), (obj_), 1, \
|
||||
__VA_ARGS__)
|
||||
|
||||
#define TEST_NESTED_NLATTR_ARRAY(fd_, nlh0_, hdrlen_, \
|
||||
#define TEST_NESTED_NLATTR_ARRAY_EX(fd_, nlh0_, hdrlen_, \
|
||||
init_msg_, print_msg_, \
|
||||
nla_type_, pattern_, obj_, print_elem_)\
|
||||
nla_type_, pattern_, obj_, depth_, \
|
||||
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, \
|
||||
TEST_NLATTR_((fd_), (nlh0_) - NLA_HDRLEN * depth_, \
|
||||
(hdrlen_) + NLA_HDRLEN * depth_, \
|
||||
(init_msg_), (print_msg_), \
|
||||
(nla_type_), #nla_type_, \
|
||||
plen, (pattern_), plen, \
|
||||
print_quoted_hex((pattern_), plen); \
|
||||
printf("}")); \
|
||||
for (size_t i = 0; i < depth_; ++i) \
|
||||
printf("}")); \
|
||||
/* sizeof((obj_)[0]) < 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_, \
|
||||
sizeof(obj_) - 1, \
|
||||
@ -294,10 +296,12 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
|
||||
if (i) printf(", "); \
|
||||
(print_elem_)(&(obj_)[i], i); \
|
||||
} \
|
||||
printf("]}")); \
|
||||
printf("]"); \
|
||||
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_, \
|
||||
sizeof(obj_), \
|
||||
@ -308,12 +312,14 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
|
||||
if (i) printf(", "); \
|
||||
(print_elem_)(&(obj_)[i], i); \
|
||||
} \
|
||||
printf(", ... /* %p */]}", \
|
||||
printf(", ... /* %p */]", \
|
||||
RTA_DATA(TEST_NLATTR_nla) \
|
||||
+ sizeof(obj_) - sizeof((obj_)[0]))); \
|
||||
+ sizeof(obj_) - sizeof((obj_)[0])); \
|
||||
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_, \
|
||||
sizeof(obj_), \
|
||||
@ -324,5 +330,15 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
|
||||
if (i) printf(", "); \
|
||||
(print_elem_)(&(obj_)[i], i); \
|
||||
} \
|
||||
printf("]}")); \
|
||||
printf("]"); \
|
||||
for (i = 0; i < depth_; ++i) \
|
||||
printf("}")); \
|
||||
} while (0)
|
||||
|
||||
#define TEST_NESTED_NLATTR_ARRAY(fd_, nlh0_, hdrlen_, \
|
||||
init_msg_, print_msg_, \
|
||||
nla_type_, pattern_, obj_, print_elem_)\
|
||||
TEST_NESTED_NLATTR_ARRAY_EX((fd_), (nlh0_), (hdrlen_), \
|
||||
(init_msg_), (print_msg_), \
|
||||
nla_type_, (pattern_), (obj_), 1, \
|
||||
(print_elem_))
|
||||
|
Loading…
x
Reference in New Issue
Block a user