configure: enable -Wformat=2
[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#
9d16b343 5# SPDX-License-Identifier: LGPL-2.1-only
f62a3871
MJ
6
7TEST_DESC="Kernel tracer - Namespace contexts"
8
9CURDIR=$(dirname "$0")/
10TESTDIR=$CURDIR/../..
11
12TESTS_PER_NS=11
13
d37ac3cd 14NUM_TESTS=$((TESTS_PER_NS * 8))
f62a3871
MJ
15
16source "$TESTDIR/utils/utils.sh"
17
18# MUST set TESTDIR before calling those functions
19function add_context_kernel_skip_ok()
20{
21 local session_name=$1
22 local channel_name=$2
23 local context_name=$3
24 local skip_num=$4
25
26 local ret
27
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"
31 ret=$?
32
33 if [ "$ret" == "4" ]; then
34 skip 0 "Current kernel doesn't implement '$context_name' context" $((skip_num + 1))
35 else
36 ok $ret "Add context command for type: $context_name"
37 fi
38
39 return $ret
40}
41
42function enable_kernel_lttng_event_filter_ok()
43{
44 local session_name=$1
45 local syscall_name=$2
46 local channel_name=$3
47 local filter=$4
48
49 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event -k \
50 -c "$channel_name" -s "$session_name" \
51 --syscall "$syscall_name" \
52 -f "$filter" \
53 1>"$OUTPUT_DEST" 2>"$ERROR_OUTPUT_DEST"
54
55 ok $? "Add syscall with filter"
56}
57
58function test_ns()
59{
60 local ns=$1
61
62 local session_name="${ns}_ns"
63 local chan_name="${ns}_ns"
64 local context_name="${ns}_ns"
65
66 local trace_path
67 local ns_inode
68
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
72 return
73 fi
74
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"
78
33e55711 79 trace_path=$(mktemp --tmpdir -d tmp.{FUNCNAME[0]}_trace_path.XXXXXX)
f62a3871
MJ
80
81 start_lttng_sessiond
82
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"
89
90 # Make sure there is at least one read syscall
91 cat /proc/cmdline >/dev/null
92
93 stop_lttng_tracing_ok "$session_name"
94
95 # Check that the events contain the right namespace inode number
96 validate_trace "${ns}_ns = $ns_inode" "$trace_path"
97 fi
98
99 destroy_lttng_session_ok "$session_name"
100 stop_lttng_sessiond
101
102 rm -rf "$trace_path"
103}
104
105
106plan_tests $NUM_TESTS
107
108print_test_banner "$TEST_DESC"
109
110
111isroot=0
112if [ "$(id -u)" == "0" ]; then
113 isroot=1
114fi
115
116skip $isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" && exit 0
117
118
119system_has_ns=0
120if [ -d "/proc/$$/ns" ]; then
121 system_has_ns=1
122fi
123
124skip $system_has_ns "System does not support namespaces" $NUM_TESTS && exit 0
125
126
127validate_lttng_modules_present
128
129test_ns cgroup
130test_ns ipc
131test_ns mnt
132test_ns net
133test_ns pid
d37ac3cd 134test_ns time
f62a3871
MJ
135test_ns user
136test_ns uts
This page took 0.044478 seconds and 4 git commands to generate.