Backport: Tests: use modprobe to test for the presence of lttng-modules
[lttng-tools.git] / tests / regression / tools / snapshots / test_kernel_streaming
1 #!/bin/bash
2 #
3 # Copyright (C) - 2013 David Goulet <dgoulet@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 TEST_DESC="Streaming - Snapshot Kernel tracing"
18
19 CURDIR=$(dirname $0)/
20 TESTDIR=$CURDIR/../../..
21 EVENT_NAME="sched_switch"
22 PID_RELAYD=0
23 SESSION_NAME=""
24 CHANNEL_NAME="chan1"
25
26 TRACE_PATH=$(mktemp -d)
27
28 NUM_TESTS=61
29
30 source $TESTDIR/utils/utils.sh
31
32 function snapshot_add_output ()
33 {
34 local sess_name=$1
35 local trace_path=$2
36 local name=$3
37 local extra_opt=""
38
39 if [ ! -z $name ]; then
40 extra_opt="-n $name"
41 fi
42
43 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name $extra_opt $trace_path >/dev/null 2>&1
44 ok $? "Added snapshot output $trace_path"
45 }
46
47 # Test a snapshot using a default name for the output destination.
48 function test_kernel_default_name_with_del()
49 {
50 diag "Test kernel snapshot streaming with default name with delete output"
51 create_lttng_session_no_output $SESSION_NAME
52 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
53 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
54 start_lttng_tracing_ok $SESSION_NAME
55 snapshot_add_output $SESSION_NAME "net://localhost"
56 lttng_snapshot_record $SESSION_NAME
57
58 # Validate test
59 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1*
60 if [ $? -ne 0 ]; then
61 return $?
62 fi
63
64 lttng_snapshot_del_output_ok $SESSION_NAME 1
65 snapshot_add_output $SESSION_NAME "net://localhost"
66 lttng_snapshot_record $SESSION_NAME
67
68 # Validate test with the next ID since a del output was done prior.
69 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-2*
70 if [ $? -ne 0 ]; then
71 return $?
72 fi
73
74 stop_lttng_tracing_ok $SESSION_NAME
75 destroy_lttng_session_ok $SESSION_NAME
76
77 return 0
78 }
79
80 # Test a snapshot using a default name for the output destination.
81 function test_kernel_default_name()
82 {
83 diag "Test kernel snapshot streaming with default name"
84 create_lttng_session_no_output $SESSION_NAME
85 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
86 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
87 start_lttng_tracing_ok $SESSION_NAME
88 snapshot_add_output $SESSION_NAME "net://localhost"
89 lttng_snapshot_record $SESSION_NAME
90 stop_lttng_tracing_ok $SESSION_NAME
91 destroy_lttng_session_ok $SESSION_NAME
92 # Validate test
93 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1*
94 out=$?
95
96 return $out
97 }
98
99 # Test a snapshot using a custom name for the output destination.
100 function test_kernel_custom_name()
101 {
102 local out
103 local name="asnapshotname"
104
105 diag "Test kernel snapshot streaming with custom name"
106 create_lttng_session_no_output $SESSION_NAME
107 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
108 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
109 start_lttng_tracing_ok $SESSION_NAME
110 snapshot_add_output $SESSION_NAME "net://localhost" $name
111 lttng_snapshot_record $SESSION_NAME
112 stop_lttng_tracing_ok $SESSION_NAME
113 destroy_lttng_session_ok $SESSION_NAME
114
115 if ls $TRACE_PATH/$HOSTNAME/$name* &> /dev/null; then
116 ok 0 "Custom name snapshot exists"
117 # Validate test
118 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$name-*
119 out=$?
120 else
121 fail "No custom name snapshot found"
122 out=1
123 fi
124
125 return $out
126 }
127
128 function test_kernel_n_snapshot()
129 {
130 diag "Test kernel snapshot streaming multiple consecutive snapshot"
131 create_lttng_session_no_output $SESSION_NAME
132 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
133 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
134 snapshot_add_output $SESSION_NAME "net://localhost"
135
136 for i in {1..5};
137 do
138 start_lttng_tracing_ok $SESSION_NAME
139 lttng_snapshot_record $SESSION_NAME
140 stop_lttng_tracing_ok $SESSION_NAME
141 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1*
142 if [ $? -ne 0 ]; then
143 return 1
144 fi
145 set -u
146 rm -rf $TRACE_PATH/$HOSTNAME
147 set +u
148 done
149
150 destroy_lttng_session_ok $SESSION_NAME
151 return 0
152 }
153
154 plan_tests $NUM_TESTS
155
156 print_test_banner "$TEST_DESC"
157
158 if [ "$(id -u)" == "0" ]; then
159 isroot=1
160 else
161 isroot=0
162 fi
163
164 skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS ||
165 {
166 validate_lttng_modules_present
167
168 start_lttng_relayd "-o $TRACE_PATH"
169 start_lttng_sessiond
170
171 tests=( test_kernel_default_name
172 test_kernel_custom_name
173 test_kernel_default_name_with_del
174 test_kernel_n_snapshot
175 )
176
177 for fct_test in ${tests[@]};
178 do
179 SESSION_NAME=$(randstring 16 0)
180 ${fct_test}
181 if [ $? -eq 0 ]; then
182 # Only delete if successful
183 rm -rf $TRACE_PATH
184 else
185 break
186 fi
187 done
188
189 stop_lttng_sessiond
190 stop_lttng_relayd
191 }
This page took 0.050384 seconds and 5 git commands to generate.