d201b53af5ec650d300d7412de14e2df99f10c41
[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 stop_lttng_relayd
98 rm -rf ${mi_output_file}
99 }
100
101 function test_all_load()
102 {
103 diag "Test load all sessions"
104
105 # Start relayd with localhost binding. The complex session uses those
106 # custom values.
107 start_lttng_relayd "-C tcp://localhost:8172 -D tcp://localhost:9817"
108
109 lttng_load_ok "-a -i $CURDIR"
110
111 destroy_lttng_session_ok $SESSION_NAME
112 destroy_lttng_session_ok "$SESSION_NAME-complex"
113 destroy_lttng_session_ok "$SESSION_NAME-trackers"
114
115 stop_lttng_relayd
116 }
117
118 function test_overwrite()
119 {
120 diag "Test load overwrite"
121
122 lttng_load_ok "-i $CURDIR/$SESSION_NAME.lttng"
123
124 # This one should succeed
125 lttng_load_ok "-f -i $CURDIR $SESSION_NAME"
126
127 destroy_lttng_session_ok $SESSION_NAME
128 }
129
130 function test_trackers()
131 {
132 diag "Test trackers loading"
133
134 lttng_load_ok "-i $CURDIR/$SESSION_NAME-trackers.lttng"
135
136 diag "Test pid tracker"
137 local mi_output_file=$(mktemp)
138 if [ $? -ne 0 ]; then
139 break;
140 fi
141 $TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi XML list "$SESSION_NAME-trackers" > $mi_output_file
142 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")
143 if [[ $mi_result = "true" ]]; then
144 ok 0 "Pid target is present"
145 else
146 fail "Pid target missing"
147 fi
148
149 # Test to remove the target just to make sure
150 lttng_untrack_ok "-p 666 -u -s $SESSION_NAME-trackers"
151
152 destroy_lttng_session_ok "$SESSION_NAME-trackers"
153 rm -rf ${mi_output_file}
154 }
155
156 function test_override_url_normal()
157 {
158 local local_url_override="file:///tmp/override/to/here"
159 local local_path_override="/tmp/override/to/here"
160 local local_path_compare_value="/tmp/override/to/here/"
161 local stream_url_override="net://127.0.0.1:8172:9817"
162 local stream_url_compare="tcp4://127.0.0.1:8172/ [data: 9817]"
163
164 diag "Test url override for normal session"
165
166 start_lttng_relayd "-C tcp://127.0.0.1:8172 -D tcp://127.0.0.1:9817"
167
168 local mi_output_file=$(mktemp)
169 if [ $? -ne 0 ]; then
170 break;
171 fi
172
173 # Url of style file://
174 lttng_load_ok "-i $CURDIR/$SESSION_NAME.lttng --override-url=${local_url_override}"
175 $TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi XML list "$SESSION_NAME" > $mi_output_file
176 mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:path")
177
178 test $mi_result = "${local_path_compare_value}"
179 ok $? "Path url file:// override [{$mi_result}, ${local_path_compare_value}]"
180 destroy_lttng_session_ok "$SESSION_NAME"
181
182 # Url of style /
183 lttng_load_ok "-i $CURDIR/$SESSION_NAME.lttng --override-url=${local_path_override}"
184 $TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi XML list "$SESSION_NAME" > $mi_output_file
185 mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:path")
186
187 test $mi_result = "${local_path_compare_value}"
188 ok $? "Path url / override [{$mi_result}, ${local_path_compare_value}]"
189 destroy_lttng_session_ok "$SESSION_NAME"
190
191 # Url of style net://ip:port:port
192 lttng_load_ok "-i $CURDIR/$SESSION_NAME.lttng --override-url=${stream_url_override}"
193 $TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi XML list "$SESSION_NAME" > $mi_output_file
194 mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:path")
195
196 test "$mi_result" = "${stream_url_compare}"
197 ok $? "Path url net://host:port:port override [${mi_result}, ${stream_url_compare}]"
198
199 destroy_lttng_session_ok "$SESSION_NAME"
200 stop_lttng_relayd
201 rm -rf ${mi_output_file}
202 }
203
204 function test_override_url_snapshot()
205 {
206 local url_override="file:///tmp/override/to/here"
207 local path_override="/tmp/override/to/here"
208 local path_compare_value="/tmp/override/to/here/"
209 local stream_url_override="net://127.0.0.1:8172:9817"
210 local stream_url_compare_ctrl="tcp4://127.0.0.1:8172/"
211 local stream_url_compare_data="tcp4://127.0.0.1:9817/"
212 local local_session_name="${SESSION_NAME}-snapshot"
213
214 diag "Test url override for snapshot session"
215
216 start_lttng_relayd "-C tcp://127.0.0.1:8172 -D tcp://127.0.0.1:9817"
217
218 local mi_output_file=$(mktemp)
219 if [ $? -ne 0 ]; then
220 break;
221 fi
222
223 # Url of style file://
224 lttng_load_ok "-i $CONFIG_DIR/$local_session_name.lttng --override-url=${url_override}"
225 $TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi XML snapshot list-output -s "$local_session_name" > $mi_output_file
226 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")
227
228 test $mi_result = "${path_compare_value}"
229 ok $? "Path url file:// override [{$mi_result}, ${path_compare_value}]"
230 destroy_lttng_session_ok "$local_session_name"
231
232 # Url of style /
233 lttng_load_ok "-i $CONFIG_DIR/$local_session_name.lttng --override-url=${path_override}"
234 $TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi XML snapshot list-output -s "$local_session_name" > $mi_output_file
235 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")
236
237 test $mi_result = "${path_compare_value}"
238 ok $? "Path url / override [{$mi_result}, ${path_compare_value}]"
239 destroy_lttng_session_ok "$local_session_name"
240
241 # Url of style net://ip:port:port
242 lttng_load_ok "-i $CONFIG_DIR/$local_session_name.lttng --override-url=${stream_url_override}"
243 $TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi XML snapshot list-output -s "$local_session_name" > $mi_output_file
244 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")
245
246 test "$mi_result" = "${stream_url_compare_ctrl}"
247 ok $? "Path url ctrl net://host:port:port override [${mi_result}, ${stream_url_compare_ctrl}]"
248
249 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")
250
251 test "$mi_result" = "${stream_url_compare_data}"
252 ok $? "Path url data net://host:port:port override [${mi_result}, ${stream_url_compare_data}]"
253
254 destroy_lttng_session_ok "$local_session_name"
255 stop_lttng_relayd
256 rm -rf ${mi_output_file}
257 }
258
259 function test_override_url_live()
260 {
261 local url_override="file:///tmp/override/to/here"
262 local path_override="/tmp/override/to/here"
263 local path_compare_value="/tmp/override/to/here/"
264 local stream_url_override="net://127.0.0.1:8172:9817"
265 local stream_url_compare="tcp4://127.0.0.1:8172/ [data: 9817]"
266 local local_session_name="${SESSION_NAME}-live"
267
268 diag "Test url override for live session"
269
270 start_lttng_relayd "-C tcp://127.0.0.1:8172 -D tcp://127.0.0.1:9817"
271
272 local mi_output_file=$(mktemp)
273 if [ $? -ne 0 ]; then
274 break;
275 fi
276
277 # Url of style file://
278 # Expect this to fail since live session should never accept local
279 # output.
280 lttng_load_fail "-i $CONFIG_DIR/$local_session_name.lttng --override-url=${url_override}"
281 destroy_lttng_session_fail "$local_session_name"
282
283 # Url of style /
284 # Expect this to fail since live session should never accept local
285 # output.
286 lttng_load_fail "-i $CONFIG_DIR/$local_session_name.lttng --override-url=${path_override}"
287 destroy_lttng_session_fail "$local_session_name"
288
289 # Url of style net://ip:port:port
290 lttng_load_ok "-i $CONFIG_DIR/$local_session_name.lttng --override-url=${stream_url_override}"
291 $TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi XML list "$local_session_name" > $mi_output_file
292 mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:path")
293
294 test "$mi_result" = "${stream_url_compare}"
295 ok $? "Path url net://host:port:port override [${mi_result}, ${stream_url_compare}]"
296
297 destroy_lttng_session_ok "$local_session_name"
298 stop_lttng_relayd
299 rm -rf ${mi_output_file}
300 }
301
302 function test_override_session_name()
303 {
304 diag "Test session name override"
305 local override_name="PinkyAndTheBrain"
306 local output_path="/tmp/lttng/load-42-1"
307
308 local mi_output_file=$(mktemp)
309 if [ $? -ne 0 ]; then
310 break;
311 fi
312
313 lttng_load_ok "-i ${CURDIR}/${SESSION_NAME}.lttng --override-name=${override_name} ${SESSION_NAME}"
314 ${TESTDIR}/../src/bin/lttng/${LTTNG_BIN} --mi XML list "${SESSION_NAME}" &> /dev/null
315 if [ $? -eq 0 ]; then
316 fail "Expected a failure on listing for old session name"
317 fi
318
319 ${TESTDIR}/../src/bin/lttng/${LTTNG_BIN} --mi XML list "${override_name}" > $mi_output_file
320 mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:name")
321
322 test "${mi_result}" = "${override_name}"
323 ok $? "Override name successful [${SESSION_NAME} to ${override_name}]"
324
325 # Make sure that the name override did not change something else
326 mi_result=$($CURDIR/../mi/extract_xml $mi_output_file "//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:path")
327 test "${mi_result}" = "${output_path}"
328 ok $? "Output path is not affected by name override"
329
330 destroy_lttng_session_ok "${override_name}"
331
332 diag "Test session name override with all (Do not permit)"
333 lttng_load_fail "-i ${CURDIR}/${SESSION_NAME}.lttng --override-name=${override_name}"
334
335 rm -rf ${mi_output_file}
336 }
337
338 start_lttng_sessiond
339
340 TESTS=(
341 test_basic_load
342 test_complex_load
343 test_all_load
344 test_overwrite
345 test_trackers
346 test_override_session_name
347 test_override_url_normal
348 test_override_url_snapshot
349 test_override_url_live
350 )
351
352 for fct_test in ${TESTS[@]};
353 do
354 TRACE_PATH=$(mktemp -d)
355
356 ${fct_test}
357 if [ $? -ne 0 ]; then
358 break;
359 fi
360 # Only delete if successful
361 rm -rf $TRACE_PATH
362 done
363
364 stop_lttng_sessiond
This page took 0.037489 seconds and 3 git commands to generate.