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"
24 BIN_NAME
="gen-nevents"
25 TESTAPP_PATH
="$TESTDIR/utils/testapp"
26 TESTAPP_NAME
="gen-ust-events"
27 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_test_app
()
60 local tmp_file
=$
(mktemp
-u)
62 # Start application with a temporary file.
63 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file &
65 APPS_PID
="${APPS_PID} ${!}"
66 ok
$ret "Start application to trace"
68 # Wait for the application file to appear indicating that at least one
69 # tracepoint has been fired.
70 while [ ! -f "$tmp_file" ]; do
73 diag
"Removing test app temporary file $tmp_file"
77 function stop_test_apps
()
79 diag
"Stopping $TESTAPP_NAME"
80 for p
in ${APPS_PID}; do
87 # Test a snapshot using a default name for the output destination.
88 function test_ust_default_name_with_del
()
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
93 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
94 start_lttng_tracing_ok
$SESSION_NAME
98 snapshot_add_output
$SESSION_NAME "net://localhost"
99 lttng_snapshot_record
$SESSION_NAME
102 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1
*
103 if [ $?
-ne 0 ]; then
108 lttng_snapshot_del_output_ok
$SESSION_NAME 1
109 snapshot_add_output
$SESSION_NAME "net://localhost"
110 lttng_snapshot_record
$SESSION_NAME
112 # Validate test with the next ID since a del output was done prior.
113 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-2
*
114 if [ $?
-ne 0 ]; then
119 stop_lttng_tracing_ok
$SESSION_NAME
120 destroy_lttng_session_ok
$SESSION_NAME
127 # Test a snapshot using a default name for the output destination.
128 function test_ust_default_name
()
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
133 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
134 start_lttng_tracing_ok
$SESSION_NAME
138 snapshot_add_output
$SESSION_NAME "net://localhost"
139 lttng_snapshot_record
$SESSION_NAME
140 stop_lttng_tracing_ok
$SESSION_NAME
141 destroy_lttng_session_ok
$SESSION_NAME
143 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1
*
151 function test_ust_default_name_custom_uri
()
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
156 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
157 start_lttng_tracing_ok
$SESSION_NAME
161 snapshot_add_output
$SESSION_NAME "-C tcp://localhost:5342 -D tcp://localhost:5343"
162 lttng_snapshot_record
$SESSION_NAME
163 stop_lttng_tracing_ok
$SESSION_NAME
164 destroy_lttng_session_ok
$SESSION_NAME
166 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1
*
174 # Test a snapshot using a custom name for the output destination.
175 function test_ust_custom_name
()
178 local name
="asnapshotname"
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
183 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
184 start_lttng_tracing_ok
$SESSION_NAME
188 snapshot_add_output
$SESSION_NAME "net://localhost" $name
189 lttng_snapshot_record
$SESSION_NAME
190 stop_lttng_tracing_ok
$SESSION_NAME
191 destroy_lttng_session_ok
$SESSION_NAME
193 if ls $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name* &> /dev
/null
; then
194 ok
0 "Custom name snapshot exists"
196 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name-*
199 fail
"No custom name snapshot found"
208 function test_ust_n_snapshot
()
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
218 start_lttng_tracing_ok
$SESSION_NAME
219 lttng_snapshot_record
$SESSION_NAME
220 stop_lttng_tracing_ok
$SESSION_NAME
221 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1
*
222 if [ $?
-ne 0 ]; then
226 rm -rf $TRACE_PATH/$HOSTNAME
230 destroy_lttng_session_ok
$SESSION_NAME
235 plan_tests
$NUM_TESTS
237 print_test_banner
"$TEST_DESC"
239 if [ "$(id -u)" == "0" ]; then
245 start_lttng_relayd
"-o $TRACE_PATH"
248 tests
=( test_ust_default_name_with_del
249 test_ust_default_name
251 test_ust_default_name_custom_uri
255 for fct_test
in ${tests[@]};
257 SESSION_NAME
=$
(randstring
16 0)
259 if [ $?
-eq 0 ]; then
260 # Only delete if successful