| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) - 2015 Jonathan Rajotte <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="LTTng-crash & shm testing" |
| 19 | |
| 20 | CURDIR=$(dirname $0)/ |
| 21 | TESTDIR=$CURDIR/../../../ |
| 22 | CRASH_BIN="lttng-crash" |
| 23 | |
| 24 | # Test app for ust event |
| 25 | TESTAPP_PATH="$TESTDIR/utils/testapp" |
| 26 | TESTAPP_NAME="gen-ust-events" |
| 27 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" |
| 28 | NR_USEC_WAIT=0 |
| 29 | NR_ITER=-1 |
| 30 | |
| 31 | # Temp file output |
| 32 | OUTPUT_DIR=$(mktemp -d) |
| 33 | |
| 34 | LAST_APP_PID= |
| 35 | |
| 36 | NUM_TESTS=77 |
| 37 | |
| 38 | source $TESTDIR/utils/utils.sh |
| 39 | |
| 40 | # Global declaration for simplification |
| 41 | LTTNG_CRASH=$TESTDIR/../src/bin/lttng-crash/$CRASH_BIN |
| 42 | |
| 43 | # MUST set TESTDIR before calling those functions |
| 44 | plan_tests $NUM_TESTS |
| 45 | |
| 46 | print_test_banner "$TEST_DESC" |
| 47 | |
| 48 | function start_test_app() |
| 49 | { |
| 50 | local tmp_file=$(mktemp -u) |
| 51 | |
| 52 | # Start application with a temporary file. |
| 53 | $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file & |
| 54 | ret=$? |
| 55 | LAST_APP_PID="${!}" |
| 56 | APPS_PID="${APPS_PID} ${!}" |
| 57 | ok $ret "Start application to trace" |
| 58 | |
| 59 | # Wait for the application file to appear indicating that at least one |
| 60 | # tracepoint has been fired. |
| 61 | while [ ! -f "$tmp_file" ]; do |
| 62 | sleep 0.5 |
| 63 | done |
| 64 | diag "Removing test app temporary file $tmp_file" |
| 65 | rm -rf $tmp_file |
| 66 | } |
| 67 | |
| 68 | function stop_test_apps() |
| 69 | { |
| 70 | diag "Stopping $TESTAPP_NAME" |
| 71 | for p in ${APPS_PID}; do |
| 72 | diag "Stopping $p" |
| 73 | kill ${p} 2>/dev/null |
| 74 | wait ${p} 2>/dev/null |
| 75 | diag "Stopped $p" |
| 76 | done |
| 77 | APPS_PID= |
| 78 | } |
| 79 | |
| 80 | function stop_test_app() |
| 81 | { |
| 82 | local pid="$1" |
| 83 | for p in ${pid}; do |
| 84 | diag "Stopping $p" |
| 85 | kill ${p} 2>/dev/null |
| 86 | wait ${p} 2>/dev/null |
| 87 | diag "Stopped $p" |
| 88 | done |
| 89 | } |
| 90 | |
| 91 | function verify_path_dont_exists() |
| 92 | { |
| 93 | local path=$1 |
| 94 | |
| 95 | while find $path -mindepth 1 -maxdepth 1 &>/dev/null ; do |
| 96 | sleep 2 |
| 97 | done |
| 98 | return 0 |
| 99 | } |
| 100 | |
| 101 | function test_shm_path_per_pid() |
| 102 | { |
| 103 | diag "Shm: ust per-pid test" |
| 104 | local session_name=shm_path_per_pid |
| 105 | local channel_name=channel_per_pid |
| 106 | local shm_path=$(mktemp -d) |
| 107 | |
| 108 | # Build up |
| 109 | start_lttng_sessiond |
| 110 | create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path" |
| 111 | enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-pid" |
| 112 | |
| 113 | start_lttng_tracing_ok $session_name |
| 114 | |
| 115 | diag "Shm: clean state" |
| 116 | file_count=$(find $shm_path -mindepth 1 -maxdepth 1 | wc -l) |
| 117 | test $file_count -eq "0" |
| 118 | ok $? "No file created on set-up" |
| 119 | |
| 120 | # Look for per-pid folder structure |
| 121 | # Start first test app |
| 122 | diag "Shm: check folder creation and structure" |
| 123 | |
| 124 | start_test_app |
| 125 | first_app_pid=$LAST_APP_PID |
| 126 | shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1) |
| 127 | |
| 128 | file_count=$(echo "$shm_session_path"| wc -l) |
| 129 | test $file_count -eq "1" |
| 130 | ok $? "Path $shm_session_path created on application creation" |
| 131 | |
| 132 | first_pid_path=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1) |
| 133 | ok $? "Pid path exists: $first_pid_path" |
| 134 | |
| 135 | file_count=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1 | wc -l) |
| 136 | test $file_count -eq "1" |
| 137 | ok $? "Expect 1 pid registration folder got $file_count" |
| 138 | |
| 139 | # Check for buffer and metadata presence in ust/pid/appfolder |
| 140 | file_count=$(find $first_pid_path/ -mindepth 1 -maxdepth 1 | wc -l) |
| 141 | test $file_count -ne "0" |
| 142 | ok $? "Expect > 0 buffer and metadata files got $file_count" |
| 143 | |
| 144 | # Start second application pid |
| 145 | diag "Shm: check basic creation of second ust application" |
| 146 | |
| 147 | start_test_app |
| 148 | second_app_pid=$LAST_APP_PID |
| 149 | second_pid_path=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1) |
| 150 | ok $? "Pid path exist found $second_pid_path" |
| 151 | |
| 152 | file_count=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1 | wc -l) |
| 153 | test $file_count -eq "2" |
| 154 | ok $? "Expect 2 pid registration folder got $file_count" |
| 155 | |
| 156 | # Stop first test application and check for cleanup |
| 157 | stop_test_app "$first_app_pid" |
| 158 | APPS_PID="$second_app_pid" |
| 159 | verify_path_dont_exists "$first_pid_path" |
| 160 | ok $? "First pid cleanup" |
| 161 | |
| 162 | # Stop all applications and check for full cleanup |
| 163 | stop_test_apps |
| 164 | verify_path_dont_exists "$shm_session_path" |
| 165 | ok $? "Full cleanup" |
| 166 | |
| 167 | # Tear down |
| 168 | destroy_lttng_session_ok $session_name |
| 169 | stop_lttng_sessiond |
| 170 | rm -rf $shm_path |
| 171 | } |
| 172 | |
| 173 | function test_shm_path_per_uid() |
| 174 | { |
| 175 | diag "Shm: ust per-uid test" |
| 176 | local session_name=shm_path_per_uid |
| 177 | local channel_name=channel_per_uid |
| 178 | local shm_path=$(mktemp -d) |
| 179 | |
| 180 | # Build up |
| 181 | start_lttng_sessiond |
| 182 | create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path" |
| 183 | enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid" |
| 184 | |
| 185 | start_lttng_tracing_ok $session_name |
| 186 | |
| 187 | diag "Shm: test clean state" |
| 188 | file_count=$(find $shm_path -mindepth 1 -maxdepth 1 | wc -l) |
| 189 | test $file_count -eq "0" |
| 190 | ok $? "No files created on set-up" |
| 191 | |
| 192 | # Look for per-pid folder structure |
| 193 | # Start first test app |
| 194 | diag "Shm: check folder creation and structure" |
| 195 | |
| 196 | start_test_app |
| 197 | shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1) |
| 198 | file_count=$(echo "$shm_session_path"| wc -l) |
| 199 | test $file_count -eq "1" |
| 200 | ok $? "Path $shm_session_path created on application creation" |
| 201 | |
| 202 | uid_path=$(find $shm_session_path/ust/uid -mindepth 1 -maxdepth 1) |
| 203 | ok $? "uid path exist found $uid_path" |
| 204 | |
| 205 | file_count=$(find $shm_session_path/ust/uid -mindepth 1 -maxdepth 1 | wc -l) |
| 206 | test $file_count -eq "1" |
| 207 | ok $? "Expect 1 uid registration folder got $file_count" |
| 208 | |
| 209 | # Stop all applications and check for uid presence |
| 210 | stop_test_apps |
| 211 | file_count=$(find $shm_session_path/ust/uid -mindepth 1 -maxdepth 1 | wc -l) |
| 212 | test $file_count -eq "1" |
| 213 | ok $? "Expect 1 uid registration folder got $file_count" |
| 214 | |
| 215 | # Test full cleanup |
| 216 | destroy_lttng_session_ok $session_name |
| 217 | verify_path_dont_exists "$shm_session_path" |
| 218 | ok $? "Full cleanup" |
| 219 | |
| 220 | stop_lttng_sessiond |
| 221 | rm -rf $shm_path |
| 222 | } |
| 223 | |
| 224 | function test_lttng_crash() |
| 225 | { |
| 226 | diag "Lttng-crash: basic recuperation" |
| 227 | local session_name=crash_test |
| 228 | local channel_name=channel_crash |
| 229 | local shm_path=$(mktemp -d) |
| 230 | local shm_path_symlink=$(mktemp -d) |
| 231 | local event_name="tp:tptest" |
| 232 | |
| 233 | # Create a session in snapshot mode to deactivate any use of consumerd |
| 234 | start_lttng_sessiond |
| 235 | create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot" |
| 236 | enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid" |
| 237 | enable_ust_lttng_event_ok $session_name $event_name $channel_name |
| 238 | start_lttng_tracing_ok $session_name |
| 239 | |
| 240 | # Generate 10 events |
| 241 | $TESTAPP_BIN 10 0 |
| 242 | stop_lttng_tracing_ok |
| 243 | |
| 244 | crash_recup_count=$($LTTNG_CRASH $shm_path | wc -l) |
| 245 | test $crash_recup_count -eq "10" |
| 246 | ok $? "Expect 10 recup event from buffers got $crash_recup_count" |
| 247 | |
| 248 | # Test with symlink |
| 249 | cp -rs $shm_path/. $shm_path_symlink |
| 250 | crash_recup_count=$($LTTNG_CRASH $shm_path_symlink | wc -l) |
| 251 | test $crash_recup_count -eq "10" |
| 252 | ok $? "Expect 10 recup event from symlink buffers got $crash_recup_count" |
| 253 | |
| 254 | # Tear down |
| 255 | destroy_lttng_session_ok $session_name |
| 256 | stop_lttng_sessiond |
| 257 | rm -rf $shm_path |
| 258 | rm -rf $shm_path_symlink |
| 259 | } |
| 260 | |
| 261 | function test_lttng_crash_extraction() |
| 262 | { |
| 263 | diag "Lttng-crash: extraction to path" |
| 264 | local session_name=crash_test |
| 265 | local channel_name=channel_crash |
| 266 | local shm_path=$(mktemp -d) |
| 267 | local extraction_dir_path=$(mktemp -d) |
| 268 | local extraction_path=$extraction_dir_path/extract |
| 269 | local event_name="tp:tptest" |
| 270 | |
| 271 | # Create a session in snapshot mode to deactivate any use of consumerd |
| 272 | start_lttng_sessiond |
| 273 | create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot" |
| 274 | enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid" |
| 275 | enable_ust_lttng_event_ok $session_name $event_name $channel_name |
| 276 | |
| 277 | start_lttng_tracing_ok $session_name |
| 278 | # Generate 10 events |
| 279 | $TESTAPP_BIN 10 0 |
| 280 | stop_lttng_tracing_ok |
| 281 | |
| 282 | $LTTNG_CRASH -x $extraction_path $shm_path |
| 283 | ok $? "Extraction of crashed buffers to path" |
| 284 | |
| 285 | # Test extracted trace |
| 286 | trace_match_only $event_name 10 $extraction_path |
| 287 | |
| 288 | # Tear down |
| 289 | destroy_lttng_session_ok $session_name |
| 290 | stop_lttng_sessiond |
| 291 | rm -rf $shm_path |
| 292 | rm -rf $extraction_dir_path |
| 293 | } |
| 294 | |
| 295 | function test_shm_path_per_pid_sigint() |
| 296 | { |
| 297 | diag "Shm: ust per-pid test sigint" |
| 298 | local session_name=shm_path_per_pid |
| 299 | local channel_name=channel_per_pid |
| 300 | local shm_path=$(mktemp -d) |
| 301 | local num_files=0 |
| 302 | |
| 303 | # Build up |
| 304 | start_lttng_sessiond |
| 305 | create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path" |
| 306 | enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-pid" |
| 307 | |
| 308 | start_lttng_tracing_ok $session_name |
| 309 | |
| 310 | start_test_app |
| 311 | start_test_app |
| 312 | shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1) |
| 313 | |
| 314 | # Stop sessiond with sigint |
| 315 | stop_lttng_sessiond SIGINT |
| 316 | |
| 317 | # Looking for a full cleanup |
| 318 | verify_path_dont_exists "$shm_session_path" |
| 319 | ok $? "Full cleanup on sigint" |
| 320 | |
| 321 | # Tear down |
| 322 | stop_test_apps |
| 323 | rm -rf $shm_path |
| 324 | } |
| 325 | |
| 326 | function test_shm_path_per_uid_sigint() |
| 327 | { |
| 328 | diag "Shm: ust per-uid test sigint" |
| 329 | local session_name=shm_path_per_uid_sigint |
| 330 | local channel_name=channel_per_uid_sigint |
| 331 | local shm_path=$(mktemp -d) |
| 332 | local ret=0 |
| 333 | |
| 334 | # Build up |
| 335 | start_lttng_sessiond |
| 336 | create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path" |
| 337 | enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid" |
| 338 | |
| 339 | start_lttng_tracing_ok $session_name |
| 340 | |
| 341 | start_test_app |
| 342 | start_test_app |
| 343 | shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1) |
| 344 | |
| 345 | # Test full cleanup on SIGINT |
| 346 | stop_lttng_sessiond SIGINT |
| 347 | |
| 348 | # Looking for a full cleanup |
| 349 | verify_path_dont_exists "$shm_session_path" |
| 350 | ok $? "Full cleanup on sigint" |
| 351 | |
| 352 | # Tear down |
| 353 | stop_test_apps |
| 354 | rm -rf $shm_path |
| 355 | } |
| 356 | |
| 357 | function test_lttng_crash_extraction_sigkill() |
| 358 | { |
| 359 | diag "Lttng-crash: extraction with sigkill" |
| 360 | local session_name=crash_test |
| 361 | local channel_name=channel_crash |
| 362 | local shm_path=$(mktemp -d) |
| 363 | local extraction_dir_path=$(mktemp -d) |
| 364 | local extraction_path=$extraction_dir_path/extract |
| 365 | local event_name="tp:tptest" |
| 366 | local ret=0 |
| 367 | |
| 368 | start_lttng_sessiond |
| 369 | create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path" |
| 370 | enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid" |
| 371 | enable_ust_lttng_event_ok $session_name $event_name $channel_name |
| 372 | start_lttng_tracing_ok $session_name |
| 373 | |
| 374 | # Generate 10 events |
| 375 | $TESTAPP_BIN 10 0 |
| 376 | |
| 377 | sigstop_lttng_sessiond |
| 378 | sigstop_lttng_consumerd |
| 379 | |
| 380 | # Kill the consumers then sessiond with sigkill |
| 381 | stop_lttng_consumerd SIGKILL |
| 382 | stop_lttng_sessiond SIGKILL |
| 383 | |
| 384 | $LTTNG_CRASH -x $extraction_path $shm_path |
| 385 | ret=$? |
| 386 | ok $ret "Extraction of crashed buffers to path $extraction_path" |
| 387 | |
| 388 | # Test extracted trace |
| 389 | trace_match_only $event_name 10 $extraction_path |
| 390 | |
| 391 | # Tear down |
| 392 | stop_test_apps |
| 393 | rm -rf $shm_path |
| 394 | rm -rf $extraction_dir_path |
| 395 | } |
| 396 | |
| 397 | function interrupt_cleanup() |
| 398 | { |
| 399 | diag "*** Cleaning-up test ***" |
| 400 | stop_test_apps |
| 401 | full_cleanup |
| 402 | } |
| 403 | |
| 404 | TESTS=( |
| 405 | test_shm_path_per_uid |
| 406 | test_shm_path_per_pid |
| 407 | test_shm_path_per_pid_sigint |
| 408 | test_shm_path_per_uid_sigint |
| 409 | test_lttng_crash |
| 410 | test_lttng_crash_extraction |
| 411 | test_lttng_crash_extraction_sigkill |
| 412 | ) |
| 413 | |
| 414 | trap interrupt_cleanup SIGTERM SIGINT |
| 415 | |
| 416 | for fct_test in ${TESTS[@]}; |
| 417 | do |
| 418 | ${fct_test} |
| 419 | if [ $? -ne 0 ]; then |
| 420 | break; |
| 421 | fi |
| 422 | done |
| 423 | rm -rf $OUTPUT_DIR |
| 424 | |
| 425 | OUTPUT_DEST=/dev/null 2>&1 |