summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolay Marchuk <marchuk.nikolay.a@gmail.com>2017-07-19 12:47:51 +0700
committerDmitry V. Levin <ldv@altlinux.org>2018-06-13 15:05:09 +0000
commit0fdb1f18e9905daed2493664c8d045f274c1b713 (patch)
tree8484f2885f951cdb51e3705ede4b77cf8f08f9f8
parent98e1b86c8ce2dfbe2e6c9ab7fcdad3fac4b41a31 (diff)
downloadstrace-0fdb1f18e9905daed2493664c8d045f274c1b713.tar.gz
tests: check fd filter
* tests/filtering_fd-syntax.test: New file. * tests/filtering_fd.c: Likewise. * tests/filtering_fd.test: Likewise. * tests/mmap_name.sh: Likewise. * tests/mmap.test: Move mmap name testing to mmap_name.sh. * tests/options-syntax.test: Remove fd filtering checks. * tests/.gitignore: Add filtering_fd. * tests/Makefile.am (check_PROGRAMS): Add filtering_fd. (MISC_TESTS): Add filering_fd-syntax.test, filtering_fd.test. (EXTRA_DIST): Add mmap_name.sh.
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.am3
-rwxr-xr-xtests/filtering_fd-syntax.test19
-rw-r--r--tests/filtering_fd.c204
-rwxr-xr-xtests/filtering_fd.test17
-rwxr-xr-xtests/mmap.test18
-rw-r--r--tests/mmap_name.sh51
7 files changed, 297 insertions, 16 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index b42b13124..a054e2d79 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -84,6 +84,7 @@ fflush
file_handle
file_ioctl
filter-unavailable
+filtering_fd
finit_module
flock
fork-f
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e34404954..72dd2979f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -109,6 +109,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
execve-v \
execveat-v \
filter-unavailable \
+ filtering_fd \
fork-f \
fsync-y \
getpid \
@@ -307,6 +308,7 @@ MISC_TESTS = \
filtering_expression-empty.test \
filtering_expression-syntax.test \
filtering_fd-syntax.test \
+ filtering_fd.test \
filtering_syscall-syntax.test \
fflush.test \
get_regs.test \
@@ -387,6 +389,7 @@ EXTRA_DIST = \
ipc.sh \
ksysent.sed \
lstatx.c \
+ mmap_name.sh \
match.awk \
net.expected \
netlink_sock_diag-v.sh \
diff --git a/tests/filtering_fd-syntax.test b/tests/filtering_fd-syntax.test
index 4f4e9c733..d5c4cdf5d 100755
--- a/tests/filtering_fd-syntax.test
+++ b/tests/filtering_fd-syntax.test
@@ -30,6 +30,13 @@
. "${srcdir=.}/syntax.sh"
+check_fd_new()
+{
+ [ -z "$2" ] || check_e "invalid descriptor '$1'" -e "trace(fd $2)"
+ [ -z "$2" ] || check_e "invalid descriptor '$1'" -e "fd $2"
+ [ -z "$2" ] || check_e "invalid descriptor '$1'" -e"fd $2"
+}
+
check_fd_qualify()
{
check_e "invalid descriptor '$1'" -e"read=$2"
@@ -39,6 +46,8 @@ check_fd_qualify()
}
for arg in '' , ,, ,,, ; do
+ check_fd_new "$arg" "$arg"
+ check_fd_new "!" "!$arg"
check_fd_qualify "$arg" "$arg"
check_fd_qualify "!$arg" "!$arg"
done
@@ -48,6 +57,10 @@ for arg in -1 -42 \
2147483648 \
4294967296 \
; do
+ check_fd_new "$arg" "$arg"
+ check_fd_new "$arg" "1,$arg"
+ check_fd_new "$arg" "$arg,1"
+ check_fd_new "!$arg" "!$arg"
check_fd_qualify "$arg" "$arg"
check_fd_qualify "$arg" "1,$arg"
check_fd_qualify "$arg" "$arg,1"
@@ -57,4 +70,10 @@ done
for arg in ! all none; do
check_fd_qualify "$arg" "1,$arg"
check_fd_qualify "!$arg" "1,!$arg"
+ check_fd_new "$arg" "1,$arg"
+ check_fd_new "!$arg" "1,!$arg"
+done
+
+for arg in 1 2 all none; do
+ check_fd_new "!$arg" "!$arg"
done
diff --git a/tests/filtering_fd.c b/tests/filtering_fd.c
new file mode 100644
index 000000000..fee7826ea
--- /dev/null
+++ b/tests/filtering_fd.c
@@ -0,0 +1,204 @@
+/*
+ * Check decoding of non-standard fd filters
+ *
+ * Copyright (c) 2017 Nikolay Marchuk <marchuk.nikolay.a@gmail.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "tests.h"
+#include <asm/unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#define FD_TRACED_DEFAULT 5
+
+#ifdef __NR_dup2
+void
+test_dup2(int fd_base)
+{
+ int rc = syscall(__NR_dup2, fd_base, -1);
+ printf("dup2(%d, -1) = %s\n", fd_base, sprintrc(rc));
+ syscall(__NR_dup2, fd_base + 1, -1);
+
+ rc = syscall(__NR_dup2, -1, fd_base);
+ printf("dup2(-1, %d) = %s\n", fd_base, sprintrc(rc));
+ syscall(__NR_dup2, -1, fd_base + 1);
+}
+#else
+void
+test_dup2(int fd_base)
+{
+}
+#endif
+
+#ifdef __NR_linkat
+void
+test_linkat(int fd_base)
+{
+ int rc = syscall(__NR_linkat, fd_base, "old", -1, "new", 0);
+ printf("linkat(%d, \"old\", -1, \"new\", 0) = %s\n",
+ fd_base, sprintrc(rc));
+ syscall(__NR_linkat, fd_base + 1, "old", -1, "new", 0);
+
+ rc = syscall(__NR_linkat, -1, "old", fd_base, "new", 0);
+ printf("linkat(-1, \"old\", %d, \"new\", 0) = %s\n",
+ fd_base, sprintrc(rc));
+ syscall(__NR_linkat, "old", fd_base + 1, "new", 0);
+}
+#else
+void
+test_linkat(int fd_base)
+{
+}
+#endif
+
+#ifdef __NR_symlinkat
+void
+test_symlinkat(int fd_base)
+{
+ int rc = syscall(__NR_symlinkat, "new", fd_base, "old");
+ printf("symlinkat(\"new\", %d, \"old\") = %s\n",
+ fd_base, sprintrc(rc));
+ syscall(__NR_symlinkat, "new", fd_base + 1, "old");
+}
+#else
+void
+test_symlinkat(int fd_base)
+{
+}
+#endif
+
+#ifdef __NR_epoll_ctl
+# include <sys/epoll.h>
+void
+test_epoll(int fd_base)
+{
+ int rc = syscall(__NR_epoll_ctl, -1, EPOLL_CTL_ADD, fd_base, NULL);
+ printf("epoll_ctl(-1, EPOLL_CTL_ADD, %d, NULL) = %s\n",
+ fd_base, sprintrc(rc));
+ syscall(__NR_epoll_ctl, -1, EPOLL_CTL_ADD, fd_base + 1, NULL);
+}
+#else
+void
+test_epoll(int fd_base)
+{
+}
+#endif
+
+#if defined HAVE_SYS_FANOTIFY_H && defined HAVE_FANOTIFY_MARK && \
+ defined __NR_fanotify_mark
+#include <sys/fanotify.h>
+void
+test_fanotify_mark(int fd_base)
+{
+ int rc = fanotify_mark(-1, 0, 0, fd_base, ".");
+ printf("fanotify_mark(-1, 0, 0, %d, \".\") = %s\n",
+ fd_base, sprintrc(rc));
+ fanotify_mark(-1, 0, 0, fd_base + 1, ".");
+}
+#else
+void
+test_fanotify_mark(int fd_base)
+{
+}
+#endif
+
+#if defined __NR_select || defined __NR__newselect
+# include <sys/select.h>
+void
+test_select(int fd_base)
+{
+ int rc;
+ fd_set positive_set, negative_set;
+
+ FD_ZERO(&positive_set);
+ FD_SET(fd_base, &positive_set);
+ FD_ZERO(&negative_set);
+ FD_SET(fd_base + 1, &negative_set);
+# ifndef __NR__newselect
+ rc = syscall(__NR_select, fd_base + 1, &positive_set, NULL, NULL, NULL);
+ printf("select(%d, [%d], NULL, NULL, NULL) = %s\n",
+ fd_base + 1, fd_base, sprintrc(rc));
+ syscall(__NR_select, fd_base + 2, &negative_set, NULL, NULL,NULL);
+# else
+ rc = syscall(__NR__newselect, fd_base + 1, &positive_set, NULL, NULL,
+ NULL);
+ printf("_newselect(%d, [%d], NULL, NULL, NULL) = %s\n",
+ fd_base + 1, fd_base, sprintrc(rc));
+ syscall(__NR__newselect, fd_base + 2, &negative_set, NULL, NULL, NULL);
+# endif
+}
+#else
+void
+test_select(int fd_base)
+{
+}
+#endif
+
+#ifdef __NR_poll
+# include <poll.h>
+void
+test_poll(int fd_base)
+{
+ struct pollfd positive_fds = {.fd = fd_base, .events = POLLIN};
+ struct pollfd negative_fds = {.fd = fd_base + 1, .events = POLLIN};
+
+ syscall(__NR_poll, &positive_fds, 1, 1);
+ printf("poll([{fd=%d, events=POLLIN}], 1, 1) = 1 "
+ "([{fd=%d, revents=POLLNVAL}])\n", fd_base, fd_base);
+ syscall(__NR_poll, &negative_fds, 1, 1);
+}
+#else
+void
+test_poll(int fd_base)
+{
+}
+#endif
+
+int
+main(int argc, char **argv)
+{
+ const char *const name = argc > 1 ? argv[1] : "mmap";
+ long tmp_fd_base = argc > 2 ? strtol(argv[2], NULL, 10) :
+ FD_TRACED_DEFAULT;
+ int fd_base = (tmp_fd_base > 0 && tmp_fd_base < 1023) ?
+ (int) tmp_fd_base : FD_TRACED_DEFAULT;
+
+ test_dup2(fd_base);
+ test_linkat(fd_base);
+ mmap(NULL, 0, PROT_NONE, MAP_FILE, fd_base, 0);
+ printf("%s(NULL, 0, PROT_NONE, MAP_FILE, %d, 0) = -1 EBADF (%m)\n",
+ name, fd_base);
+ test_symlinkat(fd_base);
+ test_epoll(fd_base);
+ test_fanotify_mark(fd_base);
+ test_select(fd_base);
+ test_poll(fd_base);
+
+ puts("+++ exited with 0 +++");
+ return 0;
+}
diff --git a/tests/filtering_fd.test b/tests/filtering_fd.test
new file mode 100755
index 000000000..f3ad256c1
--- /dev/null
+++ b/tests/filtering_fd.test
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+# Check fd filtering
+
+. "${srcdir=.}/mmap_name.sh"
+
+fd_base=5
+
+get_mmap_name "&& fd $fd_base"
+
+for arg in "trace(fd $fd_base)" \
+ "trace(syscall %desc,%network and fd $fd_base)" \
+ ; do
+ run_prog "../$NAME" "$mmap" "$fd_base" > /dev/null
+ run_strace -a12 -e "$arg" $args > "$EXP"
+ match_diff "$LOG" "$EXP"
+done
diff --git a/tests/mmap.test b/tests/mmap.test
index 4c30a65d9..ed1077d46 100755
--- a/tests/mmap.test
+++ b/tests/mmap.test
@@ -29,30 +29,16 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-. "${srcdir=.}/init.sh"
+. "${srcdir=.}/mmap_name.sh"
-check_prog grep
check_prog sed
-run_prog > /dev/null
xlat_opt=""
[ "$#" -gt 0 ] && xlat_opt="-X$1"
align=20
[ "$#" -gt 1 ] && align="$2"
-syscall=
-for n in mmap mmap2; do
- $STRACE -e$n -h > /dev/null && syscall=$syscall,$n
-done
-run_strace -e$syscall $args > /dev/null
-
-if grep '^mmap(NULL, 0, \(0 /* PROT_NONE */\|0\|PROT_NONE\),' < "$LOG" > /dev/null; then
- mmap=mmap
-elif grep '^mmap2(NULL, 0, \(0 \/\* PROT_NONE \*\/\|0\|PROT_NONE\),' < "$LOG" > /dev/null; then
- mmap=mmap2
-else
- dump_log_and_fail_with "mmap/mmap2 not found in $STRACE $args output"
-fi
+get_mmap_name ""
syscall=$mmap,madvise,mlockall,mprotect,mremap,msync,munmap
diff --git a/tests/mmap_name.sh b/tests/mmap_name.sh
new file mode 100644
index 000000000..afc19984d
--- /dev/null
+++ b/tests/mmap_name.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+#
+# Define mmap testing helper function.
+#
+# Copyright (c) 2017 Nikolay Marchuk <marchuk.nikolay.a@gmail.com>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. The name of the author may not be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+. "${srcdir=.}/init.sh"
+
+get_mmap_name()
+{
+ check_prog grep
+ run_prog > /dev/null
+
+ local filter="$1"; shift
+ local syscall=
+ for n in mmap mmap2; do
+ $STRACE -e$n -h > /dev/null && syscall=$syscall,$n
+ done
+ run_strace -e "trace(syscall $syscall $filter)" $args > /dev/null
+
+ if grep '^mmap(NULL, 0, \(0 /* PROT_NONE */\|0\|PROT_NONE\),' < "$LOG" > /dev/null; then
+ mmap=mmap
+ elif grep '^mmap2(NULL, 0, \(0 \/\* PROT_NONE \*\/\|0\|PROT_NONE\),' < "$LOG" > /dev/null; then
+ mmap=mmap2
+ else
+ dump_log_and_fail_with "mmap/mmap2 not found in $STRACE $args output"
+ fi
+}