Tests: fix racy UST snapshot post mortem test
[lttng-tools.git] / tests / regression / tools / snapshots / test_ust
index d4fe165ee153be8a95a44353fe87b985fa56a974..bdc6f74d63192aa426935c346f0ca4f196984450 100755 (executable)
@@ -19,7 +19,6 @@ TEST_DESC="Snapshots - UST tracing"
 CURDIR=$(dirname $0)/
 TESTDIR=$CURDIR/../../..
 EVENT_NAME="tp:tptest"
-BIN_NAME="gen-nevents"
 PID_RELAYD=0
 SESSION_NAME=""
 CHANNEL_NAME="snapchan"
@@ -31,7 +30,7 @@ NR_USEC_WAIT=100
 
 TRACE_PATH=$(mktemp -d)
 
-NUM_TESTS=2029
+NUM_TESTS=2076
 
 source $TESTDIR/utils/utils.sh
 
@@ -39,6 +38,107 @@ if [ ! -x "$TESTAPP_BIN" ]; then
        BAIL_OUT "No UST events binary detected."
 fi
 
+function start_test_app()
+{
+       local tmp_file="/tmp/lttng_test_ust.42.file"
+
+       # Start application with a temporary file.
+       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file &
+       ok $? "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 -f $tmp_file
+}
+
+function kill_test_app()
+{
+       diag "Killing $TESTAPP_NAME"
+       PID_APP=`pidof $TESTAPP_NAME`
+       kill $PID_APP >/dev/null 2>&1
+}
+
+function snapshot_add_output ()
+{
+       local sess_name=$1
+       local trace_path=$2
+       local name=$3
+       local max_size=$4
+       local extra_opt=""
+
+       if [ ! -z $name ]; then
+               extra_opt+=" -n $name "
+       fi
+
+       if [ ! -z $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
+
+       ok $? "Added snapshot output $trace_path ($extra_opt)"
+}
+
+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
+
+       ok $? "Deleted snapshot output named $name"
+}
+
+function enable_mmap_overwrite_subbuf_ust_channel ()
+{
+       local sess_name=$1
+       local chan_name=$2
+       local subbuf_size=$3
+
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name \
+               $chan_name -u --output mmap --overwrite \
+               --subbuf-size $subbuf_size > /dev/null 2>&1
+
+       ok $? "Enable channel $channel_name for session $sess_name with subbuf size $subbuf_size"
+}
+
+
+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 $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
+
+       start_lttng_tracing $SESSION_NAME
+
+       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
+       ok $? "Snapshot named ${output_names[0]} present in list-output listing"
+
+       snapshot_del_output $SESSION_NAME ${output_names[0]}
+
+       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
+
+       ok $? "Snapshot named ${output_names[1]} present in list-output listing"
+
+       stop_lttng_tracing $SESSION_NAME
+       destroy_lttng_session $SESSION_NAME
+}
+
 function test_ust_local_snapshot ()
 {
        diag "Test local UST snapshots"
@@ -47,8 +147,10 @@ function test_ust_local_snapshot ()
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
        start_lttng_tracing $SESSION_NAME
        lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
-       ok $? "Start application to trace"
+
+       # Returns once the application has at least fired ONE tracepoint.
+       start_test_app
+
        lttng_snapshot_record $SESSION_NAME
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
@@ -61,9 +163,85 @@ function test_ust_local_snapshot ()
        else
                break
        fi
-       diag "Killing $TESTAPP_NAME"
-       PID_APP=`pidof $TESTAPP_NAME`
-       kill $PID_APP >/dev/null 2>&1
+
+       kill_test_app
+}
+
+function test_ust_local_snapshot_max_size ()
+{
+       subbuf_size=8192
+       num_cpus=`nproc`
+
+       # The minimum size limit is min(subbuf_size) * nb_streams
+       max_size=$(($subbuf_size*$num_cpus))
+
+       diag "Test local UST snapshots with max size $max_size"
+       create_lttng_session_no_output $SESSION_NAME
+
+       enable_mmap_overwrite_subbuf_ust_channel $SESSION_NAME $CHANNEL_NAME $subbuf_size
+
+       enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
+       start_lttng_tracing $SESSION_NAME
+
+       snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" "" $max_size
+
+       # Returns once the application has at least fired ONE tracepoint.
+       start_test_app
+
+       lttng_snapshot_record $SESSION_NAME
+
+       # Check file size
+       sum_size_tracefiles=$(find $TRACE_PATH -name "${CHANNEL_NAME}_*" \
+               -exec stat -c '%s' {} \; | awk '{s = s + $1}END{print s}')
+
+       if [ "$sum_size_tracefiles" -gt "$max_size" ]; then
+               fail "Tracefiles size sum validation"
+               diag "Tracefiles size sum: $sum_size_tracefiles Expected max: $max_size"
+       fi
+
+       pass "Tracefiles size sum validation"
+
+       stop_lttng_tracing $SESSION_NAME
+       destroy_lttng_session $SESSION_NAME
+
+       # Validate test
+       validate_trace $EVENT_NAME $TRACE_PATH/
+
+       if [ $? -eq 0 ]; then
+               # Only delete if successful
+               rm -rf $TRACE_PATH
+       fi
+
+       kill_test_app
+}
+
+function test_ust_local_snapshot_large_metadata ()
+{
+       LM_EVENT="tp:tptest1,tp:tptest2,tp:tptest3,tp:tptest4,tp:tptest5"
+       LM_PATH="$TESTDIR/utils/testapp"
+       LM_NAME="gen-ust-nevents"
+       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 $SESSION_NAME $LM_EVENT $CHANNEL_NAME
+       start_lttng_tracing $SESSION_NAME
+       lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH
+       $LM_BIN 1 1
+       ok $? "Start application to trace"
+       lttng_snapshot_record $SESSION_NAME
+       stop_lttng_tracing $SESSION_NAME
+       destroy_lttng_session $SESSION_NAME
+
+       # Validate test
+       validate_trace $LM_EVENT $TRACE_PATH/
+       if [ $? -eq 0 ]; then
+               # Only delete if successful
+               rm -rf $TRACE_PATH
+       else
+               break
+       fi
 }
 
 function enable_channel_per_uid_mmap_overwrite()
