| 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 | |
| 19 | TEST_DESC="Python support" |
| 20 | |
| 21 | CURDIR=$(dirname $0)/ |
| 22 | TESTDIR=$CURDIR/../../.. |
| 23 | NR_ITER=5 |
| 24 | NR_SEC_WAIT=0 |
| 25 | TESTAPP_NAME="test" |
| 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" |
| 32 | |
| 33 | python_versions=(@PYTHON2_AGENT@ @PYTHON3_AGENT@) |
| 34 | run_test=@RUN_PYTHON_AGENT_TEST@ |
| 35 | |
| 36 | if [[ -z "$run_test" ]]; then |
| 37 | NUM_TESTS=1 |
| 38 | else |
| 39 | NUM_TESTS=$(((154 * ${#python_versions[@]})+2)) |
| 40 | fi |
| 41 | |
| 42 | source $TESTDIR/utils/utils.sh |
| 43 | |
| 44 | function run_app |
| 45 | { |
| 46 | local python=$1 |
| 47 | local debug_tp=$2 |
| 48 | local fire_second_tp=$3 |
| 49 | |
| 50 | $python $TESTAPP_PATH/$TESTAPP_BIN $NR_ITER $NR_SEC_WAIT $debug_tp $fire_second_tp |
| 51 | } |
| 52 | |
| 53 | function run_app_background |
| 54 | { |
| 55 | run_app $@ & |
| 56 | } |
| 57 | |
| 58 | function enable_python_loglevel_only() |
| 59 | { |
| 60 | sess_name=$1 |
| 61 | event_name="$2" |
| 62 | loglevel=$3 |
| 63 | channel_name=$4 |
| 64 | |
| 65 | if [ -z $channel_name ]; then |
| 66 | # default channel if none specified |
| 67 | chan="" |
| 68 | else |
| 69 | chan="-c $channel_name" |
| 70 | fi |
| 71 | |
| 72 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel-only $loglevel "$event_name" $chan -s $sess_name -p >$OUTPUT_DEST |
| 73 | ok $? "Enable Python event $event_name for session $sess_name with loglevel-only $loglevel" |
| 74 | } |
| 75 | |
| 76 | function enable_python_filter() |
| 77 | { |
| 78 | local sess_name="$1" |
| 79 | local event_name="$2" |
| 80 | local filter="$3" |
| 81 | |
| 82 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -p --filter "$filter" >$OUTPUT_DEST |
| 83 | ok $? "Enable event $event_name with filter $filter for session $sess_name" |
| 84 | } |
| 85 | |
| 86 | function enable_python_filter_loglevel_only() |
| 87 | { |
| 88 | local sess_name="$1" |
| 89 | local event_name="$2" |
| 90 | local filter="$3" |
| 91 | local loglevel="$4" |
| 92 | |
| 93 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel-only $loglevel "$event_name" -s $sess_name -p --filter "$filter" >$OUTPUT_DEST |
| 94 | ok $? "Enable event $event_name with filter \"$filter\" and loglevel-only $loglevel for session $sess_name" |
| 95 | } |
| 96 | |
| 97 | # MUST set TESTDIR before calling those functions |
| 98 | |
| 99 | function test_python_before_start () |
| 100 | { |
| 101 | diag "Test Python application BEFORE tracing starts" |
| 102 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 103 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 104 | |
| 105 | # Run 5 times with a 1 second delay |
| 106 | run_app_background $1 |
| 107 | |
| 108 | start_lttng_tracing_ok $SESSION_NAME |
| 109 | |
| 110 | # Wait for the applications started in background |
| 111 | wait |
| 112 | |
| 113 | stop_lttng_tracing_ok $SESSION_NAME |
| 114 | destroy_lttng_session_ok $SESSION_NAME |
| 115 | |
| 116 | # Validate test. Expecting all events. |
| 117 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH |
| 118 | if [ $? -ne 0 ]; then |
| 119 | return $? |
| 120 | fi |
| 121 | } |
| 122 | |
| 123 | function test_python_after_start () |
| 124 | { |
| 125 | diag "Test Python application AFTER tracing starts" |
| 126 | |
| 127 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 128 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 129 | start_lttng_tracing_ok $SESSION_NAME |
| 130 | |
| 131 | # Run 5 times with a 1 second delay |
| 132 | run_app $1 |
| 133 | |
| 134 | stop_lttng_tracing_ok $SESSION_NAME |
| 135 | destroy_lttng_session_ok $SESSION_NAME |
| 136 | |
| 137 | # Validate test. Expecting all events. |
| 138 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH |
| 139 | if [ $? -ne 0 ]; then |
| 140 | return $? |
| 141 | fi |
| 142 | } |
| 143 | |
| 144 | function test_python_loglevel () |
| 145 | { |
| 146 | diag "Test Python application with loglevel" |
| 147 | |
| 148 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 149 | enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "INFO" |
| 150 | start_lttng_tracing_ok $SESSION_NAME |
| 151 | |
| 152 | # Run 5 times with a 1 second delay |
| 153 | run_app $1 |
| 154 | |
| 155 | stop_lttng_tracing_ok $SESSION_NAME |
| 156 | destroy_lttng_session_ok $SESSION_NAME |
| 157 | |
| 158 | # Validate test. Expecting all events. |
| 159 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH |
| 160 | if [ $? -ne 0 ]; then |
| 161 | return $? |
| 162 | fi |
| 163 | |
| 164 | diag "Test Python applications with lower loglevel" |
| 165 | |
| 166 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 167 | enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "CRITICAL" |
| 168 | start_lttng_tracing_ok $SESSION_NAME |
| 169 | |
| 170 | # Run 5 times with a 1 second delay |
| 171 | run_app $1 |
| 172 | |
| 173 | stop_lttng_tracing_ok $SESSION_NAME |
| 174 | destroy_lttng_session_ok $SESSION_NAME |
| 175 | |
| 176 | # Validate test. Expecting 0 events. |
| 177 | trace_match_only $EVENT_NAME 0 $TRACE_PATH |
| 178 | if [ $? -ne 0 ]; then |
| 179 | return $? |
| 180 | fi |
| 181 | |
| 182 | diag "Test Python applications with higher loglevel" |
| 183 | |
| 184 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 185 | enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "DEBUG" |
| 186 | start_lttng_tracing_ok $SESSION_NAME |
| 187 | |
| 188 | # Run 5 times with a 1 second delay |
| 189 | run_app $1 |
| 190 | |
| 191 | stop_lttng_tracing_ok $SESSION_NAME |
| 192 | destroy_lttng_session_ok $SESSION_NAME |
| 193 | |
| 194 | # Validate test. Expecting all events. |
| 195 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH |
| 196 | return $? |
| 197 | } |
| 198 | |
| 199 | function test_python_loglevel_multiple () |
| 200 | { |
| 201 | diag "Test Python application with multiple loglevel" |
| 202 | |
| 203 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 204 | enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "INFO" |
| 205 | enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "DEBUG" |
| 206 | start_lttng_tracing_ok $SESSION_NAME |
| 207 | |
| 208 | # Run 5 times with a 1 second delay and fire two TP. |
| 209 | run_app $1 1 |
| 210 | |
| 211 | stop_lttng_tracing_ok $SESSION_NAME |
| 212 | destroy_lttng_session_ok $SESSION_NAME |
| 213 | |
| 214 | # Validate test. Expecting all events times two. |
| 215 | trace_match_only $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH |
| 216 | if [ $? -ne 0 ]; then |
| 217 | return $? |
| 218 | fi |
| 219 | |
| 220 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 221 | enable_python_lttng_event_loglevel $SESSION_NAME '*' "INFO" |
| 222 | enable_python_lttng_event_loglevel $SESSION_NAME '*' "DEBUG" |
| 223 | start_lttng_tracing_ok $SESSION_NAME |
| 224 | |
| 225 | # Run 5 times with a 1 second delay and fire two TP. |
| 226 | run_app $1 1 |
| 227 | |
| 228 | stop_lttng_tracing_ok $SESSION_NAME |
| 229 | destroy_lttng_session_ok $SESSION_NAME |
| 230 | |
| 231 | # Validate test. Expecting all events times two. |
| 232 | trace_match_only $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH |
| 233 | if [ $? -ne 0 ]; then |
| 234 | return $? |
| 235 | fi |
| 236 | } |
| 237 | |
| 238 | function test_python_multi_session_loglevel() |
| 239 | { |
| 240 | diag "Test Python with multiple session" |
| 241 | |
| 242 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 |
| 243 | enable_python_loglevel_only $SESSION_NAME-1 '*' "INFO" |
| 244 | start_lttng_tracing_ok $SESSION_NAME-1 |
| 245 | |
| 246 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 |
| 247 | enable_python_loglevel_only $SESSION_NAME-2 '*' "DEBUG" |
| 248 | start_lttng_tracing_ok $SESSION_NAME-2 |
| 249 | |
| 250 | # Run 5 times with a 1 second delay and fire second TP. |
| 251 | run_app $1 1 1 |
| 252 | |
| 253 | stop_lttng_tracing_ok $SESSION_NAME-1 |
| 254 | stop_lttng_tracing_ok $SESSION_NAME-2 |
| 255 | destroy_lttng_session_ok $SESSION_NAME-1 |
| 256 | destroy_lttng_session_ok $SESSION_NAME-2 |
| 257 | |
| 258 | # Expecting NR_ITER events being the main event and the second tp one. |
| 259 | trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1 |
| 260 | if [ $? -ne 0 ]; then |
| 261 | return $? |
| 262 | fi |
| 263 | trace_matches $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1 |
| 264 | if [ $? -ne 0 ]; then |
| 265 | return $? |
| 266 | fi |
| 267 | |
| 268 | # Expectin NR_ITER events being the debug TP. |
| 269 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2 |
| 270 | if [ $? -ne 0 ]; then |
| 271 | return $? |
| 272 | fi |
| 273 | } |
| 274 | |
| 275 | function test_python_multi_session_disable() |
| 276 | { |
| 277 | diag "Test Python with multiple session with disabled event" |
| 278 | |
| 279 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 |
| 280 | enable_python_lttng_event $SESSION_NAME-1 $EVENT_NAME |
| 281 | enable_python_lttng_event $SESSION_NAME-1 $EVENT_NAME2 |
| 282 | disable_python_lttng_event $SESSION_NAME-1 $EVENT_NAME |
| 283 | start_lttng_tracing_ok $SESSION_NAME-1 |
| 284 | |
| 285 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 |
| 286 | enable_python_lttng_event $SESSION_NAME-2 $EVENT_NAME2 |
| 287 | start_lttng_tracing_ok $SESSION_NAME-2 |
| 288 | |
| 289 | # Run 5 times with a 1 second delay and fire second TP. |
| 290 | run_app $1 0 1 |
| 291 | |
| 292 | stop_lttng_tracing_ok $SESSION_NAME-1 |
| 293 | stop_lttng_tracing_ok $SESSION_NAME-2 |
| 294 | destroy_lttng_session_ok $SESSION_NAME-1 |
| 295 | destroy_lttng_session_ok $SESSION_NAME-2 |
| 296 | |
| 297 | # Validate test. Expecting one event of the second TP. |
| 298 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1 |
| 299 | if [ $? -ne 0 ]; then |
| 300 | return $? |
| 301 | fi |
| 302 | |
| 303 | # Validate test. Expecting one event of the second TP. |
| 304 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2 |
| 305 | if [ $? -ne 0 ]; then |
| 306 | return $? |
| 307 | fi |
| 308 | } |
| 309 | |
| 310 | function test_python_multi_session_disable_wildcard() |
| 311 | { |
| 312 | diag "Test Python with multiple session with disabled wildcard event" |
| 313 | |
| 314 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 |
| 315 | enable_python_lttng_event $SESSION_NAME-1 '*' |
| 316 | |
| 317 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 |
| 318 | enable_python_lttng_event $SESSION_NAME-2 '*' |
| 319 | |
| 320 | disable_python_lttng_event $SESSION_NAME-1 '*' |
| 321 | |
| 322 | start_lttng_tracing_ok $SESSION_NAME-1 |
| 323 | start_lttng_tracing_ok $SESSION_NAME-2 |
| 324 | |
| 325 | run_app $1 |
| 326 | |
| 327 | stop_lttng_tracing_ok $SESSION_NAME-1 |
| 328 | stop_lttng_tracing_ok $SESSION_NAME-2 |
| 329 | destroy_lttng_session_ok $SESSION_NAME-1 |
| 330 | destroy_lttng_session_ok $SESSION_NAME-2 |
| 331 | |
| 332 | # Validate test. Expecting NO event of the first TP. |
| 333 | trace_match_only $EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME-1 |
| 334 | if [ $? -ne 0 ]; then |
| 335 | return $? |
| 336 | fi |
| 337 | |
| 338 | # Validate test. Expecting all events of the first TP. |
| 339 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2 |
| 340 | if [ $? -ne 0 ]; then |
| 341 | return $? |
| 342 | fi |
| 343 | } |
| 344 | |
| 345 | function test_python_disable_all() |
| 346 | { |
| 347 | diag "Test Python with multiple session with disabled all event" |
| 348 | |
| 349 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
| 350 | enable_python_lttng_event $SESSION_NAME '*' |
| 351 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 352 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME2 |
| 353 | |
| 354 | disable_python_lttng_event $SESSION_NAME -a |
| 355 | |
| 356 | start_lttng_tracing_ok $SESSION_NAME |
| 357 | |
| 358 | run_app $1 0 1 |
| 359 | |
| 360 | stop_lttng_tracing_ok $SESSION_NAME |
| 361 | destroy_lttng_session_ok $SESSION_NAME |
| 362 | |
| 363 | # Validate test. Expecting NO event of the first TP and second TP. |
| 364 | trace_match_only $EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME |
| 365 | trace_match_only $EVENT_NAME2 0 $TRACE_PATH/$SESSION_NAME |
| 366 | if [ $? -ne 0 ]; then |
| 367 | return $? |
| 368 | fi |
| 369 | } |
| 370 | |
| 371 | function test_python_multi_session() |
| 372 | { |
| 373 | diag "Test Python with multiple session" |
| 374 | |
| 375 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 |
| 376 | enable_python_lttng_event $SESSION_NAME-1 $EVENT_NAME |
| 377 | start_lttng_tracing_ok $SESSION_NAME-1 |
| 378 | |
| 379 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 |
| 380 | enable_python_lttng_event $SESSION_NAME-2 $EVENT_NAME2 |
| 381 | start_lttng_tracing_ok $SESSION_NAME-2 |
| 382 | |
| 383 | # Run 5 times with a 1 second delay and fire second TP. |
| 384 | run_app $1 0 1 |
| 385 | |
| 386 | stop_lttng_tracing_ok $SESSION_NAME-1 |
| 387 | stop_lttng_tracing_ok $SESSION_NAME-2 |
| 388 | destroy_lttng_session_ok $SESSION_NAME-1 |
| 389 | destroy_lttng_session_ok $SESSION_NAME-2 |
| 390 | |
| 391 | # Validate test. Expecting all events of first TP |
| 392 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1 |
| 393 | if [ $? -ne 0 ]; then |
| 394 | return $? |
| 395 | fi |
| 396 | |
| 397 | # Validate test. Expecting one event of the second TP. |
| 398 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2 |
| 399 | if [ $? -ne 0 ]; then |
| 400 | return $? |
| 401 | fi |
| 402 | } |
| 403 | |
| 404 | function test_python_destroy_session() |
| 405 | { |
| 406 | diag "Test Python two session with destroy" |
| 407 | |
| 408 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/first-sess |
| 409 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 410 | start_lttng_tracing_ok $SESSION_NAME |
| 411 | |
| 412 | # Run 5 times with a 1 second delay |
| 413 | run_app_background $1 0 1 |
| 414 | |
| 415 | # Wait for the applications started in background |
| 416 | wait |
| 417 | |
| 418 | stop_lttng_tracing_ok $SESSION_NAME |
| 419 | destroy_lttng_session_ok $SESSION_NAME |
| 420 | |
| 421 | # Validate test. Expecting at least one event num 1 |
| 422 | validate_trace $EVENT_NAME $TRACE_PATH/first-sess |
| 423 | if [ $? -ne 0 ]; then |
| 424 | return $? |
| 425 | fi |
| 426 | |
| 427 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/second-sess |
| 428 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME2 |
| 429 | start_lttng_tracing_ok $SESSION_NAME |
| 430 | |
| 431 | # Run 5 times with a 1 second delay |
| 432 | run_app_background $1 0 1 |
| 433 | |
| 434 | # Wait for the applications started in background |
| 435 | wait |
| 436 | |
| 437 | stop_lttng_tracing_ok $SESSION_NAME |
| 438 | destroy_lttng_session_ok $SESSION_NAME |
| 439 | |
| 440 | # Validate test. Expecting only one event num 2 |
| 441 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/second-sess |
| 442 | if [ $? -ne 0 ]; then |
| 443 | return $? |
| 444 | fi |
| 445 | } |
| 446 | |
| 447 | function test_python_filtering() |
| 448 | { |
| 449 | diag "Test Python filtering" |
| 450 | |
| 451 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
| 452 | # Enable all event with a filter. |
| 453 | enable_python_filter $SESSION_NAME '*' 'msg == "python-ev-test2 fired [INFO]"' |
| 454 | start_lttng_tracing_ok $SESSION_NAME |
| 455 | |
| 456 | # Run 5 times with a 1 second delay and fire second TP. |
| 457 | run_app $1 0 1 |
| 458 | |
| 459 | stop_lttng_tracing_ok $SESSION_NAME |
| 460 | destroy_lttng_session_ok $SESSION_NAME |
| 461 | |
| 462 | # Validate test. Expecting one event of the second TP only. |
| 463 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME |
| 464 | if [ $? -ne 0 ]; then |
| 465 | return $? |
| 466 | fi |
| 467 | |
| 468 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
| 469 | # Enable first Logger but filter msg payload for the INFO one while |
| 470 | # triggering the debug and second TP. |
| 471 | enable_python_filter $SESSION_NAME $EVENT_NAME 'msg == "python-ev-test1 fired [INFO]"' |
| 472 | start_lttng_tracing_ok $SESSION_NAME |
| 473 | |
| 474 | # Run 5 times with a 1 second delay, fire debug and second TP. |
| 475 | run_app $1 1 1 |
| 476 | |
| 477 | stop_lttng_tracing_ok $SESSION_NAME |
| 478 | destroy_lttng_session_ok $SESSION_NAME |
| 479 | |
| 480 | # Validate test. Expecting NR_ITER event of the main INFO tp. |
| 481 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME |
| 482 | if [ $? -ne 0 ]; then |
| 483 | return $? |
| 484 | fi |
| 485 | } |
| 486 | |
| 487 | function test_python_disable() |
| 488 | { |
| 489 | diag "Test Python disable event" |
| 490 | |
| 491 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
| 492 | # Enable all event with a filter. |
| 493 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 494 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME2 |
| 495 | disable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 496 | start_lttng_tracing_ok $SESSION_NAME |
| 497 | |
| 498 | # Run 5 times with a 1 second delay and fire second TP. |
| 499 | run_app $1 0 1 |
| 500 | |
| 501 | stop_lttng_tracing_ok $SESSION_NAME |
| 502 | destroy_lttng_session_ok $SESSION_NAME |
| 503 | |
| 504 | # Validate test. Expecting one event of the second TP only. |
| 505 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME |
| 506 | if [ $? -ne 0 ]; then |
| 507 | return $? |
| 508 | fi |
| 509 | } |
| 510 | |
| 511 | function test_python_disable_enable() |
| 512 | { |
| 513 | diag "Test Python disable event followed by an enable" |
| 514 | |
| 515 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
| 516 | # Enable all event with a filter. |
| 517 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 518 | disable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 519 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 520 | start_lttng_tracing_ok $SESSION_NAME |
| 521 | |
| 522 | # Run 5 times with a 1 second delay and fire second TP. |
| 523 | run_app $1 0 1 |
| 524 | |
| 525 | stop_lttng_tracing_ok $SESSION_NAME |
| 526 | destroy_lttng_session_ok $SESSION_NAME |
| 527 | |
| 528 | # Validate test. Expecting NR_ITER event of the main INFO tp. |
| 529 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME |
| 530 | if [ $? -ne 0 ]; then |
| 531 | return $? |
| 532 | fi |
| 533 | } |
| 534 | |
| 535 | function test_python_filter_loglevel() |
| 536 | { |
| 537 | local BOGUS_EVENT_NAME="not_a_real_event" |
| 538 | local FILTER="int_loglevel > 30 || int_loglevel < 30" |
| 539 | local ALL_EVENTS="." |
| 540 | |
| 541 | diag "Test Python a filter with a loglevel" |
| 542 | |
| 543 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
| 544 | # Enable an event with a filter and the loglevel-only option. |
| 545 | enable_python_filter_loglevel_only $SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" "INFO" |
| 546 | disable_python_lttng_event $SESSION_NAME $BOGUS_EVENT_NAME |
| 547 | enable_python_filter_loglevel_only $SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" "INFO" |
| 548 | start_lttng_tracing_ok $SESSION_NAME |
| 549 | |
| 550 | # Run 5 times with a 1 second delay and fire second TP. |
| 551 | run_app $1 0 1 |
| 552 | |
| 553 | stop_lttng_tracing_ok $SESSION_NAME |
| 554 | destroy_lttng_session_ok $SESSION_NAME |
| 555 | |
| 556 | # Validate test. Expecting no events. |
| 557 | trace_match_only $ALL_EVENTS 0 $TRACE_PATH/$SESSION_NAME |
| 558 | if [ $? -ne 0 ]; then |
| 559 | return $? |
| 560 | fi |
| 561 | } |
| 562 | |
| 563 | plan_tests $NUM_TESTS |
| 564 | |
| 565 | print_test_banner "$TEST_DESC" |
| 566 | |
| 567 | if [[ ${#python_versions[@]} -eq 0 || "x$run_test" != "xyes" ]]; then |
| 568 | skip_agent=0 |
| 569 | else |
| 570 | skip_agent=1 |
| 571 | fi |
| 572 | |
| 573 | skip $skip_agent "Python agent test skipped." $NUM_TESTS || |
| 574 | { |
| 575 | start_lttng_sessiond |
| 576 | |
| 577 | tests=( |
| 578 | test_python_multi_session_disable_wildcard |
| 579 | test_python_multi_session_disable |
| 580 | test_python_disable |
| 581 | test_python_disable_enable |
| 582 | test_python_disable_all |
| 583 | test_python_filtering |
| 584 | test_python_multi_session_loglevel |
| 585 | test_python_destroy_session |
| 586 | test_python_loglevel |
| 587 | test_python_loglevel_multiple |
| 588 | test_python_before_start |
| 589 | test_python_after_start |
| 590 | test_python_multi_session |
| 591 | test_python_filter_loglevel |
| 592 | ) |
| 593 | |
| 594 | |
| 595 | for python_version in ${python_versions[*]}; |
| 596 | do |
| 597 | for fct_test in ${tests[@]}; |
| 598 | do |
| 599 | TRACE_PATH=$(mktemp -d) |
| 600 | |
| 601 | diag "(Python $python_version)" |
| 602 | ${fct_test} $python_version |
| 603 | if [ $? -ne 0 ]; then |
| 604 | break; |
| 605 | fi |
| 606 | rm -rf $TRACE_PATH |
| 607 | done |
| 608 | done |
| 609 | stop_lttng_sessiond |
| 610 | } |