From c1896e2d809e0d32d2d9b8a840755de6d5d70eaf Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Thu, 8 Jun 2023 11:05:17 -0400 Subject: [PATCH] Tests: Avoid looping on app PIDs during cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When the list of app PIDs becomes long, eg. in the case for `tests/regression/ust/nprocesses/test_nprocesses`, then performing the following type of loop can be quite slow, especially if the apps have some teardown time internally: ``` for p in ${APP_PIDS} ; do kill ${p} wait ${p} done ``` Both `kill` and `wait` take a list of PIDs, so the cleanup is easily factorable to ``` kill ${APP_PIDS} wait ${APP_PIDS} ``` In the case of `test_nprocesses`, the test run time drops from ~25s to ~4s. The difference is less important in tests with fewer apps. Signed-off-by: Kienan Stewart Signed-off-by: Jérémie Galarneau Change-Id: I9619939b4f1201a99f9666dee3e19551a67c9fb6 --- .../tools/snapshots/test_ust_streaming | 174 +++++------ tests/regression/tools/snapshots/ust_test | 271 +++++++++--------- .../regression/ust/nprocesses/test_nprocesses | 43 +-- .../test_periodical_metadata_flush | 104 +++---- .../stress/test_multi_sessions_per_uid_10app | 65 ++--- ...test_multi_sessions_per_uid_5app_streaming | 79 ++--- ...essions_per_uid_5app_streaming_kill_relayd | 81 +++--- 7 files changed, 407 insertions(+), 410 deletions(-) diff --git a/tests/regression/tools/snapshots/test_ust_streaming b/tests/regression/tools/snapshots/test_ust_streaming index 3104afb3b..2e04d667e 100755 --- a/tests/regression/tools/snapshots/test_ust_streaming +++ b/tests/regression/tools/snapshots/test_ust_streaming @@ -6,24 +6,24 @@ TEST_DESC="Streaming - Snapshot UST tracing" -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../../.. +CURDIR=$(dirname "$0")/ +TESTDIR="$CURDIR/../../.." EVENT_NAME="tp:tptest" SESSION_NAME="" CHANNEL_NAME="chan1" -BIN_NAME="gen-nevents" TESTAPP_PATH="$TESTDIR/utils/testapp" TESTAPP_NAME="gen-ust-events" TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" NR_ITER=-1 NR_USEC_WAIT=100 -APPS_PID= +APP_PIDS=() TRACE_PATH=$(mktemp -d -t tmp.test_snapshots_ust_streaming_trace_path.XXXXXX) NUM_TESTS=85 -source $TESTDIR/utils/utils.sh +# shellcheck source-path=SCRIPTDIR/../../../ +source "$TESTDIR/utils/utils.sh" if [ ! -x "$TESTAPP_BIN" ]; then BAIL_OUT "No UST events binary detected." @@ -34,25 +34,42 @@ function snapshot_add_output () local sess_name=$1 local trace_path=$2 local name=$3 - local extra_opt="" + local options=() + local args=() - if [ ! -z $name ]; then - extra_opt="-n $name" + if [ -n "$sess_name" ] ; then + options+=(-s "$sess_name") fi - $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name $extra_opt $trace_path >/dev/null 2>&1 + if [ -n "$name" ]; then + options+=(-n "$name") + fi + + # Checking for any other optional arguments that should be passed to the lttng command + args=("$@") + if [ -n "${args[*]:3}" ] ; then + options+=("${args[@]:3}") + fi + + # The trace_path is a positional argument and must always come last if it is defined + if [ -n "$trace_path" ] ; then + options+=("$trace_path") + fi + + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" snapshot add-output "${options[@]}" >/dev/null 2>&1 ok $? "Added snapshot output $trace_path" } # Start trace application and return once one event has been hit. function start_test_app() { - local tmp_file=$(mktemp -u -t tmp.test_${FUNCNAME[0]}_tmp_file.XXXXXX) + local tmp_file + tmp_file=$(mktemp -u -t tmp.test_"${FUNCNAME[0]}"_tmp_file.XXXXXX) # Start application with a temporary file. - $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event $tmp_file & + $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event "$tmp_file" & ret=$? - APPS_PID="${APPS_PID} ${!}" + APP_PIDS+=(${!}) ok $ret "Start application to trace" # Wait for the application file to appear indicating that at least one @@ -61,55 +78,51 @@ function start_test_app() sleep 0.5 done diag "Removing test app temporary file $tmp_file" - rm -f $tmp_file + rm -f "$tmp_file" } function stop_test_apps() { diag "Stopping $TESTAPP_NAME" - for p in ${APPS_PID}; do - kill ${p} - wait ${p} 2>/dev/null - done - APPS_PID= + kill "${APP_PIDS[@]}" + wait "${APP_PIDS[@]}" 2>/dev/null + APP_PIDS=() } # Test a snapshot using a default name for the output destination. function test_ust_default_name_with_del() { diag "Test UST snapshot streaming with default name with delete output" - create_lttng_session_no_output $SESSION_NAME - enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME - enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME - start_lttng_tracing_ok $SESSION_NAME + create_lttng_session_no_output "$SESSION_NAME" + enable_lttng_mmap_overwrite_ust_channel "$SESSION_NAME" $CHANNEL_NAME + enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME + start_lttng_tracing_ok "$SESSION_NAME" start_test_app - snapshot_add_output $SESSION_NAME "net://localhost" - lttng_snapshot_record $SESSION_NAME + snapshot_add_output "$SESSION_NAME" "net://localhost" + lttng_snapshot_record "$SESSION_NAME" # Validate test validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0 - validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1* - if [ $? -ne 0 ]; then + if ! validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*" ; then stop_test_apps return $? fi - lttng_snapshot_del_output_ok $SESSION_NAME 1 - snapshot_add_output $SESSION_NAME "net://localhost" - lttng_snapshot_record $SESSION_NAME + lttng_snapshot_del_output_ok "$SESSION_NAME" 1 + snapshot_add_output "$SESSION_NAME" "net://localhost" + lttng_snapshot_record "$SESSION_NAME" # Validate test with the next ID since a del output was done prior. validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-2" 1 - validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-2* - if [ $? -ne 0 ]; then + if ! validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-2*" ; then stop_test_apps return $? fi - stop_lttng_tracing_ok $SESSION_NAME - destroy_lttng_session_ok $SESSION_NAME + stop_lttng_tracing_ok "$SESSION_NAME" + destroy_lttng_session_ok "$SESSION_NAME" stop_test_apps @@ -120,20 +133,20 @@ function test_ust_default_name_with_del() function test_ust_default_name() { diag "Test UST snapshot streaming with default name" - create_lttng_session_no_output $SESSION_NAME - enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME - enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME - start_lttng_tracing_ok $SESSION_NAME + create_lttng_session_no_output "$SESSION_NAME" + enable_lttng_mmap_overwrite_ust_channel "$SESSION_NAME" $CHANNEL_NAME + enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME + start_lttng_tracing_ok "$SESSION_NAME" start_test_app - snapshot_add_output $SESSION_NAME "net://localhost" - lttng_snapshot_record $SESSION_NAME - stop_lttng_tracing_ok $SESSION_NAME - destroy_lttng_session_ok $SESSION_NAME + snapshot_add_output "$SESSION_NAME" "net://localhost" + lttng_snapshot_record "$SESSION_NAME" + stop_lttng_tracing_ok "$SESSION_NAME" + destroy_lttng_session_ok "$SESSION_NAME" # Validate test validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0 - validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1* + validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*" out=$? stop_test_apps @@ -144,20 +157,20 @@ function test_ust_default_name() function test_ust_default_name_custom_uri() { diag "Test UST snapshot streaming with default name with custom URL" - create_lttng_session_no_output $SESSION_NAME - enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME - enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME - start_lttng_tracing_ok $SESSION_NAME + create_lttng_session_no_output "$SESSION_NAME" + enable_lttng_mmap_overwrite_ust_channel "$SESSION_NAME" $CHANNEL_NAME + enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME + start_lttng_tracing_ok "$SESSION_NAME" start_test_app - snapshot_add_output $SESSION_NAME "-C tcp://localhost:5342 -D tcp://localhost:5343" - lttng_snapshot_record $SESSION_NAME - stop_lttng_tracing_ok $SESSION_NAME - destroy_lttng_session_ok $SESSION_NAME + snapshot_add_output "$SESSION_NAME" '' '' -C tcp://localhost:5342 -D tcp://localhost:5343 + lttng_snapshot_record "$SESSION_NAME" + stop_lttng_tracing_ok "$SESSION_NAME" + destroy_lttng_session_ok "$SESSION_NAME" # Validate test validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0 - validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1* + validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*" out=$? stop_test_apps @@ -172,23 +185,23 @@ function test_ust_custom_name() local name="asnapshotname" diag "Test UST snapshot streaming with custom name" - create_lttng_session_no_output $SESSION_NAME - enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME - enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME - start_lttng_tracing_ok $SESSION_NAME + create_lttng_session_no_output "$SESSION_NAME" + enable_lttng_mmap_overwrite_ust_channel "$SESSION_NAME" $CHANNEL_NAME + enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME + start_lttng_tracing_ok "$SESSION_NAME" start_test_app - snapshot_add_output $SESSION_NAME "net://localhost" $name - lttng_snapshot_record $SESSION_NAME - stop_lttng_tracing_ok $SESSION_NAME - destroy_lttng_session_ok $SESSION_NAME + snapshot_add_output "$SESSION_NAME" "net://localhost" $name + lttng_snapshot_record "$SESSION_NAME" + stop_lttng_tracing_ok "$SESSION_NAME" + destroy_lttng_session_ok "$SESSION_NAME" - if ls $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name* &> /dev/null; then + if ls "$TRACE_PATH/$HOSTNAME/$SESSION_NAME"*/"$name"* &> /dev/null; then ok 0 "Custom name snapshot exists" # Validate test validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "$name" 0 - validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name-* + validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name-*" out=$? else fail "No custom name snapshot found" @@ -203,27 +216,26 @@ function test_ust_custom_name() function test_ust_n_snapshot() { diag "Test ust snapshot streaming multiple consecutive snapshot" - create_lttng_session_no_output $SESSION_NAME - enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME - enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME - snapshot_add_output $SESSION_NAME "net://localhost" + create_lttng_session_no_output "$SESSION_NAME" + enable_lttng_mmap_overwrite_ust_channel "$SESSION_NAME" $CHANNEL_NAME + enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME + snapshot_add_output "$SESSION_NAME" "net://localhost" start_test_app for i in {0..4}; do - start_lttng_tracing_ok $SESSION_NAME - lttng_snapshot_record $SESSION_NAME - stop_lttng_tracing_ok $SESSION_NAME - validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" $i - validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1* - if [ $? -ne 0 ]; then + start_lttng_tracing_ok "$SESSION_NAME" + lttng_snapshot_record "$SESSION_NAME" + stop_lttng_tracing_ok "$SESSION_NAME" + validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" "$i" + if ! validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*" ; then return 1 fi set -u - rm -rf $TRACE_PATH/$HOSTNAME + rm -rf "${TRACE_PATH:?}/${HOSTNAME}" set +u done - destroy_lttng_session_ok $SESSION_NAME + destroy_lttng_session_ok "$SESSION_NAME" stop_test_apps return 0 } @@ -234,13 +246,8 @@ print_test_banner "$TEST_DESC" bail_out_if_no_babeltrace -if [ "$(id -u)" == "0" ]; then - isroot=1 -else - isroot=0 -fi - start_lttng_relayd "-o $TRACE_PATH" +# shellcheck disable=SC2119 start_lttng_sessiond tests=( test_ust_default_name_with_del @@ -250,17 +257,18 @@ tests=( test_ust_default_name_with_del test_ust_n_snapshot ) -for fct_test in ${tests[@]}; +for fct_test in "${tests[@]}"; do SESSION_NAME=$(randstring 16 0) - ${fct_test} - if [ $? -eq 0 ]; then + if ${fct_test} ; then # Only delete if successful - rm -rf $TRACE_PATH + rm -rf "$TRACE_PATH" else break fi done +# shellcheck disable=SC2119 stop_lttng_sessiond +# shellcheck disable=SC2119 stop_lttng_relayd diff --git a/tests/regression/tools/snapshots/ust_test b/tests/regression/tools/snapshots/ust_test index 9cd5a48c9..5188c2b5b 100755 --- a/tests/regression/tools/snapshots/ust_test +++ b/tests/regression/tools/snapshots/ust_test @@ -6,42 +6,44 @@ TEST_DESC="Snapshots - UST tracing" -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../../.. +CURDIR=$(dirname "$0")/ +TESTDIR="$CURDIR/../../.." EVENT_NAME="tp:tptest" SESSION_NAME="" CHANNEL_NAME="snapchan" TESTAPP_PATH="$TESTDIR/utils/testapp" TESTAPP_NAME="gen-ust-events" TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" -APPS_PID= +APPS_PID=() NUM_TESTS=104 TRACE_PATH=$(mktemp -d -t tmp.test_snapshots_ust_trace_path.XXXXXX) -source $TESTDIR/utils/utils.sh +# shellcheck source-path=SCRIPTDIR/../../../ +source "$TESTDIR/utils/utils.sh" if [ ! -x "$TESTAPP_BIN" ]; then BAIL_OUT "No UST events binary detected" fi # Need the number of snapshot to do. -if [ -z $1 ]; then +if [ -z "$1" ]; then BAIL_OUT "A number of snapshot is needed" fi NR_SNAPSHOT=$1 -NUM_TESTS=$(($NUM_TESTS + ($NR_SNAPSHOT * 3))) +NUM_TESTS=$((NUM_TESTS + (NR_SNAPSHOT * 3))) function start_test_app() { - local tmp_file=$(mktemp -u -t "tmp.${FUNCNAME[0]}_tmp_file.XXXXXX") + local tmp_file + tmp_file=$(mktemp -u -t "tmp.${FUNCNAME[0]}_tmp_file.XXXXXX") # Start application with a temporary file. - $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event $tmp_file & + $TESTAPP_BIN -i "$NR_ITER" -w "$NR_USEC_WAIT" --sync-after-first-event "$tmp_file" & ret=$? - APPS_PID="${APPS_PID} ${!}" + APPS_PID+=(${!}) ok $ret "Start application to trace" # Wait for the application file to appear indicating that at least one @@ -50,25 +52,21 @@ function start_test_app() sleep 0.5 done diag "Removing test app temporary file $tmp_file" - rm -f $tmp_file + rm -f "$tmp_file" } function wait_test_apps() { diag "Waiting for $TESTAPP_NAME" - for p in ${APPS_PID}; do - wait ${p} 2>/dev/null - done + wait "${APPS_PID[@]}" 2>/dev/null } function stop_test_apps() { diag "Stopping $TESTAPP_NAME" - for p in ${APPS_PID}; do - kill ${p} - wait ${p} 2>/dev/null - done - APPS_PID= + kill "${APPS_PID[@]}" + wait "${APPS_PID[@]}" + APPS_PID=() } function snapshot_add_output () @@ -77,20 +75,20 @@ function snapshot_add_output () local trace_path=$2 local name=$3 local max_size=$4 - local extra_opt="" + local extra_opt=() - if [ ! -z $name ]; then - extra_opt+=" -n $name " + if [ -n "$name" ]; then + extra_opt+=(-n "$name") fi - if [ ! -z $max_size ]; then - extra_opt+=" -m $max_size " + if [ -n "$max_size" ]; then + extra_opt+=(-m "$max_size") fi - $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output \ - -s $sess_name $extra_opt $trace_path > /dev/null 2>&1 + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" snapshot add-output \ + -s "$sess_name" "${extra_opt[@]}" "$trace_path" > /dev/null 2>&1 - ok $? "Added snapshot output $trace_path ($extra_opt)" + ok $? "Added snapshot output $trace_path (${extra_opt[*]})" } function snapshot_del_output () @@ -98,8 +96,8 @@ function snapshot_del_output () local sess_name=$1 local name=$2 - $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output \ - -s $sess_name $name > /dev/null 2>&1 + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" snapshot del-output \ + -s "$sess_name" "$name" > /dev/null 2>&1 ok $? "Deleted snapshot output named $name" } @@ -111,10 +109,10 @@ function enable_mmap_overwrite_subbuf_ust_channel () local subbuf_size=$3 local subbuf_count=$4 - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name \ - $chan_name -u --output mmap --overwrite \ - --num-subbuf=$subbuf_count \ - --subbuf-size $subbuf_size > /dev/null 2>&1 + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel -s "$sess_name" \ + "$chan_name" -u --output mmap --overwrite \ + --num-subbuf="$subbuf_count" \ + --subbuf-size "$subbuf_size" > /dev/null 2>&1 ok $? "Enable channel $channel_name for session $sess_name with subbuf size $subbuf_size" } @@ -124,9 +122,9 @@ function enable_mmap_small_discard_ust_channel () local sess_name=$1 local chan_name=$2 - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name \ - $chan_name -u --output mmap --discard \ - --subbuf-size $(getconf PAGE_SIZE) --num-subbuf 2 \ + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel -s "$sess_name" \ + "$chan_name" -u --output mmap --discard \ + --subbuf-size "$(getconf PAGE_SIZE)" --num-subbuf 2 \ > /dev/null 2>&1 ok $? "Enable channel $channel_name for session $sess_name with small discard buffers" @@ -137,9 +135,9 @@ function enable_mmap_small_overwrite_ust_channel () local sess_name=$1 local chan_name=$2 - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name \ - $chan_name -u --output mmap --overwrite \ - --subbuf-size $(getconf PAGE_SIZE) --num-subbuf 2 \ + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel -s "$sess_name" \ + "$chan_name" -u --output mmap --overwrite \ + --subbuf-size "$(getconf PAGE_SIZE)" --num-subbuf 2 \ > /dev/null 2>&1 ok $? "Enable channel $channel_name for session $sess_name with small discard buffers" @@ -150,29 +148,29 @@ function test_ust_list_output () output_names=("randomname" "somesnapshot") diag "Test UST snapshot output listing" - create_lttng_session_no_output $SESSION_NAME - enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME - enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME + create_lttng_session_no_output "$SESSION_NAME" + enable_lttng_mmap_overwrite_ust_channel "$SESSION_NAME" $CHANNEL_NAME + enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME - start_lttng_tracing_ok $SESSION_NAME + start_lttng_tracing_ok "$SESSION_NAME" - snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" ${output_names[0]} + snapshot_add_output "$SESSION_NAME" "file://$TRACE_PATH" "${output_names[0]}" - $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output \ - -s $SESSION_NAME 2>&1 | grep ${output_names[0]} > /dev/null + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" snapshot list-output \ + -s "$SESSION_NAME" 2>&1 | grep "${output_names[0]}" > /dev/null ok $? "Snapshot named ${output_names[0]} present in list-output listing" - snapshot_del_output $SESSION_NAME ${output_names[0]} + snapshot_del_output "$SESSION_NAME" "${output_names[0]}" - snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" ${output_names[1]} + snapshot_add_output "$SESSION_NAME" "file://$TRACE_PATH" "${output_names[1]}" - $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output \ - -s $SESSION_NAME 2>&1 | grep ${output_names[1]} > /dev/null + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" snapshot list-output \ + -s "$SESSION_NAME" 2>&1 | grep "${output_names[1]}" > /dev/null ok $? "Snapshot named ${output_names[1]} present in list-output listing" - stop_lttng_tracing_ok $SESSION_NAME - destroy_lttng_session_ok $SESSION_NAME + stop_lttng_tracing_ok "$SESSION_NAME" + destroy_lttng_session_ok "$SESSION_NAME" } function test_ust_local_snapshot () @@ -181,25 +179,24 @@ function test_ust_local_snapshot () NR_USEC_WAIT=100 diag "Test local UST snapshots" - create_lttng_session_no_output $SESSION_NAME - enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME - enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME - start_lttng_tracing_ok $SESSION_NAME - lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH + create_lttng_session_no_output "$SESSION_NAME" + enable_lttng_mmap_overwrite_ust_channel "$SESSION_NAME" $CHANNEL_NAME + enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME + start_lttng_tracing_ok "$SESSION_NAME" + lttng_snapshot_add_output_ok "$SESSION_NAME" "file://$TRACE_PATH" # Returns once the application has at least fired ONE tracepoint. start_test_app - lttng_snapshot_record $SESSION_NAME - stop_lttng_tracing_ok $SESSION_NAME - destroy_lttng_session_ok $SESSION_NAME + lttng_snapshot_record "$SESSION_NAME" + stop_lttng_tracing_ok "$SESSION_NAME" + destroy_lttng_session_ok "$SESSION_NAME" # Validate test validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0 - validate_trace $EVENT_NAME $TRACE_PATH/ - if [ $? -eq 0 ]; then + if validate_trace $EVENT_NAME "$TRACE_PATH/" ; then # Only delete if successful - rm -rf $TRACE_PATH + rm -rf "$TRACE_PATH" fi stop_test_apps @@ -213,31 +210,31 @@ function test_ust_local_snapshot_small_discard_buffers () diag "Test local UST snapshots with small discard buffers" taskset -c "$(get_any_available_cpu)" -p $$ 1>/dev/null 2>&1 - create_lttng_session_no_output $SESSION_NAME - enable_mmap_small_discard_ust_channel $SESSION_NAME $CHANNEL_NAME - enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME - start_lttng_tracing_ok $SESSION_NAME - lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH + create_lttng_session_no_output "$SESSION_NAME" + enable_mmap_small_discard_ust_channel "$SESSION_NAME" $CHANNEL_NAME + enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME + start_lttng_tracing_ok "$SESSION_NAME" + lttng_snapshot_add_output_ok "$SESSION_NAME" "file://$TRACE_PATH" # Run test apps, wait for them to complete. start_test_app wait_test_apps # Take first snapshot, remember first line. - lttng_snapshot_record $SESSION_NAME - FIRST_LINE="$(trace_first_line $TRACE_PATH/)" + lttng_snapshot_record "$SESSION_NAME" + FIRST_LINE="$(trace_first_line "$TRACE_PATH/")" diag "First line (1st snapshot): $FIRST_LINE" - rm -rf $TRACE_PATH/ + rm -rf "${TRACE_PATH:?}/" # Run test apps, wait for them to complete. start_test_app wait_test_apps # Take second snapshot, remember first line. - lttng_snapshot_record $SESSION_NAME - FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)" + lttng_snapshot_record "$SESSION_NAME" + FIRST_LINE_2="$(trace_first_line "$TRACE_PATH/")" diag "First line (2nd snapshot): $FIRST_LINE_2" - rm -rf $TRACE_PATH/ + rm -rf "${TRACE_PATH:?}/" if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then fail "First snapshot event do not match" @@ -245,9 +242,9 @@ function test_ust_local_snapshot_small_discard_buffers () pass "First snapshot event match" fi - stop_lttng_tracing_ok $SESSION_NAME - destroy_lttng_session_ok $SESSION_NAME - taskset -p $OLDCPUSET $$ 1>/dev/null 2>&1 + stop_lttng_tracing_ok "$SESSION_NAME" + destroy_lttng_session_ok "$SESSION_NAME" + taskset -p "$OLDCPUSET" $$ 1>/dev/null 2>&1 } function test_ust_local_snapshot_small_overwrite_buffers () @@ -258,31 +255,31 @@ function test_ust_local_snapshot_small_overwrite_buffers () diag "Test local UST snapshots with small overwrite buffers" taskset -p "$(get_any_available_cpu)" $$ 1>/dev/null 2>&1 - create_lttng_session_no_output $SESSION_NAME - enable_mmap_small_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME - enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME - start_lttng_tracing_ok $SESSION_NAME - lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH + create_lttng_session_no_output "$SESSION_NAME" + enable_mmap_small_overwrite_ust_channel "$SESSION_NAME" $CHANNEL_NAME + enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME + start_lttng_tracing_ok "$SESSION_NAME" + lttng_snapshot_add_output_ok "$SESSION_NAME" "file://$TRACE_PATH" # Run test apps, wait for them to complete. start_test_app wait_test_apps # Take first snapshot, remember first line. - lttng_snapshot_record $SESSION_NAME - FIRST_LINE="$(trace_first_line $TRACE_PATH/)" + lttng_snapshot_record "$SESSION_NAME" + FIRST_LINE="$(trace_first_line "$TRACE_PATH/")" diag "First line (1st snapshot): $FIRST_LINE" - rm -rf $TRACE_PATH/ + rm -rf "${TRACE_PATH:?}/" # Run test apps, wait for them to complete. start_test_app wait_test_apps # Take second snapshot, remember first line. - lttng_snapshot_record $SESSION_NAME - FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)" + lttng_snapshot_record "$SESSION_NAME" + FIRST_LINE_2="$(trace_first_line "$TRACE_PATH/")" diag "First line (2nd snapshot): $FIRST_LINE_2" - rm -rf $TRACE_PATH/ + rm -rf "${TRACE_PATH:?}/" if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then pass "First snapshot event do not match" @@ -290,9 +287,9 @@ function test_ust_local_snapshot_small_overwrite_buffers () fail "First snapshot event match" fi - stop_lttng_tracing_ok $SESSION_NAME - destroy_lttng_session_ok $SESSION_NAME - taskset -p $OLDCPUSET $$ 1>/dev/null 2>&1 + stop_lttng_tracing_ok "$SESSION_NAME" + destroy_lttng_session_ok "$SESSION_NAME" + taskset -p "$OLDCPUSET" $$ 1>/dev/null 2>&1 } function test_ust_local_snapshot_max_size () @@ -371,23 +368,22 @@ function test_ust_local_snapshot_large_metadata () LM_BIN="$LM_PATH/$LM_NAME/$LM_NAME" diag "Test local UST snapshots with > 4kB metadata" - create_lttng_session_no_output $SESSION_NAME - enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME - enable_ust_lttng_event_ok $SESSION_NAME $LM_EVENT $CHANNEL_NAME - start_lttng_tracing_ok $SESSION_NAME - lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH + create_lttng_session_no_output "$SESSION_NAME" + enable_lttng_mmap_overwrite_ust_channel "$SESSION_NAME" $CHANNEL_NAME + enable_ust_lttng_event_ok "$SESSION_NAME" $LM_EVENT $CHANNEL_NAME + start_lttng_tracing_ok "$SESSION_NAME" + lttng_snapshot_add_output_ok "$SESSION_NAME" "file://$TRACE_PATH" $LM_BIN --iter 1 --wait 1 ok $? "Start application to trace" - lttng_snapshot_record $SESSION_NAME - stop_lttng_tracing_ok $SESSION_NAME - destroy_lttng_session_ok $SESSION_NAME + lttng_snapshot_record "$SESSION_NAME" + stop_lttng_tracing_ok "$SESSION_NAME" + destroy_lttng_session_ok "$SESSION_NAME" # Validate test validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0 - validate_trace $LM_EVENT $TRACE_PATH/ - if [ $? -eq 0 ]; then + if validate_trace $LM_EVENT "$TRACE_PATH/" ; then # Only delete if successful - rm -rf $TRACE_PATH + rm -rf "${TRACE_PATH:?}/" fi } @@ -396,7 +392,7 @@ function enable_channel_per_uid_mmap_overwrite() sess_name=$1 channel_name=$2 - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name --output mmap --overwrite >/dev/null 2>&1 + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffers-uid -u "$channel_name" -s "$sess_name" --output mmap --overwrite >/dev/null 2>&1 ok $? "Enable channel $channel_name per UID for session $sess_name" } @@ -405,25 +401,24 @@ function test_ust_per_uid_local_snapshot () NR_ITER=-1 NR_USEC_WAIT=100 diag "Test per-uid local UST snapshots" - create_lttng_session_no_output $SESSION_NAME - enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME - enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME - start_lttng_tracing_ok $SESSION_NAME - lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH + create_lttng_session_no_output "$SESSION_NAME" + enable_channel_per_uid_mmap_overwrite "$SESSION_NAME" $CHANNEL_NAME + enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME + start_lttng_tracing_ok "$SESSION_NAME" + lttng_snapshot_add_output_ok "$SESSION_NAME" "file://$TRACE_PATH" # Returns once the application has at least fired ONE tracepoint. start_test_app - lttng_snapshot_record $SESSION_NAME - stop_lttng_tracing_ok $SESSION_NAME - destroy_lttng_session_ok $SESSION_NAME + lttng_snapshot_record "$SESSION_NAME" + stop_lttng_tracing_ok "$SESSION_NAME" + destroy_lttng_session_ok "$SESSION_NAME" # Validate test validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0 - validate_trace $EVENT_NAME $TRACE_PATH/ - if [ $? -eq 0 ]; then + if validate_trace $EVENT_NAME "$TRACE_PATH/" ; then # Only delete if successful - rm -rf $TRACE_PATH + rm -rf "${TRACE_PATH:?}/" fi stop_test_apps @@ -435,26 +430,25 @@ function test_ust_per_uid_local_snapshot_post_mortem () NR_USEC_WAIT=100 diag "Test local UST snapshots post-mortem" - create_lttng_session_no_output $SESSION_NAME - enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME - enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME - start_lttng_tracing_ok $SESSION_NAME - lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH + create_lttng_session_no_output "$SESSION_NAME" + enable_channel_per_uid_mmap_overwrite "$SESSION_NAME" $CHANNEL_NAME + enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME + start_lttng_tracing_ok "$SESSION_NAME" + lttng_snapshot_add_output_ok "$SESSION_NAME" "file://$TRACE_PATH" # Returns once the application has at least fired ONE tracepoint. start_test_app stop_test_apps - lttng_snapshot_record $SESSION_NAME - stop_lttng_tracing_ok $SESSION_NAME - destroy_lttng_session_ok $SESSION_NAME + lttng_snapshot_record "$SESSION_NAME" + stop_lttng_tracing_ok "$SESSION_NAME" + destroy_lttng_session_ok "$SESSION_NAME" # Validate test validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0 - validate_trace $EVENT_NAME $TRACE_PATH/ - if [ $? -eq 0 ]; then + if validate_trace $EVENT_NAME "$TRACE_PATH/" ; then # Only delete if successful - rm -rf $TRACE_PATH + rm -rf "${TRACE_PATH:?}/" fi } @@ -464,29 +458,28 @@ function test_ust_local_snapshots () NR_USEC_WAIT=100 diag "Test $NR_SNAPSHOT local UST snapshots" - create_lttng_session_no_output $SESSION_NAME - enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME - enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME - start_lttng_tracing_ok $SESSION_NAME - lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH + create_lttng_session_no_output "$SESSION_NAME" + enable_lttng_mmap_overwrite_ust_channel "$SESSION_NAME" $CHANNEL_NAME + enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME + start_lttng_tracing_ok "$SESSION_NAME" + lttng_snapshot_add_output_ok "$SESSION_NAME" "file://$TRACE_PATH" # Returns once the application has at least fired ONE tracepoint. start_test_app - for i in $(seq 1 $NR_SNAPSHOT); do + for i in $(seq 1 "$NR_SNAPSHOT"); do diag "Snapshot $i/$NR_SNAPSHOT" - rm -rf $TRACE_PATH/snapshot/* 2>/dev/null - lttng_snapshot_record $SESSION_NAME + rm -rf "$TRACE_PATH/snapshot/*" 2>/dev/null + lttng_snapshot_record "$SESSION_NAME" # Validate test validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" $((i - 1)) - validate_trace $EVENT_NAME $TRACE_PATH/ - if [ $? -eq 0 ]; then + if validate_trace $EVENT_NAME "$TRACE_PATH/" ; then # Only delete if successful - rm -rf $TRACE_PATH + rm -rf "${TRACE_PATH:?}/" fi done - stop_lttng_tracing_ok $SESSION_NAME - destroy_lttng_session_ok $SESSION_NAME + stop_lttng_tracing_ok "$SESSION_NAME" + destroy_lttng_session_ok "$SESSION_NAME" stop_test_apps } @@ -497,6 +490,7 @@ print_test_banner "$TEST_DESC" bail_out_if_no_babeltrace +# shellcheck disable=SC2119 start_lttng_sessiond tests=( test_ust_list_output test_ust_local_snapshot @@ -509,10 +503,11 @@ tests=( test_ust_list_output test_ust_local_snapshot_small_overwrite_buffers ) -for fct_test in ${tests[@]}; +for fct_test in "${tests[@]}"; do SESSION_NAME=$(randstring 16 0) ${fct_test} done +# shellcheck disable=SC2119 stop_lttng_sessiond diff --git a/tests/regression/ust/nprocesses/test_nprocesses b/tests/regression/ust/nprocesses/test_nprocesses index 5e16164e5..cd897d42b 100755 --- a/tests/regression/ust/nprocesses/test_nprocesses +++ b/tests/regression/ust/nprocesses/test_nprocesses @@ -7,20 +7,20 @@ NUM_PROCESS=30 TEST_DESC="UST tracer - Generate $NUM_PROCESS process" -CURDIR=$(dirname $0)/ +CURDIR=$(dirname "$0")/ TESTDIR=$CURDIR/../../.. -NR_ITER=-1 # infinite loop +NR_ITER=-1 # infinite loop NR_USEC_WAIT=1000000 TESTAPP_PATH="$TESTDIR/utils/testapp" TESTAPP_NAME="gen-ust-events" TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" SESSION_NAME="ust-nprocesses" EVENT_NAME="tp:tptest" -TEST_WAIT_SEC=5 NUM_TESTS=9 -APPS_PID= +APP_PIDS=() -source $TESTDIR/utils/utils.sh +# shellcheck source-path=SCRIPTDIR/../../../ +source "${TESTDIR}/utils/utils.sh" if [ ! -x "$TESTAPP_BIN" ]; then BAIL_OUT "No UST $TESTAPP_BIN binary detected." @@ -32,6 +32,7 @@ plan_tests $NUM_TESTS print_test_banner "$TEST_DESC" +# shellcheck disable=SC2119 start_lttng_sessiond # Start tests. Each is an infinite tracing loop. @@ -40,32 +41,33 @@ file_sync_after_first=$(mktemp -u -t tmp.test_nprocesses_sync_after_first.XXXXXX file_sync_before_last=$(mktemp -u -t tmp.test_nprocesses_sync_before_last.XXXXXX) diag "Starting $NUM_PROCESS test applications" -for i in `seq 1 $NUM_PROCESS` +# shellcheck disable=SC2034 +for i in $(seq 1 $NUM_PROCESS) do $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \ - --sync-after-first-event ${file_sync_after_first} \ - --sync-before-last-event ${file_sync_before_last} >/dev/null 2>&1 & - APPS_PID="${APPS_PID} ${!}" + --sync-after-first-event "${file_sync_after_first}" \ + --sync-before-last-event "${file_sync_before_last}" >/dev/null 2>&1 & + APP_PIDS+=(${!}) done diag "Waiting for applications to be registered to sessiond" reg_app_count=0 while [ $reg_app_count -ne $NUM_PROCESS ]; do - listing=$($TESTDIR/../src/bin/lttng/$LTTNG_BIN list -u) - reg_app_count=$(echo -n $listing | sed "s#$TESTAPP_BIN#$TESTAPP_BIN\n#g" | grep "$TESTAPP_BIN" | wc -l) + listing=$("${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}" list -u) + reg_app_count=$(echo -n "${listing}" | sed "s#$TESTAPP_BIN#$TESTAPP_BIN\n#g" | grep -c "$TESTAPP_BIN") done pass "All applications are registered to sessiond" TRACE_PATH=$(mktemp -d -t tmp.test_nprocesses_trace_path.XXXXXX) -create_lttng_session_ok $SESSION_NAME $TRACE_PATH +create_lttng_session_ok $SESSION_NAME "${TRACE_PATH}" enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME start_lttng_tracing_ok $SESSION_NAME -touch ${file_sync_before_last} +touch "${file_sync_before_last}" # We don't validate whether the applications have traced here, rather # just that they registered to sessiond (above). @@ -75,17 +77,16 @@ destroy_lttng_session_ok $SESSION_NAME #TODO: add trace validation. -rm -rf $TRACE_PATH +rm -rf "${TRACE_PATH}" diag "Stopping all spawned applications" -for p in ${APPS_PID}; do - kill ${p} - wait ${p} 2>/dev/null -done -APPS_PID= +kill "${APP_PIDS[@]}" +wait "${APP_PIDS[@]}" 2>/dev/null +APP_PIDS=() pass "Stopped all spawned applications" -rm -f ${file_sync_after_first} -rm -f ${file_sync_before_last} +rm -f "${file_sync_after_first}" +rm -f "${file_sync_before_last}" +# shellcheck disable=SC2119 stop_lttng_sessiond diff --git a/tests/regression/ust/periodical-metadata-flush/test_periodical_metadata_flush b/tests/regression/ust/periodical-metadata-flush/test_periodical_metadata_flush index 56c23ff40..f1132c2e4 100755 --- a/tests/regression/ust/periodical-metadata-flush/test_periodical_metadata_flush +++ b/tests/regression/ust/periodical-metadata-flush/test_periodical_metadata_flush @@ -6,8 +6,8 @@ TEST_DESC="UST tracer - Tracing with per UID buffers and periodical flush" -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../../.. +CURDIR=$(dirname "$0")/ +TESTDIR="$CURDIR/../../.." NR_ITER=100 NR_USEC_WAIT=100000 TESTAPP_PATH="$TESTDIR/utils/testapp" @@ -15,12 +15,12 @@ TESTAPP_NAME="gen-ust-events" TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" SESSION_NAME="periodical-flush" EVENT_NAME="tp:tptest" -BIN_NAME="gen-nevents" NUM_TESTS=38 APP_TMP_FILE=$(mktemp -u -t tmp.test_periodical_metadata_flush_ust_app_tmp_file.XXXXXX) -APPS_PID= +APP_PIDS=() -source $TESTDIR/utils/utils.sh +# shellcheck source-path=SCRIPTDIR/../../../ +source "$TESTDIR/utils/utils.sh" if [ ! -x "$TESTAPP_BIN" ]; then BAIL_OUT "No UST events binary detected." @@ -33,7 +33,7 @@ function enable_channel_per_uid() local sess_name=$1 local channel_name=$2 - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name --switch-timer 100000 >/dev/null 2>&1 + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffers-uid -u "$channel_name" -s "$sess_name" --switch-timer 100000 >/dev/null 2>&1 ok $? "Enable channel $channel_name per UID for session $sess_name" } @@ -42,7 +42,7 @@ function enable_channel_per_pid() local sess_name=$1 local channel_name=$2 - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-pid -u $channel_name -s $sess_name --switch-timer 100000 >/dev/null 2>&1 + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffers-pid -u "$channel_name" -s "$sess_name" --switch-timer 100000 >/dev/null 2>&1 ok $? "Enable channel $channel_name per UID for session $sess_name" } @@ -51,7 +51,7 @@ function enable_metadata_per_uid() local sess_name=$1 local channel_name="metadata" - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name --switch-timer 200000 >/dev/null 2>&1 + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffers-uid -u "$channel_name" -s "$sess_name" --switch-timer 200000 2>&1 ok $? "Enable channel $channel_name per UID for session $sess_name" } @@ -60,7 +60,7 @@ function enable_metadata_per_pid() local sess_name=$1 local channel_name="metadata" - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-pid -u $channel_name -s $sess_name --switch-timer 200000 >/dev/null 2>&1 + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffers-pid -u "$channel_name" -s "$sess_name" --switch-timer 200000 >/dev/null 2>&1 ok $? "Enable channel $channel_name per PID for session $sess_name" } @@ -68,8 +68,8 @@ function validate_trace() { local out - out=$("$BABELTRACE_BIN" $TRACE_PATH | grep $EVENT_NAME | wc -l) - if [ $out -eq 0 ]; then + out=$("$BABELTRACE_BIN" "$TRACE_PATH" | grep -c $EVENT_NAME) + if [ "$out" -eq 0 ]; then fail "Trace validation" diag "No event(s) found. We are supposed to have at least one." out=1 @@ -90,15 +90,15 @@ function check_app_tmp_file() sleep 0.5 done diag "Removing test app temporary file $APP_TMP_FILE" - rm -f $APP_TMP_FILE + rm -f "$APP_TMP_FILE" } function start_trace_app() { # Start application with a temporary file. - $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event $APP_TMP_FILE & + $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event "$APP_TMP_FILE" & ret=$? - APPS_PID="${APPS_PID} ${!}" + APP_PIDS+=(${!}) ok $ret "Start application to trace" } @@ -111,20 +111,18 @@ function start_check_trace_app() function wait_trace_apps() { - for p in ${APPS_PID}; do - wait ${p} 2>/dev/null - done - APPS_PID= + wait "${APP_PIDS[@]}" 2> /dev/null + APP_PIDS=() } test_after_app_pid() { local out - APPS_PID= + APP_PIDS=() diag "Start application AFTER tracing is started" - create_lttng_session_ok $SESSION_NAME $TRACE_PATH + create_lttng_session_ok $SESSION_NAME "$TRACE_PATH" enable_metadata_per_pid $SESSION_NAME enable_channel_per_pid $SESSION_NAME "channel0" enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" @@ -137,20 +135,17 @@ test_after_app_pid() { # Make sure the application does not generate any more data, # thus ensuring that we are not flushing a packet concurrently # with validate_trace. - for p in ${APPS_PID}; do - kill -s SIGSTOP ${p} - done + kill -s SIGSTOP "${APP_PIDS[@]}" # Give time to the consumer to write inflight data. sleep 2 + # shellcheck disable=SC2119 validate_trace out=$? - for p in ${APPS_PID}; do - kill -s SIGKILL ${p} - wait ${p} 2>/dev/null - done + kill -s SIGKILL "${APP_PIDS[@]}" + wait "${APP_PIDS[@]}" 2>/dev/null stop_lttng_tracing_ok $SESSION_NAME destroy_lttng_session_ok $SESSION_NAME @@ -161,16 +156,15 @@ test_after_app_pid() { test_before_app_pid() { local out - local tmp_file="/tmp/lttng_test_ust.42.file" - APPS_PID= + APP_PIDS=() diag "Start application BEFORE tracing is started" start_trace_app # Start application before tracing - create_lttng_session_ok $SESSION_NAME $TRACE_PATH + create_lttng_session_ok $SESSION_NAME "$TRACE_PATH" enable_metadata_per_pid $SESSION_NAME enable_channel_per_pid $SESSION_NAME "channel0" enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" @@ -183,20 +177,17 @@ test_before_app_pid() { # Make sure the application does not generate any more data, # thus ensuring that we are not flushing a packet concurrently # with validate_trace. - for p in ${APPS_PID}; do - kill -s SIGSTOP ${p} - done + kill -s SIGSTOP "${APP_PIDS[@]}" # Give time to the consumer to write inflight data. sleep 2 + # shellcheck disable=SC2119 validate_trace out=$? - for p in ${APPS_PID}; do - kill -s SIGKILL ${p} - wait ${p} 2>/dev/null - done + kill -s SIGKILL "${APP_PIDS[@]}" + wait "${APP_PIDS[@]}" 2>/dev/null stop_lttng_tracing_ok $SESSION_NAME destroy_lttng_session_ok $SESSION_NAME @@ -209,11 +200,11 @@ test_before_app_pid() { test_after_app_uid() { local out - APPS_PID= + APP_PIDS=() diag "Start application AFTER tracing is started" - create_lttng_session_ok $SESSION_NAME $TRACE_PATH + create_lttng_session_ok $SESSION_NAME "$TRACE_PATH" enable_metadata_per_uid $SESSION_NAME enable_channel_per_uid $SESSION_NAME "channel0" enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" @@ -226,21 +217,17 @@ test_after_app_uid() { # Make sure the application does not generate any more data, # thus ensuring that we are not flushing a packet concurrently # with validate_trace. - for p in ${APPS_PID}; do - kill -s SIGSTOP ${p} - done - + kill -s SIGSTOP "${APP_PIDS[@]}" # Give time to the consumer to write inflight data. sleep 2 + # shellcheck disable=SC2119 validate_trace out=$? - for p in ${APPS_PID}; do - kill -s SIGKILL ${p} - wait ${p} 2>/dev/null - done + kill -s SIGKILL "${APP_PIDS[@]}" + wait "${APP_PIDS[@]}" stop_lttng_tracing_ok $SESSION_NAME destroy_lttng_session_ok $SESSION_NAME @@ -252,14 +239,14 @@ test_after_app_uid() { test_before_app_uid() { local out - APPS_PID= + APP_PIDS=() diag "Start application BEFORE tracing is started" # Start application before tracing start_trace_app - create_lttng_session_ok $SESSION_NAME $TRACE_PATH + create_lttng_session_ok $SESSION_NAME "$TRACE_PATH" enable_metadata_per_uid $SESSION_NAME enable_channel_per_uid $SESSION_NAME "channel0" enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" @@ -272,20 +259,17 @@ test_before_app_uid() { # Make sure the application does not generate any more data, # thus ensuring that we are not flushing a packet concurrently # with validate_trace. - for p in ${APPS_PID}; do - kill -s SIGSTOP ${p} - done + kill -s SIGSTOP "${APP_PIDS[@]}" # Give time to the consumer to write inflight data. sleep 2 + # shellcheck disable=SC2119 validate_trace out=$? - for p in ${APPS_PID}; do - kill -s SIGKILL ${p} - wait ${p} 2>/dev/null - done + kill -s SIGKILL "${APP_PIDS[@]}" + wait "${APP_PIDS[@]}" stop_lttng_tracing_ok $SESSION_NAME destroy_lttng_session_ok $SESSION_NAME @@ -310,13 +294,15 @@ TESTS=( TEST_COUNT=${#TESTS[@]} i=0 +# shellcheck disable=SC2119 start_lttng_sessiond -while [ $i -lt $TEST_COUNT ]; do +while [ $i -lt "$TEST_COUNT" ]; do TRACE_PATH=$(mktemp -d -t tmp.test_periodical_metadata_flush_ust_trace_path.XXXXXX) ${TESTS[$i]} - rm -rf $TRACE_PATH - let "i++" + rm -rf "$TRACE_PATH" + (( "i++" )) done +# shellcheck disable=SC2119 stop_lttng_sessiond diff --git a/tests/stress/test_multi_sessions_per_uid_10app b/tests/stress/test_multi_sessions_per_uid_10app index 68cfc4572..5ddc6be64 100755 --- a/tests/stress/test_multi_sessions_per_uid_10app +++ b/tests/stress/test_multi_sessions_per_uid_10app @@ -5,8 +5,8 @@ # SPDX-License-Identifier: LGPL-2.1-only # -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/.. +CURDIR=$(dirname "$0")/ +TESTDIR="$CURDIR/.." LAUNCH_APP="launch_ust_app" SESSION_NAME="stress" EVENT_NAME="tp:tptest" @@ -17,32 +17,34 @@ NR_APP=10 NR_SESSION=5 NR_LOOP=1000 COREDUMP_FILE=$(cat /proc/sys/kernel/core_pattern) -APPS_PID= +APP_PIDS=() TEST_DESC="Stress test - $NR_SESSION sessions per UID with $NR_APP apps" -source $TESTDIR/utils/utils.sh +# shellcheck source-path=SCRIPTDIR/../ +source "$TESTDIR/utils/utils.sh" # MUST set TESTDIR before calling those functions function enable_channel_per_uid() { - local sess_name=$1 - local channel_name=$2 + local sess_name=$1 + local channel_name=$2 - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name >/dev/null 2>&1 - ok $? "Enable channel $channel_name per UID for session $sess_name" + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffers-uid -u "$channel_name" -s "$sess_name" >/dev/null 2>&1 + ok $? "Enable channel $channel_name per UID for session $sess_name" } function check_sessiond() { - if [ -z "$(lttng_pgrep lt-lttng-sessiond)" ]; then - local str_date=$(date +%H%M%S-%d%m%Y) + local str_date='' + if [ -z "$(lttng_pgrep lttng-sessiond)" ]; then + str_date=$(date +%H%M%S-%d%m%Y) diag "!!!The session daemon died unexpectedly!!!" - mv $LOG_FILE $LOG_FILE-$str_date - if [ -e $COREDUMP_FILE ]; then - mv $COREDUMP_FILE $COREDUMP_FILE-$str_date + mv $LOG_FILE "$LOG_FILE-$str_date" + if [ -e "$COREDUMP_FILE" ]; then + mv "$COREDUMP_FILE" "$COREDUMP_FILE-$str_date" fi exit 1 fi @@ -50,16 +52,15 @@ function check_sessiond() function start_sessiond() { - validate_kernel_version - if [ $? -ne 0 ]; then + if ! validate_kernel_version ; then fail "Start session daemon" BAIL_OUT "*** Kernel too old for session daemon tests ***" fi - if [ -z $(lttng_pgrep lt-$SESSIOND_BIN) ]; then + if [ -z "$(lttng_pgrep $SESSIOND_BIN)" ]; then # We have to start it like this so the ulimit -c is used by this # process. Also, we collect any error message printed out. - $TESTDIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --quiet --background --consumerd32-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" >$LOG_FILE 2>&1 + "$TESTDIR/../src/bin/lttng-sessiond/$SESSIOND_BIN" --quiet --background --consumerd32-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" >$LOG_FILE 2>&1 status=$? ok $status "Start session daemon" fi @@ -67,22 +68,23 @@ function start_sessiond() test_stress() { + # shellcheck disable=SC2034 for b in $(seq 1 $NR_LOOP); do for a in $(seq 1 $NR_SESSION); do - create_lttng_session_ok $SESSION_NAME-$a $TRACE_PATH + create_lttng_session_ok $SESSION_NAME-"$a" "$TRACE_PATH" check_sessiond - enable_channel_per_uid $SESSION_NAME-$a $CHANNEL_NAME + enable_channel_per_uid $SESSION_NAME-"$a" $CHANNEL_NAME check_sessiond - enable_ust_lttng_event_ok $SESSION_NAME-$a $EVENT_NAME + enable_ust_lttng_event_ok $SESSION_NAME-"$a" $EVENT_NAME check_sessiond - start_lttng_tracing_ok $SESSION_NAME-$a + start_lttng_tracing_ok $SESSION_NAME-"$a" check_sessiond done for a in $(seq 1 $NR_SESSION); do - stop_lttng_tracing_ok $SESSION_NAME-$a + stop_lttng_tracing_ok $SESSION_NAME-"$a" check_sessiond - destroy_lttng_session_ok $SESSION_NAME-$a + destroy_lttng_session_ok $SESSION_NAME-"$a" check_sessiond done done @@ -93,18 +95,17 @@ test_stress() function cleanup() { diag "Cleaning up!" - for p in ${APPS_PID}; do - kill -s SIGKILL ${p} - wait ${p} 2>/dev/null - done - APPS_PID= + kill -s SIGKILL "${APP_PIDS[@]}" + wait "${APP_PIDS[@]}" 2>/dev/null + APP_PIDS=() + # shellcheck disable=SC2119 stop_lttng_sessiond } function sighandler() { cleanup - rm $LOG_FILE + rm "$LOG_FILE" full_cleanup } @@ -123,8 +124,8 @@ start_sessiond diag "Starting applications" # Start NR_APP applications script that will spawn apps non stop. -./$TESTDIR/stress/$LAUNCH_APP $NR_APP & -APPS_PID="${APPS_PID} ${!}" +"./$TESTDIR/stress/$LAUNCH_APP" $NR_APP & +APP_PIDS+=(${!}) TRACE_PATH=$(mktemp -d -t tmp.test_multi_sess_per_uid_10app.XXXXXX) @@ -136,6 +137,6 @@ if [ $out -ne 0 ]; then fi cleanup -rm -rf $TRACE_PATH +rm -rf "${TRACE_PATH:?}/" rm $LOG_FILE exit 0 diff --git a/tests/stress/test_multi_sessions_per_uid_5app_streaming b/tests/stress/test_multi_sessions_per_uid_5app_streaming index d1d192c02..8800f6f23 100755 --- a/tests/stress/test_multi_sessions_per_uid_5app_streaming +++ b/tests/stress/test_multi_sessions_per_uid_5app_streaming @@ -5,8 +5,8 @@ # SPDX-License-Identifier: LGPL-2.1-only # -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/.. +CURDIR=$(dirname "$0")/ +TESTDIR="$CURDIR/.." LAUNCH_APP="launch_ust_app" SESSION_NAME="stress" EVENT_NAME="tp:tptest" @@ -18,32 +18,34 @@ NR_SESSION=5 NR_LOOP=1000 COREDUMP_FILE=$(cat /proc/sys/kernel/core_pattern) NUM_TESTS=16 -APPS_PID= +APP_PIDS=() TEST_DESC="Stress test - $NR_SESSION sessions per UID streaming with $NR_APP apps" -source $TESTDIR/utils/utils.sh +# shellcheck source-path=SCRIPTDIR/../ +source "$TESTDIR/utils/utils.sh" # MUST set TESTDIR before calling those functions function enable_channel_per_uid() { - local sess_name=$1 - local channel_name=$2 + local sess_name=$1 + local channel_name=$2 - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name >/dev/null 2>&1 - ok $? "Enable channel $channel_name per UID for session $sess_name" + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffers-uid -u "$channel_name" -s "$sess_name" >/dev/null 2>&1 + ok $? "Enable channel $channel_name per UID for session $sess_name" } function check_sessiond() { - if [ -z "$(lttng_pgrep lt-lttng-sessiond)" ]; then - local str_date=$(date +%H%M%S-%d%m%Y) + local str_date + if [ -z "$(lttng_pgrep lttng-sessiond)" ]; then + str_date=$(date +%H%M%S-%d%m%Y) diag "!!!The session daemon died unexpectedly!!!" - mv $LOG_FILE_SESSIOND $LOG_FILE_SESSIOND-$str_date - if [ -e $COREDUMP_FILE ]; then - mv $COREDUMP_FILE $COREDUMP_FILE-$str_date + mv $LOG_FILE_SESSIOND "$LOG_FILE_SESSIOND-$str_date" + if [ -e "$COREDUMP_FILE" ]; then + mv "$COREDUMP_FILE" "$COREDUMP_FILE-$str_date" fi exit 1 fi @@ -51,13 +53,14 @@ function check_sessiond() function check_relayd() { - if [ -z "$(lttng_pgrep lt-lttng-relayd)" ]; then - local str_date=$(date +%H%M%S-%d%m%Y) + local str_date + if [ -z "$(lttng_pgrep lttng-relayd)" ]; then + str_date=$(date +%H%M%S-%d%m%Y) diag "!!!The relay daemon died unexpectedly!!!" - mv $LOG_FILE_RELAYD $LOG_FILE_RELAYD-$str_date - if [ -e $COREDUMP_FILE ]; then - mv $COREDUMP_FILE $COREDUMP_FILE-$str_date + mv $LOG_FILE_RELAYD "$LOG_FILE_RELAYD-$str_date" + if [ -e "$COREDUMP_FILE" ]; then + mv "$COREDUMP_FILE" "$COREDUMP_FILE-$str_date" fi exit 1 fi @@ -65,16 +68,15 @@ function check_relayd() function start_sessiond() { - validate_kernel_version - if [ $? -ne 0 ]; then + if ! validate_kernel_version ; then fail "Start session daemon" BAIL_OUT "*** Kernel too old for session daemon tests ***" fi - if [ -z $(lttng_pgrep lt-$SESSIOND_BIN) ]; then + if [ -z "$(lttng_pgrep lt-$SESSIOND_BIN)" ]; then # We have to start it like this so the ulimit -c is used by this # process. Also, we collect any error message printed out. - $TESTDIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --quiet --background --consumerd32-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" >$LOG_FILE_SESSIOND 2>&1 + "$TESTDIR/../src/bin/lttng-sessiond/$SESSIOND_BIN" --quiet --background --consumerd32-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" >$LOG_FILE_SESSIOND 2>&1 status=$? ok $status "Start session daemon" fi @@ -84,35 +86,36 @@ function start_relayd { local opt=$1 - if [ -z $(lttng_pgrep lt-$RELAYD_BIN) ]; then - $TESTDIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt >$LOG_FILE_RELAYD 2>&1 & + if [ -z "$(lttng_pgrep lt-$RELAYD_BIN)" ]; then + "$TESTDIR/../src/bin/lttng-relayd/$RELAYD_BIN" "$opt" >"$LOG_FILE_RELAYD" 2>&1 & ok $? "Start lttng-relayd (opt: \"$opt\")" fi } test_stress() { + # shellcheck disable=SC2034 for b in $(seq 1 $NR_LOOP); do for a in $(seq 1 $NR_SESSION); do - create_lttng_session_uri $SESSION_NAME-$a net://localhost + create_lttng_session_uri $SESSION_NAME-"$a" net://localhost check_sessiond check_relayd - enable_channel_per_uid $SESSION_NAME-$a $CHANNEL_NAME + enable_channel_per_uid $SESSION_NAME-"$a" $CHANNEL_NAME check_sessiond check_relayd - enable_ust_lttng_event_ok $SESSION_NAME-$a $EVENT_NAME + enable_ust_lttng_event_ok $SESSION_NAME-"$a" $EVENT_NAME check_sessiond check_relayd - start_lttng_tracing_ok $SESSION_NAME-$a + start_lttng_tracing_ok $SESSION_NAME-"$a" check_sessiond check_relayd done for a in $(seq 1 $NR_SESSION); do - stop_lttng_tracing_ok $SESSION_NAME-$a + stop_lttng_tracing_ok $SESSION_NAME-"$a" check_sessiond check_relayd - destroy_lttng_session_ok $SESSION_NAME-$a + destroy_lttng_session_ok $SESSION_NAME-"$a" check_sessiond check_relayd done @@ -124,12 +127,12 @@ test_stress() function cleanup() { diag "Cleaning up!" - for p in ${APPS_PID}; do - kill -s SIGKILL ${p} - wait ${p} 2>/dev/null - done - APPS_PID= + kill -s SIGKILL "${APP_PIDS[@]}" + wait "${APP_PIDS[@]}" 2>/dev/null + APP_PIDS=() + # shellcheck disable=SC2119 stop_lttng_sessiond + # shellcheck disable=SC2119 stop_lttng_relayd } @@ -158,8 +161,8 @@ start_sessiond diag "Starting applications launcher" # Start NR_APP applications script that will spawn apps non stop. -./$TESTDIR/stress/$LAUNCH_APP $NR_APP & -APPS_PID="${APPS_PID} ${!}" +"./$TESTDIR/stress/$LAUNCH_APP" $NR_APP & +APP_PIDS+=(${!}) test_stress out=$? @@ -169,6 +172,6 @@ if [ $out -ne 0 ]; then fi cleanup -rm -rf $TRACE_PATH +rm -rf "${TRACE_PATH:?}/" rm $LOG_FILE_SESSIOND $LOG_FILE_RELAYD exit 0 diff --git a/tests/stress/test_multi_sessions_per_uid_5app_streaming_kill_relayd b/tests/stress/test_multi_sessions_per_uid_5app_streaming_kill_relayd index 53411cb6d..3d5da8f84 100755 --- a/tests/stress/test_multi_sessions_per_uid_5app_streaming_kill_relayd +++ b/tests/stress/test_multi_sessions_per_uid_5app_streaming_kill_relayd @@ -5,8 +5,8 @@ # SPDX-License-Identifier: LGPL-2.1-only # -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/.. +CURDIR=$(dirname "$0")/ +TESTDIR="$CURDIR/.." LAUNCH_APP="launch_ust_app" KILL_RELAYD_HELPER="kill_relayd" SESSION_NAME="stress" @@ -19,32 +19,34 @@ NR_SESSION=5 NR_LOOP=100000 COREDUMP_FILE=$(cat /proc/sys/kernel/core_pattern) NUM_TESTS=16 -APPS_PID= +APP_PIDS=() TEST_DESC="Stress test - $NR_SESSION sessions per UID streaming with $NR_APP apps. The relayd is killed sporadically" -source $TESTDIR/utils/utils.sh +# shellcheck source-path=SCRIPTDIR/../ +source "$TESTDIR/utils/utils.sh" # MUST set TESTDIR before calling those functions function enable_channel_per_uid() { - local sess_name=$1 - local channel_name=$2 + local sess_name=$1 + local channel_name=$2 - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name >/dev/null 2>&1 - ok $? "Enable channel $channel_name per UID for session $sess_name" + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffers-uid -u "$channel_name" -s "$sess_name" >/dev/null 2>&1 + ok $? "Enable channel $channel_name per UID for session $sess_name" } function check_sessiond() { - if [ -z "$(lttng_pgrep lt-lttng-sessiond)" ]; then - local str_date=$(date +%H%M%S-%d%m%Y) + local str_date + if [ -z "$(lttng_pgrep lttng-sessiond)" ]; then + str_date=$(date +%H%M%S-%d%m%Y) diag "!!!The session daemon died unexpectedly!!!" - mv $LOG_FILE_SESSIOND $LOG_FILE_SESSIOND-$str_date - if [ -e $COREDUMP_FILE ]; then - mv $COREDUMP_FILE $COREDUMP_FILE-$str_date + mv $LOG_FILE_SESSIOND "$LOG_FILE_SESSIOND-$str_date" + if [ -e "$COREDUMP_FILE" ]; then + mv "$COREDUMP_FILE" "$COREDUMP_FILE-$str_date" fi exit 1 fi @@ -52,17 +54,16 @@ function check_sessiond() function start_sessiond() { - validate_kernel_version - if [ $? -ne 0 ]; then + if ! validate_kernel_version ; then fail "Start session daemon" BAIL_OUT "*** Kernel too old for session daemon tests ***" fi - if [ -z $(lttng_pgrep lt-$SESSIOND_BIN) ]; then + if [ -z "$(lttng_pgrep $SESSIOND_BIN)" ]; then # We have to start it like this so the ulimit -c is used by this # process. Also, we collect any error message printed out. #$TESTDIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --quiet --background --consumerd32-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" >$LOG_FILE_SESSIOND 2>&1 - $TESTDIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --verbose-consumer -vvv --background --consumerd32-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" >$LOG_FILE_SESSIOND 2>&1 + "$TESTDIR/../src/bin/lttng-sessiond/$SESSIOND_BIN" --verbose-consumer -vvv --background --consumerd32-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" >$LOG_FILE_SESSIOND 2>&1 #$TESTDIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --background --consumerd32-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$TESTDIR/../src/bin/lttng-consumerd/lttng-consumerd" >$LOG_FILE_SESSIOND 2>&1 status=$? ok $status "Start session daemon" @@ -73,20 +74,21 @@ function start_relayd { local opt=$1 - if [ -z $(lttng_pgrep lt-$RELAYD_BIN) ]; then - $TESTDIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt >$LOG_FILE_RELAYD 2>&1 & + if [ -z "$(lttng_pgrep $RELAYD_BIN)" ]; then + "$TESTDIR/../src/bin/lttng-relayd/$RELAYD_BIN" "$opt" >$LOG_FILE_RELAYD 2>&1 & ok $? "Start lttng-relayd (opt: \"$opt\")" fi } function check_relayd() { - if [ -z "$(lttng_pgrep lt-lttng-relayd)" ]; then - local str_date=$(date +%H%M%S-%d%m%Y) + local str_date + if [ -z "$(lttng_pgrep lttng-relayd)" ]; then + str_date=$(date +%H%M%S-%d%m%Y) #diag "Relay daemon died. Starting it again" - if [ -e $COREDUMP_FILE ]; then - mv $COREDUMP_FILE $COREDUMP_FILE-$str_date + if [ -e "$COREDUMP_FILE" ]; then + mv "$COREDUMP_FILE" "$COREDUMP_FILE-$str_date" fi start_relayd fi @@ -94,27 +96,28 @@ function check_relayd() test_stress() { + # shellcheck disable=SC2034 for b in $(seq 1 $NR_LOOP); do for a in $(seq 1 $NR_SESSION); do - create_lttng_session_uri $SESSION_NAME-$a net://localhost + create_lttng_session_uri $SESSION_NAME-"$a" net://localhost check_sessiond check_relayd - enable_channel_per_uid $SESSION_NAME-$a $CHANNEL_NAME + enable_channel_per_uid $SESSION_NAME-"$a" $CHANNEL_NAME check_sessiond check_relayd - enable_ust_lttng_event_ok $SESSION_NAME-$a $EVENT_NAME + enable_ust_lttng_event_ok $SESSION_NAME-"$a" $EVENT_NAME check_sessiond check_relayd - start_lttng_tracing_ok $SESSION_NAME-$a + start_lttng_tracing_ok $SESSION_NAME-"$a" check_sessiond check_relayd done for a in $(seq 1 $NR_SESSION); do - stop_lttng_tracing_ok $SESSION_NAME-$a + stop_lttng_tracing_ok $SESSION_NAME-"$a" check_sessiond check_relayd - destroy_lttng_session_ok $SESSION_NAME-$a + destroy_lttng_session_ok $SESSION_NAME-"$a" check_sessiond check_relayd done @@ -126,12 +129,12 @@ test_stress() function cleanup() { diag "Cleaning up!" - for p in ${APPS_PID}; do - kill ${p} - wait ${p} 2>/dev/null - done - APPS_PID= + kill "${APP_PIDS[@]}" + wait "${APP_PIDS[@]}" 2>/dev/null + APP_PIDS=() + # shellcheck disable=SC2119 stop_lttng_sessiond + # shellcheck disable=SC2119 stop_lttng_relayd } @@ -160,12 +163,12 @@ start_sessiond diag "Starting applications launcher" # Start NR_APP applications script that will spawn apps non stop. -./$TESTDIR/stress/$LAUNCH_APP $NR_APP & -APPS_PID="${APPS_PID} ${!}" +"./$TESTDIR/stress/$LAUNCH_APP" $NR_APP & +APP_PIDS+=(${!}) # Launch the helper script that will randomly kill the relayd at vitam eternam. -./$TESTDIR/stress/$KILL_RELAYD_HELPER 1 1 & -APPS_PID="${APPS_PID} ${!}" +"./$TESTDIR/stress/$KILL_RELAYD_HELPER" 1 1 & +APP_PIDS+=(${!}) test_stress out=$? @@ -175,6 +178,6 @@ if [ $out -ne 0 ]; then fi cleanup -rm -rf $TRACE_PATH +rm -rf "${TRACE_PATH:?}/" rm $LOG_FILE_SESSIOND $LOG_FILE_RELAYD exit 0 -- 2.34.1