3 # Copyright (C) 2015 Julien Desfossez <jdesfossez@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 TEST_DESC
="Streaming - User space tracing"
10 TESTDIR
=$CURDIR/..
/..
/..
13 TESTAPP_PATH
="$TESTDIR/utils/testapp"
14 TESTAPP_NAME
="gen-ust-events"
15 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
17 EVENT_NAME
="tp:tptest"
19 TRACE_PATH
=$
(mktemp
--tmpdir -d tmp.test_regen_metadata_ust_trace_path.XXXXXX
)
23 source $TESTDIR/utils
/utils.sh
25 if [ ! -x "$TESTAPP_BIN" ]; then
26 BAIL_OUT
"No UST events binary detected."
29 function enable_channel_per_pid
()
34 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
--buffers-pid -u $channel_name -s $sess_name >/dev
/null
2>&1
35 ok $?
"Enable channel $channel_name per PID for session $sess_name"
38 # MUST set TESTDIR before calling those functions
40 function test_ust_streaming
()
42 local file_sync_after_first
=$
(mktemp
--tmpdir -u "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX")
43 local file_sync_before_last
=$
(mktemp
--tmpdir -u "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
46 diag
"Test UST streaming with metadata regeneration"
47 create_lttng_session_uri
$SESSION_NAME net
://localhost
48 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME
50 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
51 --sync-after-first-event ${file_sync_after_first} \
52 --sync-before-last-event ${file_sync_before_last} >/dev
/null
2>&1 &
54 start_lttng_tracing_ok
$SESSION_NAME
56 touch ${file_sync_before_last}
58 # Wait for the applications started in background
61 # Expect a valid trace
62 stop_lttng_tracing_ok
$SESSION_NAME
63 validate_trace
$EVENT_NAME "$TRACE_PATH/$HOSTNAME/$SESSION_NAME"*
65 # Find the metadata file
66 metadata_path
=$
(find "$TRACE_PATH/$HOSTNAME/$SESSION_NAME"* -name "metadata")
68 # Empty the metadata file
69 echo -n > "$metadata_path"
71 start_lttng_tracing_ok
$SESSION_NAME
72 regenerate_metadata_ok
$SESSION_NAME
73 stop_lttng_tracing_ok
$SESSION_NAME
75 # Metadata file must have been regenerated
76 validate_trace
$EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
77 destroy_lttng_session_ok
$SESSION_NAME
80 rm -f ${file_sync_after_first}
81 rm -f ${file_sync_before_last}
84 function test_ust_local
()
86 local file_sync_after_first
=$
(mktemp
--tmpdir -u "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX")
87 local file_sync_before_last
=$
(mktemp
--tmpdir -u "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
90 diag
"Test UST local with metadata regeneration"
91 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
92 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME
94 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
95 --sync-after-first-event ${file_sync_after_first} \
96 --sync-before-last-event ${file_sync_before_last} > /dev
/null
2>&1 &
98 start_lttng_tracing_ok
$SESSION_NAME
100 touch ${file_sync_before_last}
102 # Wait for the applications started in background
105 # Expect a valid trace
106 stop_lttng_tracing_ok
$SESSION_NAME
107 validate_trace
$EVENT_NAME "$TRACE_PATH"
109 # Find the metadata file
110 metadata_path
=$
(find "$TRACE_PATH"* -name "metadata")
112 # Empty the metadata file
113 echo -n > "$metadata_path"
115 start_lttng_tracing_ok
$SESSION_NAME
116 regenerate_metadata_ok
$SESSION_NAME
117 stop_lttng_tracing_ok
$SESSION_NAME
119 # Metadata file must have been regenerated
120 validate_trace
$EVENT_NAME $TRACE_PATH
121 destroy_lttng_session_ok
$SESSION_NAME
124 rm -f ${file_sync_after_first}
125 rm -f ${file_sync_before_last}
128 function test_ust_pid
()
130 local file_sync_after_first
=$
(mktemp
--tmpdir -u "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX")
131 local file_sync_before_last
=$
(mktemp
--tmpdir -u "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
133 diag
"Test UST per-pid with metadata regeneration (expect failure)"
134 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
135 enable_channel_per_pid
$SESSION_NAME "channel0"
136 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME "channel0"
138 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
139 --sync-after-first-event ${file_sync_after_first} \
140 --sync-before-last-event ${file_sync_before_last} >/dev
/null
2>&1 &
142 start_lttng_tracing_ok
$SESSION_NAME
144 touch ${file_sync_before_last}
146 # Wait for the applications started in background
148 regenerate_metadata_fail
$SESSION_NAME
150 stop_lttng_tracing_ok
$SESSION_NAME
151 destroy_lttng_session_ok
$SESSION_NAME
153 validate_trace
$EVENT_NAME $TRACE_PATH
154 if [ $?
-eq 0 ]; then
155 # Only delete if successful
158 rm -f ${file_sync_after_first}
159 rm -f ${file_sync_before_last}
162 function test_ust_live
()
164 local file_sync_after_first
=$
(mktemp
--tmpdir -u "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX")
165 local file_sync_before_last
=$
(mktemp
--tmpdir -u "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
167 diag
"Test UST live with metadata regeneration (expect failure)"
168 create_lttng_session_uri
$SESSION_NAME net
://localhost
--live
169 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME
171 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
172 --sync-after-first-event ${file_sync_after_first} \
173 --sync-before-last-event ${file_sync_before_last} >/dev
/null
2>&1 &
175 start_lttng_tracing_ok
$SESSION_NAME
177 touch ${file_sync_before_last}
179 # Wait for the applications started in background
181 regenerate_metadata_fail
$SESSION_NAME
183 stop_lttng_tracing_ok
$SESSION_NAME
184 destroy_lttng_session_ok
$SESSION_NAME
186 validate_trace
$EVENT_NAME $TRACE_PATH
187 if [ $?
-eq 0 ]; then
188 # Only delete if successful
191 rm -f ${file_sync_after_first}
192 rm -f ${file_sync_before_last}
195 plan_tests
$NUM_TESTS
197 print_test_banner
"$TEST_DESC"
199 start_lttng_relayd
"-o $TRACE_PATH"
202 tests
=( test_ust_streaming test_ust_local test_ust_pid test_ust_live
)
204 for fct_test
in ${tests[@]};
206 SESSION_NAME
=$
(randstring
16 0)