From: Dmitry V. Levin Date: Mon, 3 Jul 2017 15:14:54 +0000 (+0000) Subject: tests: adjust TEST_NLATTR_OBJECT and TEST_NLATTR_ARRAY for large objects X-Git-Tag: v4.18~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dbd060526c877e639b3a116c6f784bfcf6aed102;p=strace tests: adjust TEST_NLATTR_OBJECT and TEST_NLATTR_ARRAY for large objects * tests/test_nlattr.h (TEST_NLATTR_OBJECT, TEST_NLATTR_ARRAY): Add support for objects larger than DEFAULT_STRLEN. * tests/nlattr_inet_diag_msg.c (main): Change pattern size from DEFAULT_STRLEN to 4096. * tests/nlattr_netlink_diag_msg.c: Likewise. * tests/nlattr_unix_diag_msg.c: Likewise. Reported-by: JingPiao Chen --- diff --git a/tests/nlattr_inet_diag_msg.c b/tests/nlattr_inet_diag_msg.c index 306b8665..d9d564c3 100644 --- a/tests/nlattr_inet_diag_msg.c +++ b/tests/nlattr_inet_diag_msg.c @@ -96,7 +96,7 @@ main(void) const unsigned int hdrlen = sizeof(struct inet_diag_msg); void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); - static char pattern[DEFAULT_STRLEN]; + static char pattern[4096]; fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); static const struct inet_diag_meminfo minfo = { diff --git a/tests/nlattr_netlink_diag_msg.c b/tests/nlattr_netlink_diag_msg.c index 37e3a012..76a2d19e 100644 --- a/tests/nlattr_netlink_diag_msg.c +++ b/tests/nlattr_netlink_diag_msg.c @@ -80,7 +80,7 @@ main(void) const unsigned int hdrlen = sizeof(struct netlink_diag_msg); void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); - static char pattern[DEFAULT_STRLEN]; + static char pattern[4096]; fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); static const unsigned long groups[] = { diff --git a/tests/nlattr_unix_diag_msg.c b/tests/nlattr_unix_diag_msg.c index a11328b1..22954042 100644 --- a/tests/nlattr_unix_diag_msg.c +++ b/tests/nlattr_unix_diag_msg.c @@ -79,7 +79,7 @@ main(void) const unsigned int hdrlen = sizeof(struct unix_diag_msg); void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); - static char pattern[DEFAULT_STRLEN]; + static char pattern[4096]; fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); static const struct unix_diag_vfs uv = { diff --git a/tests/test_nlattr.h b/tests/test_nlattr.h index 097e637f..8cbb2115 100644 --- a/tests/test_nlattr.h +++ b/tests/test_nlattr.h @@ -99,14 +99,15 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type) init_msg_, print_msg_, \ nla_type_, pattern_, obj_, ...) \ do { \ + const int plen = sizeof(obj_) - 1 > DEFAULT_STRLEN \ + ? DEFAULT_STRLEN : (int) sizeof(obj_) - 1; \ /* len < sizeof(obj_) */ \ TEST_NLATTR_((fd_), (nlh0_), (hdrlen_), \ (init_msg_), (print_msg_), \ (nla_type_), #nla_type_, \ sizeof(obj_) - 1, \ (pattern_), sizeof(obj_) - 1, \ - printf("\"%.*s\"", \ - (int) sizeof(obj_) - 1, (pattern_))); \ + printf("\"%.*s\"", plen, (pattern_))); \ /* short read of sizeof(obj_) */ \ TEST_NLATTR_((fd_), (nlh0_), (hdrlen_), \ (init_msg_), (print_msg_), \ @@ -128,15 +129,16 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type) init_msg_, print_msg_, \ nla_type_, pattern_, obj_, print_elem_) \ do { \ + const int plen = \ + sizeof((obj_)[0]) - 1 > DEFAULT_STRLEN \ + ? DEFAULT_STRLEN : (int) sizeof((obj_)[0]) - 1; \ /* len < sizeof((obj_)[0]) */ \ TEST_NLATTR_((fd_), (nlh0_), (hdrlen_), \ (init_msg_), (print_msg_), \ (nla_type_), #nla_type_, \ sizeof((obj_)[0]) - 1, \ (pattern_), sizeof((obj_)[0]) - 1, \ - printf("\"%.*s\"", \ - (int) sizeof((obj_)[0]) - 1, \ - (pattern_))); \ + printf("\"%.*s\"", plen, (pattern_))); \ /* sizeof((obj_)[0]) < len < sizeof(obj_) */ \ TEST_NLATTR_((fd_), (nlh0_), (hdrlen_), \ (init_msg_), (print_msg_), \