Add Python agent support
[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"
93 create_lttng_session $SESSION_NAME $TRACE_PATH
94 enable_python_lttng_event $SESSION_NAME $EVENT_NAME
95
96 # Run 5 times with a 1 second delay
97 run_app_background
98
99 start_lttng_tracing $SESSION_NAME
100
101 # Wait for the applications started in background
102 wait ${!}
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
118 create_lttng_session $SESSION_NAME $TRACE_PATH
119 enable_python_lttng_event $SESSION_NAME $EVENT_NAME
120 start_lttng_tracing $SESSION_NAME
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
139 create_lttng_session $SESSION_NAME $TRACE_PATH
140 enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "INFO"
141 start_lttng_tracing $SESSION_NAME
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
157 create_lttng_session $SESSION_NAME $TRACE_PATH
158 enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "CRITICAL"
159 start_lttng_tracing $SESSION_NAME
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
175 create_lttng_session $SESSION_NAME $TRACE_PATH
176 enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "DEBUG"
177 start_lttng_tracing $SESSION_NAME
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
194 create_lttng_session $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
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
211 create_lttng_session $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
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
233 create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
234 enable_python_loglevel_only $SESSION_NAME-1 '*' "INFO"
235 start_lttng_tracing $SESSION_NAME-1
236
237 create_lttng_session $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
238 enable_python_loglevel_only $SESSION_NAME-2 '*' "DEBUG"
239 start_lttng_tracing $SESSION_NAME-2
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
270 create_lttng_session $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
275
276 create_lttng_session $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
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
305 create_lttng_session $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1
306 enable_python_lttng_event $SESSION_NAME-1 '*'
307
308 create_lttng_session $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2
309 enable_python_lttng_event $SESSION_NAME-2 '*'
310
311 disable_python_lttng_event $SESSION_NAME-1 '*'
312
313 start_lttng_tracing $SESSION_NAME-1
314 start_lttng_tracing $SESSION_NAME-2
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
340 create_lttng_session $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
344
345 disable_python_lttng_event $SESSION_NAME '*'
346
347 start_lttng_tracing $SESSION_NAME
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
366 create_lttng_session $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
369
370 create_lttng_session $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
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
399 create_lttng_session $SESSION_NAME $TRACE_PATH/first-sess
400 enable_python_lttng_event $SESSION_NAME $EVENT_NAME
401 start_lttng_tracing $SESSION_NAME
402
403 # Run 5 times with a 1 second delay
404 run_app_background 0 1
405
406 sleep 1
407
408 stop_lttng_tracing $SESSION_NAME
409 destroy_lttng_session $SESSION_NAME
410
411 # Validate test. Expecting at least one event num 1
412 validate_trace $EVENT_NAME $TRACE_PATH/first-sess
413 if [ $? -ne 0 ]; then
414 return $?
415 fi
416
417 create_lttng_session $SESSION_NAME $TRACE_PATH/second-sess
418 enable_python_lttng_event $SESSION_NAME $EVENT_NAME2
419 start_lttng_tracing $SESSION_NAME
420
421 # Wait for the applications started in background
422 wait ${!}
423
424 stop_lttng_tracing $SESSION_NAME
425 destroy_lttng_session $SESSION_NAME
426
427 # Validate test. Expecting only one event num 2
428 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/second-sess
429 if [ $? -ne 0 ]; then
430 return $?
431 fi
432}
433
434function test_python_filtering()
435{
436 diag "Test Python filtering"
437
438 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
439 # Enable all event with a filter.
440 enable_python_filter $SESSION_NAME '*' 'msg == "python-ev-test2 fired"'
441 start_lttng_tracing $SESSION_NAME
442
443 # Run 5 times with a 1 second delay and fire second TP.
444 run_app 0 1
445
446 stop_lttng_tracing $SESSION_NAME
447 destroy_lttng_session $SESSION_NAME
448
449 # Validate test. Expecting one event of the second TP only.
450 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
451 if [ $? -ne 0 ]; then
452 return $?
453 fi
454
455 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
456 # Enable first Logger but filter msg payload for the INFO one while
457 # triggering the debug and second TP.
458 enable_python_filter $SESSION_NAME $EVENT_NAME 'msg == "python-ev-test1 fired"'
459 start_lttng_tracing $SESSION_NAME
460
461 # Run 5 times with a 1 second delay, fire debug and second TP.
462 run_app 1 1
463
464 stop_lttng_tracing $SESSION_NAME
465 destroy_lttng_session $SESSION_NAME
466
467 # Validate test. Expecting NR_ITER event of the main INFO tp.
468 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
469 if [ $? -ne 0 ]; then
470 return $?
471 fi
472}
473
474function test_python_disable()
475{
476 diag "Test Python disable event"
477
478 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
479 # Enable all event with a filter.
480 enable_python_lttng_event $SESSION_NAME $EVENT_NAME
481 enable_python_lttng_event $SESSION_NAME $EVENT_NAME2
482 disable_python_lttng_event $SESSION_NAME $EVENT_NAME
483 start_lttng_tracing $SESSION_NAME
484
485 # Run 5 times with a 1 second delay and fire second TP.
486 run_app 0 1
487
488 stop_lttng_tracing $SESSION_NAME
489 destroy_lttng_session $SESSION_NAME
490
491 # Validate test. Expecting one event of the second TP only.
492 trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME
493 if [ $? -ne 0 ]; then
494 return $?
495 fi
496}
497
498function test_python_disable_enable()
499{
500 diag "Test Python disable event followed by an enable"
501
502 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
503 # Enable all event with a filter.
504 enable_python_lttng_event $SESSION_NAME $EVENT_NAME
505 disable_python_lttng_event $SESSION_NAME $EVENT_NAME
506 enable_python_lttng_event $SESSION_NAME $EVENT_NAME
507 start_lttng_tracing $SESSION_NAME
508
509 # Run 5 times with a 1 second delay and fire second TP.
510 run_app 0 1
511
512 stop_lttng_tracing $SESSION_NAME
513 destroy_lttng_session $SESSION_NAME
514
515 # Validate test. Expecting NR_ITER event of the main INFO tp.
516 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME
517 if [ $? -ne 0 ]; then
518 return $?
519 fi
520}
521
522function test_python_filter_loglevel()
523{
524 local BOGUS_EVENT_NAME="not_a_real_event"
525 local FILTER="int_loglevel > 30 || int_loglevel < 30"
526 local ALL_EVENTS="."
527
528 diag "Test Python a filter with a loglevel"
529
530 create_lttng_session $SESSION_NAME $TRACE_PATH/$SESSION_NAME
531 # Enable an event with a filter and the loglevel-only option.
532 enable_python_filter_loglevel_only $SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" "INFO"
533 disable_python_lttng_event $SESSION_NAME $BOGUS_EVENT_NAME
534 enable_python_filter_loglevel_only $SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" "INFO"
535 start_lttng_tracing $SESSION_NAME
536
537 # Run 5 times with a 1 second delay and fire second TP.
538 run_app 0 1
539
540 stop_lttng_tracing $SESSION_NAME
541 destroy_lttng_session $SESSION_NAME
542
543 # Validate test. Expecting no events.
544 trace_match_only $ALL_EVENTS 0 $TRACE_PATH/$SESSION_NAME
545 if [ $? -ne 0 ]; then
546 return $?
547 fi
548}
549
550plan_tests $NUM_TESTS
551
552print_test_banner "$TEST_DESC"
553
554if [ ! -f "$TESTAPP_BIN" ]; then
555 withapp=0
556else
557 withapp=1
558fi
559
560skip $withapp "Python support is needed. Skipping all tests." $NUM_TESTS ||
561{
562 start_lttng_sessiond
563
564 tests=(
565 test_python_multi_session_disable_wildcard
566 test_python_multi_session_disable
567 test_python_disable
568 test_python_disable_enable
569 test_python_disable_all
570 test_python_filtering
571 test_python_multi_session_loglevel
572 test_python_destroy_session
573 test_python_loglevel
574 test_python_loglevel_multiple
575 test_python_before_start
576 test_python_after_start
577 test_python_multi_session
578 test_python_filter_loglevel
579 )
580
581 for fct_test in ${tests[@]};
582 do
583 TRACE_PATH=$(mktemp -d)
584
585 ${fct_test}
586 if [ $? -ne 0 ]; then
587 break;
588 fi
589 rm -rf $TRACE_PATH
590 done
591
592 stop_lttng_sessiond
593}
This page took 0.044036 seconds and 4 git commands to generate.