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 _run_lttng_cmd
"$(lttng_client_log_file)" "$(lttng_client_err_file)" add-context
-k \
29 -s "$session_name" -c "$channel_name" -t "$context_name"
32 if [ "$ret" == "4" ]; then
33 skip
0 "Current kernel doesn't implement '$context_name' context" $
((skip_num
+ 1))
35 ok
$ret "Add context command for type: $context_name"
41 function enable_kernel_lttng_event_filter_ok
()
48 _run_lttng_cmd
"$(lttng_client_log_file)" "$(lttng_client_err_file)" enable-event
-k \
49 -c "$channel_name" -s "$session_name" --syscall "$syscall_name" \
52 ok $?
"Add syscall with filter"
59 local session_name
="${ns}_ns"
60 local chan_name
="${ns}_ns"
61 local context_name
="${ns}_ns"
66 # Check if the kernel has support for this ns type
67 if [ ! -f "/proc/$$/ns/$ns" ]; then
68 skip
0 "System has no $ns namespace support" $TESTS_PER_NS
72 # Get the current ns inode number
73 ns_inode
=$
(stat
-c '%i' -L "/proc/$$/ns/$ns")
74 ok $?
"Get current $ns namespace inode: $ns_inode"
76 trace_path
=$
(mktemp
-d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
80 create_lttng_session_ok
"$session_name" "$trace_path"
81 enable_kernel_lttng_channel_ok
"$session_name" "$chan_name"
82 add_context_kernel_skip_ok
"$session_name" "$chan_name" "$context_name" 4
83 if [ "$?" != "4" ]; then
84 enable_kernel_lttng_event_filter_ok
"$session_name" "read" "$chan_name" "\$ctx.$context_name == $ns_inode"
85 start_lttng_tracing_ok
"$session_name"
87 # Make sure there is at least one read syscall
88 cat /proc
/cmdline
>/dev
/null
90 stop_lttng_tracing_ok
"$session_name"
92 # Check that the events contain the right namespace inode number
93 validate_trace
"${ns}_ns = $ns_inode" "$trace_path"
96 destroy_lttng_session_ok
"$session_name"
103 plan_tests
$NUM_TESTS
105 print_test_banner
"$TEST_DESC"
108 check_skip_kernel_test
"$NUM_TESTS" "Skipping all tests." && exit 0
111 if [ -d "/proc/$$/ns" ]; then
115 skip
$system_has_ns "System does not support namespaces" $NUM_TESTS && exit 0
118 validate_lttng_modules_present