3 # Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 TEST_DESC
="Kernel tracer - Namespace contexts"
9 CURDIR
=$
(dirname "$0")/
14 NUM_TESTS
=$
((TESTS_PER_NS
* 8))
16 source "$TESTDIR/utils/utils.sh"
18 # MUST set TESTDIR before calling those functions
19 function add_context_kernel_skip_ok
()
28 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" add-context
-k \
29 -s "$session_name" -c "$channel_name" \
30 -t "$context_name" 1>"$OUTPUT_DEST" 2>"$ERROR_OUTPUT_DEST"
33 if [ "$ret" == "4" ]; then
34 skip
0 "Current kernel doesn't implement '$context_name' context" $
((skip_num
+ 1))
36 ok
$ret "Add context command for type: $context_name"
42 function enable_kernel_lttng_event_filter_ok
()
49 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event
-k \
50 -c "$channel_name" -s "$session_name" \
51 --syscall "$syscall_name" \
53 1>"$OUTPUT_DEST" 2>"$ERROR_OUTPUT_DEST"
55 ok $?
"Add syscall with filter"
62 local session_name
="${ns}_ns"
63 local chan_name
="${ns}_ns"
64 local context_name
="${ns}_ns"
69 # Check if the kernel has support for this ns type
70 if [ ! -f "/proc/$$/ns/$ns" ]; then
71 skip
0 "System has no $ns namespace support" $TESTS_PER_NS
75 # Get the current ns inode number
76 ns_inode
=$
(stat
-c '%i' -L "/proc/$$/ns/$ns")
77 ok $?
"Get current $ns namespace inode: $ns_inode"
79 trace_path
=$
(mktemp
--tmpdir -d tmp.
{FUNCNAME
[0]}_trace_path.XXXXXX
)
83 create_lttng_session_ok
"$session_name" "$trace_path"
84 enable_kernel_lttng_channel_ok
"$session_name" "$chan_name"
85 add_context_kernel_skip_ok
"$session_name" "$chan_name" "$context_name" 4
86 if [ "$?" != "4" ]; then
87 enable_kernel_lttng_event_filter_ok
"$session_name" "read" "$chan_name" "\$ctx.$context_name == $ns_inode"
88 start_lttng_tracing_ok
"$session_name"
90 # Make sure there is at least one read syscall
91 cat /proc
/cmdline
>/dev
/null
93 stop_lttng_tracing_ok
"$session_name"
95 # Check that the events contain the right namespace inode number
96 validate_trace
"${ns}_ns = $ns_inode" "$trace_path"
99 destroy_lttng_session_ok
"$session_name"
106 plan_tests
$NUM_TESTS
108 print_test_banner
"$TEST_DESC"
112 if [ "$(id -u)" == "0" ]; then
116 skip
$isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" && exit 0
120 if [ -d "/proc/$$/ns" ]; then
124 skip
$system_has_ns "System does not support namespaces" $NUM_TESTS && exit 0
127 validate_lttng_modules_present