From 005c67a900e69fc016d62ce15da346b0def48f64 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Mon, 3 Jul 2017 15:14:54 +0000 Subject: [PATCH] tests: move DEFAULT_STRLEN macro to tests.h * tests/tests.h [!DEFAULT_STRLEN] (DEFAULT_STRLEN): New macro. * tests/mincore.c (DEFAULT_STRLEN): Remove. * tests/mmsg_name.c: Likewise. * tests/msg_control.c: Likewise. * tests/netlink_protocol.c: Likewise. * tests/nlattr.c: Likewise. * tests/nlattr_inet_diag_msg.c: Likewise. * tests/nlattr_netlink_diag_msg.c: Likewise. * tests/nlattr_unix_diag_msg.c: Likewise. * tests/printstr.c: Likewise. * tests/xattr.c: Likewise. * tests/execve.c: Likewise. (main): Initialize str_a and str_b arrays at run time. * tests/execveat.c: Likewise. Suggested-by: JingPiao Chen --- tests/execve.c | 11 ++++++++--- tests/execveat.c | 11 ++++++++--- tests/mincore.c | 2 -- tests/mmsg_name.c | 2 -- tests/msg_control.c | 2 -- tests/netlink_protocol.c | 1 - tests/nlattr.c | 1 - tests/nlattr_inet_diag_msg.c | 1 - tests/nlattr_netlink_diag_msg.c | 1 - tests/nlattr_unix_diag_msg.c | 1 - tests/printstr.c | 2 -- tests/tests.h | 5 +++++ tests/xattr.c | 2 -- 13 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/execve.c b/tests/execve.c index c558dd3b..da3bc520 100644 --- a/tests/execve.c +++ b/tests/execve.c @@ -127,9 +127,14 @@ main(void) #endif ); - char str_a[] = "012345678901234567890123456789012"; - char str_b[] = "_abcdefghijklmnopqrstuvwxyz()[]{}"; -#define DEFAULT_STRLEN ((unsigned int) sizeof(str_a) - 2) + char *const str_a = tail_alloc(DEFAULT_STRLEN + 2); + fill_memory_ex(str_a, DEFAULT_STRLEN + 1, '0', 10); + str_a[DEFAULT_STRLEN + 1] = '\0'; + + char *const str_b = tail_alloc(DEFAULT_STRLEN + 2); + fill_memory_ex(str_b, DEFAULT_STRLEN + 1, '_', 32); + str_b[DEFAULT_STRLEN + 1] = '\0'; + char **const a = tail_alloc(sizeof(*a) * (DEFAULT_STRLEN + 2)); char **const b = tail_alloc(sizeof(*b) * (DEFAULT_STRLEN + 2)); unsigned int i; diff --git a/tests/execveat.c b/tests/execveat.c index 8ffc4d58..566a59f9 100644 --- a/tests/execveat.c +++ b/tests/execveat.c @@ -133,9 +133,14 @@ main(void) #endif errno2name()); - char str_a[] = "012345678901234567890123456789012"; - char str_b[] = "_abcdefghijklmnopqrstuvwxyz()[]{}"; -#define DEFAULT_STRLEN ((unsigned int) sizeof(str_a) - 2) + char *const str_a = tail_alloc(DEFAULT_STRLEN + 2); + fill_memory_ex(str_a, DEFAULT_STRLEN + 1, '0', 10); + str_a[DEFAULT_STRLEN + 1] = '\0'; + + char *const str_b = tail_alloc(DEFAULT_STRLEN + 2); + fill_memory_ex(str_b, DEFAULT_STRLEN + 1, '_', 32); + str_b[DEFAULT_STRLEN + 1] = '\0'; + char **const a = tail_alloc(sizeof(*a) * (DEFAULT_STRLEN + 2)); char **const b = tail_alloc(sizeof(*b) * (DEFAULT_STRLEN + 2)); unsigned int i; diff --git a/tests/mincore.c b/tests/mincore.c index ea2b49e3..0ede687d 100644 --- a/tests/mincore.c +++ b/tests/mincore.c @@ -29,8 +29,6 @@ #include #include -#define DEFAULT_STRLEN 32 - static void print_mincore(const unsigned int pages, void *const addr, const size_t size, unsigned char *const vec) diff --git a/tests/mmsg_name.c b/tests/mmsg_name.c index ac8dcde7..ad5a482d 100644 --- a/tests/mmsg_name.c +++ b/tests/mmsg_name.c @@ -40,8 +40,6 @@ #include "msghdr.h" -#define DEFAULT_STRLEN 32 - #define IOV_MAX1 (IOV_MAX + 1) #ifndef TEST_NAME diff --git a/tests/msg_control.c b/tests/msg_control.c index 5b6b25a5..b63f2d04 100644 --- a/tests/msg_control.c +++ b/tests/msg_control.c @@ -63,8 +63,6 @@ get_cmsghdr(void *const page, const size_t len) return page - CMSG_ALIGN(len); } -#define DEFAULT_STRLEN 32 - static void print_fds(const struct cmsghdr *const cmsg, const size_t cmsg_len) { diff --git a/tests/netlink_protocol.c b/tests/netlink_protocol.c index d0479805..f09dd9a9 100644 --- a/tests/netlink_protocol.c +++ b/tests/netlink_protocol.c @@ -169,7 +169,6 @@ send_query(const int fd) (unsigned) sizeof(*reqs), sprintrc(rc)); /* abbreviated output */ -# define DEFAULT_STRLEN 32 # define ABBREV_LEN (DEFAULT_STRLEN + 1) const unsigned int msg_len = sizeof(struct nlmsghdr) * ABBREV_LEN; struct nlmsghdr *const msgs = tail_alloc(msg_len); diff --git a/tests/nlattr.c b/tests/nlattr.c index 15a0ad1f..7361eced 100644 --- a/tests/nlattr.c +++ b/tests/nlattr.c @@ -210,7 +210,6 @@ test_nlattr(const int fd) fd, msg_len, nla->nla_len, msg_len, sprintrc(rc)); /* abbreviated output */ -#define DEFAULT_STRLEN 32 #define ABBREV_LEN (DEFAULT_STRLEN + 1) msg_len = NLA_HDRLEN * ABBREV_LEN + NLMSG_SPACE(sizeof(msg->udm)); msg = tail_memdup(&c_msg, msg_len); diff --git a/tests/nlattr_inet_diag_msg.c b/tests/nlattr_inet_diag_msg.c index 33397c78..306b8665 100644 --- a/tests/nlattr_inet_diag_msg.c +++ b/tests/nlattr_inet_diag_msg.c @@ -96,7 +96,6 @@ main(void) const unsigned int hdrlen = sizeof(struct inet_diag_msg); void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); -#define DEFAULT_STRLEN 32 static char pattern[DEFAULT_STRLEN]; fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); diff --git a/tests/nlattr_netlink_diag_msg.c b/tests/nlattr_netlink_diag_msg.c index a7f7e58e..37e3a012 100644 --- a/tests/nlattr_netlink_diag_msg.c +++ b/tests/nlattr_netlink_diag_msg.c @@ -80,7 +80,6 @@ main(void) const unsigned int hdrlen = sizeof(struct netlink_diag_msg); void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); -#define DEFAULT_STRLEN 32 static char pattern[DEFAULT_STRLEN]; fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); diff --git a/tests/nlattr_unix_diag_msg.c b/tests/nlattr_unix_diag_msg.c index 59444c45..a11328b1 100644 --- a/tests/nlattr_unix_diag_msg.c +++ b/tests/nlattr_unix_diag_msg.c @@ -79,7 +79,6 @@ main(void) const unsigned int hdrlen = sizeof(struct unix_diag_msg); void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); -#define DEFAULT_STRLEN 32 static char pattern[DEFAULT_STRLEN]; fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); diff --git a/tests/printstr.c b/tests/printstr.c index 356ae2ec..8e226813 100644 --- a/tests/printstr.c +++ b/tests/printstr.c @@ -34,8 +34,6 @@ #include #include -#define DEFAULT_STRLEN 32 - int main(void) { diff --git a/tests/tests.h b/tests/tests.h index 00d10eae..094f3650 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -51,6 +51,11 @@ # define VERBOSE 0 #endif +#ifndef DEFAULT_STRLEN +/* Default maximum # of bytes printed in printstr et al. */ +# define DEFAULT_STRLEN 32 +#endif + /* Cached sysconf(_SC_PAGESIZE). */ size_t get_page_size(void); diff --git a/tests/xattr.c b/tests/xattr.c index a772eced..03b4270a 100644 --- a/tests/xattr.c +++ b/tests/xattr.c @@ -36,8 +36,6 @@ # define XATTR_SIZE_MAX 65536 # endif -#define DEFAULT_STRLEN 32 - int main(void) { -- 2.40.0