| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) - 2019 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com> |
| 4 | # |
| 5 | # This library is free software; you can redistribute it and/or modify it under |
| 6 | # the terms of the GNU Lesser General Public License as published by the Free |
| 7 | # Software Foundation; version 2.1 of the License. |
| 8 | # |
| 9 | # This library 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 Lesser General Public License for more |
| 12 | # details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU Lesser General Public License |
| 15 | # along with this library; if not, write to the Free Software Foundation, Inc., |
| 16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | |
| 18 | TEST_DESC="Clear - UST tracing" |
| 19 | |
| 20 | CURDIR=$(dirname $0)/ |
| 21 | TESTDIR=$CURDIR/../../.. |
| 22 | EVENT_NAME="tp:tptest" |
| 23 | SESSION_NAME="" |
| 24 | TESTAPP_PATH="$TESTDIR/utils/testapp" |
| 25 | TESTAPP_NAME="gen-ust-events" |
| 26 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" |
| 27 | |
| 28 | NUM_TESTS=1683 |
| 29 | |
| 30 | PAGE_SIZE=$(getconf PAGE_SIZE) |
| 31 | TRACE_PATH=$(mktemp -d) |
| 32 | |
| 33 | source $TESTDIR/utils/utils.sh |
| 34 | |
| 35 | if [ ! -x "$TESTAPP_BIN" ]; then |
| 36 | BAIL_OUT "No UST events binary detected." |
| 37 | fi |
| 38 | |
| 39 | function clean_path () |
| 40 | { |
| 41 | local trace_path=$1 |
| 42 | set -u |
| 43 | rm -rf $trace_path/* |
| 44 | set +u |
| 45 | } |
| 46 | |
| 47 | function cond_start_tracing () |
| 48 | { |
| 49 | local session_name=$1 |
| 50 | local tracing_active=$2 |
| 51 | |
| 52 | if [[ $tracing_active -ne 1 ]]; then |
| 53 | start_lttng_tracing_ok $session_name |
| 54 | fi |
| 55 | } |
| 56 | |
| 57 | function cond_stop_tracing () |
| 58 | { |
| 59 | local session_name=$1 |
| 60 | local tracing_active=$2 |
| 61 | |
| 62 | if [[ $tracing_active -ne 1 ]]; then |
| 63 | stop_lttng_tracing_ok $session_name |
| 64 | fi |
| 65 | } |
| 66 | |
| 67 | function do_clear_session () |
| 68 | { |
| 69 | local session_name=$1 |
| 70 | local tracing_active=$2 |
| 71 | local clear_twice=$3 |
| 72 | local rotate_before=$4 |
| 73 | local rotate_after=$5 |
| 74 | |
| 75 | cond_stop_tracing $session_name $tracing_active |
| 76 | if [[ $rotate_before -eq 1 ]]; then |
| 77 | rotate_session_ok $SESSION_NAME |
| 78 | fi |
| 79 | lttng_clear_session_ok $SESSION_NAME |
| 80 | if [[ $clear_twice -eq 1 ]]; then |
| 81 | lttng_clear_session_ok $SESSION_NAME |
| 82 | fi |
| 83 | if [[ $rotate_after -eq 1 ]]; then |
| 84 | if [[ $tracing_active -eq 1 ]]; then |
| 85 | rotate_session_ok $SESSION_NAME |
| 86 | else |
| 87 | # Expect failure |
| 88 | rotate_session_fail $SESSION_NAME |
| 89 | fi |
| 90 | fi |
| 91 | cond_start_tracing $session_name $tracing_active |
| 92 | } |
| 93 | |
| 94 | function test_ust_streaming () |
| 95 | { |
| 96 | local tracing_active=$1 |
| 97 | local clear_twice=$2 |
| 98 | local rotate_before=$3 |
| 99 | local rotate_after=$4 |
| 100 | local buffer_type=$5 |
| 101 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" |
| 102 | local channel_name="chan" |
| 103 | |
| 104 | diag "Test ust streaming clear" |
| 105 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" |
| 106 | create_lttng_session_uri $SESSION_NAME net://localhost |
| 107 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type |
| 108 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name |
| 109 | start_lttng_tracing_ok $SESSION_NAME |
| 110 | $TESTAPP_BIN -i 10 |
| 111 | do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after |
| 112 | stop_lttng_tracing_ok $SESSION_NAME |
| 113 | |
| 114 | if [[ $rotate_before -eq 1 ]]; then |
| 115 | validate_trace_count $EVENT_NAME $local_path 10 |
| 116 | else |
| 117 | if [[ "$buffer_type" == "uid" ]]; then |
| 118 | validate_trace_empty $local_path |
| 119 | else # pid |
| 120 | validate_directory_empty $local_path |
| 121 | fi |
| 122 | fi |
| 123 | |
| 124 | destroy_lttng_session_ok $SESSION_NAME |
| 125 | } |
| 126 | |
| 127 | function test_ust_streaming_rotate_clear () |
| 128 | { |
| 129 | local tracing_active=$1 |
| 130 | local clear_twice=$2 |
| 131 | local rotate_before=$3 |
| 132 | local rotate_after=$4 |
| 133 | local buffer_type=$5 |
| 134 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" |
| 135 | local channel_name="chan" |
| 136 | |
| 137 | diag "Test ust streaming rotate-clear" |
| 138 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" |
| 139 | create_lttng_session_uri $SESSION_NAME net://localhost |
| 140 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type |
| 141 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name |
| 142 | start_lttng_tracing_ok $SESSION_NAME |
| 143 | $TESTAPP_BIN -i 1 |
| 144 | rotate_session_ok $SESSION_NAME |
| 145 | $TESTAPP_BIN -i 2 |
| 146 | do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after |
| 147 | $TESTAPP_BIN -i 3 |
| 148 | stop_lttng_tracing_ok $SESSION_NAME |
| 149 | |
| 150 | if [[ $rotate_before -eq 1 ]]; then |
| 151 | local expect_count=6 |
| 152 | else |
| 153 | local expect_count=4 |
| 154 | fi |
| 155 | validate_trace_count $EVENT_NAME $local_path $expect_count |
| 156 | |
| 157 | destroy_lttng_session_ok $SESSION_NAME |
| 158 | } |
| 159 | |
| 160 | function test_ust_streaming_clear_rotate () |
| 161 | { |
| 162 | local tracing_active=$1 |
| 163 | local clear_twice=$2 |
| 164 | local rotate_before=$3 |
| 165 | local rotate_after=$4 |
| 166 | local buffer_type=$5 |
| 167 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" |
| 168 | local channel_name="chan" |
| 169 | |
| 170 | diag "Test ust streaming clear-rotate" |
| 171 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" |
| 172 | create_lttng_session_uri $SESSION_NAME net://localhost |
| 173 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type |
| 174 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name |
| 175 | start_lttng_tracing_ok $SESSION_NAME |
| 176 | $TESTAPP_BIN -i 1 |
| 177 | do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after |
| 178 | $TESTAPP_BIN -i 2 |
| 179 | rotate_session_ok $SESSION_NAME |
| 180 | $TESTAPP_BIN -i 3 |
| 181 | stop_lttng_tracing_ok $SESSION_NAME |
| 182 | |
| 183 | if [[ $rotate_before -eq 1 ]]; then |
| 184 | local expect_count=6 |
| 185 | else |
| 186 | local expect_count=5 |
| 187 | fi |
| 188 | validate_trace_count $EVENT_NAME $local_path $expect_count |
| 189 | |
| 190 | destroy_lttng_session_ok $SESSION_NAME |
| 191 | } |
| 192 | |
| 193 | function test_ust_streaming_live () |
| 194 | { |
| 195 | local tracing_active=$1 |
| 196 | local clear_twice=$2 |
| 197 | # 3, 4 unused |
| 198 | local buffer_type=$5 |
| 199 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" |
| 200 | local channel_name="chan" |
| 201 | |
| 202 | diag "Test ust streaming live clear" |
| 203 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" |
| 204 | create_lttng_session_uri $SESSION_NAME net://localhost "--live" |
| 205 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type |
| 206 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name |
| 207 | start_lttng_tracing_ok $SESSION_NAME |
| 208 | $TESTAPP_BIN -i 10 |
| 209 | do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0 |
| 210 | stop_lttng_tracing_ok $SESSION_NAME |
| 211 | |
| 212 | validate_directory_empty $local_path |
| 213 | |
| 214 | destroy_lttng_session_ok $SESSION_NAME |
| 215 | } |
| 216 | |
| 217 | #no clear |
| 218 | function test_ust_basic_streaming_live_viewer () |
| 219 | { |
| 220 | local tracing_active=$1 |
| 221 | local clear_twice=$2 |
| 222 | # 3, 4 unused |
| 223 | local buffer_type=$5 |
| 224 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" |
| 225 | local remote_trace_path="${HOSTNAME}/${SESSION_NAME}" |
| 226 | local channel_name="chan" |
| 227 | local bt_output_path=$(mktemp -u) |
| 228 | local file_sync_before_exit=$(mktemp -u) |
| 229 | |
| 230 | diag "Test ust basic streaming live with viewer" |
| 231 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" |
| 232 | create_lttng_session_uri $SESSION_NAME net://localhost "--live" |
| 233 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type |
| 234 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name |
| 235 | start_lttng_tracing_ok $SESSION_NAME |
| 236 | |
| 237 | wait_live_trace_ready net://localhost |
| 238 | |
| 239 | # Connect a live viewer |
| 240 | $BABELTRACE_BIN -i lttng-live net://localhost/host/$remote_trace_path > $bt_output_path & |
| 241 | local viewer_pid=$! |
| 242 | |
| 243 | wait_live_viewer_connect net://localhost |
| 244 | |
| 245 | $TESTAPP_BIN -i 10 --sync-before-exit $file_sync_before_exit & |
| 246 | local app_pid=$! |
| 247 | |
| 248 | diag "Wait until viewer sees all 10 expected events" |
| 249 | local evcount=0 |
| 250 | while [ $evcount -ne 10 ]; do |
| 251 | evcount=$(cat $bt_output_path | wc -l) |
| 252 | sleep 0.5 |
| 253 | done |
| 254 | pass "Live viewer read $evcount events, expect 10" |
| 255 | |
| 256 | destroy_lttng_session_ok $SESSION_NAME |
| 257 | touch $file_sync_before_exit |
| 258 | diag "Wait for application to exit" |
| 259 | wait $app_pid |
| 260 | pass "Wait for application to exit" |
| 261 | diag "Wait for viewer to exit" |
| 262 | wait $viewer_pid |
| 263 | ok $? "Babeltrace succeeds" |
| 264 | pass "Wait for viewer to exit" |
| 265 | |
| 266 | rm -f $bt_output_path |
| 267 | rm -f $file_sync_before_exit |
| 268 | } |
| 269 | |
| 270 | function test_ust_streaming_live_viewer () |
| 271 | { |
| 272 | local tracing_active=$1 |
| 273 | local clear_twice=$2 |
| 274 | # 3, 4 unused |
| 275 | local buffer_type=$5 |
| 276 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" |
| 277 | local remote_trace_path="${HOSTNAME}/${SESSION_NAME}" |
| 278 | local channel_name="chan" |
| 279 | local bt_output_path=$(mktemp -d)/bt-output.txt |
| 280 | |
| 281 | diag "Test ust streaming live clear with viewer" |
| 282 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" |
| 283 | create_lttng_session_uri $SESSION_NAME net://localhost "--live" |
| 284 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type |
| 285 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name |
| 286 | start_lttng_tracing_ok $SESSION_NAME |
| 287 | |
| 288 | wait_live_trace_ready net://localhost |
| 289 | |
| 290 | # Connect a live viewer |
| 291 | $BABELTRACE_BIN -i lttng-live net://localhost/host/$remote_trace_path > $bt_output_path & |
| 292 | local viewer_pid=$! |
| 293 | |
| 294 | wait_live_viewer_connect net://localhost |
| 295 | |
| 296 | $TESTAPP_BIN -i 10 |
| 297 | do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0 |
| 298 | stop_lttng_tracing_ok $SESSION_NAME |
| 299 | |
| 300 | destroy_lttng_session_ok $SESSION_NAME |
| 301 | diag "Wait for viewer to exit" |
| 302 | wait $viewer_pid |
| 303 | ok $? "Babeltrace succeeds" |
| 304 | pass "Wait for viewer to exit" |
| 305 | |
| 306 | clean_path $bt_output_path |
| 307 | } |
| 308 | |
| 309 | function test_ust_local () |
| 310 | { |
| 311 | local tracing_active=$1 |
| 312 | local clear_twice=$2 |
| 313 | local rotate_before=$3 |
| 314 | local rotate_after=$4 |
| 315 | local buffer_type=$5 |
| 316 | local channel_name="chan" |
| 317 | |
| 318 | diag "Test ust local" |
| 319 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" |
| 320 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 321 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type |
| 322 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name |
| 323 | start_lttng_tracing_ok $SESSION_NAME |
| 324 | $TESTAPP_BIN -i 10 |
| 325 | do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after |
| 326 | stop_lttng_tracing_ok $SESSION_NAME |
| 327 | |
| 328 | if [[ $rotate_before -eq 1 ]]; then |
| 329 | validate_trace_count $EVENT_NAME $TRACE_PATH 10 |
| 330 | else |
| 331 | if [[ "$buffer_type" == "uid" ]]; then |
| 332 | validate_trace_empty $TRACE_PATH |
| 333 | else # pid |
| 334 | validate_directory_empty $TRACE_PATH |
| 335 | fi |
| 336 | fi |
| 337 | |
| 338 | destroy_lttng_session_ok $SESSION_NAME |
| 339 | } |
| 340 | |
| 341 | function test_ust_local_rotate_clear () |
| 342 | { |
| 343 | local tracing_active=$1 |
| 344 | local clear_twice=$2 |
| 345 | local rotate_before=$3 |
| 346 | local rotate_after=$4 |
| 347 | local buffer_type=$5 |
| 348 | local channel_name="chan" |
| 349 | |
| 350 | diag "Test ust local rotate-clear" |
| 351 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" |
| 352 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 353 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type |
| 354 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name |
| 355 | start_lttng_tracing_ok $SESSION_NAME |
| 356 | $TESTAPP_BIN -i 1 |
| 357 | rotate_session_ok $SESSION_NAME |
| 358 | $TESTAPP_BIN -i 2 |
| 359 | do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after |
| 360 | $TESTAPP_BIN -i 3 |
| 361 | stop_lttng_tracing_ok $SESSION_NAME |
| 362 | |
| 363 | if [[ $rotate_before -eq 1 ]]; then |
| 364 | local expect_count=6 |
| 365 | else |
| 366 | local expect_count=4 |
| 367 | fi |
| 368 | validate_trace_count $EVENT_NAME $TRACE_PATH $expect_count |
| 369 | |
| 370 | destroy_lttng_session_ok $SESSION_NAME |
| 371 | } |
| 372 | |
| 373 | function test_ust_local_clear_rotate () |
| 374 | { |
| 375 | local tracing_active=$1 |
| 376 | local clear_twice=$2 |
| 377 | local rotate_before=$3 |
| 378 | local rotate_after=$4 |
| 379 | local buffer_type=$5 |
| 380 | local channel_name="chan" |
| 381 | |
| 382 | diag "Test ust local clear-rotate" |
| 383 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" |
| 384 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 385 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type |
| 386 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name |
| 387 | start_lttng_tracing_ok $SESSION_NAME |
| 388 | $TESTAPP_BIN -i 1 |
| 389 | do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after |
| 390 | $TESTAPP_BIN -i 2 |
| 391 | rotate_session_ok $SESSION_NAME |
| 392 | $TESTAPP_BIN -i 3 |
| 393 | stop_lttng_tracing_ok $SESSION_NAME |
| 394 | |
| 395 | if [[ $rotate_before -eq 1 ]]; then |
| 396 | local expect_count=6 |
| 397 | else |
| 398 | local expect_count=5 |
| 399 | fi |
| 400 | validate_trace_count $EVENT_NAME $TRACE_PATH $expect_count |
| 401 | |
| 402 | destroy_lttng_session_ok $SESSION_NAME |
| 403 | } |
| 404 | |
| 405 | function do_ust_snapshot () |
| 406 | { |
| 407 | local session_name=$1 |
| 408 | local trace_path=$2 |
| 409 | local tracing_active=$3 |
| 410 | local clear_twice=$4 |
| 411 | local buffer_type=$5 |
| 412 | local channel_name="snapshot" |
| 413 | |
| 414 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type |
| 415 | enable_ust_lttng_event_ok $session_name $EVENT_NAME $channel_name |
| 416 | start_lttng_tracing_ok $session_name |
| 417 | |
| 418 | # Generate 10 events that will sit in the buffers. |
| 419 | $TESTAPP_BIN -i 10 |
| 420 | |
| 421 | # Take a first snapshot and validate that the events are present. |
| 422 | lttng_snapshot_record $session_name |
| 423 | stop_lttng_tracing_ok $session_name |
| 424 | validate_trace_count $EVENT_NAME $trace_path 10 |
| 425 | |
| 426 | # Clean the output path |
| 427 | clean_path $trace_path |
| 428 | start_lttng_tracing_ok $session_name |
| 429 | |
| 430 | do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0 |
| 431 | |
| 432 | # Make sure the subsequent snapshot is empty and valid. |
| 433 | lttng_snapshot_record $session_name |
| 434 | stop_lttng_tracing_ok $session_name |
| 435 | validate_trace_empty $trace_path |
| 436 | |
| 437 | # Clean the output path |
| 438 | clean_path $trace_path |
| 439 | start_lttng_tracing_ok $session_name |
| 440 | |
| 441 | # Make sure that everything still works, generate events and take a |
| 442 | # snapshot. |
| 443 | $TESTAPP_BIN -i 10 |
| 444 | lttng_snapshot_record $session_name |
| 445 | stop_lttng_tracing_ok $session_name |
| 446 | validate_trace_count $EVENT_NAME $trace_path 10 |
| 447 | } |
| 448 | |
| 449 | function test_ust_streaming_snapshot () |
| 450 | { |
| 451 | local tracing_active=$1 |
| 452 | local clear_twice=$2 |
| 453 | # 3, 4 unused. |
| 454 | local buffer_type=$5 |
| 455 | |
| 456 | diag "Test ust streaming snapshot clear" |
| 457 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" |
| 458 | |
| 459 | create_lttng_session_uri $SESSION_NAME net://localhost "--snapshot" |
| 460 | do_ust_snapshot $SESSION_NAME $TRACE_PATH $tracing_active $clear_twice $buffer_type |
| 461 | destroy_lttng_session_ok $SESSION_NAME |
| 462 | } |
| 463 | |
| 464 | function test_ust_local_snapshot () |
| 465 | { |
| 466 | local tracing_active=$1 |
| 467 | local clear_twice=$2 |
| 468 | # 3, 4 unused. |
| 469 | local buffer_type=$5 |
| 470 | |
| 471 | diag "Test ust local snapshot clear" |
| 472 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" |
| 473 | |
| 474 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot" |
| 475 | do_ust_snapshot $SESSION_NAME $TRACE_PATH $tracing_active $clear_twice $buffer_type |
| 476 | destroy_lttng_session_ok $SESSION_NAME |
| 477 | } |
| 478 | |
| 479 | # snapshot for per-pid is tested independently of the "buffer type" parameter |
| 480 | # because an application needs to be live to appear in a snapshot. |
| 481 | function test_ust_local_snapshot_per_pid () |
| 482 | { |
| 483 | local tracing_active=$1 |
| 484 | local clear_twice=$2 |
| 485 | # 3, 4 unused. |
| 486 | local buffer_type=$5 |
| 487 | local channel_name="channel0" |
| 488 | local file_sync_before_last=$(mktemp -u) |
| 489 | local file_sync_before_last_touch=$(mktemp -u) |
| 490 | local file_sync_before_exit=$(mktemp -u) |
| 491 | local file_sync_before_exit_touch=$(mktemp -u) |
| 492 | |
| 493 | diag "Test ust local snapshot clear per pid" |
| 494 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" |
| 495 | |
| 496 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot" |
| 497 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type |
| 498 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name |
| 499 | start_lttng_tracing_ok $SESSION_NAME |
| 500 | |
| 501 | # Generate 10 events that will sit in the buffers. |
| 502 | $TESTAPP_BIN -i 10 -w 0 \ |
| 503 | --sync-before-last-event ${file_sync_before_last} \ |
| 504 | --sync-before-last-event-touch ${file_sync_before_last_touch} \ |
| 505 | --sync-before-exit ${file_sync_before_exit} \ |
| 506 | --sync-before-exit-touch ${file_sync_before_exit_touch} >/dev/null 2>&1 & |
| 507 | |
| 508 | # Continue only when there is only the last event remaining. |
| 509 | while [ ! -f "${file_sync_before_last_touch}" ]; do |
| 510 | sleep 0.5 |
| 511 | done |
| 512 | |
| 513 | # Take a first snapshot and validate that the events are present. |
| 514 | lttng_snapshot_record $SESSION_NAME |
| 515 | stop_lttng_tracing_ok $SESSION_NAME |
| 516 | validate_trace_count $EVENT_NAME $TRACE_PATH 9 |
| 517 | |
| 518 | # Clean the output path |
| 519 | clean_path $TRACE_PATH |
| 520 | start_lttng_tracing_ok $SESSION_NAME |
| 521 | |
| 522 | do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0 |
| 523 | |
| 524 | # Make sure the subsequent snapshot is empty and valid. |
| 525 | lttng_snapshot_record $SESSION_NAME |
| 526 | stop_lttng_tracing_ok $SESSION_NAME |
| 527 | validate_trace_empty $TRACE_PATH |
| 528 | |
| 529 | # Validate that tracing still works and subsequent snapshots are valid. |
| 530 | # Clean the output path. |
| 531 | clean_path $TRACE_PATH |
| 532 | start_lttng_tracing_ok $SESSION_NAME |
| 533 | |
| 534 | # Continue over the last event. |
| 535 | touch ${file_sync_before_last} |
| 536 | |
| 537 | # Wait for the before exit sync point. This ensure that we went over the |
| 538 | # last tracepoint. |
| 539 | while [ ! -f "${file_sync_before_exit_touch}" ]; do |
| 540 | sleep 0.5 |
| 541 | done |
| 542 | |
| 543 | # Make sure the snapshot contains the last event. |
| 544 | lttng_snapshot_record $SESSION_NAME |
| 545 | stop_lttng_tracing_ok $SESSION_NAME |
| 546 | validate_trace_count $EVENT_NAME $TRACE_PATH 1 |
| 547 | |
| 548 | # Release the application. |
| 549 | touch ${file_sync_before_exit} |
| 550 | wait |
| 551 | destroy_lttng_session_ok $SESSION_NAME |
| 552 | |
| 553 | rm -f ${file_sync_before_last} |
| 554 | rm -f ${file_sync_before_last_touch} |
| 555 | rm -f ${file_sync_before_exit} |
| 556 | rm -f ${file_sync_before_exit_touch} |
| 557 | } |
| 558 | |
| 559 | function test_ust_streaming_tracefile_rotation () |
| 560 | { |
| 561 | local tracing_active=$1 |
| 562 | local clear_twice=$2 |
| 563 | local rotate_before=$3 |
| 564 | local rotate_after=$4 |
| 565 | local buffer_type=$5 |
| 566 | local channel_name="rotchan" |
| 567 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" |
| 568 | |
| 569 | diag "Test ust streaming clear with tracefile rotation" |
| 570 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" |
| 571 | create_lttng_session_uri $SESSION_NAME net://localhost |
| 572 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \ |
| 573 | --tracefile-size=$PAGE_SIZE --tracefile-count=2 --buffers-$buffer_type |
| 574 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name |
| 575 | start_lttng_tracing_ok $SESSION_NAME |
| 576 | $TESTAPP_BIN -i 10 |
| 577 | do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after |
| 578 | stop_lttng_tracing_ok $SESSION_NAME |
| 579 | |
| 580 | if [[ $rotate_before -eq 1 ]]; then |
| 581 | validate_trace_count $EVENT_NAME $local_path 10 |
| 582 | else |
| 583 | if [[ "$buffer_type" == "uid" ]]; then |
| 584 | validate_trace_empty $local_path |
| 585 | else # pid |
| 586 | validate_directory_empty $local_path |
| 587 | fi |
| 588 | fi |
| 589 | |
| 590 | start_lttng_tracing_ok $SESSION_NAME |
| 591 | $TESTAPP_BIN -i 20 |
| 592 | stop_lttng_tracing_ok |
| 593 | |
| 594 | if [[ $rotate_before -eq 1 ]]; then |
| 595 | validate_trace_count $EVENT_NAME $local_path 30 |
| 596 | else |
| 597 | validate_trace_count $EVENT_NAME $local_path 20 |
| 598 | fi |
| 599 | |
| 600 | destroy_lttng_session_ok $SESSION_NAME |
| 601 | } |
| 602 | |
| 603 | # With 1 byte per event (as strict minimum), generating 200000 events |
| 604 | # guarantees filling up 2 files of 64k in size, which is the maximum |
| 605 | # page size known on Linux |
| 606 | function test_ust_streaming_tracefile_rotation_overwrite_files () |
| 607 | { |
| 608 | local tracing_active=$1 |
| 609 | local clear_twice=$2 |
| 610 | local rotate_before=$3 |
| 611 | local rotate_after=$4 |
| 612 | local buffer_type=$5 |
| 613 | local channel_name="rotchan" |
| 614 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" |
| 615 | |
| 616 | diag "Test ust streaming clear with tracefile rotation, overwrite files" |
| 617 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" |
| 618 | create_lttng_session_uri $SESSION_NAME net://localhost |
| 619 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \ |
| 620 | --tracefile-size=$PAGE_SIZE --tracefile-count=2 --buffers-$buffer_type |
| 621 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name |
| 622 | start_lttng_tracing_ok $SESSION_NAME |
| 623 | taskset -c 0 $TESTAPP_BIN -i 200000 |
| 624 | do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after |
| 625 | stop_lttng_tracing_ok $SESSION_NAME |
| 626 | |
| 627 | if [[ $rotate_before -eq 1 ]]; then |
| 628 | validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 200000 |
| 629 | else |
| 630 | if [[ "$buffer_type" == "uid" ]]; then |
| 631 | validate_trace_empty $local_path |
| 632 | else # pid |
| 633 | validate_directory_empty $local_path |
| 634 | fi |
| 635 | fi |
| 636 | |
| 637 | start_lttng_tracing_ok $SESSION_NAME |
| 638 | taskset -c 0 $TESTAPP_BIN -i 400000 |
| 639 | stop_lttng_tracing_ok |
| 640 | |
| 641 | if [[ $rotate_before -eq 1 ]]; then |
| 642 | validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 600000 |
| 643 | else |
| 644 | validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 200000 |
| 645 | fi |
| 646 | |
| 647 | destroy_lttng_session_ok $SESSION_NAME |
| 648 | } |
| 649 | |
| 650 | function test_ust_disallow_clear () |
| 651 | { |
| 652 | diag "Test ust disallow clear on relay daemon" |
| 653 | SESSION_NAME=$(randstring 16 0) |
| 654 | |
| 655 | LTTNG_RELAYD_DISALLOW_CLEAR=1 start_lttng_relayd "-o $TRACE_PATH" |
| 656 | |
| 657 | start_lttng_sessiond |
| 658 | |
| 659 | create_lttng_session_uri $SESSION_NAME net://localhost |
| 660 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME |
| 661 | start_lttng_tracing_ok $SESSION_NAME |
| 662 | lttng_clear_session_fail $SESSION_NAME |
| 663 | destroy_lttng_session_ok $SESSION_NAME |
| 664 | |
| 665 | stop_lttng_sessiond |
| 666 | stop_lttng_relayd |
| 667 | clean_path $TRACE_PATH |
| 668 | } |
| 669 | |
| 670 | plan_tests $NUM_TESTS |
| 671 | |
| 672 | print_test_banner "$TEST_DESC" |
| 673 | |
| 674 | streaming_tests=(test_ust_streaming |
| 675 | test_ust_streaming_rotate_clear |
| 676 | test_ust_streaming_clear_rotate |
| 677 | test_ust_streaming_tracefile_rotation |
| 678 | test_ust_streaming_tracefile_rotation_overwrite_files |
| 679 | ) |
| 680 | |
| 681 | live_tests=(test_ust_streaming_live |
| 682 | test_ust_basic_streaming_live_viewer |
| 683 | test_ust_streaming_live_viewer |
| 684 | ) |
| 685 | |
| 686 | local_tests=(test_ust_local |
| 687 | test_ust_local_rotate_clear |
| 688 | test_ust_local_clear_rotate |
| 689 | ) |
| 690 | |
| 691 | snapshot_uid_tests=(test_ust_streaming_snapshot |
| 692 | test_ust_local_snapshot |
| 693 | ) |
| 694 | |
| 695 | snapshot_pid_tests=(test_ust_local_snapshot_per_pid) |
| 696 | |
| 697 | start_lttng_relayd "-o $TRACE_PATH" |
| 698 | start_lttng_sessiond |
| 699 | |
| 700 | # Per-UID buffers |
| 701 | |
| 702 | # Clear with tracing active, clear once |
| 703 | for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]}; |
| 704 | do |
| 705 | SESSION_NAME=$(randstring 16 0) |
| 706 | ${fct_test} 1 0 0 0 uid |
| 707 | clean_path $TRACE_PATH |
| 708 | done |
| 709 | |
| 710 | # Clear with tracing active, clear twice |
| 711 | for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]}; |
| 712 | do |
| 713 | SESSION_NAME=$(randstring 16 0) |
| 714 | ${fct_test} 1 1 0 0 uid |
| 715 | clean_path $TRACE_PATH |
| 716 | done |
| 717 | |
| 718 | # Clear with tracing inactive, clear once |
| 719 | for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]}; |
| 720 | do |
| 721 | SESSION_NAME=$(randstring 16 0) |
| 722 | ${fct_test} 0 0 0 0 uid |
| 723 | clean_path $TRACE_PATH |
| 724 | done |
| 725 | |
| 726 | # Clear with tracing inactive, clear twice |
| 727 | for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]}; |
| 728 | do |
| 729 | SESSION_NAME=$(randstring 16 0) |
| 730 | ${fct_test} 0 1 0 0 uid |
| 731 | clean_path $TRACE_PATH |
| 732 | done |
| 733 | |
| 734 | # Clear with tracing inactive, rotate-clear once |
| 735 | for fct_test in ${streaming_tests[@]} ${local_tests[@]}; |
| 736 | do |
| 737 | SESSION_NAME=$(randstring 16 0) |
| 738 | ${fct_test} 0 0 1 0 uid |
| 739 | clean_path $TRACE_PATH |
| 740 | done |
| 741 | |
| 742 | # Clear with tracing inactive, clear once-rotate(fail) |
| 743 | for fct_test in ${streaming_tests[@]} ${local_tests[@]}; |
| 744 | do |
| 745 | SESSION_NAME=$(randstring 16 0) |
| 746 | ${fct_test} 0 0 0 1 uid |
| 747 | clean_path $TRACE_PATH |
| 748 | done |
| 749 | |
| 750 | |
| 751 | # Per-PID buffers. |
| 752 | |
| 753 | # Clear with tracing active, clear once |
| 754 | for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]}; |
| 755 | do |
| 756 | SESSION_NAME=$(randstring 16 0) |
| 757 | ${fct_test} 1 0 0 0 pid |
| 758 | clean_path $TRACE_PATH |
| 759 | done |
| 760 | |
| 761 | # Clear with tracing active, clear twice |
| 762 | for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]}; |
| 763 | do |
| 764 | SESSION_NAME=$(randstring 16 0) |
| 765 | ${fct_test} 1 1 0 0 pid |
| 766 | clean_path $TRACE_PATH |
| 767 | done |
| 768 | |
| 769 | # Clear with tracing inactive, clear once |
| 770 | for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]}; |
| 771 | do |
| 772 | SESSION_NAME=$(randstring 16 0) |
| 773 | ${fct_test} 0 0 0 0 pid |
| 774 | clean_path $TRACE_PATH |
| 775 | done |
| 776 | |
| 777 | # Clear with tracing inactive, clear twice |
| 778 | for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]}; |
| 779 | do |
| 780 | SESSION_NAME=$(randstring 16 0) |
| 781 | ${fct_test} 0 1 0 0 pid |
| 782 | clean_path $TRACE_PATH |
| 783 | done |
| 784 | |
| 785 | # Clear with tracing inactive, rotate-clear once |
| 786 | for fct_test in ${streaming_tests[@]} ${local_tests[@]}; |
| 787 | do |
| 788 | SESSION_NAME=$(randstring 16 0) |
| 789 | ${fct_test} 0 0 1 0 pid |
| 790 | clean_path $TRACE_PATH |
| 791 | done |
| 792 | |
| 793 | # Clear with tracing inactive, clear once-rotate(fail) |
| 794 | for fct_test in ${streaming_tests[@]} ${local_tests[@]}; |
| 795 | do |
| 796 | SESSION_NAME=$(randstring 16 0) |
| 797 | ${fct_test} 0 0 0 1 pid |
| 798 | clean_path $TRACE_PATH |
| 799 | done |
| 800 | |
| 801 | stop_lttng_sessiond |
| 802 | stop_lttng_relayd |
| 803 | |
| 804 | test_ust_disallow_clear |