]> granicus.if.org Git - strace/commitdiff
tests: move DEFAULT_STRLEN macro to tests.h
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 3 Jul 2017 15:14:54 +0000 (15:14 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 3 Jul 2017 15:14:54 +0000 (15:14 +0000)
* 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 <chenjingpiao@gmail.com>
13 files changed:
tests/execve.c
tests/execveat.c
tests/mincore.c
tests/mmsg_name.c
tests/msg_control.c
tests/netlink_protocol.c
tests/nlattr.c
tests/nlattr_inet_diag_msg.c
tests/nlattr_netlink_diag_msg.c
tests/nlattr_unix_diag_msg.c
tests/printstr.c
tests/tests.h
tests/xattr.c

index c558dd3b2ca6d8079ee7c4b6da4361d133f7d8ed..da3bc5200c0c41b38d121d2b4c9a300d577d4fca 100644 (file)
@@ -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;
index 8ffc4d5887371a668732b5546c82b1a6f0f1cd2a..566a59f9e5c9b79b1da1e230eee628c894853d3e 100644 (file)
@@ -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;
index ea2b49e38397b0a8e2a27776886625f87c8d96f4..0ede687d654d1804ec5a2303053ca457f3f3f682 100644 (file)
@@ -29,8 +29,6 @@
 #include <stdio.h>
 #include <sys/mman.h>
 
-#define DEFAULT_STRLEN 32
-
 static void
 print_mincore(const unsigned int pages, void *const addr,
              const size_t size, unsigned char *const vec)
index ac8dcde7ec573085237e0e0dc29cf726acbdef64..ad5a482d45eed58096f8d74f994a5e302364a4ba 100644 (file)
@@ -40,8 +40,6 @@
 
 #include "msghdr.h"
 
-#define DEFAULT_STRLEN 32
-
 #define IOV_MAX1 (IOV_MAX + 1)
 
 #ifndef TEST_NAME
index 5b6b25a5d16f29ea23c7d4b3838efa8de732174b..b63f2d04e13e572d7f3a35431f5945bf43d1b4d7 100644 (file)
@@ -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)
 {
index d0479805ef456765c28d302f738bb491458c8800..f09dd9a9668100105968042c1afaac812ff562c1 100644 (file)
@@ -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);
index 15a0ad1fb005e246ab28da43154cc6a05ebf6f07..7361eced0213e47ec007a3567a3c56fea21e3f84 100644 (file)
@@ -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);
index 33397c7878dcd9a692e462e3a5e8a95ee5d22ea6..306b86654ae8fe4efb176b267af78e527aee9ed3 100644 (file)
@@ -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);
 
index a7f7e58e6eebe00d0d5fae3bf20d557c0ddfe7a3..37e3a012783767b5016621336662b87aeac54136 100644 (file)
@@ -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);
 
index 59444c458bbe844f172a236f3c02eb7cb9ae65a5..a11328b19dc9410236792ccb3532b5d34a6b2b5f 100644 (file)
@@ -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);
 
index 356ae2ecada719a72d479f4dfc4e763399a336db..8e22681358bc7dc191c95bd870043fa8b56a3554 100644 (file)
@@ -34,8 +34,6 @@
 #include <unistd.h>
 #include <sys/uio.h>
 
-#define DEFAULT_STRLEN 32
-
 int
 main(void)
 {
index 00d10eaec10645dd102531c4243b774610f2f2c8..094f365088c49b48ebe2c8efe69559c6f4c42450 100644 (file)
 # 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);
 
index a772eced6681f1019b4a4996e0c0414633bc8256..03b4270aa4b8dc8ccd6869b8e7bee826b7d3afb9 100644 (file)
@@ -36,8 +36,6 @@
 #  define XATTR_SIZE_MAX 65536
 # endif
 
-#define DEFAULT_STRLEN 32
-
 int
 main(void)
 {