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"
33 TRACE_PATH
=$
(mktemp
-d)
37 source $TESTDIR/utils
/utils.sh
39 if [ ! -x "$TESTAPP_BIN" ]; then
40 BAIL_OUT
"No UST events binary detected."
43 function snapshot_add_output
()
50 if [ ! -z $name ]; then
54 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output
-s $sess_name $extra_opt $trace_path >/dev
/null
2>&1
55 ok $?
"Added snapshot output $trace_path"
58 # Start trace application and return once one event has been hit.
59 function start_test_app
()
61 local tmp_file
="/tmp/lttng_test_ust.42.file"
63 # Start application with a temporary file.
64 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file &
66 APPS_PID
="${APPS_PID} ${!}"
67 ok
$ret "Start application to trace"
69 # Wait for the application file to appear indicating that at least one
70 # tracepoint has been fired.
71 while [ ! -f "$tmp_file" ]; do
74 diag
"Removing test app temporary file $tmp_file"
78 function stop_test_apps
()
80 diag
"Stopping $TESTAPP_NAME"
81 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
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
94 start_lttng_tracing
$SESSION_NAME
98 snapshot_add_output
$SESSION_NAME "net://localhost"
99 lttng_snapshot_record
$SESSION_NAME
102 echo $TRACE_PATH/$HOSTNAME/snapshot-1
103 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1
*
104 if [ $?
-ne 0 ]; then
109 lttng_snapshot_del_output
$SESSION_NAME 1
110 snapshot_add_output
$SESSION_NAME "net://localhost"
111 lttng_snapshot_record
$SESSION_NAME
113 # Validate test with the next ID since a del output was done prior.
114 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-2
*
115 if [ $?
-ne 0 ]; then
120 stop_lttng_tracing
$SESSION_NAME
121 destroy_lttng_session
$SESSION_NAME
128 # Test a snapshot using a default name for the output destination.
129 function test_ust_default_name
()
131 diag
"Test UST snapshot streaming with default name"
132 create_lttng_session_no_output
$SESSION_NAME
133 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
134 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
135 start_lttng_tracing
$SESSION_NAME
139 snapshot_add_output
$SESSION_NAME "net://localhost"
140 lttng_snapshot_record
$SESSION_NAME
141 stop_lttng_tracing
$SESSION_NAME
142 destroy_lttng_session
$SESSION_NAME
144 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1
*
152 function test_ust_default_name_custom_uri
()
154 diag
"Test UST snapshot streaming with default name with custom URL"
155 create_lttng_session_no_output
$SESSION_NAME
156 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
157 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
158 start_lttng_tracing
$SESSION_NAME
162 snapshot_add_output
$SESSION_NAME "-C tcp://localhost:5342 -D tcp://localhost:5343"
163 lttng_snapshot_record
$SESSION_NAME
164 stop_lttng_tracing
$SESSION_NAME
165 destroy_lttng_session
$SESSION_NAME
167 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1
*
175 # Test a snapshot using a custom name for the output destination.
176 function test_ust_custom_name
()
179 local name
="asnapshotname"
181 diag
"Test UST snapshot streaming with custom name"
182 create_lttng_session_no_output
$SESSION_NAME
183 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
184 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
185 start_lttng_tracing
$SESSION_NAME
189 snapshot_add_output
$SESSION_NAME "net://localhost" $name
190 lttng_snapshot_record
$SESSION_NAME
191 stop_lttng_tracing
$SESSION_NAME
192 destroy_lttng_session
$SESSION_NAME
194 if ls $TRACE_PATH/$HOSTNAME/$name* &> /dev
/null
; then
195 ok
0 "Custom name snapshot exists"
197 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/$name-*
200 fail
"No custom name snapshot found"
209 plan_tests
$NUM_TESTS
211 print_test_banner
"$TEST_DESC"
213 if [ "$(id -u)" == "0" ]; then
219 start_lttng_relayd
"-o $TRACE_PATH"
222 tests
=( test_ust_default_name_with_del test_ust_default_name test_ust_custom_name test_ust_default_name_custom_uri
)
224 for fct_test
in ${tests[@]};
226 SESSION_NAME
=$
(randstring
16 0)
228 if [ $?
-eq 0 ]; then
229 # Only delete if successful