Refactor: test: wrapper for start_lttng_tracing
[lttng-tools.git] / tests / regression / ust / python-logging / test_python_logging
CommitLineData
0e115563
DG
1#!/bin/bash
2#
3# Copyright (C) - 2014 David Goulet <dgoulet@efficios.com>
4#
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.
8#
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
12# details.
13#
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.
17
18TEST_DESC="Java Python support"
19
20CURDIR=$(dirname $0)/
21TESTDIR=$CURDIR/../../..
22NR_ITER=5
23NR_SEC_WAIT=1
24TESTAPP_NAME="LTTngTest"
25TESTAPP_BIN="$TESTAPP_NAME.py"
26TESTAPP_PATH="$CURDIR"
27SESSION_NAME="python-test"
28EVENT_NAME="python-ev-test1"
29EVENT_NAME2="python-ev-test2"
30OUTPUT_DEST="/dev/null"
31
32NUM_TESTS=156
33
34source $TESTDIR/utils/utils.sh
35
36function run_app
37{
38 local debug_tp=$1
39 local fire_second_tp=$2
40
41 python $TESTAPP_PATH/$TESTAPP_BIN $NR_ITER $NR_SEC_WAIT $debug_tp $fire_second_tp
42}
43
44function run_app_background
45{
46 run_app $@ &
47}
48
49function enable_python_loglevel_only()
50{
51 sess_name=$1
52 event_name="$2"
53 loglevel=$3
54 channel_name=$4
55
56 if [ -z $channel_name ]; then
57 # default channel if none specified
58 chan=""
59 else
60 chan="-c $channel_name"
61 fi
62
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"
65}
66
67function enable_python_filter()
68{
69 local sess_name="$1"
70 local event_name="$2"
71 local filter="$3"
72
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"
75}
76
77function enable_python_filter_loglevel_only()
78{
79 local sess_name="$1"
80 local event_name="$2"
81 local filter="$3"
82 local loglevel="$4"
83
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"
86}
87
88# MUST set TESTDIR before calling those functions
89
90function test_python_before_start ()
91{
92 diag "Test Python application BEFORE tracing starts"
bf6ae429 93 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
0e115563
DG
94 enable_python_lttng_event $SESSION_NAME $EVENT_NAME
95
96 # Run 5 times with a 1 second delay
97 run_app_background
98
e563bbdb 99 start_lttng_tracing_ok $SESSION_NAME
0e115563
DG
100
101 # Wait for the applications started in background
0fc2834c 102 wait
0e115563
DG
103
104 stop_lttng_tracing $SESSION_NAME
105 destroy_lttng_session $SESSION_NAME
106
107 # Validate test. Expecting all events.
108 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
109 if [ $? -ne 0 ]; then
110 return $?
111 fi
112}
113
114function test_python_after_start ()
115{
116 diag "Test Python application AFTER tracing starts"
117
bf6ae429 118 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
0e115563 119 enable_python_lttng_event $SESSION_NAME $EVENT_NAME
e563bbdb 120 start_lttng_tracing_ok $SESSION_NAME
0e115563
DG
121
122 # Run 5 times with a 1 second delay
123 run_app
124
125 stop_lttng_tracing $SESSION_NAME
126 destroy_lttng_session $SESSION_NAME
127
128 # Validate test. Expecting all events.
129 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
130 if [ $? -ne 0 ]; then
131 return $?
132 fi
133}
134
135function test_python_loglevel ()
136{
137 diag "Test Python application with loglevel"
138
bf6ae429 139 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
0e115563 140 enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "INFO"
e563bbdb 141 start_lttng_tracing_ok $SESSION_NAME
0e115563
DG
142
143 # Run 5 times with a 1 second delay
144 run_app
145
146 stop_lttng_tracing $SESSION_NAME
147 destroy_lttng_session $SESSION_NAME
148
149 # Validate test. Expecting all events.
150 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
151 if [ $? -ne 0 ]; then
152 return $?
153 fi
154
155 diag "Test Python applications with lower loglevel"
156
bf6ae429 157 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
0e115563 158 enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "CRITICAL"
e563bbdb 159 start_lttng_tracing_ok $SESSION_NAME
0e115563
DG
160
161 # Run 5 times with a 1 second delay
162 run_app
163
164 stop_lttng_tracing $SESSION_NAME
165 destroy_lttng_session $SESSION_NAME
166
167 # Validate test. Expecting 0 events.
168 trace_match_only $EVENT_NAME 0 $TRACE_PATH
169 if [ $? -ne 0 ]; then
170 return $?
171 fi
172
173 diag "Test Python applications with higher loglevel"
174
bf6ae429 175 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
0e115563 176 enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "DEBUG"
e563bbdb 177 start_lttng_tracing_ok $SESSION_NAME
0e115563
DG
178
179 # Run 5 times with a 1 second delay
180 run_app
181
182 stop_lttng_tracing $SESSION_NAME
183 destroy_lttng_session $SESSION_NAME
184
185 # Validate test. Expecting all events.
186 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
187 return $?
188}
189
190function test_python_loglevel_multiple ()
191{
192 diag "Test Python application with multiple loglevel"
193
bf6ae429 194 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
0e115563
DG
195 enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "INFO"
196 enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "DEBUG"
e563bbdb 197 start_lttng_tracing_ok $SESSION_NAME
0e115563
DG
198
199 # Run 5 times with a 1 second delay and fire two TP.
200 run_app 1
201
202 stop_lttng_tracing $SESSION_NAME
203 destroy_lttng_session $SESSION_NAME
204
205 # Validate test. Expecting all events times two.
206 trace_match_only $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH
207 if [ $? -ne 0 ]; then
208 return $?
209 fi
210
bf6ae429 211 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
0e115563
DG
212 enable_python_lttng_event_loglevel $SESSION_NAME '*' "INFO"
213 enable_python_lttng_event_loglevel $SESSION_NAME '*' "DEBUG"
e563bbdb 214 start_lttng_tracing_ok $SESSION_NAME
0e115563
DG
215
216 # Run 5 times with a 1 second delay and fire two TP.
217 run_app 1
218
219 stop_lttng_tracing $SESSION_NAME
220 destroy_lttng_session $SESSION_NAME
221
222 # Validate test. Expecting all events times two.
223 trace_match_only $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH
224 if [ $? -ne 0 ]; then
225 return $?
226 fi
227}
228
229function test_python_multi_session_loglevel()
230{
231 diag "Test Python with multiple session"
232
bf6ae429 233 create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
0e115563 234 enable_python_loglevel_only $SESSION_NAME-1 '*' "INFO"
e563bbdb 235 start_lttng_tracing_ok $SESSION_NAME-1
0e115563 236
bf6ae429 237 create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
0e115563 238 enable_python_loglevel_only $SESSION_NAME-2 '*' "DEBUG"
e563bbdb 239 start_lttng_tracing_ok $SESSION_NAME-2
0e115563
DG
240
241 # Run 5 times with a 1 second delay and fire second TP.
242 run_app 1 1
243
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
248
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
252 return $?
253 fi
254 trace_matches $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1
255 if [ $? -ne 0 ]; then
256 return $?
257 fi
258
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
262 return $?
263 fi
264}
265
266function test_python_multi_session_disable()
267{
268 diag "Test Python with multiple session with disabled event"
269
bf6ae429 270 create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
0e115563
DG
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
e563bbdb 274 start_lttng_tracing_ok $SESSION_NAME-1
0e115563 275
bf6ae429 276 create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
0e115563 277 enable_python_lttng_event $SESSION_NAME-2 $EVENT_NAME2
e563bbdb 278 start_lttng_tracing_ok $SESSION_NAME-2
0e115563
DG
279
280 # Run 5 times with a 1 second delay and fire second TP.
281 run_app 0 1
282
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
287
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
291 return $?
292 fi
293
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
297 return $?
298 fi
299}
300
301function test_python_multi_session_disable_wildcard()
302{
303 diag "Test Python with multiple session with disabled wildcard event"
304
bf6ae429 305 create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
0e115563
DG
306 enable_python_lttng_event $SESSION_NAME-1 '*'
307
bf6ae429 308 create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
0e115563
DG
309 enable_python_lttng_event $SESSION_NAME-2 '*'
310
311 disable_python_lttng_event $SESSION_NAME-1 '*'
312
e563bbdb
JR
313 start_lttng_tracing_ok $SESSION_NAME-1
314 start_lttng_tracing_ok $SESSION_NAME-2
0e115563
DG
315
316 run_app
317
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
322
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
326 return $?
327 fi
328
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
332 return $?
333 fi
334}
335
336function test_python_disable_all()
337{
338 diag "Test Python with multiple session with disabled all event"
339
bf6ae429 340 create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME
0e115563
DG
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
344
345 disable_python_lttng_event $SESSION_NAME '*'
346
e563bbdb 347 start_lttng_tracing_ok $SESSION_NAME
0e115563
DG
348
349 run_app 0 1
350
351 stop_lttng_tracing $SESSION_NAME
352 destroy_lttng_session $SESSION_NAME
353
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
358 return $?
359 fi
360}
361
362function test_python_multi_session()
363{
364 diag "Test Python with multiple session"
365
bf6ae429 366 create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
0e115563 367 enable_python_lttng_event $SESSION_NAME-1 $EVENT_NAME
e563bbdb 368 start_lttng_tracing_ok $SESSION_NAME-1
0e115563 369
bf6ae429 370 create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
0e115563 371 enable_python_lttng_event $SESSION_NAME-2 $EVENT_NAME2
e563bbdb 372 start_lttng_tracing_ok $SESSION_NAME-2
0e115563
DG
373
374 # Run 5 times with a 1 second delay and fire second TP.
375 run_app 0 1
376
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
381
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
385 return $?
386 fi
387
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
391 return $?
392 fi
393}
394
395function test_python_destroy_session()
396{
397 diag "Test Python two session with destroy"
398
bf6ae429 399 create_lttng_session_ok $SESSION_NAME $TRACE_PATH/first-sess
0e115563 400 enable_python_lttng_event $SESSION_NAME $EVENT_NAME
e563bbdb 401 start_lttng_tracing_ok $SESSION_NAME
0e115563
DG
402
403 # Run 5 times with a 1 second delay
404 run_app_background 0 1
405
0fc2834c
MD
406 # Wait for the applications started in background
407 wait
0e115563
DG
408
409 stop_lttng_tracing $SESSION_NAME
410 destroy_lttng_session $SESSION_NAME
411
412 # Validate test. Expecting at least one event num 1
413 validate_trace $EVENT_NAME $TRACE_PATH/first-sess
414 if [ $? -ne 0 ]; then
415 return $?
416 fi
417
bf6ae429 418 create_lttng_session_ok $SESSION_NAME $TRACE_PATH/second-sess
0e115563 419 enable_python_lttng_event $SESSION_NAME $EVENT_NAME2
e563bbdb 420 start_lttng_tracing_ok $SESSION_NAME
0e115563 421
0fc2834c
MD
422 # Run 5 times with a 1 second delay
423 run_app_background 0 1
424
0e115563 425 # Wait for the applications started in background
0fc2834c 426 wait
0e115563
DG
427
428 stop_lttng_tracing $SESSION_NAME
429 destroy_lttng_session $SESSION_NAME
430
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
434 return $?
435 fi
436}
437
438function test_python_filtering()
439{
440 diag "Test Python filtering"
441
bf6ae429 442 create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME
0e115563
DG
443 # Enable all event with a filter.
444 enable_python_filter $SESSION_NAME '*' 'msg == "python-ev-test2 fired"'
e563bbdb 445 start_lttng_tracing_ok $SESSION_NAME
0e115563
DG
446
447 # Run 5 times with a 1 second delay and fire second TP.
448 run_app 0 1
449
450 stop_lttng_tracing $SESSION_NAME
451 destroy_lttng_session $SESSION_NAME
452
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
456 return $?
457 fi
458
bf6ae429 459 create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME
0e115563
DG
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"'
e563bbdb 463 start_lttng_tracing_ok $SESSION_NAME
0e115563
DG
464
465 # Run 5 times with a 1 second delay, fire debug and second TP.
466 run_app 1 1
467
468 stop_lttng_tracing $SESSION_NAME
469 destroy_lttng_session $SESSION_NAME
470
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
474 return $?
475 fi
476}
477
478function test_python_disable()
479{
480 diag "Test Python disable event"
481
bf6ae429 482 create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME
0e115563
DG
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
e563bbdb 487 start_lttng_tracing_ok $SESSION_NAME
0e115563
DG
488
489 # Run 5 times with a 1 second delay and fire second TP.
490 run_app 0 1
491
492 stop_lttng_tracing $SESSION_NAME
493 destroy_lttng_session $SESSION_NAME
494
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
498 return $?
499 fi
500}
501
502function test_python_disable_enable()
503{
504 diag "Test Python disable event followed by an enable"
505
bf6ae429 506 create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME
0e115563
DG
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
e563bbdb 511 start_lttng_tracing_ok $SESSION_NAME
0e115563
DG
512
513 # Run 5 times with a 1 second delay and fire second TP.
514 run_app 0 1
515
516 stop_lttng_tracing $SESSION_NAME
517 destroy_lttng_session $SESSION_NAME
518
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
522 return $?
523 fi
524}
525
526function test_python_filter_loglevel()
527{
528 local BOGUS_EVENT_NAME="not_a_real_event"
529 local FILTER="int_loglevel > 30 || int_loglevel < 30"
530 local ALL_EVENTS="."
531
532 diag "Test Python a filter with a loglevel"
533
bf6ae429 534 create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME
0e115563
DG
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"
e563bbdb 539 start_lttng_tracing_ok $SESSION_NAME
0e115563
DG
540
541 # Run 5 times with a 1 second delay and fire second TP.
542 run_app 0 1
543
544 stop_lttng_tracing $SESSION_NAME
545 destroy_lttng_session $SESSION_NAME
546
547 # Validate test. Expecting no events.
548 trace_match_only $ALL_EVENTS 0 $TRACE_PATH/$SESSION_NAME
549 if [ $? -ne 0 ]; then
550 return $?
551 fi
552}
553
554plan_tests $NUM_TESTS
555
556print_test_banner "$TEST_DESC"
557
558if [ ! -f "$TESTAPP_BIN" ]; then
559 withapp=0
560else
561 withapp=1
562fi
563
564skip $withapp "Python support is needed. Skipping all tests." $NUM_TESTS ||
565{
566 start_lttng_sessiond
567
568 tests=(
569 test_python_multi_session_disable_wildcard
570 test_python_multi_session_disable
571 test_python_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
577 test_python_loglevel
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
583 )
584
585 for fct_test in ${tests[@]};
586 do
587 TRACE_PATH=$(mktemp -d)
588
589 ${fct_test}
590 if [ $? -ne 0 ]; then
591 break;
592 fi
593 rm -rf $TRACE_PATH
594 done
595
596 stop_lttng_sessiond
597}
This page took 0.07602 seconds and 4 git commands to generate.