Move xml utils from mi subfolder to xml-utils folder
[lttng-tools.git] / tests / regression / tools / save-load / test_load
1 #!/bin/bash
2 #
3 # Copyright (C) 2014 David Goulet <dgoulet@efficios.com>
4 #
5 # SPDX-License-Identifier: LGPL-2.1-only
6
7 TEST_DESC="Load session(s)"
8
9 CURDIR=$(dirname $0)/
10 CONFIG_DIR="${CURDIR}/configuration"
11 TESTDIR=$CURDIR/../../../
12 export LTTNG_SESSION_CONFIG_XSD_PATH=$(readlink -m ${TESTDIR}../src/common/config/)
13
14 SESSION_NAME="load-42"
15 EVENT_NAME="tp:tptest"
16
17 DIR=$(readlink -f $TESTDIR)
18
19 NUM_TESTS=75
20
21 source $TESTDIR/utils/utils.sh
22 XML_EXTRACT="$TESTDIR/utils/xml-utils/extract_xml"
23
24 # MUST set TESTDIR before calling those functions
25 plan_tests $NUM_TESTS
26
27 print_test_banner "$TEST_DESC"
28
29 function test_basic_load()
30 {
31 diag "Test basic load"
32
33 lttng_load_ok "-i $CURDIR/$SESSION_NAME.lttng"
34
35 destroy_lttng_session_ok $SESSION_NAME
36 }
37
38 function test_complex_load()
39 {
40 local sess="$SESSION_NAME-complex"
41 local mi_result=""
42 local ret=1
43 diag "Test complex load"
44
45 # Start relayd with localhost binding. The complex session uses those
46 # custom values.
47 start_lttng_relayd "-C tcp://localhost:8172 -D tcp://localhost:9817"
48
49 lttng_load_ok "-i $CURDIR/$sess.lttng"
50
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
56
57 disable_ust_lttng_channel $sess chan1
58 disable_ust_lttng_channel $sess chan2
59 disable_ust_lttng_channel $sess chan3
60
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")
63 if [ $? -ne 0 ]; then
64 break;
65 fi
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"
70 else
71 fail "Disabled event is loaded in disabled state"
72 fi
73
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"
77
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"
84
85 destroy_lttng_session_ok $sess
86
87 rm $mi_output_file
88 stop_lttng_relayd
89 rm -rf ${mi_output_file}
90 }
91
92 function test_all_load()
93 {
94 diag "Test load all sessions"
95
96 # Start relayd with localhost binding. The complex session uses those
97 # custom values.
98 start_lttng_relayd "-C tcp://localhost:8172 -D tcp://localhost:9817"
99
100 lttng_load_ok "-a -i $CURDIR"
101
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"
108
109 stop_lttng_relayd
110 }
111
112 function test_overwrite()
113 {
114 diag "Test load overwrite"
115
116 lttng_load_ok "-i $CURDIR/$SESSION_NAME.lttng"
117
118 # This one should succeed
119 lttng_load_ok "-f -i $CURDIR $SESSION_NAME"
120
121 destroy_lttng_session_ok $SESSION_NAME
122 }
123
124 function test_trackers()
125 {
126 diag "Test trackers loading"
127
128 lttng_load_ok "-i $CURDIR/$SESSION_NAME-trackers.lttng"
129
130 diag "Test pid tracker"
131 local mi_output_file=$(mktemp --tmpdir "tmp.${FUNCNAME[0]}_output_file.XXXXXX")
132 if [ $? -ne 0 ]; then
133 break;
134 fi
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"
139 else
140 fail "VPID target missing"
141 fi
142
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"
146 else
147 fail "VUID target missing"
148 fi
149
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"
153 else
154 fail "VGID target missing"
155 fi
156
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"
163
164 destroy_lttng_session_ok "$SESSION_NAME-trackers"
165 rm -f ${mi_output_file}
166 }
167
168 function test_override_url_normal()
169 {
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]"
175
176 diag "Test url override for normal session"
177
178 start_lttng_relayd "-C tcp://127.0.0.1:8172 -D tcp://127.0.0.1:9817"
179
180 local mi_output_file=$(mktemp --tmpdir "tmp.${FUNCNAME[0]}_output_file.XXXXXX")
181 if [ $? -ne 0 ]; then
182 break;
183 fi
184
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")
189
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"
193
194 # Url of style /
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")
198
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"
202
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")
207
208 test "$mi_result" = "${stream_url_compare}"
209 ok $? "Path url net://host:port:port override [${mi_result}, ${stream_url_compare}]"
210
211 destroy_lttng_session_ok "$SESSION_NAME"
212 stop_lttng_relayd
213 rm -rf ${mi_output_file}
214 }
215
216 function test_override_url_snapshot()
217 {
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"
225
226 diag "Test url override for snapshot session"
227
228 start_lttng_relayd "-C tcp://127.0.0.1:8172 -D tcp://127.0.0.1:9817"
229
230 local mi_output_file=$(mktemp --tmpdir "tmp.${FUNCNAME[0]}_output_file.XXXXXX")
231 if [ $? -ne 0 ]; then
232 break;
233 fi
234
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")
239
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"
243
244 # Url of style /
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")
248
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"
252
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")
257
258 test "$mi_result" = "${stream_url_compare_ctrl}"
259 ok $? "Path url ctrl net://host:port:port override [${mi_result}, ${stream_url_compare_ctrl}]"
260
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")
262
263 test "$mi_result" = "${stream_url_compare_data}"
264 ok $? "Path url data net://host:port:port override [${mi_result}, ${stream_url_compare_data}]"
265
266 destroy_lttng_session_ok "$local_session_name"
267 stop_lttng_relayd
268 rm -rf ${mi_output_file}
269 }
270
271 function test_override_url_live()
272 {
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"
279
280 diag "Test url override for live session"
281
282 start_lttng_relayd "-C tcp://127.0.0.1:8172 -D tcp://127.0.0.1:9817"
283
284 local mi_output_file=$(mktemp --tmpdir "tmp.${FUNCNAME[0]}_output_file.XXXXXX")
285 if [ $? -ne 0 ]; then
286 break;
287 fi
288
289 # Url of style file://
290 # Expect this to fail since live session should never accept local
291 # output.
292 lttng_load_fail "-i $CONFIG_DIR/$local_session_name.lttng --override-url=${url_override}"
293 destroy_lttng_session_fail "$local_session_name"
294
295 # Url of style /
296 # Expect this to fail since live session should never accept local
297 # output.
298 lttng_load_fail "-i $CONFIG_DIR/$local_session_name.lttng --override-url=${path_override}"
299 destroy_lttng_session_fail "$local_session_name"
300
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")
305
306 test "$mi_result" = "${stream_url_compare}"
307 ok $? "Path url net://host:port:port override [${mi_result}, ${stream_url_compare}]"
308
309 destroy_lttng_session_ok "$local_session_name"
310 stop_lttng_relayd
311 rm -rf ${mi_output_file}
312 }
313
314 function test_override_session_name()
315 {
316 diag "Test session name override"
317 local override_name="PinkyAndTheBrain"
318 local output_path="/tmp/lttng/load-42-1"
319
320 local mi_output_file=$(mktemp --tmpdir "tmp.${FUNCNAME[0]}_output_file.XXXXXX")
321 if [ $? -ne 0 ]; then
322 break;
323 fi
324
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"
329 fi
330
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")
333
334 test "${mi_result}" = "${override_name}"
335 ok $? "Override name successful [${SESSION_NAME} to ${override_name}]"
336
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"
341
342 destroy_lttng_session_ok "${override_name}"
343
344 diag "Test session name override with all (Do not permit)"
345 lttng_load_fail "-i ${CURDIR}/${SESSION_NAME}.lttng --override-name=${override_name}"
346
347 rm -rf ${mi_output_file}
348 }
349
350 start_lttng_sessiond
351
352 TESTS=(
353 test_basic_load
354 test_complex_load
355 test_all_load
356 test_overwrite
357 test_trackers
358 test_override_session_name
359 test_override_url_normal
360 test_override_url_snapshot
361 test_override_url_live
362 )
363
364 for fct_test in ${TESTS[@]};
365 do
366 TRACE_PATH=$(mktemp --tmpdir -d tmp.test_load_trace_path.XXXXXX)
367
368 ${fct_test}
369 if [ $? -ne 0 ]; then
370 break;
371 fi
372 # Only delete if successful
373 rm -rf $TRACE_PATH
374 done
375
376 stop_lttng_sessiond
This page took 0.049384 seconds and 5 git commands to generate.