3 # Copyright (C) - 2014 David Goulet <dgoulet@efficios.com>
5 # This program is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License, version 2 only, as published by
7 # the Free Software Foundation.
9 # This program 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 General Public License for more
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc., 51
16 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 TEST_DESC
="Java Python support"
21 TESTDIR
=$CURDIR/..
/..
/..
24 TESTAPP_NAME
="LTTngTest"
25 TESTAPP_BIN
="$TESTAPP_NAME.py"
26 TESTAPP_PATH
="$CURDIR"
27 SESSION_NAME
="python-test"
28 EVENT_NAME
="python-ev-test1"
29 EVENT_NAME2
="python-ev-test2"
30 OUTPUT_DEST
="/dev/null"
34 source $TESTDIR/utils
/utils.sh
39 local fire_second_tp
=$2
41 python
$TESTAPP_PATH/$TESTAPP_BIN $NR_ITER $NR_SEC_WAIT $debug_tp $fire_second_tp
44 function run_app_background
49 function enable_python_loglevel_only
()
56 if [ -z $channel_name ]; then
57 # default channel if none specified
60 chan
="-c $channel_name"
63 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel-only $loglevel "$event_name" $chan -s $sess_name -p >$OUTPUT_DEST
64 ok $?
"Enable Python event $event_name for session $sess_name with loglevel-only $loglevel"
67 function enable_python_filter
()
73 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -p --filter "$filter" >/dev
/null
2>&1
74 ok $?
"Enable event $event_name with filter $filter for session $sess_name"
77 function enable_python_filter_loglevel_only
()
84 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel-only $loglevel "$event_name" -s $sess_name -p --filter "$filter" >$OUTPUT_DEST
85 ok $?
"Enable event $event_name with filter \"$filter\" and loglevel-only $loglevel for session $sess_name"
88 # MUST set TESTDIR before calling those functions
90 function test_python_before_start
()
92 diag
"Test Python application BEFORE tracing starts"
93 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
94 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME
96 # Run 5 times with a 1 second delay
99 start_lttng_tracing
$SESSION_NAME
101 # Wait for the applications started in background
104 stop_lttng_tracing
$SESSION_NAME
105 destroy_lttng_session
$SESSION_NAME
107 # Validate test. Expecting all events.
108 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH
109 if [ $?
-ne 0 ]; then
114 function test_python_after_start
()
116 diag
"Test Python application AFTER tracing starts"
118 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
119 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME
120 start_lttng_tracing
$SESSION_NAME
122 # Run 5 times with a 1 second delay
125 stop_lttng_tracing
$SESSION_NAME
126 destroy_lttng_session
$SESSION_NAME
128 # Validate test. Expecting all events.
129 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH
130 if [ $?
-ne 0 ]; then
135 function test_python_loglevel
()
137 diag
"Test Python application with loglevel"
139 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
140 enable_python_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "INFO"
141 start_lttng_tracing
$SESSION_NAME
143 # Run 5 times with a 1 second delay
146 stop_lttng_tracing
$SESSION_NAME
147 destroy_lttng_session
$SESSION_NAME
149 # Validate test. Expecting all events.
150 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH
151 if [ $?
-ne 0 ]; then
155 diag
"Test Python applications with lower loglevel"
157 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
158 enable_python_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "CRITICAL"
159 start_lttng_tracing
$SESSION_NAME
161 # Run 5 times with a 1 second delay
164 stop_lttng_tracing
$SESSION_NAME
165 destroy_lttng_session
$SESSION_NAME
167 # Validate test. Expecting 0 events.
168 trace_match_only
$EVENT_NAME 0 $TRACE_PATH
169 if [ $?
-ne 0 ]; then
173 diag
"Test Python applications with higher loglevel"
175 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
176 enable_python_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "DEBUG"
177 start_lttng_tracing
$SESSION_NAME
179 # Run 5 times with a 1 second delay
182 stop_lttng_tracing
$SESSION_NAME
183 destroy_lttng_session
$SESSION_NAME
185 # Validate test. Expecting all events.
186 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH
190 function test_python_loglevel_multiple
()
192 diag
"Test Python application with multiple loglevel"
194 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
195 enable_python_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "INFO"
196 enable_python_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "DEBUG"
197 start_lttng_tracing
$SESSION_NAME
199 # Run 5 times with a 1 second delay and fire two TP.
202 stop_lttng_tracing
$SESSION_NAME
203 destroy_lttng_session
$SESSION_NAME
205 # Validate test. Expecting all events times two.
206 trace_match_only
$EVENT_NAME $
(($NR_ITER * 2)) $TRACE_PATH
207 if [ $?
-ne 0 ]; then
211 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
212 enable_python_lttng_event_loglevel
$SESSION_NAME '*' "INFO"
213 enable_python_lttng_event_loglevel
$SESSION_NAME '*' "DEBUG"
214 start_lttng_tracing
$SESSION_NAME
216 # Run 5 times with a 1 second delay and fire two TP.
219 stop_lttng_tracing
$SESSION_NAME
220 destroy_lttng_session
$SESSION_NAME
222 # Validate test. Expecting all events times two.
223 trace_match_only
$EVENT_NAME $
(($NR_ITER * 2)) $TRACE_PATH
224 if [ $?
-ne 0 ]; then
229 function test_python_multi_session_loglevel
()
231 diag
"Test Python with multiple session"
233 create_lttng_session_ok
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
234 enable_python_loglevel_only
$SESSION_NAME-1 '*' "INFO"
235 start_lttng_tracing
$SESSION_NAME-1
237 create_lttng_session_ok
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
238 enable_python_loglevel_only
$SESSION_NAME-2 '*' "DEBUG"
239 start_lttng_tracing
$SESSION_NAME-2
241 # Run 5 times with a 1 second delay and fire second TP.
244 stop_lttng_tracing
$SESSION_NAME-1
245 stop_lttng_tracing
$SESSION_NAME-2
246 destroy_lttng_session
$SESSION_NAME-1
247 destroy_lttng_session
$SESSION_NAME-2
249 # Expecting NR_ITER events being the main event and the second tp one.
250 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1
251 if [ $?
-ne 0 ]; then
254 trace_matches
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1
255 if [ $?
-ne 0 ]; then
259 # Expectin NR_ITER events being the debug TP.
260 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2
261 if [ $?
-ne 0 ]; then
266 function test_python_multi_session_disable
()
268 diag
"Test Python with multiple session with disabled event"
270 create_lttng_session_ok
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
271 enable_python_lttng_event
$SESSION_NAME-1 $EVENT_NAME
272 enable_python_lttng_event
$SESSION_NAME-1 $EVENT_NAME2
273 disable_python_lttng_event
$SESSION_NAME-1 $EVENT_NAME
274 start_lttng_tracing
$SESSION_NAME-1
276 create_lttng_session_ok
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
277 enable_python_lttng_event
$SESSION_NAME-2 $EVENT_NAME2
278 start_lttng_tracing
$SESSION_NAME-2
280 # Run 5 times with a 1 second delay and fire second TP.
283 stop_lttng_tracing
$SESSION_NAME-1
284 stop_lttng_tracing
$SESSION_NAME-2
285 destroy_lttng_session
$SESSION_NAME-1
286 destroy_lttng_session
$SESSION_NAME-2
288 # Validate test. Expecting one event of the second TP.
289 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1
290 if [ $?
-ne 0 ]; then
294 # Validate test. Expecting one event of the second TP.
295 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
296 if [ $?
-ne 0 ]; then
301 function test_python_multi_session_disable_wildcard
()
303 diag
"Test Python with multiple session with disabled wildcard event"
305 create_lttng_session_ok
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
306 enable_python_lttng_event
$SESSION_NAME-1 '*'
308 create_lttng_session_ok
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
309 enable_python_lttng_event
$SESSION_NAME-2 '*'
311 disable_python_lttng_event
$SESSION_NAME-1 '*'
313 start_lttng_tracing
$SESSION_NAME-1
314 start_lttng_tracing
$SESSION_NAME-2
318 stop_lttng_tracing
$SESSION_NAME-1
319 stop_lttng_tracing
$SESSION_NAME-2
320 destroy_lttng_session
$SESSION_NAME-1
321 destroy_lttng_session
$SESSION_NAME-2
323 # Validate test. Expecting NO event of the first TP.
324 trace_match_only
$EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME-1
325 if [ $?
-ne 0 ]; then
329 # Validate test. Expecting all events of the first TP.
330 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2
331 if [ $?
-ne 0 ]; then
336 function test_python_disable_all
()
338 diag
"Test Python with multiple session with disabled all event"
340 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
341 enable_python_lttng_event
$SESSION_NAME '*'
342 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME
343 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME2
345 disable_python_lttng_event
$SESSION_NAME '*'
347 start_lttng_tracing
$SESSION_NAME
351 stop_lttng_tracing
$SESSION_NAME
352 destroy_lttng_session
$SESSION_NAME
354 # Validate test. Expecting NO event of the first TP and second TP.
355 trace_match_only
$EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME
356 trace_match_only
$EVENT_NAME2 0 $TRACE_PATH/$SESSION_NAME
357 if [ $?
-ne 0 ]; then
362 function test_python_multi_session
()
364 diag
"Test Python with multiple session"
366 create_lttng_session_ok
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
367 enable_python_lttng_event
$SESSION_NAME-1 $EVENT_NAME
368 start_lttng_tracing
$SESSION_NAME-1
370 create_lttng_session_ok
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
371 enable_python_lttng_event
$SESSION_NAME-2 $EVENT_NAME2
372 start_lttng_tracing
$SESSION_NAME-2
374 # Run 5 times with a 1 second delay and fire second TP.
377 stop_lttng_tracing
$SESSION_NAME-1
378 stop_lttng_tracing
$SESSION_NAME-2
379 destroy_lttng_session
$SESSION_NAME-1
380 destroy_lttng_session
$SESSION_NAME-2
382 # Validate test. Expecting all events of first TP
383 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1
384 if [ $?
-ne 0 ]; then
388 # Validate test. Expecting one event of the second TP.
389 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
390 if [ $?
-ne 0 ]; then
395 function test_python_destroy_session
()
397 diag
"Test Python two session with destroy"
399 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/first-sess
400 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME
401 start_lttng_tracing
$SESSION_NAME
403 # Run 5 times with a 1 second delay
404 run_app_background
0 1
406 # Wait for the applications started in background
409 stop_lttng_tracing
$SESSION_NAME
410 destroy_lttng_session
$SESSION_NAME
412 # Validate test. Expecting at least one event num 1
413 validate_trace
$EVENT_NAME $TRACE_PATH/first-sess
414 if [ $?
-ne 0 ]; then
418 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/second-sess
419 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME2
420 start_lttng_tracing
$SESSION_NAME
422 # Run 5 times with a 1 second delay
423 run_app_background
0 1
425 # Wait for the applications started in background
428 stop_lttng_tracing
$SESSION_NAME
429 destroy_lttng_session
$SESSION_NAME
431 # Validate test. Expecting only one event num 2
432 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/second-sess
433 if [ $?
-ne 0 ]; then
438 function test_python_filtering
()
440 diag
"Test Python filtering"
442 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
443 # Enable all event with a filter.
444 enable_python_filter
$SESSION_NAME '*' 'msg == "python-ev-test2 fired"'
445 start_lttng_tracing
$SESSION_NAME
447 # Run 5 times with a 1 second delay and fire second TP.
450 stop_lttng_tracing
$SESSION_NAME
451 destroy_lttng_session
$SESSION_NAME
453 # Validate test. Expecting one event of the second TP only.
454 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
455 if [ $?
-ne 0 ]; then
459 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
460 # Enable first Logger but filter msg payload for the INFO one while
461 # triggering the debug and second TP.
462 enable_python_filter
$SESSION_NAME $EVENT_NAME 'msg == "python-ev-test1 fired"'
463 start_lttng_tracing
$SESSION_NAME
465 # Run 5 times with a 1 second delay, fire debug and second TP.
468 stop_lttng_tracing
$SESSION_NAME
469 destroy_lttng_session
$SESSION_NAME
471 # Validate test. Expecting NR_ITER event of the main INFO tp.
472 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
473 if [ $?
-ne 0 ]; then
478 function test_python_disable
()
480 diag
"Test Python disable event"
482 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
483 # Enable all event with a filter.
484 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME
485 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME2
486 disable_python_lttng_event
$SESSION_NAME $EVENT_NAME
487 start_lttng_tracing
$SESSION_NAME
489 # Run 5 times with a 1 second delay and fire second TP.
492 stop_lttng_tracing
$SESSION_NAME
493 destroy_lttng_session
$SESSION_NAME
495 # Validate test. Expecting one event of the second TP only.
496 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
497 if [ $?
-ne 0 ]; then
502 function test_python_disable_enable
()
504 diag
"Test Python disable event followed by an enable"
506 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
507 # Enable all event with a filter.
508 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME
509 disable_python_lttng_event
$SESSION_NAME $EVENT_NAME
510 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME
511 start_lttng_tracing
$SESSION_NAME
513 # Run 5 times with a 1 second delay and fire second TP.
516 stop_lttng_tracing
$SESSION_NAME
517 destroy_lttng_session
$SESSION_NAME
519 # Validate test. Expecting NR_ITER event of the main INFO tp.
520 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
521 if [ $?
-ne 0 ]; then
526 function test_python_filter_loglevel
()
528 local BOGUS_EVENT_NAME
="not_a_real_event"
529 local FILTER
="int_loglevel > 30 || int_loglevel < 30"
532 diag
"Test Python a filter with a loglevel"
534 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
535 # Enable an event with a filter and the loglevel-only option.
536 enable_python_filter_loglevel_only
$SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" "INFO"
537 disable_python_lttng_event
$SESSION_NAME $BOGUS_EVENT_NAME
538 enable_python_filter_loglevel_only
$SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" "INFO"
539 start_lttng_tracing
$SESSION_NAME
541 # Run 5 times with a 1 second delay and fire second TP.
544 stop_lttng_tracing
$SESSION_NAME
545 destroy_lttng_session
$SESSION_NAME
547 # Validate test. Expecting no events.
548 trace_match_only
$ALL_EVENTS 0 $TRACE_PATH/$SESSION_NAME
549 if [ $?
-ne 0 ]; then
554 plan_tests
$NUM_TESTS
556 print_test_banner
"$TEST_DESC"
558 if [ ! -f "$TESTAPP_BIN" ]; then
564 skip
$withapp "Python support is needed. Skipping all tests." $NUM_TESTS ||
569 test_python_multi_session_disable_wildcard
570 test_python_multi_session_disable
572 test_python_disable_enable
573 test_python_disable_all
574 test_python_filtering
575 test_python_multi_session_loglevel
576 test_python_destroy_session
578 test_python_loglevel_multiple
579 test_python_before_start
580 test_python_after_start
581 test_python_multi_session
582 test_python_filter_loglevel
585 for fct_test
in ${tests[@]};
587 TRACE_PATH
=$
(mktemp
-d)
590 if [ $?
-ne 0 ]; then