Tests: add kernel namespace contexts tests
authorMichael Jeanson <mjeanson@efficios.com>
Mon, 1 Apr 2019 15:53:20 +0000 (11:53 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 23 Oct 2019 21:18:33 +0000 (17:18 -0400)
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/regression/kernel/Makefile.am
tests/regression/kernel/test_ns_contexts [new file with mode: 0755]
tests/root_regression

index 3ab6d75bde10c0704e96e4f27e2b892c9e89da9c..169267adb2c18291b2a45657c3abc7e62fb5f2d7 100644 (file)
@@ -2,7 +2,8 @@ EXTRA_DIST = test_event_basic test_all_events test_syscall \
                test_clock_override test_rotation_destroy_flush \
                test_select_poll_epoll test_lttng_logger \
                test_userspace_probe test_callstack \
-               test_syscall validate_select_poll_epoll.py
+               test_syscall validate_select_poll_epoll.py \
+               test_ns_contexts
 
 noinst_PROGRAMS = select_poll_epoll
 select_poll_epoll_SOURCES = select_poll_epoll.c
diff --git a/tests/regression/kernel/test_ns_contexts b/tests/regression/kernel/test_ns_contexts
new file mode 100755 (executable)
index 0000000..843019a
--- /dev/null
@@ -0,0 +1,146 @@
+#!/bin/bash
+#
+# Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com>
+#
+# This library is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+TEST_DESC="Kernel tracer - Namespace contexts"
+
+CURDIR=$(dirname "$0")/
+TESTDIR=$CURDIR/../..
+
+TESTS_PER_NS=11
+
+NUM_TESTS=$((TESTS_PER_NS * 7))
+
+source "$TESTDIR/utils/utils.sh"
+
+# MUST set TESTDIR before calling those functions
+function add_context_kernel_skip_ok()
+{
+       local session_name=$1
+       local channel_name=$2
+       local context_name=$3
+       local skip_num=$4
+
+       local ret
+
+       "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" add-context -k \
+               -s "$session_name" -c "$channel_name" \
+               -t "$context_name"  1>"$OUTPUT_DEST" 2>"$ERROR_OUTPUT_DEST"
+       ret=$?
+
+       if [ "$ret" == "4" ]; then
+               skip 0 "Current kernel doesn't implement '$context_name' context" $((skip_num + 1))
+       else
+               ok $ret "Add context command for type: $context_name"
+       fi
+
+       return $ret
+}
+
+function enable_kernel_lttng_event_filter_ok()
+{
+       local session_name=$1
+       local syscall_name=$2
+       local channel_name=$3
+       local filter=$4
+
+       "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event -k \
+               -c "$channel_name" -s "$session_name" \
+               --syscall "$syscall_name" \
+               -f "$filter" \
+               1>"$OUTPUT_DEST" 2>"$ERROR_OUTPUT_DEST"
+
+       ok $? "Add syscall with filter"
+}
+
+function test_ns()
+{
+       local ns=$1
+
+       local session_name="${ns}_ns"
+       local chan_name="${ns}_ns"
+       local context_name="${ns}_ns"
+
+       local trace_path
+       local ns_inode
+
+       # Check if the kernel has support for this ns type
+       if [ ! -f "/proc/$$/ns/$ns" ]; then
+               skip 0 "System has no $ns namespace support" $TESTS_PER_NS
+               return
+       fi
+
+       # Get the current ns inode number
+       ns_inode=$(stat -c '%i' -L "/proc/$$/ns/$ns")
+       ok $? "Get current $ns namespace inode: $ns_inode"
+
+       trace_path=$(mktemp -d)
+
+       start_lttng_sessiond
+
+       create_lttng_session_ok "$session_name" "$trace_path"
+       enable_kernel_lttng_channel_ok "$session_name" "$chan_name"
+       add_context_kernel_skip_ok "$session_name" "$chan_name" "$context_name" 4
+       if [ "$?" != "4" ]; then
+               enable_kernel_lttng_event_filter_ok "$session_name" "read" "$chan_name" "\$ctx.$context_name == $ns_inode"
+               start_lttng_tracing_ok "$session_name"
+
+               # Make sure there is at least one read syscall
+               cat /proc/cmdline >/dev/null
+
+               stop_lttng_tracing_ok "$session_name"
+
+               # Check that the events contain the right namespace inode number
+               validate_trace "${ns}_ns = $ns_inode" "$trace_path"
+       fi
+
+       destroy_lttng_session_ok "$session_name"
+       stop_lttng_sessiond
+
+       rm -rf "$trace_path"
+}
+
+
+plan_tests $NUM_TESTS
+
+print_test_banner "$TEST_DESC"
+
+
+isroot=0
+if [ "$(id -u)" == "0" ]; then
+       isroot=1
+fi
+
+skip $isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" && exit 0
+
+
+system_has_ns=0
+if [ -d "/proc/$$/ns" ]; then
+       system_has_ns=1
+fi
+
+skip $system_has_ns "System does not support namespaces" $NUM_TESTS && exit 0
+
+
+validate_lttng_modules_present
+
+test_ns cgroup
+test_ns ipc
+test_ns mnt
+test_ns net
+test_ns pid
+test_ns user
+test_ns uts
index f1f6619978c76b94059246b651e09ca1e3beae78..c9394aa2cba0914647b38a2133b40501deb5cfae 100644 (file)
@@ -8,6 +8,7 @@ regression/kernel/test_select_poll_epoll
 regression/kernel/test_lttng_logger
 regression/kernel/test_callstack
 regression/kernel/test_userspace_probe
+regression/kernel/test_ns_contexts
 regression/tools/live/test_kernel
 regression/tools/live/test_lttng_kernel
 regression/tools/streaming/test_high_throughput_limits
This page took 0.042542 seconds and 4 git commands to generate.