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