Tests: Fix flaky live test client
[lttng-tools.git] / tests / regression / ust / python-logging / test_python_logging
... / ...
CommitLineData
1#!/bin/bash
2#
3# Copyright (C) - 2015 Philippe Proulx <pproulx@efficios.com>
4# Copyright (C) - 2014 David Goulet <dgoulet@efficios.com>
5#
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.
9#
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
13# details.
14#
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.
18
19TEST_DESC="Python support"
20
21CURDIR=$(dirname $0)/
22TESTDIR=$CURDIR/../../..
23NR_ITER=5
24NR_SEC_WAIT=1
25TESTAPP_NAME="test"
26TESTAPP_BIN="$TESTAPP_NAME.py"
27TESTAPP_PATH="$CURDIR"
28SESSION_NAME="python-test"
29EVENT_NAME="python-ev-test1"
30EVENT_NAME2="python-ev-test2"
31OUTPUT_DEST="/dev/null"
32
33NUM_TESTS=310
34
35source $TESTDIR/utils/utils.sh
36
37function run_app
38{
39 local python=$1
40 local debug_tp=$2
41 local fire_second_tp=$3
42
43 $python $TESTAPP_PATH/$TESTAPP_BIN $NR_ITER $NR_SEC_WAIT $debug_tp $fire_second_tp
44}
45
46function run_app_background
47{
48 run_app $@ &
49}
50
51function enable_python_loglevel_only()
52{
53 sess_name=$1
54 event_name="$2"
55 loglevel=$3
56 channel_name=$4
57
58 if [ -z $channel_name ]; then
59 # default channel if none specified
60 chan=""
61 else
62 chan="-c $channel_name"
63 fi
64
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"
67}
68
69function enable_python_filter()
70{
71 local sess_name="$1"
72 local event_name="$2"
73 local filter="$3"
74
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"
77}
78
79function enable_python_filter_loglevel_only()
80{
81 local sess_name="$1"
82 local event_name="$2"
83 local filter="$3"
84 local loglevel="$4"
85
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"
88}
89
90# MUST set TESTDIR before calling those functions
91
92function test_python_before_start ()
93{
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
97
98 # Run 5 times with a 1 second delay
99 run_app_background $1
100
101 start_lttng_tracing_ok $SESSION_NAME
102
103 # Wait for the applications started in background
104 wait
105
106 stop_lttng_tracing_ok $SESSION_NAME
107 destroy_lttng_session_ok $SESSION_NAME
108
109 # Validate test. Expecting all events.
110 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
111 if [ $? -ne 0 ]; then
112 return $?
113 fi
114}
115
116function test_python_after_start ()
117{
118 diag "Test Python application AFTER tracing starts"
119
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
123
124 # Run 5 times with a 1 second delay
125 run_app $1
126
127 stop_lttng_tracing_ok $SESSION_NAME
128 destroy_lttng_session_ok $SESSION_NAME
129
130 # Validate test. Expecting all events.
131 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
132 if [ $? -ne 0 ]; then
133 return $?
134 fi
135}
136
137function test_python_loglevel ()
138{
139 diag "Test Python application with loglevel"
140
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
144
145 # Run 5 times with a 1 second delay
146 run_app $1
147
148 stop_lttng_tracing_ok $SESSION_NAME
149 destroy_lttng_session_ok $SESSION_NAME
150
151 # Validate test. Expecting all events.
152 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
153 if [ $? -ne 0 ]; then
154 return $?
155 fi
156
157 diag "Test Python applications with lower loglevel"
158
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
162
163 # Run 5 times with a 1 second delay
164 run_app $1
165
166 stop_lttng_tracing_ok $SESSION_NAME
167 destroy_lttng_session_ok $SESSION_NAME
168
169 # Validate test. Expecting 0 events.
170 trace_match_only $EVENT_NAME 0 $TRACE_PATH
171 if [ $? -ne 0 ]; then
172 return $?
173 fi
174
175 diag "Test Python applications with higher loglevel"
176
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
180
181 # Run 5 times with a 1 second delay
182 run_app $1
183
184 stop_lttng_tracing_ok $SESSION_NAME
185 destroy_lttng_session_ok $SESSION_NAME
186
187 # Validate test. Expecting all events.
188 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
189 return $?
190}
191
192function test_python_loglevel_multiple ()
193{
194 diag "Test Python application with multiple loglevel"
195
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
200
201 # Run 5 times with a 1 second delay and fire two TP.
202 run_app $1 1
203
204 stop_lttng_tracing_ok $SESSION_NAME
205 destroy_lttng_session_ok $SESSION_NAME
206
207 # Validate test. Expecting all events times two.
208 trace_match_only $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH
209 if [ $? -ne 0 ]; then
210 return $?
211 fi
212
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
217
218 # Run 5 times with a 1 second delay and fire two TP.
219 run_app $1 1
220
221 stop_lttng_tracing_ok $SESSION_NAME
222 destroy_lttng_session_ok $SESSION_NAME
223
224 # Validate test. Expecting all events times two.
225 trace_match_only $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH
226 if [ $? -ne 0 ]; then
227 return $?
228 fi
229}
230
231function test_python_multi_session_loglevel()
232{
233 diag "Test Python with multiple session"
234
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
238
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
242
243 # Run 5 times with a 1 second delay and fire second TP.
244 run_app $1 1 1
245
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
250
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
254 return $?
255 fi
256 trace_matches $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1
257 if [ $? -ne 0 ]; then
258 return $?
259 fi
260
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
264 return $?
265 fi
266}
267
268function test_python_multi_session_disable()
269{
270 diag "Test Python with multiple session with disabled event"
271
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
277
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
281
282 # Run 5 times with a 1 second delay and fire second TP.
283 run_app $1 0 1
284
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
289
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
293 return $?
294 fi
295
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
299 return $?
300 fi
301}
302
303function test_python_multi_session_disable_wildcard()
304{
305 diag "Test Python with multiple session with disabled wildcard event"
306
307 create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
308 enable_python_lttng_event $SESSION_NAME-1 '*'
309
310 create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
311 enable_python_lttng_event $SESSION_NAME-2 '*'
312
313 disable_python_lttng_event $SESSION_NAME-1 '*'
314
315 start_lttng_tracing_ok $SESSION_NAME-1
316 start_lttng_tracing_ok $SESSION_NAME-2
317
318 run_app $1
319
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
324
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
328 return $?
329 fi
330
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
334 return $?
335 fi
336}
337
338function test_python_disable_all()
339{
340 diag "Test Python with multiple session with disabled all event"
341
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
346
347 disable_python_lttng_event $SESSION_NAME '*'
348
349 start_lttng_tracing_ok $SESSION_NAME
350
351 run_app $1 0 1
352
353 stop_lttng_tracing_ok $SESSION_NAME
354 destroy_lttng_session_ok $SESSION_NAME
355
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
360 return $?
361 fi
362}
363
364function test_python_multi_session()
365{
366 diag "Test Python with multiple session"
367
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
371
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
375
376 # Run 5 times with a 1 second delay and fire second TP.
377 run_app $1 0 1
378
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
383
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
387 return $?
388 fi
389
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
393 return $?
394 fi
395}
396
397function test_python_destroy_session()
398{
399 diag "Test Python two session with destroy"
400
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
404
405 # Run 5 times with a 1 second delay
406 run_app_background $1 0 1
407
408 # Wait for the applications started in background
409 wait
410
411 stop_lttng_tracing_ok $SESSION_NAME
412 destroy_lttng_session_ok $SESSION_NAME
413
414 # Validate test. Expecting at least one event num 1
415 validate_trace $EVENT_NAME $TRACE_PATH/first-sess
416 if [ $? -ne 0 ]; then
417 return $?
418 fi
419
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
423
424 # Run 5 times with a 1 second delay
425 run_app_background $1 0 1
426
427 # Wait for the applications started in background
428 wait
429
430 stop_lttng_tracing_ok $SESSION_NAME
431 destroy_lttng_session_ok $SESSION_NAME
432
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
436 return $?
437 fi
438}
439
440function test_python_filtering()
441{
442 diag "Test Python filtering"
443
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
448
449 # Run 5 times with a 1 second delay and fire second TP.
450 run_app $1 0 1
451
452 stop_lttng_tracing_ok $SESSION_NAME
453 destroy_lttng_session_ok $SESSION_NAME
454
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
458 return $?
459 fi
460
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
466
467 # Run 5 times with a 1 second delay, fire debug and second TP.
468 run_app $1 1 1
469
470 stop_lttng_tracing_ok $SESSION_NAME
471 destroy_lttng_session_ok $SESSION_NAME
472
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
476 return $?
477 fi
478}
479
480function test_python_disable()
481{
482 diag "Test Python disable event"
483
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
490
491 # Run 5 times with a 1 second delay and fire second TP.
492 run_app $1 0 1
493
494 stop_lttng_tracing_ok $SESSION_NAME
495 destroy_lttng_session_ok $SESSION_NAME
496
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
500 return $?
501 fi
502}
503
504function test_python_disable_enable()
505{
506 diag "Test Python disable event followed by an enable"
507
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
514
515 # Run 5 times with a 1 second delay and fire second TP.
516 run_app $1 0 1
517
518 stop_lttng_tracing_ok $SESSION_NAME
519 destroy_lttng_session_ok $SESSION_NAME
520
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
524 return $?
525 fi
526}
527
528function test_python_filter_loglevel()
529{
530 local BOGUS_EVENT_NAME="not_a_real_event"
531 local FILTER="int_loglevel > 30 || int_loglevel < 30"
532 local ALL_EVENTS="."
533
534 diag "Test Python a filter with a loglevel"
535
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
542
543 # Run 5 times with a 1 second delay and fire second TP.
544 run_app $1 0 1
545
546 stop_lttng_tracing_ok $SESSION_NAME
547 destroy_lttng_session_ok $SESSION_NAME
548
549 # Validate test. Expecting no events.
550 trace_match_only $ALL_EVENTS 0 $TRACE_PATH/$SESSION_NAME
551 if [ $? -ne 0 ]; then
552 return $?
553 fi
554}
555
556plan_tests $NUM_TESTS
557
558print_test_banner "$TEST_DESC"
559
560if [ ! -f "$TESTAPP_BIN" ]; then
561 withapp=0
562else
563 withapp=1
564fi
565
566skip $withapp "Python support is needed. Skipping all tests." $NUM_TESTS ||
567{
568 start_lttng_sessiond
569
570 tests=(
571 test_python_multi_session_disable_wildcard
572 test_python_multi_session_disable
573 test_python_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
579 test_python_loglevel
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
585 )
586
587 for python_version in 2 3;
588 do
589 for fct_test in ${tests[@]};
590 do
591 TRACE_PATH=$(mktemp -d)
592
593 diag "(Python $python_version)"
594 ${fct_test} python$python_version
595 if [ $? -ne 0 ]; then
596 break;
597 fi
598 rm -rf $TRACE_PATH
599 done
600 done
601
602 stop_lttng_sessiond
603}
This page took 0.024316 seconds and 4 git commands to generate.