Tests: metadata env scope values
[lttng-tools.git] / tests / regression / tools / metadata / test_kernel
diff --git a/tests/regression/tools/metadata/test_kernel b/tests/regression/tools/metadata/test_kernel
new file mode 100755 (executable)
index 0000000..c0a0392
--- /dev/null
@@ -0,0 +1,138 @@
+#!/bin/bash
+#
+# Copyright (C) - 2019 Jonathan Rajotte-Julien <jonathan.rajotte-julien@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.
+#
+# 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
+TEST_DESC="Metadata env - Kernel space tracing"
+
+CURDIR=$(dirname "$0")/
+TESTDIR=$CURDIR/../../..
+EVENT_NAME="lttng_test_filter_event"
+
+TRACE_PATH=$(mktemp -d)
+
+NUM_TESTS=13
+
+source "$TESTDIR/utils/utils.sh"
+
+# Fetch utils functions common to ust and kernel tests.
+source "$CURDIR/utils.sh"
+
+function test_kernel ()
+{
+       local metadata
+       local metadata_env
+       local metadata_path
+       local value
+
+       local expected_path="${TRACE_PATH}/lttng-traces"
+       local session_name="kernel"
+
+       metadata=$(mktemp)
+       metadata_env=$(mktemp)
+
+       diag "Test Kernel metadata env field"
+       create_lttng_session_ok "$session_name"
+       enable_kernel_lttng_event_ok "$session_name" "$EVENT_NAME"
+       start_lttng_tracing_ok "$session_name"
+
+       echo -n "10" > /proc/lttng-test-filter-event
+
+       stop_lttng_tracing_ok "$session_name"
+       destroy_lttng_session_ok "$session_name"
+
+       # bt1 accepts only a directory while bt2 accepts either the metadata
+       # file directly or a directory with an immediate metadata file.
+       # Settle for the common denominator.
+       metadata_path=$(find "${expected_path}/${session_name}"* | grep metadata)
+       metadata_path=$(dirname "$metadata_path")
+
+       $BABELTRACE_BIN --output-format=ctf-metadata "${metadata_path}" > "$metadata"
+
+       # Extract "env" scope
+       awk '/env {/,/};/' < "$metadata" > "$metadata_env"
+
+       # Construct the expected path from the env metadata and use it to
+       # validate that all information make sense. This information is present
+       # to allow trace viewer to recreate the same directory hierarchy.
+
+       # Trace name
+       value=$(get_env_value "$metadata_env" trace_name)
+       ok $? "Extracting trace_name from env metadata"
+       expected_path="${expected_path}/${value}"
+
+       # Session creation time
+       value=$(get_env_value "$metadata_env" trace_creation_datetime)
+       ok $? "Extracting trace_creation_datetime from env metadata"
+       value=$(iso8601_to_lttng_dir_datetime "$value")
+       expected_path="${expected_path}-${value}"
+
+       # Domain
+       value=$(get_env_value "$metadata_env" domain)
+       ok $? "Extracting domain from env metadata"
+       expected_path="${expected_path}/${value}"
+
+       # Append "metadata" and test that we find the file.
+       expected_path="${expected_path}/metadata"
+
+       test -e "$expected_path"
+       ok $? "Reconstructed path from metadata is valid"
+
+       # Hostname
+       # The hostname is not part of the lttng hierarchy still we can test for
+       # its validity here.
+       value=$(get_env_value "$metadata_env" hostname)
+       ok $? "Extracting hostname from env metadata"
+       is "$value" "$(hostname)" "Hostname is valid"
+
+       rm -f "$metadata"
+       rm -f "$metadata_env"
+}
+
+plan_tests $NUM_TESTS
+print_test_banner "$TEST_DESC"
+
+
+if [ "$(id -u)" == "0" ]; then
+       isroot=1
+else
+       isroot=0
+fi
+
+skip $isroot "Root access is needed. Skipping all kernel metadata tests." $NUM_TESTS ||
+{
+       validate_lttng_modules_present
+       modprobe lttng-test
+
+       # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
+       # with "<session_name>-<datetime>/...".
+       LTTNG_HOME="$TRACE_PATH"
+
+       export LTTNG_HOME
+       start_lttng_sessiond
+
+       tests=( test_kernel )
+
+       for fct_test in "${tests[@]}";
+       do
+               ${fct_test}
+       done
+
+       rmmod lttng-test
+
+       stop_lttng_sessiond
+       unset LTTNG_HOME
+}
+
+rm -rf "$TRACE_PATH"
This page took 0.024834 seconds and 4 git commands to generate.