Generate session name and default output on sessiond's end
[lttng-tools.git] / tests / regression / tools / snapshots / test_ust_streaming
CommitLineData
ebaaaf5e
JD
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
17TEST_DESC="Streaming - Snapshot UST tracing"
18
19CURDIR=$(dirname $0)/
20TESTDIR=$CURDIR/../../..
21EVENT_NAME="tp:tptest"
ebaaaf5e
JD
22SESSION_NAME=""
23CHANNEL_NAME="chan1"
24BIN_NAME="gen-nevents"
25TESTAPP_PATH="$TESTDIR/utils/testapp"
26TESTAPP_NAME="gen-ust-events"
27TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
18c9d47c 28NR_ITER=-1
ebaaaf5e 29NR_USEC_WAIT=100
0fc2834c 30APPS_PID=
ebaaaf5e
JD
31
32TRACE_PATH=$(mktemp -d)
33
b61ccd96 34NUM_TESTS=75
ebaaaf5e
JD
35
36source $TESTDIR/utils/utils.sh
37
38if [ ! -x "$TESTAPP_BIN" ]; then
39 BAIL_OUT "No UST events binary detected."
40fi
41
42function snapshot_add_output ()
43{
44 local sess_name=$1
45 local trace_path=$2
46 local name=$3
47 local extra_opt=""
48
49 if [ ! -z $name ]; then
50 extra_opt="-n $name"
51 fi
52
53 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name $extra_opt $trace_path >/dev/null 2>&1
54 ok $? "Added snapshot output $trace_path"
55}
56
8c93562f 57# Start trace application and return once one event has been hit.
0fc2834c 58function start_test_app()
8c93562f 59{
5fcaccbc 60 local tmp_file=$(mktemp -u)
8c93562f
DG
61
62 # Start application with a temporary file.
63 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file &
0fc2834c
MD
64 ret=$?
65 APPS_PID="${APPS_PID} ${!}"
66 ok $ret "Start application to trace"
8c93562f
DG
67
68 # Wait for the application file to appear indicating that at least one
69 # tracepoint has been fired.
70 while [ ! -f "$tmp_file" ]; do
71 sleep 0.5
72 done
73 diag "Removing test app temporary file $tmp_file"
74 rm -f $tmp_file
75}
76
0fc2834c 77function stop_test_apps()
5dca3876 78{
0fc2834c
MD
79 diag "Stopping $TESTAPP_NAME"
80 for p in ${APPS_PID}; do
81 kill ${p}
5402fe87 82 wait ${p} 2>/dev/null
0fc2834c 83 done
c7613334 84 APPS_PID=
5dca3876
MD
85}
86
ebaaaf5e
JD
87# Test a snapshot using a default name for the output destination.
88function test_ust_default_name_with_del()
89{
90 diag "Test UST snapshot streaming with default name with delete output"
91 create_lttng_session_no_output $SESSION_NAME
92 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
c4926bb5 93 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
e563bbdb 94 start_lttng_tracing_ok $SESSION_NAME
8c93562f 95
0fc2834c 96 start_test_app
8c93562f 97
ebaaaf5e
JD
98 snapshot_add_output $SESSION_NAME "net://localhost"
99 lttng_snapshot_record $SESSION_NAME
100
101 # Validate test
b178f53e 102 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*
ebaaaf5e 103 if [ $? -ne 0 ]; then
0fc2834c 104 stop_test_apps
ebaaaf5e
JD
105 return $?
106 fi
107
31580dc7 108 lttng_snapshot_del_output_ok $SESSION_NAME 1
ebaaaf5e
JD
109 snapshot_add_output $SESSION_NAME "net://localhost"
110 lttng_snapshot_record $SESSION_NAME
111
112 # Validate test with the next ID since a del output was done prior.
b178f53e 113 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-2*
ebaaaf5e 114 if [ $? -ne 0 ]; then
0fc2834c 115 stop_test_apps
ebaaaf5e
JD
116 return $?
117 fi
118
96340a01 119 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 120 destroy_lttng_session_ok $SESSION_NAME
ebaaaf5e 121
0fc2834c 122 stop_test_apps
ebaaaf5e
JD
123
124 return 0
125}
126
127# Test a snapshot using a default name for the output destination.
128function test_ust_default_name()
129{
130 diag "Test UST snapshot streaming with default name"
131 create_lttng_session_no_output $SESSION_NAME
132 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
c4926bb5 133 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
e563bbdb 134 start_lttng_tracing_ok $SESSION_NAME
8c93562f 135
0fc2834c 136 start_test_app
8c93562f 137
ebaaaf5e
JD
138 snapshot_add_output $SESSION_NAME "net://localhost"
139 lttng_snapshot_record $SESSION_NAME
96340a01 140 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 141 destroy_lttng_session_ok $SESSION_NAME
ebaaaf5e 142 # Validate test
b178f53e 143 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*
ebaaaf5e
JD
144 out=$?
145
0fc2834c 146 stop_test_apps
ebaaaf5e
JD
147
148 return $out
149}
150
847b88a9
CB
151function test_ust_default_name_custom_uri()
152{
153 diag "Test UST snapshot streaming with default name with custom URL"
154 create_lttng_session_no_output $SESSION_NAME
155 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
c4926bb5 156 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
e563bbdb 157 start_lttng_tracing_ok $SESSION_NAME
8c93562f 158
0fc2834c 159 start_test_app
8c93562f 160
847b88a9
CB
161 snapshot_add_output $SESSION_NAME "-C tcp://localhost:5342 -D tcp://localhost:5343"
162 lttng_snapshot_record $SESSION_NAME
96340a01 163 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 164 destroy_lttng_session_ok $SESSION_NAME
847b88a9 165 # Validate test
b178f53e 166 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*
847b88a9
CB
167 out=$?
168
0fc2834c 169 stop_test_apps
847b88a9
CB
170
171 return $out
172}
173
ebaaaf5e
JD
174# Test a snapshot using a custom name for the output destination.
175function test_ust_custom_name()
176{
177 local out
178 local name="asnapshotname"
179
180 diag "Test UST snapshot streaming with custom name"
181 create_lttng_session_no_output $SESSION_NAME
182 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
c4926bb5 183 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
e563bbdb 184 start_lttng_tracing_ok $SESSION_NAME
8c93562f 185
0fc2834c 186 start_test_app
8c93562f 187
ebaaaf5e
JD
188 snapshot_add_output $SESSION_NAME "net://localhost" $name
189 lttng_snapshot_record $SESSION_NAME
96340a01 190 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 191 destroy_lttng_session_ok $SESSION_NAME
ebaaaf5e 192
b178f53e 193 if ls $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name* &> /dev/null; then
ebaaaf5e
JD
194 ok 0 "Custom name snapshot exists"
195 # Validate test
b178f53e 196 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name-*
ebaaaf5e
JD
197 out=$?
198 else
199 fail "No custom name snapshot found"
200 out=1
201 fi
202
0fc2834c 203 stop_test_apps
ebaaaf5e
JD
204
205 return $out
206}
207
b61ccd96
JR
208function test_ust_n_snapshot()
209{
210 diag "Test ust snapshot streaming multiple consecutive snapshot"
211 create_lttng_session_no_output $SESSION_NAME
212 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
213 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
214 snapshot_add_output $SESSION_NAME "net://localhost" $name
215 start_test_app
216 for i in {1..5};
217 do
218 start_lttng_tracing_ok $SESSION_NAME
219 lttng_snapshot_record $SESSION_NAME
220 stop_lttng_tracing_ok $SESSION_NAME
b178f53e 221 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*
b61ccd96
JR
222 if [ $? -ne 0 ]; then
223 return 1
224 fi
225 set -u
226 rm -rf $TRACE_PATH/$HOSTNAME
227 set +u
228 done
229
230 destroy_lttng_session_ok $SESSION_NAME
231 stop_test_apps
232 return 0
233}
234
ebaaaf5e
JD
235plan_tests $NUM_TESTS
236
237print_test_banner "$TEST_DESC"
238
239if [ "$(id -u)" == "0" ]; then
240 isroot=1
241else
242 isroot=0
243fi
244
245start_lttng_relayd "-o $TRACE_PATH"
246start_lttng_sessiond
247
b61ccd96
JR
248tests=( test_ust_default_name_with_del
249 test_ust_default_name
250 test_ust_custom_name
251 test_ust_default_name_custom_uri
252 test_ust_n_snapshot
253)
ebaaaf5e
JD
254
255for fct_test in ${tests[@]};
256do
257 SESSION_NAME=$(randstring 16 0)
258 ${fct_test}
259 if [ $? -eq 0 ]; then
260 # Only delete if successful
261 rm -rf $TRACE_PATH
262 else
263 break
264 fi
265done
266
267stop_lttng_sessiond
268stop_lttng_relayd
This page took 0.046776 seconds and 4 git commands to generate.