Tests: Fix: Use '.logfile' instead of '.log' for test app output
[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
b445e3da
KS
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"
f62a3871
MJ
30 ret=$?
31
32 if [ "$ret" == "4" ]; then
33 skip 0 "Current kernel doesn't implement '$context_name' context" $((skip_num + 1))
34 else
35 ok $ret "Add context command for type: $context_name"
36 fi
37
38 return $ret
39}
40
41function enable_kernel_lttng_event_filter_ok()
42{
43 local session_name=$1
44 local syscall_name=$2
45 local channel_name=$3
46 local filter=$4
47
b445e3da
KS
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" \
50 -f "$filter"
f62a3871
MJ
51
52 ok $? "Add syscall with filter"
53}
54
55function test_ns()
56{
57 local ns=$1
58
59 local session_name="${ns}_ns"
60 local chan_name="${ns}_ns"
61 local context_name="${ns}_ns"
62
63 local trace_path
64 local ns_inode
65
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
69 return
70 fi
71
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"
75
9b456a42 76 trace_path=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
f62a3871
MJ
77
78 start_lttng_sessiond
79
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"
86
87 # Make sure there is at least one read syscall
88 cat /proc/cmdline >/dev/null
89
90 stop_lttng_tracing_ok "$session_name"
91
92 # Check that the events contain the right namespace inode number
93 validate_trace "${ns}_ns = $ns_inode" "$trace_path"
94 fi
95
96 destroy_lttng_session_ok "$session_name"
97 stop_lttng_sessiond
98
99 rm -rf "$trace_path"
100}
101
102
103plan_tests $NUM_TESTS
104
105print_test_banner "$TEST_DESC"
106
107
3a174400 108check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." && exit 0
f62a3871
MJ
109
110system_has_ns=0
111if [ -d "/proc/$$/ns" ]; then
112 system_has_ns=1
113fi
114
115skip $system_has_ns "System does not support namespaces" $NUM_TESTS && exit 0
116
117
118validate_lttng_modules_present
119
120test_ns cgroup
121test_ns ipc
122test_ns mnt
123test_ns net
124test_ns pid
d37ac3cd 125test_ns time
f62a3871
MJ
126test_ns user
127test_ns uts
This page took 0.055242 seconds and 5 git commands to generate.