3 # Copyright (C) - 2015 Philippe Proulx <pproulx@efficios.com>
4 # Copyright (C) - 2014 David Goulet <dgoulet@efficios.com>
6 # This program is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License, version 2 only, as published by
8 # the Free Software Foundation.
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 # You should have received a copy of the GNU General Public License along with
16 # this program; if not, write to the Free Software Foundation, Inc., 51
17 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 TEST_DESC
="Python support"
22 TESTDIR
=$CURDIR/..
/..
/..
26 TESTAPP_BIN
="$TESTAPP_NAME.py"
27 TESTAPP_PATH
="$CURDIR"
28 SESSION_NAME
="python-test"
29 EVENT_NAME
="python-ev-test1"
30 EVENT_NAME2
="python-ev-test2"
31 OUTPUT_DEST
="/dev/null"
35 source $TESTDIR/utils
/utils.sh
41 local fire_second_tp
=$3
43 $python $TESTAPP_PATH/$TESTAPP_BIN $NR_ITER $NR_SEC_WAIT $debug_tp $fire_second_tp
46 function run_app_background
51 function enable_python_loglevel_only
()
58 if [ -z $channel_name ]; then
59 # default channel if none specified
62 chan
="-c $channel_name"
65 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel-only $loglevel "$event_name" $chan -s $sess_name -p >$OUTPUT_DEST
66 ok $?
"Enable Python event $event_name for session $sess_name with loglevel-only $loglevel"
69 function enable_python_filter
()
75 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
"$event_name" -s $sess_name -p --filter "$filter" >/dev
/null
2>&1
76 ok $?
"Enable event $event_name with filter $filter for session $sess_name"
79 function enable_python_filter_loglevel_only
()
86 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
--loglevel-only $loglevel "$event_name" -s $sess_name -p --filter "$filter" >$OUTPUT_DEST
87 ok $?
"Enable event $event_name with filter \"$filter\" and loglevel-only $loglevel for session $sess_name"
90 # MUST set TESTDIR before calling those functions
92 function test_python_before_start
()
94 diag
"Test Python application BEFORE tracing starts"
95 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
96 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME
98 # Run 5 times with a 1 second delay
101 start_lttng_tracing_ok
$SESSION_NAME
103 # Wait for the applications started in background
106 stop_lttng_tracing_ok
$SESSION_NAME
107 destroy_lttng_session_ok
$SESSION_NAME
109 # Validate test. Expecting all events.
110 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH
111 if [ $?
-ne 0 ]; then
116 function test_python_after_start
()
118 diag
"Test Python application AFTER tracing starts"
120 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
121 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME
122 start_lttng_tracing_ok
$SESSION_NAME
124 # Run 5 times with a 1 second delay
127 stop_lttng_tracing_ok
$SESSION_NAME
128 destroy_lttng_session_ok
$SESSION_NAME
130 # Validate test. Expecting all events.
131 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH
132 if [ $?
-ne 0 ]; then
137 function test_python_loglevel
()
139 diag
"Test Python application with loglevel"
141 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
142 enable_python_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "INFO"
143 start_lttng_tracing_ok
$SESSION_NAME
145 # Run 5 times with a 1 second delay
148 stop_lttng_tracing_ok
$SESSION_NAME
149 destroy_lttng_session_ok
$SESSION_NAME
151 # Validate test. Expecting all events.
152 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH
153 if [ $?
-ne 0 ]; then
157 diag
"Test Python applications with lower loglevel"
159 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
160 enable_python_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "CRITICAL"
161 start_lttng_tracing_ok
$SESSION_NAME
163 # Run 5 times with a 1 second delay
166 stop_lttng_tracing_ok
$SESSION_NAME
167 destroy_lttng_session_ok
$SESSION_NAME
169 # Validate test. Expecting 0 events.
170 trace_match_only
$EVENT_NAME 0 $TRACE_PATH
171 if [ $?
-ne 0 ]; then
175 diag
"Test Python applications with higher loglevel"
177 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
178 enable_python_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "DEBUG"
179 start_lttng_tracing_ok
$SESSION_NAME
181 # Run 5 times with a 1 second delay
184 stop_lttng_tracing_ok
$SESSION_NAME
185 destroy_lttng_session_ok
$SESSION_NAME
187 # Validate test. Expecting all events.
188 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH
192 function test_python_loglevel_multiple
()
194 diag
"Test Python application with multiple loglevel"
196 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
197 enable_python_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "INFO"
198 enable_python_lttng_event_loglevel
$SESSION_NAME $EVENT_NAME "DEBUG"
199 start_lttng_tracing_ok
$SESSION_NAME
201 # Run 5 times with a 1 second delay and fire two TP.
204 stop_lttng_tracing_ok
$SESSION_NAME
205 destroy_lttng_session_ok
$SESSION_NAME
207 # Validate test. Expecting all events times two.
208 trace_match_only
$EVENT_NAME $
(($NR_ITER * 2)) $TRACE_PATH
209 if [ $?
-ne 0 ]; then
213 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
214 enable_python_lttng_event_loglevel
$SESSION_NAME '*' "INFO"
215 enable_python_lttng_event_loglevel
$SESSION_NAME '*' "DEBUG"
216 start_lttng_tracing_ok
$SESSION_NAME
218 # Run 5 times with a 1 second delay and fire two TP.
221 stop_lttng_tracing_ok
$SESSION_NAME
222 destroy_lttng_session_ok
$SESSION_NAME
224 # Validate test. Expecting all events times two.
225 trace_match_only
$EVENT_NAME $
(($NR_ITER * 2)) $TRACE_PATH
226 if [ $?
-ne 0 ]; then
231 function test_python_multi_session_loglevel
()
233 diag
"Test Python with multiple session"
235 create_lttng_session_ok
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
236 enable_python_loglevel_only
$SESSION_NAME-1 '*' "INFO"
237 start_lttng_tracing_ok
$SESSION_NAME-1
239 create_lttng_session_ok
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
240 enable_python_loglevel_only
$SESSION_NAME-2 '*' "DEBUG"
241 start_lttng_tracing_ok
$SESSION_NAME-2
243 # Run 5 times with a 1 second delay and fire second TP.
246 stop_lttng_tracing_ok
$SESSION_NAME-1
247 stop_lttng_tracing_ok
$SESSION_NAME-2
248 destroy_lttng_session_ok
$SESSION_NAME-1
249 destroy_lttng_session_ok
$SESSION_NAME-2
251 # Expecting NR_ITER events being the main event and the second tp one.
252 trace_matches
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1
253 if [ $?
-ne 0 ]; then
256 trace_matches
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1
257 if [ $?
-ne 0 ]; then
261 # Expectin NR_ITER events being the debug TP.
262 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2
263 if [ $?
-ne 0 ]; then
268 function test_python_multi_session_disable
()
270 diag
"Test Python with multiple session with disabled event"
272 create_lttng_session_ok
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
273 enable_python_lttng_event
$SESSION_NAME-1 $EVENT_NAME
274 enable_python_lttng_event
$SESSION_NAME-1 $EVENT_NAME2
275 disable_python_lttng_event
$SESSION_NAME-1 $EVENT_NAME
276 start_lttng_tracing_ok
$SESSION_NAME-1
278 create_lttng_session_ok
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
279 enable_python_lttng_event
$SESSION_NAME-2 $EVENT_NAME2
280 start_lttng_tracing_ok
$SESSION_NAME-2
282 # Run 5 times with a 1 second delay and fire second TP.
285 stop_lttng_tracing_ok
$SESSION_NAME-1
286 stop_lttng_tracing_ok
$SESSION_NAME-2
287 destroy_lttng_session_ok
$SESSION_NAME-1
288 destroy_lttng_session_ok
$SESSION_NAME-2
290 # Validate test. Expecting one event of the second TP.
291 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1
292 if [ $?
-ne 0 ]; then
296 # Validate test. Expecting one event of the second TP.
297 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
298 if [ $?
-ne 0 ]; then
303 function test_python_multi_session_disable_wildcard
()
305 diag
"Test Python with multiple session with disabled wildcard event"
307 create_lttng_session_ok
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
308 enable_python_lttng_event
$SESSION_NAME-1 '*'
310 create_lttng_session_ok
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
311 enable_python_lttng_event
$SESSION_NAME-2 '*'
313 disable_python_lttng_event
$SESSION_NAME-1 '*'
315 start_lttng_tracing_ok
$SESSION_NAME-1
316 start_lttng_tracing_ok
$SESSION_NAME-2
320 stop_lttng_tracing_ok
$SESSION_NAME-1
321 stop_lttng_tracing_ok
$SESSION_NAME-2
322 destroy_lttng_session_ok
$SESSION_NAME-1
323 destroy_lttng_session_ok
$SESSION_NAME-2
325 # Validate test. Expecting NO event of the first TP.
326 trace_match_only
$EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME-1
327 if [ $?
-ne 0 ]; then
331 # Validate test. Expecting all events of the first TP.
332 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2
333 if [ $?
-ne 0 ]; then
338 function test_python_disable_all
()
340 diag
"Test Python with multiple session with disabled all event"
342 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
343 enable_python_lttng_event
$SESSION_NAME '*'
344 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME
345 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME2
347 disable_python_lttng_event
$SESSION_NAME '*'
349 start_lttng_tracing_ok
$SESSION_NAME
353 stop_lttng_tracing_ok
$SESSION_NAME
354 destroy_lttng_session_ok
$SESSION_NAME
356 # Validate test. Expecting NO event of the first TP and second TP.
357 trace_match_only
$EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME
358 trace_match_only
$EVENT_NAME2 0 $TRACE_PATH/$SESSION_NAME
359 if [ $?
-ne 0 ]; then
364 function test_python_multi_session
()
366 diag
"Test Python with multiple session"
368 create_lttng_session_ok
$SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
369 enable_python_lttng_event
$SESSION_NAME-1 $EVENT_NAME
370 start_lttng_tracing_ok
$SESSION_NAME-1
372 create_lttng_session_ok
$SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
373 enable_python_lttng_event
$SESSION_NAME-2 $EVENT_NAME2
374 start_lttng_tracing_ok
$SESSION_NAME-2
376 # Run 5 times with a 1 second delay and fire second TP.
379 stop_lttng_tracing_ok
$SESSION_NAME-1
380 stop_lttng_tracing_ok
$SESSION_NAME-2
381 destroy_lttng_session_ok
$SESSION_NAME-1
382 destroy_lttng_session_ok
$SESSION_NAME-2
384 # Validate test. Expecting all events of first TP
385 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1
386 if [ $?
-ne 0 ]; then
390 # Validate test. Expecting one event of the second TP.
391 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2
392 if [ $?
-ne 0 ]; then
397 function test_python_destroy_session
()
399 diag
"Test Python two session with destroy"
401 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/first-sess
402 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME
403 start_lttng_tracing_ok
$SESSION_NAME
405 # Run 5 times with a 1 second delay
406 run_app_background
$1 0 1
408 # Wait for the applications started in background
411 stop_lttng_tracing_ok
$SESSION_NAME
412 destroy_lttng_session_ok
$SESSION_NAME
414 # Validate test. Expecting at least one event num 1
415 validate_trace
$EVENT_NAME $TRACE_PATH/first-sess
416 if [ $?
-ne 0 ]; then
420 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/second-sess
421 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME2
422 start_lttng_tracing_ok
$SESSION_NAME
424 # Run 5 times with a 1 second delay
425 run_app_background
$1 0 1
427 # Wait for the applications started in background
430 stop_lttng_tracing_ok
$SESSION_NAME
431 destroy_lttng_session_ok
$SESSION_NAME
433 # Validate test. Expecting only one event num 2
434 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/second-sess
435 if [ $?
-ne 0 ]; then
440 function test_python_filtering
()
442 diag
"Test Python filtering"
444 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
445 # Enable all event with a filter.
446 enable_python_filter
$SESSION_NAME '*' 'msg == "python-ev-test2 fired [INFO]"'
447 start_lttng_tracing_ok
$SESSION_NAME
449 # Run 5 times with a 1 second delay and fire second TP.
452 stop_lttng_tracing_ok
$SESSION_NAME
453 destroy_lttng_session_ok
$SESSION_NAME
455 # Validate test. Expecting one event of the second TP only.
456 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
457 if [ $?
-ne 0 ]; then
461 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
462 # Enable first Logger but filter msg payload for the INFO one while
463 # triggering the debug and second TP.
464 enable_python_filter
$SESSION_NAME $EVENT_NAME 'msg == "python-ev-test1 fired" [INFO]'
465 start_lttng_tracing_ok
$SESSION_NAME
467 # Run 5 times with a 1 second delay, fire debug and second TP.
470 stop_lttng_tracing_ok
$SESSION_NAME
471 destroy_lttng_session_ok
$SESSION_NAME
473 # Validate test. Expecting NR_ITER event of the main INFO tp.
474 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
475 if [ $?
-ne 0 ]; then
480 function test_python_disable
()
482 diag
"Test Python disable event"
484 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
485 # Enable all event with a filter.
486 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME
487 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME2
488 disable_python_lttng_event
$SESSION_NAME $EVENT_NAME
489 start_lttng_tracing_ok
$SESSION_NAME
491 # Run 5 times with a 1 second delay and fire second TP.
494 stop_lttng_tracing_ok
$SESSION_NAME
495 destroy_lttng_session_ok
$SESSION_NAME
497 # Validate test. Expecting one event of the second TP only.
498 trace_match_only
$EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
499 if [ $?
-ne 0 ]; then
504 function test_python_disable_enable
()
506 diag
"Test Python disable event followed by an enable"
508 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
509 # Enable all event with a filter.
510 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME
511 disable_python_lttng_event
$SESSION_NAME $EVENT_NAME
512 enable_python_lttng_event
$SESSION_NAME $EVENT_NAME
513 start_lttng_tracing_ok
$SESSION_NAME
515 # Run 5 times with a 1 second delay and fire second TP.
518 stop_lttng_tracing_ok
$SESSION_NAME
519 destroy_lttng_session_ok
$SESSION_NAME
521 # Validate test. Expecting NR_ITER event of the main INFO tp.
522 trace_match_only
$EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
523 if [ $?
-ne 0 ]; then
528 function test_python_filter_loglevel
()
530 local BOGUS_EVENT_NAME
="not_a_real_event"
531 local FILTER
="int_loglevel > 30 || int_loglevel < 30"
534 diag
"Test Python a filter with a loglevel"
536 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH/$SESSION_NAME
537 # Enable an event with a filter and the loglevel-only option.
538 enable_python_filter_loglevel_only
$SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" "INFO"
539 disable_python_lttng_event
$SESSION_NAME $BOGUS_EVENT_NAME
540 enable_python_filter_loglevel_only
$SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" "INFO"
541 start_lttng_tracing_ok
$SESSION_NAME
543 # Run 5 times with a 1 second delay and fire second TP.
546 stop_lttng_tracing_ok
$SESSION_NAME
547 destroy_lttng_session_ok
$SESSION_NAME
549 # Validate test. Expecting no events.
550 trace_match_only
$ALL_EVENTS 0 $TRACE_PATH/$SESSION_NAME
551 if [ $?
-ne 0 ]; then
556 plan_tests
$NUM_TESTS
558 print_test_banner
"$TEST_DESC"
560 if [ ! -f "$TESTAPP_BIN" ]; then
566 skip
$withapp "Python support is needed. Skipping all tests." $NUM_TESTS ||
571 test_python_multi_session_disable_wildcard
572 test_python_multi_session_disable
574 test_python_disable_enable
575 test_python_disable_all
576 test_python_filtering
577 test_python_multi_session_loglevel
578 test_python_destroy_session
580 test_python_loglevel_multiple
581 test_python_before_start
582 test_python_after_start
583 test_python_multi_session
584 test_python_filter_loglevel
587 for python_version
in 2 3;
589 for fct_test
in ${tests[@]};
591 TRACE_PATH
=$
(mktemp
-d)
593 diag
"(Python $python_version)"
594 ${fct_test} python
$python_version
595 if [ $?
-ne 0 ]; then