3 # Copyright (C) - 2013 David Goulet <dgoulet@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 TEST_DESC
="Streaming - Snapshot UST tracing"
10 TESTDIR
=$CURDIR/..
/..
/..
11 EVENT_NAME
="tp:tptest"
14 BIN_NAME
="gen-nevents"
15 TESTAPP_PATH
="$TESTDIR/utils/testapp"
16 TESTAPP_NAME
="gen-ust-events"
17 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
22 TRACE_PATH
=$
(mktemp
--tmpdir -d tmp.test_snapshots_ust_streaming_trace_path.XXXXXX
)
26 source $TESTDIR/utils
/utils.sh
28 if [ ! -x "$TESTAPP_BIN" ]; then
29 BAIL_OUT
"No UST events binary detected."
32 function snapshot_add_output
()
39 if [ ! -z $name ]; then
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"
47 # Start trace application and return once one event has been hit.
48 function start_test_app
()
50 local tmp_file
=$
(mktemp
--tmpdir -u tmp.test_
${FUNCNAME[0]}_tmp_file.XXXXXX
)
52 # Start application with a temporary file.
53 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event $tmp_file &
55 APPS_PID
="${APPS_PID} ${!}"
56 ok
$ret "Start application to trace"
58 # Wait for the application file to appear indicating that at least one
59 # tracepoint has been fired.
60 while [ ! -f "$tmp_file" ]; do
63 diag
"Removing test app temporary file $tmp_file"
67 function stop_test_apps
()
69 diag
"Stopping $TESTAPP_NAME"
70 for p
in ${APPS_PID}; do
77 # Test a snapshot using a default name for the output destination.
78 function test_ust_default_name_with_del
()
80 diag
"Test UST snapshot streaming with default name with delete output"
81 create_lttng_session_no_output
$SESSION_NAME
82 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
83 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
84 start_lttng_tracing_ok
$SESSION_NAME
88 snapshot_add_output
$SESSION_NAME "net://localhost"
89 lttng_snapshot_record
$SESSION_NAME
92 validate_trace_path_ust_uid_snapshot_network
"$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0
93 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1
*
99 lttng_snapshot_del_output_ok
$SESSION_NAME 1
100 snapshot_add_output
$SESSION_NAME "net://localhost"
101 lttng_snapshot_record
$SESSION_NAME
103 # Validate test with the next ID since a del output was done prior.
104 validate_trace_path_ust_uid_snapshot_network
"$TRACE_PATH" "$SESSION_NAME" "snapshot-2" 1
105 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-2
*
106 if [ $?
-ne 0 ]; then
111 stop_lttng_tracing_ok
$SESSION_NAME
112 destroy_lttng_session_ok
$SESSION_NAME
119 # Test a snapshot using a default name for the output destination.
120 function test_ust_default_name
()
122 diag
"Test UST snapshot streaming with default name"
123 create_lttng_session_no_output
$SESSION_NAME
124 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
125 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
126 start_lttng_tracing_ok
$SESSION_NAME
130 snapshot_add_output
$SESSION_NAME "net://localhost"
131 lttng_snapshot_record
$SESSION_NAME
132 stop_lttng_tracing_ok
$SESSION_NAME
133 destroy_lttng_session_ok
$SESSION_NAME
135 validate_trace_path_ust_uid_snapshot_network
"$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0
136 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1
*
144 function test_ust_default_name_custom_uri
()
146 diag
"Test UST snapshot streaming with default name with custom URL"
147 create_lttng_session_no_output
$SESSION_NAME
148 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
149 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
150 start_lttng_tracing_ok
$SESSION_NAME
154 snapshot_add_output
$SESSION_NAME "-C tcp://localhost:5342 -D tcp://localhost:5343"
155 lttng_snapshot_record
$SESSION_NAME
156 stop_lttng_tracing_ok
$SESSION_NAME
157 destroy_lttng_session_ok
$SESSION_NAME
159 validate_trace_path_ust_uid_snapshot_network
"$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0
160 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1
*
168 # Test a snapshot using a custom name for the output destination.
169 function test_ust_custom_name
()
172 local name
="asnapshotname"
174 diag
"Test UST snapshot streaming with custom name"
175 create_lttng_session_no_output
$SESSION_NAME
176 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
177 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
178 start_lttng_tracing_ok
$SESSION_NAME
182 snapshot_add_output
$SESSION_NAME "net://localhost" $name
183 lttng_snapshot_record
$SESSION_NAME
184 stop_lttng_tracing_ok
$SESSION_NAME
185 destroy_lttng_session_ok
$SESSION_NAME
187 if ls $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name* &> /dev
/null
; then
188 ok
0 "Custom name snapshot exists"
190 validate_trace_path_ust_uid_snapshot_network
"$TRACE_PATH" "$SESSION_NAME" "$name" 0
191 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name-*
194 fail
"No custom name snapshot found"
203 function test_ust_n_snapshot
()
205 diag
"Test ust snapshot streaming multiple consecutive snapshot"
206 create_lttng_session_no_output
$SESSION_NAME
207 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
208 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
209 snapshot_add_output
$SESSION_NAME "net://localhost"
213 start_lttng_tracing_ok
$SESSION_NAME
214 lttng_snapshot_record
$SESSION_NAME
215 stop_lttng_tracing_ok
$SESSION_NAME
216 validate_trace_path_ust_uid_snapshot_network
"$TRACE_PATH" "$SESSION_NAME" "snapshot-1" $i
217 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1
*
218 if [ $?
-ne 0 ]; then
222 rm -rf $TRACE_PATH/$HOSTNAME
226 destroy_lttng_session_ok
$SESSION_NAME
231 plan_tests
$NUM_TESTS
233 print_test_banner
"$TEST_DESC"
235 if [ "$(id -u)" == "0" ]; then
241 start_lttng_relayd
"-o $TRACE_PATH"
244 tests
=( test_ust_default_name_with_del
245 test_ust_default_name
247 test_ust_default_name_custom_uri
251 for fct_test
in ${tests[@]};
253 SESSION_NAME
=$
(randstring
16 0)
255 if [ $?
-eq 0 ]; then
256 # Only delete if successful