-# Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
+# Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
#
-# This library is free software; you can redistribute it and/or modify it under
-# the terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation; version 2.1 of the License.
+# SPDX-License-Identifier: LGPL-2.1-only
#
-# This library is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this library; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
SESSIOND_BIN="lttng-sessiond"
SESSIOND_MATCH=".*lttng-sess.*"
OUTPUT_DEST=/dev/null
ERROR_OUTPUT_DEST=/dev/null
+# To match 20201127-175802
+date_time_pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]"
+# The size of a long on this system
+system_long_bit_size=$(getconf LONG_BIT)
+
# Minimal kernel version supported for session daemon tests
KERNEL_MAJOR_VERSION=2
KERNEL_MINOR_VERSION=6
source $TESTDIR/utils/tap/tap.sh
-if [ -z $LTTNG_TEST_TEARDOWN_TIMEOUT ]; then
+if [ -z ${LTTNG_TEST_TEARDOWN_TIMEOUT+x} ]; then
LTTNG_TEST_TEARDOWN_TIMEOUT=60
fi
# Bail out on failure
function validate_lttng_modules_present ()
{
+ # Check for loadable modules.
modprobe -n lttng-tracer 2>/dev/null
- if [ $? -ne 0 ]; then
- BAIL_OUT "LTTng modules not detected."
+ if [ $? -eq 0 ]; then
+ return 0
+ fi
+
+ # Check for builtin modules.
+ ls /proc/lttng > /dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ return 0
fi
+
+ BAIL_OUT "LTTng modules not detected."
}
function enable_kernel_lttng_event
if [ -n "$modules" ]; then
diag "Unloading all LTTng modules"
- modprobe -r "$modules"
+ modprobe --remove "$modules"
fi
fi
fi
local sess_name="$1"
local event_name="$2"
local filter="$3"
+ local channel_name=$4
+
+ if [ -z $channel_name ]; then
+ # default channel if none specified
+ chan=""
+ else
+ chan="-c $channel_name"
+ fi
- $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
+ $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $chan "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
ok $? "Enable event $event_name with filtering for session $sess_name"
}
function lttng_snapshot_record ()
{
local sess_name=$1
+ local trace_path=$2
- $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name $trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
+ $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s "$sess_name" "$trace_path" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
ok $? "Snapshot recorded"
}
add_context_lttng 1 -k "$@"
}
-function validate_directory_empty ()
-{
- local trace_path=$1
-
- ls -A $local_path > /dev/null 2>&1
- if [ $? -eq 0 ]; then
- pass "Directory empty"
- else
- fail "Directory empty"
- fi
-}
-
function wait_live_trace_ready ()
{
local url=$1
return $ret
}
-function validate_folder_is_empty()
+function validate_directory_empty ()
{
- local folder=$1
+ local trace_path="$1"
- test -z "$(ls -A "$folder")"
- ok $? "Folder ${folder} is empty"
+ # Do not double quote `$trace_path` below as we want wildcards to be
+ # expanded.
+ files="$(ls -A $trace_path)"
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ fail "Failed to list content of directory \"$trace_path\""
+ return $ret
+ fi
+
+ nb_files="$(echo -n "$files" | wc -l)"
+ ok $nb_files "Directory \"$trace_path\" is empty"
}
function validate_trace_session_ust_empty()
{
- validate_folder_is_empty "$1"/ust
+ validate_directory_empty "$1"/ust
}
function validate_trace_session_kernel_empty()
function destructive_tests_enabled ()
{
- if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then
+ if [ "$LTTNG_ENABLE_DESTRUCTIVE_TESTS" = "will-break-my-system" ]; then
return 0
else
return 1
$TESTDIR/../src/bin/lttng/$LTTNG_BIN clear --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
ok $? "Clear all lttng sessions"
}
+
+function validate_path_pattern ()
+{
+ local message=$1
+ local pattern=$2
+ # Base path is only used in error case and is used to list the content
+ # of the base path.
+ local base_path=$3
+
+
+ [ -f $pattern ]
+ ret=$?
+ ok $ret "$message"
+
+ if [ "$ret" -ne "0" ]; then
+ diag "Path pattern expected: $pattern"
+ # List the tracepath for more info. We use find as a recursive
+ # directory lister.
+ diag "The base path content:"
+ find "$base_path" -print
+ fi
+}
+
+function validate_trace_path_ust_uid ()
+{
+ local trace_path=$1
+ local session_name=$2
+ local uid=$UID
+ local pattern="$trace_path/$session_name-$date_time_pattern/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
+
+ validate_path_pattern "UST per-uid trace path is valid" "$pattern" "$trace_path"
+}
+
+function validate_trace_path_ust_uid_network ()
+{
+ local trace_path=$1
+ local session_name=$2
+ local base_path=$3
+ local uid=$UID
+ local hostname=$HOSTNAME
+ local pattern
+ local ret
+
+ # If the session was given a network base path (e.g
+ # 127.0.0.1/my/custom/path on creation, there is no session name
+ # component to the path on the relayd side. Caller can simply not pass a
+ # session name for this scenario.
+ if [ -n "$session_name" ]; then
+ session_name="$session_name-$date_time_pattern"
+ if [ -n "$base_path" ]; then
+ fail "Session name and base path are mutually exclusive"
+ return
+ fi
+ fi
+
+ pattern="$trace_path/$hostname/$base_path/$session_name/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
+
+ validate_path_pattern "UST per-uid network trace path is valid" "$pattern" "$trace_path"
+}
+
+function validate_trace_path_ust_uid_snapshot_network ()
+{
+ local trace_path=$1
+ local session_name=$2
+ local snapshot_name=$3
+ local snapshot_number=$4
+ local base_path=$5
+ local hostname=$HOSTNAME
+ local uid=$UID
+ local pattern
+ local ret
+
+ # If the session/output was given a network base path (e.g
+ # 127.0.0.1/my/custom/path on creation, there is no session name
+ # component to the path on the relayd side. Caller can simply not pass a
+ # session name for this scenario.
+ if [ -n "$session_name" ]; then
+ session_name="$session_name-$date_time_pattern"
+ if [ -n "$base_path" ]; then
+ fail "Session name and base path are mutually exclusive"
+ return
+ fi
+ fi
+
+ pattern="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
+
+ validate_path_pattern "UST per-uid network snapshot trace path is valid" "$pattern" "$trace_path"
+}
+
+function validate_trace_path_ust_uid_snapshot ()
+{
+ local trace_path=$1
+ local session_name=$2
+ local snapshot_name=$3
+ local snapshot_number=$4
+ local base_path=$5
+ local uid=$UID
+ local pattern
+ local ret
+
+ # If the session/output was given a network base path (e.g
+ # 127.0.0.1/my/custom/path) on creation, there is no session name
+ # component to the path on the relayd side. Caller can simply not pass a
+ # session name for this scenario.
+ if [ -n "$session_name" ]; then
+ session_name="$session_name-$date_time_pattern"
+ if [ -n "$base_path" ]; then
+ fail "Session name and base path are mutually exclusive"
+ return
+ fi
+ fi
+
+ pattern="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata"
+
+ validate_path_pattern "UST per-uid snapshot trace path is valid" "$pattern" "$trace_path"
+}
+
+function validate_trace_path_ust_pid ()
+{
+ local trace_path=$1
+ local session_name=$2
+ local app_string=$3
+ local pid=$4
+ local pattern
+ local ret
+
+ # If the session was given a trace path on creation, there is no session
+ # name component to the path. Caller can simply not pass a session name
+ # for this scenario.
+ if [ -n "$session_name" ]; then
+ session_name="$session_name-$date_time_pattern"
+ fi
+
+ pattern="$trace_path/$session_name/ust/pid/$pid/$app_string-*-$date_time_pattern/metadata"
+
+ validate_path_pattern "UST per-pid trace path is valid" "$pattern" "$trace_path"
+}
+
+function validate_trace_path_kernel ()
+{
+ local trace_path=$1
+ local session_name=$2
+ local pattern
+
+ # If the session was given a trace path on creation, there is no session
+ # name component to the path. Caller can simply not pass a session name
+ # for this scenario.
+ if [ -n "$session_name" ]; then
+ session_name="$session_name-$date_time_pattern"
+ fi
+
+ pattern="$trace_path/$session_name/kernel/metadata"
+
+ validate_path_pattern "Kernel trace path is valid" "$pattern" "$trace_path"
+}
+
+function validate_trace_path_kernel_network ()
+{
+ local trace_path=$1
+ local session_name=$2
+ local hostname=$HOSTNAME
+ local pattern="$trace_path/$hostname/$session_name-$date_time_pattern/kernel/metadata"
+
+ validate_path_pattern "Kernel network trace path is valid" "$pattern" "$trace_path"
+}
+
+function validate_trace_path_kernel_snapshot ()
+{
+ local trace_path=$1
+ local session_name=$2
+ local snapshot_name=$3
+ local snapshot_number=$4
+ local base_path=$5
+ local pattern
+ local ret
+
+ # If the session/output was given a network base path (e.g
+ # 127.0.0.1/my/custom/path on creation, there is no session name
+ # component to the path on the relayd side. Caller can simply not pass a
+ # session name for this scenario.
+ if [ -n "$session_name" ]; then
+ session_name="$session_name-$date_time_pattern"
+ if [ -n "$base_path" ]; then
+ fail "Session name and base path are mutually exclusive"
+ return
+ fi
+ fi
+
+ pattern="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata"
+
+ validate_path_pattern "Kernel snapshot trace path is valid" "$pattern" "$trace_path"
+}
+
+function validate_trace_path_kernel_snapshot_network ()
+{
+ local trace_path=$1
+ local session_name=$2
+ local snapshot_name=$3
+ local snapshot_number=$4
+ local base_path=$5
+ local hostname=$HOSTNAME
+ local pattern
+ local ret
+
+ # If the session/output was given a network base path (e.g
+ # 127.0.0.1/my/custom/path on creation, there is no session name
+ # component to the path on the relayd side. Caller can simply not pass a
+ # session name for this scenario.
+ if [ -n "$session_name" ]; then
+ session_name="$session_name-$date_time_pattern"
+ if [ -n "$base_path" ]; then
+ fail "Session name and base path are mutually exclusive"
+ return
+ fi
+ fi
+
+ pattern="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata"
+
+ validate_path_pattern "Kernel network snapshot trace path is valid" "$pattern" "$trace_path"
+}