X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=tests%2Fregression%2Ftools%2Fmetadata%2Ftest_kernel;h=9e1e81232128d6000fffb55df13502ff068131cf;hb=b7a2f86d3d9b2554f80dcf684d9bd90bbf7a3213;hp=c0a039289b326be649fadac458992dd8d01eb8fe;hpb=01654d6926771be58b4350463b0f12ea2e6aa34c;p=lttng-tools.git diff --git a/tests/regression/tools/metadata/test_kernel b/tests/regression/tools/metadata/test_kernel index c0a039289..9e1e81232 100755 --- a/tests/regression/tools/metadata/test_kernel +++ b/tests/regression/tools/metadata/test_kernel @@ -1,26 +1,16 @@ #!/bin/bash # -# Copyright (C) - 2019 Jonathan Rajotte-Julien +# Copyright (C) 2019 Jonathan Rajotte # -# 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 +# SPDX-License-Identifier: LGPL-2.1-only + TEST_DESC="Metadata env - Kernel space tracing" CURDIR=$(dirname "$0")/ TESTDIR=$CURDIR/../../.. EVENT_NAME="lttng_test_filter_event" -TRACE_PATH=$(mktemp -d) +TRACE_PATH=$(mktemp -d -t tmp.test_metadata_env_kernel_trace_path.XXXXXX) NUM_TESTS=13 @@ -31,16 +21,15 @@ source "$CURDIR/utils.sh" function test_kernel () { + local metadata_path 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) + metadata=$(mktemp -t "tmp.test_kernel_metadata.XXXXXX") + metadata_env=$(mktemp -t "tmp.test_kernel_metadata_env.XXXXXX") diag "Test Kernel metadata env field" create_lttng_session_ok "$session_name" @@ -55,7 +44,7 @@ function test_kernel () # 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=$(find "${expected_path}/${session_name}"* -name "metadata") metadata_path=$(dirname "$metadata_path") $BABELTRACE_BIN --output-format=ctf-metadata "${metadata_path}" > "$metadata" @@ -68,33 +57,37 @@ function test_kernel () # 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}" + local trace_name + trace_name=$(get_env_value "$metadata_env" trace_name) + ok $? "Extracting trace_name from env metadata: \`$trace_name\`" + expected_path="${expected_path}/${trace_name}" # 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}" + local trace_creation_datetime + trace_creation_datetime=$(get_env_value "$metadata_env" trace_creation_datetime) + ok $? "Extracting trace_creation_datetime from env metadata: \`$trace_creation_datetime\`" + trace_creation_datetime=$(iso8601_to_lttng_dir_datetime "$trace_creation_datetime") + expected_path="${expected_path}-${trace_creation_datetime}" # Domain - value=$(get_env_value "$metadata_env" domain) - ok $? "Extracting domain from env metadata" - expected_path="${expected_path}/${value}" + local domain + domain=$(get_env_value "$metadata_env" domain) + ok $? "Extracting domain from env metadata: \`$domain\`" + expected_path="${expected_path}/${domain}" # 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" + test -f "$expected_path" + ok $? "Reconstructed path from metadata is an existing file: \`$expected_path\`" # 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" + local hostname + hostname=$(get_env_value "$metadata_env" hostname) + ok $? "Extracting hostname from env metadata: \`$hostname\`" + is "$hostname" "$(hostname)" "Extracted hostname matches current hostname" rm -f "$metadata" rm -f "$metadata_env" @@ -103,6 +96,7 @@ function test_kernel () plan_tests $NUM_TESTS print_test_banner "$TEST_DESC" +bail_out_if_no_babeltrace if [ "$(id -u)" == "0" ]; then isroot=1 @@ -117,9 +111,8 @@ skip $isroot "Root access is needed. Skipping all kernel metadata tests." $NUM_T # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy # with "-/...". - LTTNG_HOME="$TRACE_PATH" + export LTTNG_HOME="$TRACE_PATH" - export LTTNG_HOME start_lttng_sessiond tests=( test_kernel ) @@ -129,7 +122,7 @@ skip $isroot "Root access is needed. Skipping all kernel metadata tests." $NUM_T ${fct_test} done - rmmod lttng-test + modprobe --remove lttng-test stop_lttng_sessiond unset LTTNG_HOME