Tests: add UST namespace contexts tests
[lttng-tools.git] / tests / regression / ust / namespaces / test_ns_contexts
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
18 TEST_DESC="UST - Namespace contexts"
19
20 CURDIR=$(dirname "$0")/
21 TESTDIR=$CURDIR/../../..
22
23 TESTAPP_PATH="$TESTDIR/utils/testapp"
24 TESTAPP_NAME="gen-ust-events"
25 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
26 NUM_EVENT=10000
27 EVENT_NAME="tp:tptest"
28
29 TESTS_PER_NS=13
30
31 NUM_TESTS=$((TESTS_PER_NS * 7))
32
33 source "$TESTDIR/utils/utils.sh"
34
35 # MUST set TESTDIR before calling those functions
36 function run_app()
37 {
38 $TESTAPP_BIN $NUM_EVENT
39 ok $? "Application done"
40 }
41
42 function test_ns()
43 {
44 local ns=$1
45
46 local session_name="${ns}_ns"
47 local chan_name="${ns}_ns"
48 local context_name="${ns}_ns"
49
50 local trace_path
51 local ns_inode
52
53 # Check if the kernel has support for this ns type
54 if [ ! -f "/proc/$$/ns/$ns" ]; then
55 skip 0 "System has no $ns namespace support" $TESTS_PER_NS
56 return
57 fi
58
59 # Get the current ns inode number
60 ns_inode=$(stat -c '%i' -L "/proc/$$/ns/$ns")
61 ok $? "Get current $ns namespace inode: $ns_inode"
62
63 trace_path=$(mktemp -d)
64
65 start_lttng_sessiond
66
67 create_lttng_session_ok "$session_name" "$trace_path"
68 enable_ust_lttng_channel_ok "$session_name" "$chan_name"
69 add_context_ust_ok "$session_name" "$chan_name" "$context_name"
70 enable_ust_lttng_event_ok "$session_name" "$EVENT_NAME" "$chan_name"
71 start_lttng_tracing_ok "$session_name"
72
73 run_app
74
75 # stop and destroy
76 stop_lttng_tracing_ok "$session_name"
77 destroy_lttng_session_ok "$session_name"
78 stop_lttng_sessiond
79
80 # Check that the events contain the right namespace inode number
81 validate_trace_count "${ns}_ns = $ns_inode" "$trace_path" $NUM_EVENT
82
83 rm -rf "$trace_path"
84 }
85
86
87 plan_tests $NUM_TESTS
88
89 print_test_banner "$TEST_DESC"
90
91 system_has_ns=0
92 if [ -d "/proc/$$/ns" ]; then
93 system_has_ns=1
94 fi
95
96 skip $system_has_ns "System does not support namespaces" $NUM_TESTS && exit 0
97
98 test_ns cgroup
99 test_ns ipc
100 test_ns mnt
101 test_ns net
102 test_ns pid
103 test_ns user
104 test_ns uts
This page took 0.045232 seconds and 4 git commands to generate.