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