]> granicus.if.org Git - strace/commitdiff
tests: add sock_filtrer-v variants with different xlat verbosity levels
authorEugene Syromyatnikov <evgsyr@gmail.com>
Wed, 9 May 2018 12:44:28 +0000 (12:44 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 9 May 2018 12:44:28 +0000 (12:44 +0000)
* tests/sock_filter-v-Xabbrev.c: New file.
* tests/sock_filter-v-Xraw.c: Likewise.
* tests/sock_filter-v-Xverbose.c: Likewise.
* tests/sock_filter-v.c (PRINT_STMT_SYM, PRINT_STMT_SYM_,
PRINT_STMT_VAL, PRINT_STMT_VAL_, PRINT_JUMP_): Remove.
(HEX_FMT, XLAT_FMT, XLAT_ARGS, PRINT_STMT): New macros.
(PRINT_JUMP): Rewrite.
(print_filter): Rewrite using PRINT_STMT and new PRINT_JUMP.
(main): Print SOL_SOCKET, SO_ATTACH_FILTER, and SO_ATTACH_REUSEPORT_CBPF
using XLAT_FMT/XLAT_ARGS macros.
* tests/pure_executables.list: Add sock_filter-v-Xabbrev,
sock_filter-v-Xraw, and sock_filter-v-Xverbose.
* tests/.gitignore: Likewise.
* tests/gen_tests.in (sock_filter-v-Xabbrev, sock_filter-v-Xraw,
sock_filter-v-Xverbose): New tests.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
tests/.gitignore
tests/gen_tests.in
tests/pure_executables.list
tests/sock_filter-v-Xabbrev.c [new file with mode: 0644]
tests/sock_filter-v-Xraw.c [new file with mode: 0644]
tests/sock_filter-v-Xverbose.c [new file with mode: 0644]
tests/sock_filter-v.c

index 3aebe656680c20f275c445ce23887704c97377d5..c12cc09b4152338c76f63a2af4f94fd1fe821ed4 100644 (file)
@@ -469,6 +469,9 @@ so_peercred-Xabbrev
 so_peercred-Xraw
 so_peercred-Xverbose
 sock_filter-v
+sock_filter-v-Xabbrev
+sock_filter-v-Xraw
+sock_filter-v-Xverbose
 socketcall
 sockopt-sol_netlink
 splice
index 2e1b8479f577ff9dfb9ec2ab453f4383bc19b0ed..faf315cde6c2ed89db25e558a81f32e3b623d007 100644 (file)
@@ -412,6 +412,9 @@ so_peercred-Xabbrev -e trace=getsockopt -Xabbrev
 so_peercred-Xraw       -e trace=getsockopt -Xraw -a39
 so_peercred-Xverbose   -e trace=getsockopt -Xverbose
 sock_filter-v  -v -e trace=getsockopt,setsockopt
+sock_filter-v-Xabbrev  -v -e trace=getsockopt,setsockopt -X abbrev
+sock_filter-v-Xraw     -a 37 -v -e trace=getsockopt,setsockopt -X raw
+sock_filter-v-Xverbose -v -e trace=getsockopt,setsockopt -X verbose
 socketcall     -a20
 sockopt-sol_netlink    -e trace=getsockopt,setsockopt
 splice
index 1c88996496510a1fdfa65222427b372bef0a55cd..588861c16e3a9561b11671e2af35dff510db3c96 100755 (executable)
@@ -391,6 +391,9 @@ so_peercred-Xabbrev
 so_peercred-Xraw
 so_peercred-Xverbose
 sock_filter-v
+sock_filter-v-Xabbrev
+sock_filter-v-Xraw
+sock_filter-v-Xverbose
 socketcall
 sockopt-sol_netlink
 splice
diff --git a/tests/sock_filter-v-Xabbrev.c b/tests/sock_filter-v-Xabbrev.c
new file mode 100644 (file)
index 0000000..ac680e2
--- /dev/null
@@ -0,0 +1 @@
+#include "sock_filter-v.c"
diff --git a/tests/sock_filter-v-Xraw.c b/tests/sock_filter-v-Xraw.c
new file mode 100644 (file)
index 0000000..e85309c
--- /dev/null
@@ -0,0 +1,2 @@
+#define XLAT_RAW 1
+#include "sock_filter-v.c"
diff --git a/tests/sock_filter-v-Xverbose.c b/tests/sock_filter-v-Xverbose.c
new file mode 100644 (file)
index 0000000..59d76bd
--- /dev/null
@@ -0,0 +1,2 @@
+#define XLAT_VERBOSE 1
+#include "sock_filter-v.c"
index 16d5c1cd4fe5bc9c94aa63778c77aac86efcee1a..4fbb5b9e1c80b18eb54c2a76a3786c691ccd98db 100644 (file)
 #include <sys/socket.h>
 #include <linux/filter.h>
 
-#define PRINT_STMT_SYM(pfx, code, k)   PRINT_STMT_SYM_(pfx, #code, #k)
-#define PRINT_STMT_SYM_(pfx, code, k)  \
-       printf("%sBPF_STMT(%s, %s)", pfx, code, k)
-#define PRINT_STMT_VAL(pfx, code, k)   PRINT_STMT_VAL_(pfx, #code, k)
-#define PRINT_STMT_VAL_(pfx, code, k)  \
-       printf("%sBPF_STMT(%s, %#x)", pfx, code, k)
+#define HEX_FMT "%#x"
+
+#if XLAT_RAW
+# define XLAT_FMT HEX_FMT
+# define XLAT_ARGS(a_) (a_)
+#elif XLAT_VERBOSE
+# define XLAT_FMT HEX_FMT " /* %s */"
+# define XLAT_ARGS(a_) (a_), #a_
+#else
+# define XLAT_FMT "%s"
+# define XLAT_ARGS(a_) #a_
+#endif
+
+#define PRINT_STMT(pfx, code_fmt, k_fmt, ...)  \
+       printf("%sBPF_STMT(" code_fmt ", " k_fmt ")", pfx, __VA_ARGS__)
 
-#define PRINT_JUMP(pfx, code, k, jt, jf)       PRINT_JUMP_(pfx, #code, k, jt, jf)
-#define PRINT_JUMP_(pfx, code, k, jt, jf)      \
-       printf("%sBPF_JUMP(%s, %#x, %#x, %#x)", pfx, code, k, jt, jf)
+#define PRINT_JUMP(pfx, code_fmt, k, jt, jf, ...)              \
+       printf("%sBPF_JUMP(" code_fmt ", %#x, %#x, %#x)",       \
+              pfx, __VA_ARGS__, k, jt, jf)
 
 static const struct sock_filter bpf_filter[] = {
        BPF_STMT(BPF_LD|BPF_B|BPF_ABS, SKF_LL_OFF+4),
@@ -62,16 +71,43 @@ static const struct sock_filter bpf_filter[] = {
 static void
 print_filter(void)
 {
-       PRINT_STMT_SYM("[", BPF_LD|BPF_B|BPF_ABS, SKF_LL_OFF+4);
-       PRINT_STMT_SYM(", ", BPF_LD|BPF_B|BPF_ABS, SKF_NET_OFF+8);
-       PRINT_STMT_SYM(", ", BPF_LD|BPF_B|BPF_ABS, SKF_AD_OFF+SKF_AD_PROTOCOL);
-       PRINT_JUMP(", ", BPF_JMP|BPF_K|BPF_JEQ, IPPROTO_UDP, 0, 5);
-       PRINT_STMT_VAL(", ", BPF_LD|BPF_W|BPF_LEN, 0);
-       PRINT_JUMP(", ", BPF_JMP|BPF_K|BPF_JGE, 100, 0, 3);
-       PRINT_STMT_VAL(", ", BPF_LD|BPF_B|BPF_ABS, 42);
-       PRINT_JUMP(", ", BPF_JMP|BPF_K|BPF_JEQ, 'a', 0, 1);
-       PRINT_STMT_VAL(", ", BPF_RET|BPF_K, -1U);
-       PRINT_STMT_VAL(", ", BPF_RET|BPF_K, 0);
+       PRINT_STMT("[", XLAT_FMT "|" XLAT_FMT "|" XLAT_FMT,
+                  XLAT_FMT "+4",
+                  XLAT_ARGS(BPF_LD), XLAT_ARGS(BPF_B), XLAT_ARGS(BPF_ABS),
+                  XLAT_ARGS(SKF_LL_OFF));
+       PRINT_STMT(", ", XLAT_FMT "|" XLAT_FMT "|" XLAT_FMT,
+                  XLAT_FMT "+8",
+                  XLAT_ARGS(BPF_LD), XLAT_ARGS(BPF_B), XLAT_ARGS(BPF_ABS),
+                  XLAT_ARGS(SKF_NET_OFF));
+       PRINT_STMT(", ", XLAT_FMT "|" XLAT_FMT "|" XLAT_FMT,
+                  XLAT_FMT "+" XLAT_FMT,
+                  XLAT_ARGS(BPF_LD), XLAT_ARGS(BPF_B), XLAT_ARGS(BPF_ABS),
+                  XLAT_ARGS(SKF_AD_OFF), XLAT_ARGS(SKF_AD_PROTOCOL));
+       PRINT_JUMP(", ", XLAT_FMT "|" XLAT_FMT "|" XLAT_FMT,
+                  IPPROTO_UDP, 0, 5,
+                  XLAT_ARGS(BPF_JMP), XLAT_ARGS(BPF_K), XLAT_ARGS(BPF_JEQ));
+       PRINT_STMT(", ", XLAT_FMT "|" XLAT_FMT "|" XLAT_FMT,
+                  HEX_FMT,
+                  XLAT_ARGS(BPF_LD), XLAT_ARGS(BPF_W), XLAT_ARGS(BPF_LEN),
+                  0);
+       PRINT_JUMP(", ", XLAT_FMT "|" XLAT_FMT "|" XLAT_FMT,
+                  100, 0, 3,
+                  XLAT_ARGS(BPF_JMP), XLAT_ARGS(BPF_K), XLAT_ARGS(BPF_JGE));
+       PRINT_STMT(", ", XLAT_FMT "|" XLAT_FMT "|" XLAT_FMT,
+                  HEX_FMT,
+                  XLAT_ARGS(BPF_LD), XLAT_ARGS(BPF_B), XLAT_ARGS(BPF_ABS),
+                  42);
+       PRINT_JUMP(", ", XLAT_FMT "|" XLAT_FMT "|" XLAT_FMT,
+                  'a', 0, 1,
+                  XLAT_ARGS(BPF_JMP), XLAT_ARGS(BPF_K), XLAT_ARGS(BPF_JEQ));
+       PRINT_STMT(", ", XLAT_FMT "|" XLAT_FMT,
+                  HEX_FMT,
+                  XLAT_ARGS(BPF_RET), XLAT_ARGS(BPF_K),
+                  -1U);
+       PRINT_STMT(", ", XLAT_FMT "|" XLAT_FMT,
+                  HEX_FMT,
+                  XLAT_ARGS(BPF_RET), XLAT_ARGS(BPF_K),
+                  0);
        putchar(']');
 }
 
@@ -115,34 +151,40 @@ main(void)
        rc = get_filter(fd, NULL, len);
        if (rc)
                perror_msg_and_skip("getsockopt SOL_SOCKET SO_ATTACH_FILTER");
-       printf("getsockopt(%d, SOL_SOCKET, SO_ATTACH_FILTER"
-              ", NULL, [%u->0]) = 0\n", fd, BPF_MAXINSNS);
+       printf("getsockopt(%d, " XLAT_FMT ", " XLAT_FMT ", NULL, [%u->0]) "
+              "= 0\n",
+              fd, XLAT_ARGS(SOL_SOCKET), XLAT_ARGS(SO_ATTACH_FILTER),
+              BPF_MAXINSNS);
 
        /* getsockopt NULL optlen - EFAULT */
        rc = get_filter(fd, NULL, NULL);
-       printf("getsockopt(%d, SOL_SOCKET, SO_ATTACH_FILTER, NULL, NULL)"
-              " = %s\n", fd, errstr);
+       printf("getsockopt(%d, " XLAT_FMT ", " XLAT_FMT ", NULL, NULL) "
+              "= %s\n",
+              fd, XLAT_ARGS(SOL_SOCKET), XLAT_ARGS(SO_ATTACH_FILTER), errstr);
 
        /* attach a filter */
        rc = set_filter(fd, prog, sizeof(*prog));
        if (rc)
                perror_msg_and_skip("setsockopt SOL_SOCKET SO_ATTACH_FILTER");
-       printf("setsockopt(%d, SOL_SOCKET, SO_ATTACH_FILTER, {len=%u, filter=",
-              fd, prog->len);
+       printf("setsockopt(%d, " XLAT_FMT ", " XLAT_FMT ", {len=%u, filter=",
+              fd, XLAT_ARGS(SOL_SOCKET), XLAT_ARGS(SO_ATTACH_FILTER),
+              prog->len);
        print_filter();
        printf("}, %u) = 0\n", (unsigned int) sizeof(*prog));
 
        /* setsockopt optlen is too small - EINVAL */
        rc = set_filter(fd, prog, sizeof(*prog) - 4);
-       printf("setsockopt(%d, SOL_SOCKET, SO_ATTACH_FILTER, %p, %u) = %s\n",
-              fd, prog, (unsigned int) sizeof(*prog) - 4, errstr);
+       printf("setsockopt(%d, " XLAT_FMT ", " XLAT_FMT ", %p, %u) = %s\n",
+              fd, XLAT_ARGS(SOL_SOCKET), XLAT_ARGS(SO_ATTACH_FILTER), prog,
+              (unsigned int) sizeof(*prog) - 4, errstr);
 
 #ifdef SO_ATTACH_REUSEPORT_CBPF
        rc = setsockopt(fd, SOL_SOCKET, SO_ATTACH_REUSEPORT_CBPF,
                        prog, sizeof(*prog));
        errstr = sprintrc(rc);
-       printf("setsockopt(%d, SOL_SOCKET, SO_ATTACH_REUSEPORT_CBPF"
-              ", {len=%u, filter=", fd, prog->len);
+       printf("setsockopt(%d, " XLAT_FMT ", " XLAT_FMT ", {len=%u, filter=",
+              fd, XLAT_ARGS(SOL_SOCKET), XLAT_ARGS(SO_ATTACH_REUSEPORT_CBPF),
+              prog->len);
        print_filter();
        printf("}, %u) = %s\n", (unsigned int) sizeof(*prog), errstr);
 #endif
@@ -150,28 +192,30 @@ main(void)
        /* query sock_filter program length -> ARRAY_SIZE(bpf_filter) */
        *len = 0;
        rc = get_filter(fd, efault, len);
-       printf("getsockopt(%d, SOL_SOCKET, SO_ATTACH_FILTER, %p"
-              ", [0->%u]) = %s\n",
-              fd, efault, (unsigned int) ARRAY_SIZE(bpf_filter), errstr);
+       printf("getsockopt(%d, " XLAT_FMT ", " XLAT_FMT ", %p, [0->%u]) "
+              "= %s\n",
+              fd, XLAT_ARGS(SOL_SOCKET), XLAT_ARGS(SO_ATTACH_FILTER), efault,
+              (unsigned int) ARRAY_SIZE(bpf_filter), errstr);
 
        /* getsockopt optlen is too small - EINVAL */
        *len = ARRAY_SIZE(bpf_filter) - 1;
        rc = get_filter(fd, efault, len);
-       printf("getsockopt(%d, SOL_SOCKET, SO_ATTACH_FILTER, %p"
-              ", [%u]) = %s\n",
-              fd, efault, (unsigned int) ARRAY_SIZE(bpf_filter) - 1, errstr);
+       printf("getsockopt(%d, " XLAT_FMT ", " XLAT_FMT ", %p, [%u]) = %s\n",
+              fd, XLAT_ARGS(SOL_SOCKET), XLAT_ARGS(SO_ATTACH_FILTER), efault,
+              (unsigned int) ARRAY_SIZE(bpf_filter) - 1, errstr);
 
        /* getsockopt optval EFAULT */
        *len = ARRAY_SIZE(bpf_filter);
        rc = get_filter(fd, filter + 1, len);
-       printf("getsockopt(%d, SOL_SOCKET, SO_ATTACH_FILTER, %p"
-              ", [%u]) = %s\n", fd, filter + 1,
-              (unsigned int) ARRAY_SIZE(bpf_filter), errstr);
+       printf("getsockopt(%d, " XLAT_FMT ", " XLAT_FMT ", %p, [%u]) = %s\n",
+              fd, XLAT_ARGS(SOL_SOCKET), XLAT_ARGS(SO_ATTACH_FILTER),
+              filter + 1, (unsigned int) ARRAY_SIZE(bpf_filter), errstr);
 
        /* getsockopt optlen is too large - truncated */
        *len = ARRAY_SIZE(bpf_filter) + 1;
        rc = get_filter(fd, filter, len);
-       printf("getsockopt(%d, SOL_SOCKET, SO_ATTACH_FILTER, ", fd);
+       printf("getsockopt(%d, " XLAT_FMT ", " XLAT_FMT ", ",
+              fd, XLAT_ARGS(SOL_SOCKET), XLAT_ARGS(SO_ATTACH_FILTER));
        print_filter();
        printf(", [%u->%d]) = %s\n",
               (unsigned int) ARRAY_SIZE(bpf_filter) + 1, *len, errstr);