Tests: add a local size-based rotation test in per-uid buffering mode
[lttng-tools.git] / tests / utils / utils.sh
index 42d99444fc8e1c4d977f69aab80435da1a50043e..18b673b11452491bc3946abda5aa0225d53be587 100644 (file)
@@ -12,7 +12,7 @@ CONSUMERD_MATCH=".*lttng-consumerd.*"
 RELAYD_BIN="lttng-relayd"
 RELAYD_MATCH=".*lttng-relayd.*"
 LTTNG_BIN="lttng"
-BABELTRACE_BIN="babeltrace"
+BABELTRACE_BIN="babeltrace2"
 OUTPUT_DEST=/dev/null
 ERROR_OUTPUT_DEST=/dev/null
 MI_XSD_MAJOR_VERSION=4
@@ -682,8 +682,8 @@ function start_lttng_sessiond_opt()
            LTTNG_BAIL_OUT "*** Kernel too old for session daemon tests ***"
        fi
 
-       diag "export LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/"
-       : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/config/"}"
+       diag "export LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/"
+       : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/"}"
        export LTTNG_SESSION_CONFIG_XSD_PATH
 
        if [ -z "$(lttng_pgrep "${SESSIOND_MATCH}")" ]; then
@@ -1028,10 +1028,26 @@ function sigstop_lttng_consumerd_notap()
 
 function list_lttng_with_opts ()
 {
+       local ret
+       local withtap=$1
+       shift
        local opts=$1
        _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
                list $opts
-       ok $? "Lttng-tool list command with option $opts"
+       ret=$?
+       if [ $withtap -eq "1" ]; then
+               ok $ret "Lttng-tool list command with option $opts"
+       fi
+}
+
+function list_lttng_ok ()
+{
+       list_lttng_with_opts 1 "$@"
+}
+
+function list_lttng_notap ()
+{
+       list_lttng_with_opts 0 "$@"
 }
 
 function create_lttng_session_no_output ()
@@ -1278,39 +1294,80 @@ function enable_jul_lttng_event_loglevel()
 
 function enable_log4j_lttng_event()
 {
-       sess_name=$1
-       event_name="$2"
-       channel_name=$3
+       local sess_name=$1
+       local event_name=$2
+       local channel_name=$3
 
-       if [ -z $channel_name ]; then
-               # default channel if none specified
-               chan=""
-       else
-               chan="-c $channel_name"
+       local chan_opt=()
+
+       # default channel if none specified
+       if [ -n "$channel_name" ]; then
+               chan_opt=("-c" "$channel_name")
        fi
 
        _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
-               enable-event "$event_name" $chan -s $sess_name -l
-       ok $? "Enable LOG4J event $event_name for session $sess_name"
+               enable-event "$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j
+       ok $? "Enable LOG4J event '$event_name' for session '$sess_name'"
+}
+
+function enable_log4j_lttng_event_filter()
+{
+       local sess_name=$1
+       local event_name=$2
+       local filter=$3
+
+       _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
+               enable-event "$event_name" -s "$sess_name" --log4j --filter "$filter"
+       ok $? "Enable LOG4J event '$event_name' with filter '$filter' for session '$sess_name'"
+}
+
+function enable_log4j_lttng_event_filter_loglevel_only()
+{
+       local sess_name=$1
+       local event_name=$2
+       local filter=$3
+       local loglevel=$4
+
+       _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
+               enable-event --loglevel-only "$loglevel" "$event_name" -s "$sess_name" -l --filter "$filter"
+       ok $? "Enable LOG4J event '$event_name' with filter '$filter' and loglevel-only '$loglevel' for session '$sess_name'"
 }
 
 function enable_log4j_lttng_event_loglevel()
 {
        local sess_name=$1
-       local event_name="$2"
+       local event_name=$2
        local loglevel=$3
        local channel_name=$4
 
-       if [ -z $channel_name ]; then
-               # default channel if none specified
-               chan=""
-       else
-               chan="-c $channel_name"
+
+       # default channel if none specified
+       if [ -n "$channel_name" ]; then
+               chan_opt=("-c" "$channel_name")
+       fi
+
+       _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
+               enable-event --loglevel "$loglevel" "$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j
+       ok $? "Enable LOG4J event '$event_name' for session '$sess_name' with loglevel '$loglevel'"
+}
+
+function enable_log4j_lttng_event_loglevel_only()
+{
+       local sess_name=$1
+       local event_name=$2
+       local loglevel=$3
+       local channel_name=$4
+
+       local chan_opt=()
+
+       # default channel if none specified
+       if [ -n "$channel_name" ]; then
+               chan_opt=("-c" "$channel_name")
        fi
 
        _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
-               enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l
-       ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel"
+               enable-event --loglevel-only "$loglevel" "$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j
+       ok $? "Enable LOG4J event '$event_name' for session '$sess_name' with loglevel-only '$loglevel'"
 }
 
 function enable_python_lttng_event()
@@ -1423,8 +1480,9 @@ function disable_log4j_lttng_event ()
        local sess_name="$1"
        local event_name="$2"
 
-       $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1
-       ok $? "Disable LOG4J event $event_name for session $sess_name"
+       _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
+               disable-event "$event_name" -s "$sess_name" --log4j
+       ok $? "Disable LOG4J event '$event_name' for session '$sess_name'"
 }
 
 function disable_python_lttng_event ()
@@ -1841,6 +1899,14 @@ function wait_live_viewer_connect ()
        pass "Waiting for live viewers on url: $url"
 }
 
