3 # Copyright (C) 2014 David Goulet <dgoulet@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 TEST_DESC
="Load session(s)"
10 CONFIG_DIR
="${CURDIR}/configuration"
11 TESTDIR
=$CURDIR/..
/..
/..
/
12 export LTTNG_SESSION_CONFIG_XSD_PATH
=$
(readlink
-m ${TESTDIR}..
/src
/common
/config
/)
14 SESSION_NAME
="load-42"
15 EVENT_NAME
="tp:tptest"
17 DIR
=$
(readlink
-f $TESTDIR)
21 source $TESTDIR/utils
/utils.sh
22 XML_EXTRACT
="$TESTDIR/utils/xml-utils/extract_xml"
24 # MUST set TESTDIR before calling those functions
27 print_test_banner
"$TEST_DESC"
29 function test_basic_load
()
31 diag
"Test basic load"
33 lttng_load_ok
"-i $CURDIR/$SESSION_NAME.lttng"
35 destroy_lttng_session_ok
$SESSION_NAME
38 function test_complex_load
()
40 local sess
="$SESSION_NAME-complex"
43 diag
"Test complex load"
45 # Start relayd with localhost binding. The complex session uses those
47 start_lttng_relayd
"-C tcp://localhost:8172 -D tcp://localhost:9817"
49 lttng_load_ok
"-i $CURDIR/$sess.lttng"
51 # Once loaded, we are suppose to be able to disable certain events/channels
52 # thus having a confirmation that it's valid
53 disable_ust_lttng_event
$sess uevent1 chan1
54 disable_ust_lttng_event
$sess uevent2 chan2
55 disable_ust_lttng_event
$sess uevent3
* chan3
57 disable_ust_lttng_channel
$sess chan1
58 disable_ust_lttng_channel
$sess chan2
59 disable_ust_lttng_channel
$sess chan3
61 # Confirm that an event stored as disabled is restored in its disabled state
62 local mi_output_file
=$
(mktemp
--tmpdir "tmp.${FUNCNAME[0]}_output_file.XXXXXX")
66 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN --mi XML list
$sess -c chan2
> $mi_output_file
67 mi_result
=$
("$XML_EXTRACT" $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:domains/lttng:domain[lttng:type='UST']/lttng:channels/lttng:channel[lttng:name='chan2']/lttng:events/lttng:event[lttng:name='uevent_disabled']/lttng:enabled/text()")
68 if [[ $mi_result = "false" ]]; then
69 ok
0 "Disabled event is loaded in disabled state"
71 fail
"Disabled event is loaded in disabled state"
74 mi_result
=$
("$XML_EXTRACT" $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:domains/lttng:domain/lttng:channels/lttng:channel[lttng:name='chan2']/lttng:events/lttng:event[lttng:name='uevent_disabled']/lttng:enabled/text()")
75 test $mi_result = "false"
76 ok $?
"Disabled event is loaded in disabled state"
78 # Check that uevent_same_name_diff_llevel with log level 6 (TRACE_INFO) is enabled
79 # This ensure that the state of events with similar name but not same
80 # descriptor tuple (exclusion,filter,loglevel) is restored correctly.
81 mi_result
=$
("$XML_EXTRACT" $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:domains/lttng:domain/lttng:channels/lttng:channel[lttng:name='chan2']/lttng:events/lttng:event[lttng:name='uevent_same_name_diff_llevel' and lttng:loglevel='TRACE_INFO']/lttng:enabled/text()")
82 test $mi_result = "true"
83 ok $?
"Enabled event with same name but different loglevel is in disabled state"
85 destroy_lttng_session_ok
$sess
89 rm -rf ${mi_output_file}
92 function test_all_load
()
94 diag
"Test load all sessions"
96 # Start relayd with localhost binding. The complex session uses those
98 start_lttng_relayd
"-C tcp://localhost:8172 -D tcp://localhost:9817"
100 lttng_load_ok
"-a -i $CURDIR"
102 destroy_lttng_session_ok
$SESSION_NAME
103 destroy_lttng_session_ok
"$SESSION_NAME-complex"
104 destroy_lttng_session_ok
"$SESSION_NAME-trackers"
105 destroy_lttng_session_ok
"tracker_legacy_all"
106 destroy_lttng_session_ok
"tracker_legacy_none"
107 destroy_lttng_session_ok
"tracker_legacy_selective"
112 function test_overwrite
()
114 diag
"Test load overwrite"
116 lttng_load_ok
"-i $CURDIR/$SESSION_NAME.lttng"
118 # This one should succeed
119 lttng_load_ok
"-f -i $CURDIR $SESSION_NAME"
121 destroy_lttng_session_ok
$SESSION_NAME
124 function test_trackers
()
126 diag
"Test trackers loading"
128 lttng_load_ok
"-i $CURDIR/$SESSION_NAME-trackers.lttng"
130 diag
"Test pid tracker"
131 local mi_output_file
=$
(mktemp
--tmpdir "tmp.${FUNCNAME[0]}_output_file.XXXXXX")
132 if [ $?
-ne 0 ]; then
135 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN --mi XML list
"$SESSION_NAME-trackers" > $mi_output_file
136 mi_result
=$
("$XML_EXTRACT" -e $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:domains/lttng:domain/lttng:process_attr_trackers/lttng:vpid_process_attr_tracker/lttng:process_attr_values/lttng:vpid")
137 if [[ $mi_result = "true" ]]; then
138 ok
0 "VPID target is present"
140 fail
"VPID target missing"
143 mi_result
=$
("$XML_EXTRACT" -e $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:domains/lttng:domain/lttng:process_attr_trackers/lttng:vuid_process_attr_tracker/lttng:process_attr_values/lttng:vuid")
144 if [[ $mi_result = "true" ]]; then
145 ok
0 "VUID target is present"
147 fail
"VUID target missing"
150 mi_result
=$
("$XML_EXTRACT" -e $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:domains/lttng:domain/lttng:process_attr_trackers/lttng:vgid_process_attr_tracker/lttng:process_attr_values/lttng:vgid")
151 if [[ $mi_result = "true" ]]; then
152 ok
0 "VGID target is present"
154 fail
"VGID target missing"
157 # Test to remove the target just to make sure
158 lttng_untrack_ok
"--vpid 666 -u -s $SESSION_NAME-trackers"
159 lttng_untrack_ok
"--vuid 777 -u -s $SESSION_NAME-trackers"
160 lttng_untrack_ok
"--vgid 888 -u -s $SESSION_NAME-trackers"
161 # Actually using vpid (backward compat)
162 lttng_untrack_ok
"--pid 999 -u -s $SESSION_NAME-trackers"
164 destroy_lttng_session_ok
"$SESSION_NAME-trackers"
165 rm -f ${mi_output_file}
168 function test_override_url_normal
()
170 local local_url_override
="file:///tmp/override/to/here"
171 local local_path_override
="/tmp/override/to/here"
172 local local_path_compare_value
="/tmp/override/to/here/"
173 local stream_url_override
="net://127.0.0.1:8172:9817"
174 local stream_url_compare
="tcp4://127.0.0.1:8172/ [data: 9817]"
176 diag
"Test url override for normal session"
178 start_lttng_relayd
"-C tcp://127.0.0.1:8172 -D tcp://127.0.0.1:9817"
180 local mi_output_file
=$
(mktemp
--tmpdir "tmp.${FUNCNAME[0]}_output_file.XXXXXX")
181 if [ $?
-ne 0 ]; then
185 # Url of style file://
186 lttng_load_ok
"-i $CURDIR/$SESSION_NAME.lttng --override-url=${local_url_override}"
187 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN --mi XML list
"$SESSION_NAME" > $mi_output_file
188 mi_result
=$
("$XML_EXTRACT" $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:path")
190 test $mi_result = "${local_path_compare_value}"
191 ok $?
"Path url file:// override [{$mi_result}, ${local_path_compare_value}]"
192 destroy_lttng_session_ok
"$SESSION_NAME"
195 lttng_load_ok
"-i $CURDIR/$SESSION_NAME.lttng --override-url=${local_path_override}"
196 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN --mi XML list
"$SESSION_NAME" > $mi_output_file
197 mi_result
=$
("$XML_EXTRACT" $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:path")
199 test $mi_result = "${local_path_compare_value}"
200 ok $?
"Path url / override [{$mi_result}, ${local_path_compare_value}]"
201 destroy_lttng_session_ok
"$SESSION_NAME"
203 # Url of style net://ip:port:port
204 lttng_load_ok
"-i $CURDIR/$SESSION_NAME.lttng --override-url=${stream_url_override}"
205 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN --mi XML list
"$SESSION_NAME" > $mi_output_file
206 mi_result
=$
("$XML_EXTRACT" $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:path")
208 test "$mi_result" = "${stream_url_compare}"
209 ok $?
"Path url net://host:port:port override [${mi_result}, ${stream_url_compare}]"
211 destroy_lttng_session_ok
"$SESSION_NAME"
213 rm -rf ${mi_output_file}
216 function test_override_url_snapshot
()
218 local url_override
="file:///tmp/override/to/here"
219 local path_override
="/tmp/override/to/here"
220 local path_compare_value
="/tmp/override/to/here/"
221 local stream_url_override
="net://127.0.0.1:8172:9817"
222 local stream_url_compare_ctrl
="tcp4://127.0.0.1:8172/"
223 local stream_url_compare_data
="tcp4://127.0.0.1:9817/"
224 local local_session_name
="${SESSION_NAME}-snapshot"
226 diag
"Test url override for snapshot session"
228 start_lttng_relayd
"-C tcp://127.0.0.1:8172 -D tcp://127.0.0.1:9817"
230 local mi_output_file
=$
(mktemp
--tmpdir "tmp.${FUNCNAME[0]}_output_file.XXXXXX")
231 if [ $?
-ne 0 ]; then
235 # Url of style file://
236 lttng_load_ok
"-i $CONFIG_DIR/$local_session_name.lttng --override-url=${url_override}"
237 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN --mi XML snapshot list-output
-s "$local_session_name" > $mi_output_file
238 mi_result
=$
("$XML_EXTRACT" $mi_output_file "//lttng:command/lttng:output/lttng:snapshot_action/lttng:output/lttng:session/lttng:snapshots/lttng:snapshot/lttng:ctrl_url")
240 test $mi_result = "${path_compare_value}"
241 ok $?
"Path url file:// override [{$mi_result}, ${path_compare_value}]"
242 destroy_lttng_session_ok
"$local_session_name"
245 lttng_load_ok
"-i $CONFIG_DIR/$local_session_name.lttng --override-url=${path_override}"
246 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN --mi XML snapshot list-output
-s "$local_session_name" > $mi_output_file
247 mi_result
=$
("$XML_EXTRACT" $mi_output_file "//lttng:command/lttng:output/lttng:snapshot_action/lttng:output/lttng:session/lttng:snapshots/lttng:snapshot/lttng:ctrl_url")
249 test $mi_result = "${path_compare_value}"
250 ok $?
"Path url / override [{$mi_result}, ${path_compare_value}]"
251 destroy_lttng_session_ok
"$local_session_name"
253 # Url of style net://ip:port:port
254 lttng_load_ok
"-i $CONFIG_DIR/$local_session_name.lttng --override-url=${stream_url_override}"
255 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN --mi XML snapshot list-output
-s "$local_session_name" > $mi_output_file
256 mi_result
=$
("$XML_EXTRACT" $mi_output_file "//lttng:command/lttng:output/lttng:snapshot_action/lttng:output/lttng:session/lttng:snapshots/lttng:snapshot/lttng:ctrl_url")
258 test "$mi_result" = "${stream_url_compare_ctrl}"
259 ok $?
"Path url ctrl net://host:port:port override [${mi_result}, ${stream_url_compare_ctrl}]"
261 mi_result
=$
("$XML_EXTRACT" $mi_output_file "//lttng:command/lttng:output/lttng:snapshot_action/lttng:output/lttng:session/lttng:snapshots/lttng:snapshot/lttng:data_url")
263 test "$mi_result" = "${stream_url_compare_data}"
264 ok $?
"Path url data net://host:port:port override [${mi_result}, ${stream_url_compare_data}]"
266 destroy_lttng_session_ok
"$local_session_name"
268 rm -rf ${mi_output_file}
271 function test_override_url_live
()
273 local url_override
="file:///tmp/override/to/here"
274 local path_override
="/tmp/override/to/here"
275 local path_compare_value
="/tmp/override/to/here/"
276 local stream_url_override
="net://127.0.0.1:8172:9817"
277 local stream_url_compare
="tcp4://127.0.0.1:8172/ [data: 9817]"
278 local local_session_name
="${SESSION_NAME}-live"
280 diag
"Test url override for live session"
282 start_lttng_relayd
"-C tcp://127.0.0.1:8172 -D tcp://127.0.0.1:9817"
284 local mi_output_file
=$
(mktemp
--tmpdir "tmp.${FUNCNAME[0]}_output_file.XXXXXX")
285 if [ $?
-ne 0 ]; then
289 # Url of style file://
290 # Expect this to fail since live session should never accept local
292 lttng_load_fail
"-i $CONFIG_DIR/$local_session_name.lttng --override-url=${url_override}"
293 destroy_lttng_session_fail
"$local_session_name"
296 # Expect this to fail since live session should never accept local
298 lttng_load_fail
"-i $CONFIG_DIR/$local_session_name.lttng --override-url=${path_override}"
299 destroy_lttng_session_fail
"$local_session_name"
301 # Url of style net://ip:port:port
302 lttng_load_ok
"-i $CONFIG_DIR/$local_session_name.lttng --override-url=${stream_url_override}"
303 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN --mi XML list
"$local_session_name" > $mi_output_file
304 mi_result
=$
("$XML_EXTRACT" $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:path")
306 test "$mi_result" = "${stream_url_compare}"
307 ok $?
"Path url net://host:port:port override [${mi_result}, ${stream_url_compare}]"
309 destroy_lttng_session_ok
"$local_session_name"
311 rm -rf ${mi_output_file}
314 function test_override_session_name
()
316 diag
"Test session name override"
317 local override_name
="PinkyAndTheBrain"
318 local output_path
="/tmp/lttng/load-42-1"
320 local mi_output_file
=$
(mktemp
--tmpdir "tmp.${FUNCNAME[0]}_output_file.XXXXXX")
321 if [ $?
-ne 0 ]; then
325 lttng_load_ok
"-i ${CURDIR}/${SESSION_NAME}.lttng --override-name=${override_name} ${SESSION_NAME}"
326 ${TESTDIR}/../src/bin/lttng/${LTTNG_BIN} --mi XML list "${SESSION_NAME}" &> /dev/null
327 if [ $? -eq 0 ]; then
328 fail "Expected a failure on listing
for old session name
"
331 ${TESTDIR}/../src/bin/lttng/${LTTNG_BIN} --mi XML list "${override_name}" > $mi_output_file
332 mi_result
=$
("$XML_EXTRACT" $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:name")
334 test "${mi_result}" = "${override_name}"
335 ok $?
"Override name successful [${SESSION_NAME} to ${override_name}]"
337 # Make sure that the name override did not change something else
338 mi_result
=$
("$XML_EXTRACT" $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:path")
339 test "${mi_result}" = "${output_path}"
340 ok $?
"Output path is not affected by name override"
342 destroy_lttng_session_ok
"${override_name}"
344 diag
"Test session name override with all (Do not permit)"
345 lttng_load_fail
"-i ${CURDIR}/${SESSION_NAME}.lttng --override-name=${override_name}"
347 rm -rf ${mi_output_file}
358 test_override_session_name
359 test_override_url_normal
360 test_override_url_snapshot
361 test_override_url_live
364 for fct_test
in ${TESTS[@]};
366 TRACE_PATH
=$
(mktemp
--tmpdir -d tmp.test_load_trace_path.XXXXXX
)
369 if [ $?
-ne 0 ]; then
372 # Only delete if successful