| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2015 Philippe Proulx <pproulx@efficios.com> |
| 4 | # Copyright (C) 2014 David Goulet <dgoulet@efficios.com> |
| 5 | # |
| 6 | # SPDX-License-Identifier: GPL-2.0-only |
| 7 | |
| 8 | TEST_DESC="Python support" |
| 9 | |
| 10 | CURDIR=$(dirname $0)/ |
| 11 | TESTDIR=$CURDIR/../../.. |
| 12 | NR_ITER=5 |
| 13 | NR_SEC_WAIT=0 |
| 14 | TESTAPP_NAME="gen-py-events" |
| 15 | TESTAPP_BIN="$TESTAPP_NAME.py" |
| 16 | TESTAPP_PATH="$TESTDIR/utils/testapp/$TESTAPP_NAME/" |
| 17 | SESSION_NAME="python-test" |
| 18 | EVENT_NAME="python-ev-test1" |
| 19 | EVENT_NAME2="python-ev-test2" |
| 20 | OUTPUT_DEST="/dev/null" |
| 21 | |
| 22 | python_versions=(@PYTHON2_AGENT@ @PYTHON3_AGENT@) |
| 23 | run_test=@RUN_PYTHON_AGENT_TEST@ |
| 24 | |
| 25 | if [[ -z "$run_test" ]]; then |
| 26 | NUM_TESTS=1 |
| 27 | else |
| 28 | NUM_TESTS=$(((199 * ${#python_versions[@]})+2)) |
| 29 | fi |
| 30 | |
| 31 | source $TESTDIR/utils/utils.sh |
| 32 | |
| 33 | function run_app |
| 34 | { |
| 35 | local python=$1 |
| 36 | local debug_tp=$2 |
| 37 | local fire_second_tp=$3 |
| 38 | local ready_file=$4 |
| 39 | local go_file=$5 |
| 40 | local opt="" |
| 41 | |
| 42 | if [[ -n "$debug_tp" ]] && [ "$debug_tp" -eq "1" ]; then |
| 43 | opt="${opt} -d" |
| 44 | fi |
| 45 | |
| 46 | if [[ -n "$fire_second_tp" ]] && [ "$fire_second_tp" -eq "1" ]; then |
| 47 | opt="${opt} -e" |
| 48 | fi |
| 49 | |
| 50 | if [[ -n "$ready_file" ]]; then |
| 51 | opt="${opt} -r ${ready_file}" |
| 52 | fi |
| 53 | |
| 54 | if [[ -n "$go_file" ]]; then |
| 55 | opt="${opt} -g ${go_file}" |
| 56 | fi |
| 57 | |
| 58 | $python $TESTAPP_PATH/$TESTAPP_BIN -n $NR_ITER -s $NR_SEC_WAIT $opt |
| 59 | } |
| 60 | |
| 61 | function run_app_background |
| 62 | { |
| 63 | run_app "$@" & |
| 64 | } |
| 65 | |
| 66 | function enable_python_loglevel_only() |
| 67 | { |
| 68 | sess_name=$1 |
| 69 | event_name="$2" |
| 70 | loglevel=$3 |
| 71 | channel_name=$4 |
| 72 | |
| 73 | if [ -z $channel_name ]; then |
| 74 | # default channel if none specified |
| 75 | chan="" |
| 76 | else |
| 77 | chan="-c $channel_name" |
| 78 | fi |
| 79 | |
| 80 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel-only $loglevel "$event_name" $chan -s $sess_name -p >$OUTPUT_DEST |
| 81 | ok $? "Enable Python event $event_name for session $sess_name with loglevel-only $loglevel" |
| 82 | } |
| 83 | |
| 84 | function enable_python_filter() |
| 85 | { |
| 86 | local sess_name="$1" |
| 87 | local event_name="$2" |
| 88 | local filter="$3" |
| 89 | |
| 90 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -p --filter "$filter" >$OUTPUT_DEST |
| 91 | ok $? "Enable event $event_name with filter $filter for session $sess_name" |
| 92 | } |
| 93 | |
| 94 | function enable_python_filter_loglevel_only() |
| 95 | { |
| 96 | local sess_name="$1" |
| 97 | local event_name="$2" |
| 98 | local filter="$3" |
| 99 | local loglevel="$4" |
| 100 | |
| 101 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel-only $loglevel "$event_name" -s $sess_name -p --filter "$filter" >$OUTPUT_DEST |
| 102 | ok $? "Enable event $event_name with filter \"$filter\" and loglevel-only $loglevel for session $sess_name" |
| 103 | } |
| 104 | |
| 105 | # MUST set TESTDIR before calling those functions |
| 106 | |
| 107 | function test_python_before_start () |
| 108 | { |
| 109 | local ready_file=$(mktemp -u -t) |
| 110 | local go_file=$(mktemp -u -t) |
| 111 | |
| 112 | diag "Test Python application BEFORE tracing starts" |
| 113 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 114 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 115 | |
| 116 | # Run 5 times with a 1 second delay |
| 117 | run_app_background $1 "" "" $ready_file $go_file |
| 118 | |
| 119 | # Wait for ready file |
| 120 | while [ ! -e ${ready_file} ]; do |
| 121 | sleep 0.5 |
| 122 | done |
| 123 | |
| 124 | start_lttng_tracing_ok $SESSION_NAME |
| 125 | |
| 126 | # Wait for the applications started in background |
| 127 | echo "1" > ${go_file} |
| 128 | wait |
| 129 | |
| 130 | stop_lttng_tracing_ok $SESSION_NAME |
| 131 | destroy_lttng_session_ok $SESSION_NAME |
| 132 | |
| 133 | # Validate test. Expecting all events. |
| 134 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH |
| 135 | if [ $? -ne 0 ]; then |
| 136 | return $? |
| 137 | fi |
| 138 | |
| 139 | rm $go_file |
| 140 | } |
| 141 | |
| 142 | function test_python_after_start () |
| 143 | { |
| 144 | diag "Test Python application AFTER tracing starts" |
| 145 | |
| 146 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 147 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 148 | start_lttng_tracing_ok $SESSION_NAME |
| 149 | |
| 150 | # Run 5 times with a 1 second delay |
| 151 | run_app $1 |
| 152 | |
| 153 | stop_lttng_tracing_ok $SESSION_NAME |
| 154 | destroy_lttng_session_ok $SESSION_NAME |
| 155 | |
| 156 | # Validate test. Expecting all events. |
| 157 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH |
| 158 | if [ $? -ne 0 ]; then |
| 159 | return $? |
| 160 | fi |
| 161 | } |
| 162 | |
| 163 | function test_python_loglevel () |
| 164 | { |
| 165 | diag "Test Python application with loglevel" |
| 166 | |
| 167 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 168 | enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "INFO" |
| 169 | start_lttng_tracing_ok $SESSION_NAME |
| 170 | |
| 171 | # Run 5 times with a 1 second delay |
| 172 | run_app $1 |
| 173 | |
| 174 | stop_lttng_tracing_ok $SESSION_NAME |
| 175 | destroy_lttng_session_ok $SESSION_NAME |
| 176 | |
| 177 | # Validate test. Expecting all events. |
| 178 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH |
| 179 | if [ $? -ne 0 ]; then |
| 180 | return $? |
| 181 | fi |
| 182 | |
| 183 | diag "Test Python applications with lower loglevel" |
| 184 | |
| 185 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 186 | enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "CRITICAL" |
| 187 | start_lttng_tracing_ok $SESSION_NAME |
| 188 | |
| 189 | # Run 5 times with a 1 second delay |
| 190 | run_app $1 |
| 191 | |
| 192 | stop_lttng_tracing_ok $SESSION_NAME |
| 193 | destroy_lttng_session_ok $SESSION_NAME |
| 194 | |
| 195 | # Validate test. Expecting 0 events. |
| 196 | trace_match_only $EVENT_NAME 0 $TRACE_PATH |
| 197 | if [ $? -ne 0 ]; then |
| 198 | return $? |
| 199 | fi |
| 200 | |
| 201 | diag "Test Python applications with higher loglevel" |
| 202 | |
| 203 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 204 | enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "DEBUG" |
| 205 | start_lttng_tracing_ok $SESSION_NAME |
| 206 | |
| 207 | # Run 5 times with a 1 second delay |
| 208 | run_app $1 |
| 209 | |
| 210 | stop_lttng_tracing_ok $SESSION_NAME |
| 211 | destroy_lttng_session_ok $SESSION_NAME |
| 212 | |
| 213 | # Validate test. Expecting all events. |
| 214 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH |
| 215 | return $? |
| 216 | } |
| 217 | |
| 218 | function test_python_loglevel_multiple () |
| 219 | { |
| 220 | diag "Test Python application with multiple loglevel" |
| 221 | |
| 222 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 223 | enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "INFO" |
| 224 | enable_python_lttng_event_loglevel $SESSION_NAME $EVENT_NAME "DEBUG" |
| 225 | start_lttng_tracing_ok $SESSION_NAME |
| 226 | |
| 227 | # Run 5 times with a 1 second delay and fire two TP. |
| 228 | run_app $1 1 |
| 229 | |
| 230 | stop_lttng_tracing_ok $SESSION_NAME |
| 231 | destroy_lttng_session_ok $SESSION_NAME |
| 232 | |
| 233 | # Validate test. Expecting all events times two. |
| 234 | trace_match_only $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH |
| 235 | if [ $? -ne 0 ]; then |
| 236 | return $? |
| 237 | fi |
| 238 | |
| 239 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 240 | enable_python_lttng_event_loglevel $SESSION_NAME '*' "INFO" |
| 241 | enable_python_lttng_event_loglevel $SESSION_NAME '*' "DEBUG" |
| 242 | start_lttng_tracing_ok $SESSION_NAME |
| 243 | |
| 244 | # Run 5 times with a 1 second delay and fire two TP. |
| 245 | run_app $1 1 |
| 246 | |
| 247 | stop_lttng_tracing_ok $SESSION_NAME |
| 248 | destroy_lttng_session_ok $SESSION_NAME |
| 249 | |
| 250 | # Validate test. Expecting all events times two. |
| 251 | trace_match_only $EVENT_NAME $(($NR_ITER * 2)) $TRACE_PATH |
| 252 | if [ $? -ne 0 ]; then |
| 253 | return $? |
| 254 | fi |
| 255 | } |
| 256 | |
| 257 | function test_python_multi_session_loglevel() |
| 258 | { |
| 259 | diag "Test Python with multiple session" |
| 260 | |
| 261 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 |
| 262 | enable_python_loglevel_only $SESSION_NAME-1 '*' "INFO" |
| 263 | start_lttng_tracing_ok $SESSION_NAME-1 |
| 264 | |
| 265 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 |
| 266 | enable_python_loglevel_only $SESSION_NAME-2 '*' "DEBUG" |
| 267 | start_lttng_tracing_ok $SESSION_NAME-2 |
| 268 | |
| 269 | # Run 5 times with a 1 second delay and fire second TP. |
| 270 | run_app $1 1 1 |
| 271 | |
| 272 | stop_lttng_tracing_ok $SESSION_NAME-1 |
| 273 | stop_lttng_tracing_ok $SESSION_NAME-2 |
| 274 | destroy_lttng_session_ok $SESSION_NAME-1 |
| 275 | destroy_lttng_session_ok $SESSION_NAME-2 |
| 276 | |
| 277 | # Expecting NR_ITER events being the main event and the second tp one. |
| 278 | trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1 |
| 279 | if [ $? -ne 0 ]; then |
| 280 | return $? |
| 281 | fi |
| 282 | trace_matches $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1 |
| 283 | if [ $? -ne 0 ]; then |
| 284 | return $? |
| 285 | fi |
| 286 | |
| 287 | # Expectin NR_ITER events being the debug TP. |
| 288 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2 |
| 289 | if [ $? -ne 0 ]; then |
| 290 | return $? |
| 291 | fi |
| 292 | } |
| 293 | |
| 294 | function test_python_multi_session_disable() |
| 295 | { |
| 296 | diag "Test Python with multiple session with disabled event" |
| 297 | |
| 298 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 |
| 299 | enable_python_lttng_event $SESSION_NAME-1 $EVENT_NAME |
| 300 | enable_python_lttng_event $SESSION_NAME-1 $EVENT_NAME2 |
| 301 | disable_python_lttng_event $SESSION_NAME-1 $EVENT_NAME |
| 302 | start_lttng_tracing_ok $SESSION_NAME-1 |
| 303 | |
| 304 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 |
| 305 | enable_python_lttng_event $SESSION_NAME-2 $EVENT_NAME2 |
| 306 | start_lttng_tracing_ok $SESSION_NAME-2 |
| 307 | |
| 308 | # Run 5 times with a 1 second delay and fire second TP. |
| 309 | run_app $1 0 1 |
| 310 | |
| 311 | stop_lttng_tracing_ok $SESSION_NAME-1 |
| 312 | stop_lttng_tracing_ok $SESSION_NAME-2 |
| 313 | destroy_lttng_session_ok $SESSION_NAME-1 |
| 314 | destroy_lttng_session_ok $SESSION_NAME-2 |
| 315 | |
| 316 | # Validate test. Expecting one event of the second TP. |
| 317 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-1 |
| 318 | if [ $? -ne 0 ]; then |
| 319 | return $? |
| 320 | fi |
| 321 | |
| 322 | # Validate test. Expecting one event of the second TP. |
| 323 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2 |
| 324 | if [ $? -ne 0 ]; then |
| 325 | return $? |
| 326 | fi |
| 327 | } |
| 328 | |
| 329 | function test_python_multi_session_disable_wildcard() |
| 330 | { |
| 331 | diag "Test Python with multiple session with disabled wildcard event" |
| 332 | |
| 333 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 |
| 334 | enable_python_lttng_event $SESSION_NAME-1 '*' |
| 335 | |
| 336 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 |
| 337 | enable_python_lttng_event $SESSION_NAME-2 '*' |
| 338 | |
| 339 | disable_python_lttng_event $SESSION_NAME-1 '*' |
| 340 | |
| 341 | start_lttng_tracing_ok $SESSION_NAME-1 |
| 342 | start_lttng_tracing_ok $SESSION_NAME-2 |
| 343 | |
| 344 | run_app $1 |
| 345 | |
| 346 | stop_lttng_tracing_ok $SESSION_NAME-1 |
| 347 | stop_lttng_tracing_ok $SESSION_NAME-2 |
| 348 | destroy_lttng_session_ok $SESSION_NAME-1 |
| 349 | destroy_lttng_session_ok $SESSION_NAME-2 |
| 350 | |
| 351 | # Validate test. Expecting NO event of the first TP. |
| 352 | trace_match_only $EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME-1 |
| 353 | if [ $? -ne 0 ]; then |
| 354 | return $? |
| 355 | fi |
| 356 | |
| 357 | # Validate test. Expecting all events of the first TP. |
| 358 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2 |
| 359 | if [ $? -ne 0 ]; then |
| 360 | return $? |
| 361 | fi |
| 362 | } |
| 363 | |
| 364 | function test_python_multi_session_disable_wildcard_begin() |
| 365 | { |
| 366 | ev_name='*ev-test1' |
| 367 | diag "Test Python with multiple session with disabled wildcard (at the beginning) event" |
| 368 | |
| 369 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 |
| 370 | enable_python_lttng_event $SESSION_NAME-1 "$ev_name" |
| 371 | |
| 372 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 |
| 373 | enable_python_lttng_event $SESSION_NAME-2 "$ev_name" |
| 374 | |
| 375 | disable_python_lttng_event $SESSION_NAME-1 "$ev_name" |
| 376 | |
| 377 | start_lttng_tracing_ok $SESSION_NAME-1 |
| 378 | start_lttng_tracing_ok $SESSION_NAME-2 |
| 379 | |
| 380 | run_app $1 0 1 |
| 381 | |
| 382 | stop_lttng_tracing_ok $SESSION_NAME-1 |
| 383 | stop_lttng_tracing_ok $SESSION_NAME-2 |
| 384 | destroy_lttng_session_ok $SESSION_NAME-1 |
| 385 | destroy_lttng_session_ok $SESSION_NAME-2 |
| 386 | |
| 387 | # Validate test. Expecting NO event of the first TP. |
| 388 | trace_match_only $EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME-1 |
| 389 | if [ $? -ne 0 ]; then |
| 390 | return $? |
| 391 | fi |
| 392 | |
| 393 | # Validate test. Expecting all events of the first TP. |
| 394 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2 |
| 395 | if [ $? -ne 0 ]; then |
| 396 | return $? |
| 397 | fi |
| 398 | } |
| 399 | |
| 400 | function test_python_multi_session_disable_wildcard_middle() |
| 401 | { |
| 402 | ev_name='python-*-test1' |
| 403 | diag "Test Python with multiple session with disabled wildcard (at the middle) event" |
| 404 | |
| 405 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 |
| 406 | enable_python_lttng_event $SESSION_NAME-1 "$ev_name" |
| 407 | |
| 408 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 |
| 409 | enable_python_lttng_event $SESSION_NAME-2 "$ev_name" |
| 410 | |
| 411 | disable_python_lttng_event $SESSION_NAME-1 "$ev_name" |
| 412 | |
| 413 | start_lttng_tracing_ok $SESSION_NAME-1 |
| 414 | start_lttng_tracing_ok $SESSION_NAME-2 |
| 415 | |
| 416 | run_app $1 0 1 |
| 417 | |
| 418 | stop_lttng_tracing_ok $SESSION_NAME-1 |
| 419 | stop_lttng_tracing_ok $SESSION_NAME-2 |
| 420 | destroy_lttng_session_ok $SESSION_NAME-1 |
| 421 | destroy_lttng_session_ok $SESSION_NAME-2 |
| 422 | |
| 423 | # Validate test. Expecting NO event of the first TP. |
| 424 | trace_match_only $EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME-1 |
| 425 | if [ $? -ne 0 ]; then |
| 426 | return $? |
| 427 | fi |
| 428 | |
| 429 | # Validate test. Expecting all events of the first TP. |
| 430 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2 |
| 431 | if [ $? -ne 0 ]; then |
| 432 | return $? |
| 433 | fi |
| 434 | } |
| 435 | |
| 436 | function test_python_multi_session_disable_wildcard_end() |
| 437 | { |
| 438 | ev_name='python-*' |
| 439 | diag "Test Python with multiple session with disabled wildcard (at the end) event" |
| 440 | |
| 441 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 |
| 442 | enable_python_lttng_event $SESSION_NAME-1 "$ev_name" |
| 443 | |
| 444 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 |
| 445 | enable_python_lttng_event $SESSION_NAME-2 "$ev_name" |
| 446 | |
| 447 | disable_python_lttng_event $SESSION_NAME-1 "$ev_name" |
| 448 | |
| 449 | start_lttng_tracing_ok $SESSION_NAME-1 |
| 450 | start_lttng_tracing_ok $SESSION_NAME-2 |
| 451 | |
| 452 | run_app $1 0 1 |
| 453 | |
| 454 | stop_lttng_tracing_ok $SESSION_NAME-1 |
| 455 | stop_lttng_tracing_ok $SESSION_NAME-2 |
| 456 | destroy_lttng_session_ok $SESSION_NAME-1 |
| 457 | destroy_lttng_session_ok $SESSION_NAME-2 |
| 458 | |
| 459 | # Validate test. Expecting NO event of the first TP. |
| 460 | trace_match_only $EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME-1 |
| 461 | if [ $? -ne 0 ]; then |
| 462 | return $? |
| 463 | fi |
| 464 | |
| 465 | # Validate test. Expecting all events of the first TP. |
| 466 | trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-2 |
| 467 | if [ $? -ne 0 ]; then |
| 468 | return $? |
| 469 | fi |
| 470 | |
| 471 | trace_matches $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2 |
| 472 | if [ $? -ne 0 ]; then |
| 473 | return $? |
| 474 | fi |
| 475 | } |
| 476 | |
| 477 | function test_python_disable_all() |
| 478 | { |
| 479 | diag "Test Python with multiple session with disabled all event" |
| 480 | |
| 481 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
| 482 | enable_python_lttng_event $SESSION_NAME '*' |
| 483 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 484 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME2 |
| 485 | |
| 486 | disable_python_lttng_event $SESSION_NAME -a |
| 487 | |
| 488 | start_lttng_tracing_ok $SESSION_NAME |
| 489 | |
| 490 | run_app $1 0 1 |
| 491 | |
| 492 | stop_lttng_tracing_ok $SESSION_NAME |
| 493 | destroy_lttng_session_ok $SESSION_NAME |
| 494 | |
| 495 | # Validate test. Expecting NO event of the first TP and second TP. |
| 496 | trace_match_only $EVENT_NAME 0 $TRACE_PATH/$SESSION_NAME |
| 497 | trace_match_only $EVENT_NAME2 0 $TRACE_PATH/$SESSION_NAME |
| 498 | if [ $? -ne 0 ]; then |
| 499 | return $? |
| 500 | fi |
| 501 | } |
| 502 | |
| 503 | function test_python_multi_session() |
| 504 | { |
| 505 | diag "Test Python with multiple session" |
| 506 | |
| 507 | create_lttng_session_ok $SESSION_NAME-1 $TRACE_PATH/$SESSION_NAME-1 |
| 508 | enable_python_lttng_event $SESSION_NAME-1 $EVENT_NAME |
| 509 | start_lttng_tracing_ok $SESSION_NAME-1 |
| 510 | |
| 511 | create_lttng_session_ok $SESSION_NAME-2 $TRACE_PATH/$SESSION_NAME-2 |
| 512 | enable_python_lttng_event $SESSION_NAME-2 $EVENT_NAME2 |
| 513 | start_lttng_tracing_ok $SESSION_NAME-2 |
| 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-1 |
| 519 | stop_lttng_tracing_ok $SESSION_NAME-2 |
| 520 | destroy_lttng_session_ok $SESSION_NAME-1 |
| 521 | destroy_lttng_session_ok $SESSION_NAME-2 |
| 522 | |
| 523 | # Validate test. Expecting all events of first TP |
| 524 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME-1 |
| 525 | if [ $? -ne 0 ]; then |
| 526 | return $? |
| 527 | fi |
| 528 | |
| 529 | # Validate test. Expecting one event of the second TP. |
| 530 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME-2 |
| 531 | if [ $? -ne 0 ]; then |
| 532 | return $? |
| 533 | fi |
| 534 | } |
| 535 | |
| 536 | function test_python_destroy_session() |
| 537 | { |
| 538 | diag "Test Python two session with destroy" |
| 539 | |
| 540 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/first-sess |
| 541 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 542 | start_lttng_tracing_ok $SESSION_NAME |
| 543 | |
| 544 | # Run 5 times with a 1 second delay |
| 545 | run_app $1 0 1 |
| 546 | |
| 547 | stop_lttng_tracing_ok $SESSION_NAME |
| 548 | destroy_lttng_session_ok $SESSION_NAME |
| 549 | |
| 550 | # Validate test. Expecting at least one event num 1 |
| 551 | validate_trace $EVENT_NAME $TRACE_PATH/first-sess |
| 552 | if [ $? -ne 0 ]; then |
| 553 | return $? |
| 554 | fi |
| 555 | |
| 556 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/second-sess |
| 557 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME2 |
| 558 | start_lttng_tracing_ok $SESSION_NAME |
| 559 | |
| 560 | run_app $1 0 1 |
| 561 | |
| 562 | stop_lttng_tracing_ok $SESSION_NAME |
| 563 | destroy_lttng_session_ok $SESSION_NAME |
| 564 | |
| 565 | # Validate test. Expecting only one event num 2 |
| 566 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/second-sess |
| 567 | if [ $? -ne 0 ]; then |
| 568 | return $? |
| 569 | fi |
| 570 | } |
| 571 | |
| 572 | function test_python_filtering() |
| 573 | { |
| 574 | diag "Test Python filtering" |
| 575 | |
| 576 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
| 577 | # Enable all event with a filter. |
| 578 | enable_python_filter $SESSION_NAME '*' 'msg == "python-ev-test2 fired [INFO]"' |
| 579 | start_lttng_tracing_ok $SESSION_NAME |
| 580 | |
| 581 | # Run 5 times with a 1 second delay and fire second TP. |
| 582 | run_app $1 0 1 |
| 583 | |
| 584 | stop_lttng_tracing_ok $SESSION_NAME |
| 585 | destroy_lttng_session_ok $SESSION_NAME |
| 586 | |
| 587 | # Validate test. Expecting one event of the second TP only. |
| 588 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME |
| 589 | if [ $? -ne 0 ]; then |
| 590 | return $? |
| 591 | fi |
| 592 | |
| 593 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
| 594 | # Enable first Logger but filter msg payload for the INFO one while |
| 595 | # triggering the debug and second TP. |
| 596 | enable_python_filter $SESSION_NAME $EVENT_NAME 'msg == "python-ev-test1 fired [INFO]"' |
| 597 | start_lttng_tracing_ok $SESSION_NAME |
| 598 | |
| 599 | # Run 5 times with a 1 second delay, fire debug and second TP. |
| 600 | run_app $1 1 1 |
| 601 | |
| 602 | stop_lttng_tracing_ok $SESSION_NAME |
| 603 | destroy_lttng_session_ok $SESSION_NAME |
| 604 | |
| 605 | # Validate test. Expecting NR_ITER event of the main INFO tp. |
| 606 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME |
| 607 | if [ $? -ne 0 ]; then |
| 608 | return $? |
| 609 | fi |
| 610 | } |
| 611 | |
| 612 | function test_python_disable() |
| 613 | { |
| 614 | diag "Test Python disable event" |
| 615 | |
| 616 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
| 617 | # Enable all event with a filter. |
| 618 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 619 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME2 |
| 620 | disable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 621 | start_lttng_tracing_ok $SESSION_NAME |
| 622 | |
| 623 | # Run 5 times with a 1 second delay and fire second TP. |
| 624 | run_app $1 0 1 |
| 625 | |
| 626 | stop_lttng_tracing_ok $SESSION_NAME |
| 627 | destroy_lttng_session_ok $SESSION_NAME |
| 628 | |
| 629 | # Validate test. Expecting one event of the second TP only. |
| 630 | trace_match_only $EVENT_NAME2 1 $TRACE_PATH/$SESSION_NAME |
| 631 | if [ $? -ne 0 ]; then |
| 632 | return $? |
| 633 | fi |
| 634 | } |
| 635 | |
| 636 | function test_python_disable_enable() |
| 637 | { |
| 638 | diag "Test Python disable event followed by an enable" |
| 639 | |
| 640 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
| 641 | # Enable all event with a filter. |
| 642 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 643 | disable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 644 | enable_python_lttng_event $SESSION_NAME $EVENT_NAME |
| 645 | start_lttng_tracing_ok $SESSION_NAME |
| 646 | |
| 647 | # Run 5 times with a 1 second delay and fire second TP. |
| 648 | run_app $1 0 1 |
| 649 | |
| 650 | stop_lttng_tracing_ok $SESSION_NAME |
| 651 | destroy_lttng_session_ok $SESSION_NAME |
| 652 | |
| 653 | # Validate test. Expecting NR_ITER event of the main INFO tp. |
| 654 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH/$SESSION_NAME |
| 655 | if [ $? -ne 0 ]; then |
| 656 | return $? |
| 657 | fi |
| 658 | } |
| 659 | |
| 660 | function test_python_filter_loglevel() |
| 661 | { |
| 662 | local BOGUS_EVENT_NAME="not_a_real_event" |
| 663 | local FILTER="int_loglevel > 30 || int_loglevel < 30" |
| 664 | local ALL_EVENTS="." |
| 665 | |
| 666 | diag "Test Python a filter with a loglevel" |
| 667 | |
| 668 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH/$SESSION_NAME |
| 669 | # Enable an event with a filter and the loglevel-only option. |
| 670 | enable_python_filter_loglevel_only $SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" "INFO" |
| 671 | disable_python_lttng_event $SESSION_NAME $BOGUS_EVENT_NAME |
| 672 | enable_python_filter_loglevel_only $SESSION_NAME $BOGUS_EVENT_NAME "$FILTER" "INFO" |
| 673 | start_lttng_tracing_ok $SESSION_NAME |
| 674 | |
| 675 | # Run 5 times with a 1 second delay and fire second TP. |
| 676 | run_app $1 0 1 |
| 677 | |
| 678 | stop_lttng_tracing_ok $SESSION_NAME |
| 679 | destroy_lttng_session_ok $SESSION_NAME |
| 680 | |
| 681 | # Validate test. Expecting no events. |
| 682 | trace_match_only $ALL_EVENTS 0 $TRACE_PATH/$SESSION_NAME |
| 683 | if [ $? -ne 0 ]; then |
| 684 | return $? |
| 685 | fi |
| 686 | } |
| 687 | |
| 688 | function test_python_trigger_notify_action |
| 689 | { |
| 690 | uid=$(id --user) |
| 691 | tmp_expected_stdout=$(mktemp -t test_list_triggers_python_cli_expected_stdout.XXXXXX) |
| 692 | |
| 693 | diag "Test Python trigger with notify action" |
| 694 | |
| 695 | lttng_add_trigger_ok "my_python_trigger" \ |
| 696 | --condition event-rule-matches --type=python --action notify |
| 697 | |
| 698 | cat > "${tmp_expected_stdout}" <<- EOF |
| 699 | - name: my_python_trigger |
| 700 | owner uid: ${uid} |
| 701 | condition: event rule matches |
| 702 | rule: * (type: python:logging) |
| 703 | errors: none |
| 704 | actions: |
| 705 | notify |
| 706 | errors: none |
| 707 | errors: none |
| 708 | EOF |
| 709 | |
| 710 | list_triggers_matches_ok "Python trigger listing" "${tmp_expected_stdout}" |
| 711 | |
| 712 | lttng_remove_trigger_ok "my_python_trigger" |
| 713 | |
| 714 | rm -f "${tmp_expected_stdout}" |
| 715 | } |
| 716 | |
| 717 | plan_tests $NUM_TESTS |
| 718 | |
| 719 | print_test_banner "$TEST_DESC" |
| 720 | |
| 721 | if [[ ${#python_versions[@]} -eq 0 || "x$run_test" != "xyes" ]]; then |
| 722 | skip_agent=0 |
| 723 | else |
| 724 | skip_agent=1 |
| 725 | fi |
| 726 | |
| 727 | skip $skip_agent "Python agent test skipped." $NUM_TESTS || |
| 728 | { |
| 729 | start_lttng_sessiond |
| 730 | |
| 731 | tests=( |
| 732 | test_python_multi_session_disable_wildcard |
| 733 | test_python_multi_session_disable_wildcard_begin |
| 734 | test_python_multi_session_disable_wildcard_middle |
| 735 | test_python_multi_session_disable_wildcard_end |
| 736 | test_python_multi_session_disable |
| 737 | test_python_disable |
| 738 | test_python_disable_enable |
| 739 | test_python_disable_all |
| 740 | test_python_filtering |
| 741 | test_python_multi_session_loglevel |
| 742 | test_python_destroy_session |
| 743 | test_python_loglevel |
| 744 | test_python_loglevel_multiple |
| 745 | test_python_before_start |
| 746 | test_python_after_start |
| 747 | test_python_multi_session |
| 748 | test_python_filter_loglevel |
| 749 | test_python_trigger_notify_action |
| 750 | ) |
| 751 | |
| 752 | |
| 753 | for python_version in ${python_versions[*]}; |
| 754 | do |
| 755 | for fct_test in ${tests[@]}; |
| 756 | do |
| 757 | TRACE_PATH=$(mktemp -d -t tmp.test_python_logging_trace_path.XXXXXX) |
| 758 | |
| 759 | diag "(Python $python_version)" |
| 760 | ${fct_test} $python_version |
| 761 | if [ $? -ne 0 ]; then |
| 762 | break; |
| 763 | fi |
| 764 | rm -rf $TRACE_PATH |
| 765 | done |
| 766 | done |
| 767 | stop_lttng_sessiond |
| 768 | } |