3 # Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com>
5 # This library is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation; version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this library; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 TEST_DESC
="Kernel tracer - Namespace contexts"
20 CURDIR
=$
(dirname "$0")/
25 NUM_TESTS
=$
((TESTS_PER_NS
* 7))
27 source "$TESTDIR/utils/utils.sh"
29 # MUST set TESTDIR before calling those functions
30 function add_context_kernel_skip_ok
()
39 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" add-context
-k \
40 -s "$session_name" -c "$channel_name" \
41 -t "$context_name" 1>"$OUTPUT_DEST" 2>"$ERROR_OUTPUT_DEST"
44 if [ "$ret" == "4" ]; then
45 skip
0 "Current kernel doesn't implement '$context_name' context" $
((skip_num
+ 1))
47 ok
$ret "Add context command for type: $context_name"
53 function enable_kernel_lttng_event_filter_ok
()
60 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
-k \
61 -c "$channel_name" -s "$session_name" \
62 --syscall "$syscall_name" \
64 1>"$OUTPUT_DEST" 2>"$ERROR_OUTPUT_DEST"
66 ok $?
"Add syscall with filter"
73 local session_name
="${ns}_ns"
74 local chan_name
="${ns}_ns"
75 local context_name
="${ns}_ns"
80 # Check if the kernel has support for this ns type
81 if [ ! -f "/proc/$$/ns/$ns" ]; then
82 skip
0 "System has no $ns namespace support" $TESTS_PER_NS
86 # Get the current ns inode number
87 ns_inode
=$
(stat
-c '%i' -L "/proc/$$/ns/$ns")
88 ok $?
"Get current $ns namespace inode: $ns_inode"
90 trace_path
=$
(mktemp
-d)
94 create_lttng_session_ok
"$session_name" "$trace_path"
95 enable_kernel_lttng_channel_ok
"$session_name" "$chan_name"
96 add_context_kernel_skip_ok
"$session_name" "$chan_name" "$context_name" 4
97 if [ "$?" != "4" ]; then
98 enable_kernel_lttng_event_filter_ok
"$session_name" "read" "$chan_name" "\$ctx.$context_name == $ns_inode"
99 start_lttng_tracing_ok
"$session_name"
101 # Make sure there is at least one read syscall
102 cat /proc
/cmdline
>/dev
/null
104 stop_lttng_tracing_ok
"$session_name"
106 # Check that the events contain the right namespace inode number
107 validate_trace
"${ns}_ns = $ns_inode" "$trace_path"
110 destroy_lttng_session_ok
"$session_name"
117 plan_tests
$NUM_TESTS
119 print_test_banner
"$TEST_DESC"
123 if [ "$(id -u)" == "0" ]; then
127 skip
$isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" && exit 0
131 if [ -d "/proc/$$/ns" ]; then
135 skip
$system_has_ns "System does not support namespaces" $NUM_TESTS && exit 0
138 validate_lttng_modules_present