5e38b46b64e57c16f890a733723c40b8314df7cd
[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 # 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.
8 #
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
12 # details.
13 #
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
18 TEST_DESC="Load session(s)"
19
20 CURDIR=$(dirname $0)/
21 CONFIG_DIR="${CURDIR}/configuration"
22 TESTDIR=$CURDIR/../../../
23 export LTTNG_SESSION_CONFIG_XSD_PATH=$(readlink -m ${TESTDIR}../src/common/config/)
24
25 SESSION_NAME="load-42"
26 EVENT_NAME="tp:tptest"
27
28 DIR=$(readlink -f $TESTDIR)
29
30 NUM_TESTS=67
31
32 source $TESTDIR/utils/utils.sh
33
34 # MUST set TESTDIR before calling those functions
35 plan_tests $NUM_TESTS
36
37 print_test_banner "$TEST_DESC"
38
39 function test_basic_load()
40 {
41 diag "Test basic load"
42
43 lttng_load_ok "-i $CURDIR/$SESSION_NAME.lttng"
44
45 destroy_lttng_session_ok $SESSION_NAME
46 }
47
48 function test_complex_load()
49 {
50 local sess="$SESSION_NAME-complex"
51 local mi_result=""
52 local ret=1
53 diag "Test complex load"
54
55 # Start relayd with localhost binding. The complex session uses those
56 # custom values.
57 start_lttng_relayd "-C tcp://localhost:8172 -D tcp://localhost:9817"
58
59 lttng_load_ok "-i $CURDIR/$sess.lttng"
60
61 # Once loaded, we are suppose to be able to disable certain events/channels
62 # thus having a confirmation that it's valid
63 disable_ust_lttng_event $sess uevent1 chan1
64 disable_ust_lttng_event $sess uevent2 chan2
65 disable_ust_lttng_event $sess uevent3* chan3
66
67 disable_ust_lttng_channel $sess chan1
68 disable_ust_lttng_channel $sess chan2
69 disable_ust_lttng_channel $sess chan3
70
71 # Confirm that an event stored as disabled is restored in its disabled state
72 local mi_output_file=$(mktemp)
73 if [ $? -ne 0 ]; then
74 break;
75 fi
76 $TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi XML list $sess -c chan2 > $mi_output_file
77 mi_result=$($CURDIR/../mi/extract_xml $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()")
78 if [[ $mi_result = "false" ]]; then
79 ok 0 "Disabled event is loaded in disabled state"
80 else
81 fail "Disabled event is loaded in disabled state"
82 fi
83
84 mi_result=$($CURDIR/../mi/extract_xml $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()")
85 test $mi_result = "false"
86 ok $? "Disabled event is loaded in disabled state"
87
88 # Check that uevent_same_name_diff_llevel with log level 6 (TRACE_INFO) is enabled
89 # This ensure that the state of events with similar name but not same
90 # descriptor tuple (exclusion,filter,loglevel) is restored correctly.
91 mi_result=$($CURDIR/../mi/extract_xml $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()")
92 test $mi_result = "true"
93 ok $? "Enabled event with same name but different loglevel is in disabled state"
94
95 destroy_lttng_session_ok $sess
96
97 rm $mi_output_file
98 stop_lttng_relayd
99 rm -rf ${mi_output_file}
100 }
101
102 function test_all_load()
103 {
104 diag "Test load all sessions"
105
106 # Start relayd with localhost binding. The complex session uses those
107 # custom values.
108 start_lttng_relayd "-C tcp://localhost:8172 -D tcp://localhost:9817"
109
110 lttng_load_ok "-a -i $CURDIR"
111
112 destroy_lttng_session_ok $SESSION_NAME
113 destroy_lttng_session_ok "$SESSION_NAME-complex"
114 destroy_lttng_session_ok "$SESSION_NAME-trackers"
115
116 stop_lttng_relayd
117 }
118
119 function test_overwrite()
120 {
121 diag "Test load overwrite"
122
123 lttng_load_ok "-i $CURDIR/$SESSION_NAME.lttng"
124
125 # This one should succeed
126 lttng_load_ok "-f -i $CURDIR $SESSION_NAME"
127
128 destroy_lttng_session_ok $SESSION_NAME
129 }
130
131 function test_trackers()
132 {
133 diag "Test trackers loading"
134
135 lttng_load_ok "-i $CURDIR/$SESSION_NAME-trackers.lttng"
136
137 diag "Test pid tracker"
138 local mi_output_file=$(mktemp)
139 if [ $? -ne 0 ]; then
140 break;
141 fi
142 $TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi XML list "$SESSION_NAME-trackers" > $mi_output_file
143 mi_result=$($CURDIR/../mi/extract_xml -e $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:domains/lttng:domain/lttng:trackers/lttng:pid_tracker/lttng:targets/lttng:pid_target")
144 if [[ $mi_result = "true" ]]; then
145 ok 0 "Pid target is present"
146 else
147 fail "Pid target missing"
148 fi
149
150 # Test to remove the target just to make sure
151 lttng_untrack_ok "-p 666 -u -s $SESSION_NAME-trackers"
152 rm $mi_output_file
153
154 destroy_lttng_session_ok "$SESSION_NAME-trackers"
155 rm -rf ${mi_output_file}
156 }
157
158 function test_override_url_normal()
159 {
160 local local_url_override="file:///tmp/override/to/here"
161 local local_path_override="/tmp/override/to/here"
162 local local_path_compare_value="/tmp/override/to/here/"
163 local stream_url_override="net://127.0.0.1:8172:9817"
164 local stream_url_compare="tcp4://127.0.0.1:8172/ [data: 9817]"
165
166 diag "Test url override for normal session"
167
168 start_lttng_relayd "-C tcp://127.0.0.1:8172 -D tcp://127.0.0.1:9817"
169
170 local mi_output_file=$(mktemp)
171 if [ $? -ne 0 ]; then
172 break;
173 fi
174
175 # Url of style file://
176 lttng_load_ok "-i $CURDIR/$SESSION_NAME.lttng --override-url=${local_url_override}"
177 $TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi XML list "$SESSION_NAME" > $mi_output_file
178 mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:path")
179
180 test $mi_result = "${local_path_compare_value}"
181 ok $? "Path url file:// override [{$mi_result}, ${local_path_compare_value}]"
182 destroy_lttng_session_ok "$SESSION_NAME"
183
184 # Url of style /
185 lttng_load_ok "-i $CURDIR/$SESSION_NAME.lttng --override-url=${local_path_override}"
186 $TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi XML list "$SESSION_NAME" > $mi_output_file
187 mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:path")
188
189 test $mi_result = "${local_path_compare_value}"
190 ok $? "Path url / override [{$mi_result}, ${local_path_compare_value}]"
191 destroy_lttng_session_ok "$SESSION_NAME"
192
193 # Url of style net://ip:port:port
194 lttng_load_ok "-i $CURDIR/$SESSION_NAME.lttng --override-url=${stream_url_override}"
195 $TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi XML list "$SESSION_NAME" > $mi_output_file
196 mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:path")
197
198 test "$mi_result" = "${stream_url_compare}"
199 ok $? "Path url net://host:port:port override [${mi_result}, ${stream_url_compare}]"
200
201 destroy_lttng_session_ok "$SESSION_NAME"
202 stop_lttng_relayd
203 rm -rf ${mi_output_file}
204 }
205
206 function test_override_url_snapshot()
207 {
208 local url_override="file:///tmp/override/to/here"
209 local path_override="/tmp/override/to/here"
210 local path_compare_value="/tmp/override/to/here/"
211 local stream_url_override="net://127.0.0.1:8172:9817"
212 local stream_url_compare_ctrl="tcp4://127.0.0.1:8172/"
213 local stream_url_compare_data="tcp4://127.0.0.1:9817/"
214 local local_session_name="${SESSION_NAME}-snapshot"
215
216 diag "Test url override for snapshot session"
217
218 start_lttng_relayd "-C tcp://127.0.0.1:8172 -D tcp://127.0.0.1:9817"
219
220 local mi_output_file=$(mktemp)
221 if [ $? -ne 0 ]; then
222 break;
223 fi
224
225 # Url of style file://
226 lttng_load_ok "-i $CONFIG_DIR/$local_session_name.lttng --override-url=${url_override}"
227 $TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi XML snapshot list-output -s "$local_session_name" > $mi_output_file
228 mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "//lttng:command/lttng:output/lttng:snapshot_action/lttng:output/lttng:session/lttng:snapshots/lttng:snapshot/lttng:ctrl_url")
229
230 test $mi_result = "${path_compare_value}"
231 ok $? "Path url file:// override [{$mi_result}, ${path_compare_value}]"
232 destroy_lttng_session_ok "$local_session_name"
233
234 # Url of style /
235 lttng_load_ok "-i $CONFIG_DIR/$local_session_name.lttng --override-url=${path_override}"
236 $TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi XML snapshot list-output -s "$local_session_name" > $mi_output_file
237 mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "//lttng:command/lttng:output/lttng:snapshot_action/lttng:output/lttng:session/lttng:snapshots/lttng:snapshot/lttng:ctrl_url")
238
239 test $mi_result = "${path_compare_value}"
240 ok $? "Path url / override [{$mi_result}, ${path_compare_value}]"
241 destroy_lttng_session_ok "$local_session_name"
242
243 # Url of style net://ip:port:port
244 lttng_load_ok "-i $CONFIG_DIR/$local_session_name.lttng --override-url=${stream_url_override}"
245 $TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi XML snapshot list-output -s "$local_session_name" > $mi_output_file
246 mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "//lttng:command/lttng:output/lttng:snapshot_action/lttng:output/lttng:session/lttng:snapshots/lttng:snapshot/lttng:ctrl_url")
247
248 test "$mi_result" = "${stream_url_compare_ctrl}"
249 ok $? "Path url ctrl net://host:port:port override [${mi_result}, ${stream_url_compare_ctrl}]"
250
251 mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "//lttng:command/lttng:output/lttng:snapshot_action/lttng:output/lttng:session/lttng:snapshots/lttng:snapshot/lttng:data_url")
252
253 test "$mi_result" = "${stream_url_compare_data}"
254 ok $? "Path url data net://host:port:port override [${mi_result}, ${stream_url_compare_data}]"
255
256 destroy_lttng_session_ok "$local_session_name"
257 stop_lttng_relayd
258 rm -rf ${mi_output_file}
259 }
260
261 function test_override_url_live()
262 {
263 local url_override="file:///tmp/override/to/here"
264 local path_override="/tmp/override/to/here"
265 local path_compare_value="/tmp/override/to/here/"
266 local stream_url_override="net://127.0.0.1:8172:9817"
267 local stream_url_compare="tcp4://127.0.0.1:8172/ [data: 9817]"
268 local local_session_name="${SESSION_NAME}-live"
269
270 diag "Test url override for live session"
271
272 start_lttng_relayd "-C tcp://127.0.0.1:8172 -D tcp://127.0.0.1:9817"
273
274 local mi_output_file=$(mktemp)
275 if [ $? -ne 0 ]; then
276 break;
277 fi
278
279 # Url of style file://
280 # Expect this to fail since live session should never accept local
281 # output.
282 lttng_load_fail "-i $CONFIG_DIR/$local_session_name.lttng --override-url=${url_override}"
283 destroy_lttng_session_fail "$local_session_name"
284
285 # Url of style /
286 # Expect this to fail since live session should never accept local
287 # output.
288 lttng_load_fail "-i $CONFIG_DIR/$local_session_name.lttng --override-url=${path_override}"
289 destroy_lttng_session_fail "$local_session_name"
290
291 # Url of style net://ip:port:port
292 lttng_load_ok "-i $CONFIG_DIR/$local_session_name.lttng --override-url=${stream_url_override}"
293 $TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi XML list "$local_session_name" > $mi_output_file
294 mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:path")
295
296 test "$mi_result" = "${stream_url_compare}"
297 ok $? "Path url net://host:port:port override [${mi_result}, ${stream_url_compare}]"
298
299 destroy_lttng_session_ok "$local_session_name"
300 stop_lttng_relayd
301 rm -rf ${mi_output_file}
302 }
303
304 function test_override_session_name()
305 {
306 diag "Test session name override"
307 local override_name="PinkyAndTheBrain"
308 local output_path="/tmp/lttng/load-42-1"
309
310 local mi_output_file=$(mktemp)
311 if [ $? -ne 0 ]; then
312 break;
313 fi
314
315 lttng_load_ok "-i ${CURDIR}/${SESSION_NAME}.lttng --override-name=${override_name} ${SESSION_NAME}"
316 ${TESTDIR}/../src/bin/lttng/${LTTNG_BIN} --mi XML list "${SESSION_NAME}" &> /dev/null
317 if [ $? -eq 0 ]; then
318 fail "Expected a failure on listing for old session name"
319 fi
320
321 ${TESTDIR}/../src/bin/lttng/${LTTNG_BIN} --mi XML list "${override_name}" > $mi_output_file
322 mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:name")
323
324 test "${mi_result}" = "${override_name}"
325 ok $? "Override name successful [${SESSION_NAME} to ${override_name}]"
326
327 # Make sure that the name override did not change something else
328 mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:path")
329 test "${mi_result}" = "${output_path}"
330 ok $? "Output path is not affected by name override"
331
332 destroy_lttng_session_ok "${override_name}"
333
334 diag "Test session name override with all (Do not permit)"
335 lttng_load_fail "-i ${CURDIR}/${SESSION_NAME}.lttng --override-name=${override_name}"
336
337 rm -rf ${mi_output_file}
338 }
339
340 start_lttng_sessiond
341
342 TESTS=(
343 test_basic_load
344 test_complex_load
345 test_all_load
346 test_overwrite
347 test_trackers
348 test_override_session_name
349 test_override_url_normal
350 test_override_url_snapshot
351 test_override_url_live
352 )
353
354 for fct_test in ${TESTS[@]};
355 do
356 TRACE_PATH=$(mktemp -d)
357
358 ${fct_test}
359 if [ $? -ne 0 ]; then
360 break;
361 fi
362 # Only delete if successful
363 rm -rf $TRACE_PATH
364 done
365
366 stop_lttng_sessiond
This page took 0.054797 seconds and 3 git commands to generate.