3 # Copyright (C) - 2013 David Goulet <dgoulet@efficios.com>
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.
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
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 UST tracing"
20 TESTDIR
=$CURDIR/..
/..
/..
21 EVENT_NAME
="tp:tptest"
25 BIN_NAME
="gen-nevents"
26 TESTAPP_PATH
="$TESTDIR/utils/testapp"
27 TESTAPP_NAME
="gen-ust-events"
28 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
32 TRACE_PATH
=$
(mktemp
-d)
36 source $TESTDIR/utils
/utils.sh
38 if [ ! -x "$TESTAPP_BIN" ]; then
39 BAIL_OUT
"No UST events binary detected."
42 function snapshot_add_output
()
49 if [ ! -z $name ]; then
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"
57 # Start trace application and return once one event has been hit.
58 function start_trace_app
()
60 local tmp_file
="/tmp/lttng_test_ust.42.file"
62 # Start application with a temporary file.
63 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file &
64 ok $?
"Start application to trace"
66 # Wait for the application file to appear indicating that at least one
67 # tracepoint has been fired.
68 while [ ! -f "$tmp_file" ]; do
71 diag
"Removing test app temporary file $tmp_file"
75 # Test a snapshot using a default name for the output destination.
76 function test_ust_default_name_with_del
()
78 diag
"Test UST snapshot streaming with default name with delete output"
79 create_lttng_session_no_output
$SESSION_NAME
80 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
81 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
82 start_lttng_tracing
$SESSION_NAME
86 snapshot_add_output
$SESSION_NAME "net://localhost"
87 lttng_snapshot_record
$SESSION_NAME
90 echo $TRACE_PATH/$HOSTNAME/snapshot-1
91 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1
*
96 lttng_snapshot_del_output
$SESSION_NAME 1
97 snapshot_add_output
$SESSION_NAME "net://localhost"
98 lttng_snapshot_record
$SESSION_NAME
100 # Validate test with the next ID since a del output was done prior.
101 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-2
*
102 if [ $?
-ne 0 ]; then
106 stop_lttng_tracing
$SESSION_NAME
107 destroy_lttng_session
$SESSION_NAME
109 diag
"Killing $TESTAPP_NAME"
110 PID_APP
=`pidof $TESTAPP_NAME`
111 kill $PID_APP >/dev
/null
2>&1
116 # Test a snapshot using a default name for the output destination.
117 function test_ust_default_name
()
119 diag
"Test UST snapshot streaming with default name"
120 create_lttng_session_no_output
$SESSION_NAME
121 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
122 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
123 start_lttng_tracing
$SESSION_NAME
127 snapshot_add_output
$SESSION_NAME "net://localhost"
128 lttng_snapshot_record
$SESSION_NAME
129 stop_lttng_tracing
$SESSION_NAME
130 destroy_lttng_session
$SESSION_NAME
132 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1
*
135 diag
"Killing $TESTAPP_NAME"
136 PID_APP
=`pidof $TESTAPP_NAME`
137 kill $PID_APP >/dev
/null
2>&1
142 function test_ust_default_name_custom_uri
()
144 diag
"Test UST snapshot streaming with default name with custom URL"
145 create_lttng_session_no_output
$SESSION_NAME
146 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
147 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
148 start_lttng_tracing
$SESSION_NAME
152 snapshot_add_output
$SESSION_NAME "-C tcp://localhost:5342 -D tcp://localhost:5343"
153 lttng_snapshot_record
$SESSION_NAME
154 stop_lttng_tracing
$SESSION_NAME
155 destroy_lttng_session
$SESSION_NAME
157 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1
*
160 diag
"Killing $TESTAPP_NAME"
161 PID_APP
=`pidof $TESTAPP_NAME`
162 kill $PID_APP >/dev
/null
2>&1
167 # Test a snapshot using a custom name for the output destination.
168 function test_ust_custom_name
()
171 local name
="asnapshotname"
173 diag
"Test UST snapshot streaming with custom name"
174 create_lttng_session_no_output
$SESSION_NAME
175 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
176 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
177 start_lttng_tracing
$SESSION_NAME
181 snapshot_add_output
$SESSION_NAME "net://localhost" $name
182 lttng_snapshot_record
$SESSION_NAME
183 stop_lttng_tracing
$SESSION_NAME
184 destroy_lttng_session
$SESSION_NAME
186 if ls $TRACE_PATH/$HOSTNAME/$name* &> /dev
/null
; then
187 ok
0 "Custom name snapshot exists"
189 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/$name-*
192 fail
"No custom name snapshot found"
196 diag
"Killing $TESTAPP_NAME"
197 PID_APP
=`pidof $TESTAPP_NAME`
198 kill $PID_APP >/dev
/null
2>&1
203 plan_tests
$NUM_TESTS
205 print_test_banner
"$TEST_DESC"
207 if [ "$(id -u)" == "0" ]; then
213 start_lttng_relayd
"-o $TRACE_PATH"
216 tests
=( test_ust_default_name_with_del test_ust_default_name test_ust_custom_name test_ust_default_name_custom_uri
)
218 for fct_test
in ${tests[@]};
220 SESSION_NAME
=$
(randstring
16 0)
222 if [ $?
-eq 0 ]; then
223 # Only delete if successful