+function bail_out_if_no_babeltrace()
+{
+       which "$BABELTRACE_BIN" >/dev/null
+       if [ $? -ne 0 ]; then
+               LTTNG_BAIL_OUT "\"$BABELTRACE_BIN\" binary not found. Skipping tests"
+       fi
+}
+
 function validate_metadata_event ()
 {
        local event_name=$1
@@ -1850,16 +1916,15 @@ function validate_metadata_event ()
        local metadata_file=$(find $trace_path -name "metadata")
        local metadata_path=$(dirname $metadata_file)
 
-       which $BABELTRACE_BIN >/dev/null
-       skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
+       bail_out_if_no_babeltrace
 
        local count=$($BABELTRACE_BIN --output-format=ctf-metadata $metadata_path | grep $event_name | wc -l)
 
        if [ "$count" -ne "$nr_event_id" ]; then
-               fail "Metadata match with the metadata of $count event(s) named $event_name"
-               diag "$count matching event id found in metadata"
+               fail "Metadata match with the metadata of $nr_event_id event(s) named $event_name"
+               diag "$count matching event names found in metadata"
        else
-               pass "Metadata match with the metadata of $count event(s) named $event_name"
+               pass "Metadata match with the metadata of $nr_event_id event(s) named $event_name"
        fi
 
 }
@@ -1870,8 +1935,7 @@ function trace_matches ()
        local nr_iter=$2
        local trace_path=$3
 
-       which $BABELTRACE_BIN >/dev/null
-       skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
+       bail_out_if_no_babeltrace
 
        local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
 
@@ -1889,8 +1953,9 @@ function trace_match_only()
        local nr_iter=$2
        local trace_path=$3
 
-       which $BABELTRACE_BIN >/dev/null
-       skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
+       bail_out_if_no_babeltrace
+       #which "$BABELTRACE_BIN" >/dev/null
+       #skip $? -ne 0 "\"$BABELTRACE_BIN\" binary not found. Skipping trace comparison"
 
        local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
        local total=$($BABELTRACE_BIN $trace_path | wc -l)
@@ -1908,10 +1973,7 @@ function validate_trace
        local event_name=$1
        local trace_path=$2
 
-       which $BABELTRACE_BIN >/dev/null
-       if [ $? -ne 0 ]; then
-           skip 0 "Babeltrace binary not found. Skipping trace validation"
-       fi
+       bail_out_if_no_babeltrace
 
        OLDIFS=$IFS
        IFS=","
@@ -1935,10 +1997,7 @@ function validate_trace_count
        local trace_path=$2
        local expected_count=$3
 
-       which $BABELTRACE_BIN >/dev/null
-       if [ $? -ne 0 ]; then
-           skip 0 "Babeltrace binary not found. Skipping trace validation"
-       fi
+       bail_out_if_no_babeltrace
 
        cnt=0
        OLDIFS=$IFS
@@ -1965,10 +2024,7 @@ function validate_trace_count_range_incl_min_excl_max
        local expected_min=$3
        local expected_max=$4
 
-       which $BABELTRACE_BIN >/dev/null
-       if [ $? -ne 0 ]; then
-           skip 0 "Babeltrace binary not found. Skipping trace validation"
-       fi
+       bail_out_if_no_babeltrace
 
        cnt=0
        OLDIFS=$IFS
@@ -1992,11 +2048,6 @@ function trace_first_line
 {
        local trace_path=$1
 
-       which $BABELTRACE_BIN >/dev/null
-       if [ $? -ne 0 ]; then
-           skip 0 "Babeltrace binary not found. Skipping trace validation"
-       fi
-
        $BABELTRACE_BIN $trace_path 2>/dev/null | head -n 1
 }
 
@@ -2005,8 +2056,7 @@ function validate_trace_exp()
        local event_exp=$1
        local trace_path=$2
 
-       which $BABELTRACE_BIN >/dev/null
-       skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation"
+       bail_out_if_no_babeltrace
 
        traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep --extended-regexp ${event_exp} | wc -l)
        if [ "$traced" -ne 0 ]; then
@@ -2024,8 +2074,7 @@ function validate_trace_only_exp()
        local event_exp=$1
        local trace_path=$2
 
-       which $BABELTRACE_BIN >/dev/null
-       skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches"
+       bail_out_if_no_babeltrace
 
        local count=$($BABELTRACE_BIN $trace_path | grep --extended-regexp ${event_exp} | wc -l)
        local total=$($BABELTRACE_BIN $trace_path | wc -l)
@@ -2044,10 +2093,7 @@ function validate_trace_empty()
 {
        local trace_path=$1
 
-       which $BABELTRACE_BIN >/dev/null
-       if [ $? -ne 0 ]; then
-           skip 0 "Babeltrace binary not found. Skipping trace validation"
-       fi
+       bail_out_if_no_babeltrace
 
        events=$($BABELTRACE_BIN $trace_path 2>/dev/null)
        ret=$?
@@ -2219,9 +2265,9 @@ function lttng_enable_rotation_size ()
        ret=$?
        if [[ $expected_to_fail -eq "1" ]]; then
                test "$ret" -ne "0"
-               ok $? "Expected fail on rotate session $sess_name"
+               ok $? "Expected to fail to set a periodic rotation of session $sess_name" "every " $size " bytes"
        else
-               ok $ret "Rotate session $sess_name"
+               ok $ret "Set a scheduled rotation of session $sess_name" "every " $size " bytes"
        fi
 }
 
This page took 0.029624 seconds and 4 git commands to generate.