Tests: add kernel namespace contexts tests
[lttng-tools.git] / tests / regression / kernel / test_ns_contexts
CommitLineData
f62a3871
MJ
1#!/bin/bash
2#
3# Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com>
4#
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.
8#
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
12# details.
13#
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
17
18TEST_DESC="Kernel tracer - Namespace contexts"
19
20CURDIR=$(dirname "$0")/
21TESTDIR=$CURDIR/../..
22
23TESTS_PER_NS=11
24
25NUM_TESTS=$((TESTS_PER_NS * 7))
26
27source "$TESTDIR/utils/utils.sh"
28
29# MUST set TESTDIR before calling those functions
30function add_context_kernel_skip_ok()
31{
32 local session_name=$1
33 local channel_name=$2
34 local context_name=$3
35 local skip_num=$4
36
37 local ret
38
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"
42 ret=$?
43
44 if [ "$ret" == "4" ]; then
45 skip 0 "Current kernel doesn't implement '$context_name' context" $((skip_num + 1))
46 else
47 ok $ret "Add context command for type: $context_name"
48 fi
49
50 return $ret
51}
52
53function enable_kernel_lttng_event_filter_ok()
54{
55 local session_name=$1
56 local syscall_name=$2
57 local channel_name=$3
58 local filter=$4
59
60 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event -k \
61 -c "$channel_name" -s "$session_name" \
62 --syscall "$syscall_name" \
63 -f "$filter" \
64 1>"$OUTPUT_DEST" 2>"$ERROR_OUTPUT_DEST"
65
66 ok $? "Add syscall with filter"
67}
68
69function test_ns()
70{
71 local ns=$1
72
73 local session_name="${ns}_ns"
74 local chan_name="${ns}_ns"
75 local context_name="${ns}_ns"
76
77 local trace_path
78 local ns_inode
79
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
83 return
84 fi
85
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"
89
90 trace_path=$(mktemp -d)
91
92 start_lttng_sessiond
93
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"
100
101 # Make sure there is at least one read syscall
102 cat /proc/cmdline >/dev/null
103
104 stop_lttng_tracing_ok "$session_name"
105
106 # Check that the events contain the right namespace inode number
107 validate_trace "${ns}_ns = $ns_inode" "$trace_path"
108 fi
109
110 destroy_lttng_session_ok "$session_name"
111 stop_lttng_sessiond
112
113 rm -rf "$trace_path"
114}
115
116
117plan_tests $NUM_TESTS
118
119print_test_banner "$TEST_DESC"
120
121
122isroot=0
123if [ "$(id -u)" == "0" ]; then
124 isroot=1
125fi
126
127skip $isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" && exit 0
128
129
130system_has_ns=0
131if [ -d "/proc/$$/ns" ]; then
132 system_has_ns=1
133fi
134
135skip $system_has_ns "System does not support namespaces" $NUM_TESTS && exit 0
136
137
138validate_lttng_modules_present
139
140test_ns cgroup
141test_ns ipc
142test_ns mnt
143test_ns net
144test_ns pid
145test_ns user
146test_ns uts
This page took 0.040322 seconds and 4 git commands to generate.