@@ -83,8 +261,39 @@ function test_ust_per_uid_local_snapshot ()
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
        start_lttng_tracing $SESSION_NAME
        lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
-       ok $? "Start application to trace"
+
+       # Returns once the application has at least fired ONE tracepoint.
+       start_test_app
+
+       lttng_snapshot_record $SESSION_NAME
+       stop_lttng_tracing $SESSION_NAME
+       destroy_lttng_session $SESSION_NAME
+
+       # Validate test
+       validate_trace $EVENT_NAME $TRACE_PATH/
+       if [ $? -eq 0 ]; then
+               # Only delete if successful
+               rm -rf $TRACE_PATH
+       else
+               break
+       fi
+
+       kill_test_app
+}
+
+function test_ust_per_uid_local_snapshot_post_mortem ()
+{
+       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 $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
+       start_lttng_tracing $SESSION_NAME
+       lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH
+
+       # Returns once the application has at least fired ONE tracepoint.
+       start_test_app
+       kill_test_app
+
        lttng_snapshot_record $SESSION_NAME
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
@@ -97,9 +306,6 @@ function test_ust_per_uid_local_snapshot ()
        else
                break
        fi
-       diag "Killing $TESTAPP_NAME"
-       PID_APP=`pidof $TESTAPP_NAME`
-       kill $PID_APP >/dev/null 2>&1
 }
 
 function test_ust_1000_local_snapshots ()
@@ -112,7 +318,10 @@ function test_ust_1000_local_snapshots ()
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
        start_lttng_tracing $SESSION_NAME
        lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
+
+       # Returns once the application has at least fired ONE tracepoint.
+       start_test_app
+
        for i in $(seq 1 $NB_SNAP); do
                diag "Snapshot $i/$NB_SNAP"
                rm -rf $TRACE_PATH/snapshot/* 2>/dev/null
@@ -128,9 +337,8 @@ function test_ust_1000_local_snapshots ()
        done
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
-       diag "Killing $TESTAPP_NAME"
-       PID_APP=`pidof $TESTAPP_NAME`
-#      kill $PID_APP >/dev/null 2>&1
+
+       kill_test_app
 }
 
 plan_tests $NUM_TESTS
@@ -145,13 +353,18 @@ fi
 
 start_lttng_sessiond
 
-tests=( test_ust_local_snapshot test_ust_per_uid_local_snapshot test_ust_1000_local_snapshots )
+tests=( test_ust_list_output
+       test_ust_local_snapshot
+       test_ust_local_snapshot_max_size
+       test_ust_per_uid_local_snapshot
+       test_ust_per_uid_local_snapshot_post_mortem
+       test_ust_local_snapshot_large_metadata
+       test_ust_1000_local_snapshots )
 
 for fct_test in ${tests[@]};
 do
        SESSION_NAME=$(randstring 16 0)
        ${fct_test}
-
 done
 
 stop_lttng_sessiond
This page took 0.030036 seconds and 5 git commands to generate.