Tests: metadata env scope values
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Thu, 5 Sep 2019 23:24:04 +0000 (19:24 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 5 Sep 2019 23:26:20 +0000 (19:26 -0400)
The tests extract information from the metadata env scope of the trace
and reconstruct an lttng directory hierarchy to validate that the
information found in the metadata is correct.

Testing this way simulate a viewer that must reconstruct a lttng directory
hierarchy from metadata information only. This information is mostly there
for this purpose.

While there we validate the value of other env field when possible.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
configure.ac
tests/regression/Makefile.am
tests/regression/tools/Makefile.am
tests/regression/tools/metadata/Makefile.am [new file with mode: 0644]
tests/regression/tools/metadata/test_kernel [new file with mode: 0755]
tests/regression/tools/metadata/test_ust [new file with mode: 0755]
tests/regression/tools/metadata/utils.sh [new file with mode: 0644]
tests/utils/utils.sh

index f001bd6c3141bf680a017ee977dea5e8cf4218ef..0a6e5aac20d565ca914442e0ee6d7ea1a8f0c019 100644 (file)
@@ -1133,6 +1133,7 @@ AC_CONFIG_FILES([
        tests/regression/tools/notification/Makefile
        tests/regression/tools/rotation/Makefile
        tests/regression/tools/base-path/Makefile
+       tests/regression/tools/metadata/Makefile
        tests/regression/ust/Makefile
        tests/regression/ust/nprocesses/Makefile
        tests/regression/ust/high-throughput/Makefile
index 7752404056e322cd97ec2f9c899956d8f4199f69..73eb9f7dae597ef1fe743ee1d5f094d66ef4a47e 100644 (file)
@@ -31,7 +31,8 @@ TESTS = tools/filtering/test_invalid_filter \
        tools/rotation/test_ust \
        tools/rotation/test_kernel \
        tools/rotation/test_save_load_mi \
-       tools/rotation/test_schedule_api
+       tools/rotation/test_schedule_api \
+       tools/metadata/test_kernel
 
 if HAVE_LIBLTTNG_UST_CTL
 SUBDIRS += ust
@@ -50,7 +51,8 @@ TESTS += ust/before-after/test_before_after \
        ust/test_event_perf \
        ust/blocking/test_blocking \
        ust/multi-lib/test_multi_lib \
-       ust/rotation-destroy-flush/test_rotation_destroy_flush
+       ust/rotation-destroy-flush/test_rotation_destroy_flush \
+       tools/metadata/test_ust
 endif # HAVE_LIBLTTNG_UST_CTL
 
 if PYTHON_BINDING
index 856eecc086a01ba29888d535721f256b01eb37f1..c5046759923474de80ebbbf0c87bf6190e2aff0f 100644 (file)
@@ -1,3 +1,3 @@
 SUBDIRS = streaming filtering health tracefile-limits snapshots live exclusion save-load mi \
                wildcard crash regen-metadata regen-statedump notification rotation \
-               base-path
+               base-path metadata
diff --git a/tests/regression/tools/metadata/Makefile.am b/tests/regression/tools/metadata/Makefile.am
new file mode 100644 (file)
index 0000000..0f839a1
--- /dev/null
@@ -0,0 +1,16 @@
+noinst_SCRIPTS = test_ust test_kernel utils.sh
+EXTRA_DIST = test_ust test_kernel utils.sh
+
+all-local:
+       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+               for script in $(EXTRA_DIST); do \
+                       cp -f $(srcdir)/$$script $(builddir); \
+               done; \
+       fi
+
+clean-local:
+       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+               for script in $(EXTRA_DIST); do \
+                       rm -f $(builddir)/$$script; \
+               done; \
+       fi
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"
diff --git a/tests/regression/tools/metadata/test_ust b/tests/regression/tools/metadata/test_ust
new file mode 100755 (executable)
index 0000000..529b0a2
--- /dev/null
@@ -0,0 +1,258 @@
+#!/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 - User space tracing"
+
+CURDIR=$(dirname "$0")/
+TESTDIR=$CURDIR/../../..
+TESTAPP_PATH="$TESTDIR/utils/testapp"
+TESTAPP_NAME="gen-ust-events"
+TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
+EVENT_NAME="tp:tptest"
+
+TRACE_PATH=$(mktemp -d)
+
+NUM_TESTS=37
+
+NR_ITER=10
+NR_USEC_WAIT=0
+
+source "$TESTDIR/utils/utils.sh"
+
+# Fetch utils functions common to ust and kernel tests.
+source "$CURDIR/utils.sh"
+
+if [ ! -x "$TESTAPP_BIN" ]; then
+       BAIL_OUT "No UST events binary detected."
+fi
+
+function test_per_uid ()
+{
+       local metadata
+       local metadata_env
+       local metadata_path
+       local value
+       local value2
+
+       local expected_path="${TRACE_PATH}/lttng-traces"
+       local session_name="per-uid"
+
+       metadata=$(mktemp)
+       metadata_env=$(mktemp)
+
+       diag "Test UST metadata env field in per-uid mode"
+       create_lttng_session_ok "$session_name"
+       enable_ust_lttng_event_ok "$session_name" $EVENT_NAME
+       start_lttng_tracing_ok "$session_name"
+
+       $TESTAPP_BIN $NR_ITER
+
+       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}"
+
+       # Buffering scheme
+       value=$(get_env_value "$metadata_env" tracer_buffering_scheme)
+       ok $? "Extracting tracer_buffering_scheme from env metadata"
+       expected_path="${expected_path}/${value}"
+
+       # tracer_buffering_id
+       value=$(get_env_value "$metadata_env" tracer_buffering_id)
+       ok $? "Extracting tracer_buffering_id from env metadata"
+       expected_path="${expected_path}/${value}"
+
+       # Check that the uid is the one we expect from the current user
+       is "$value" "$(id -u)" "tracer_buffering_id match current user uid"
+
+       # Architecture_bit_width
+       value=$(get_env_value "$metadata_env" architecture_bit_width)
+       ok $? "Extracting architecture_bit_width from env metadata"
+       expected_path="${expected_path}/${value}-bit"
+
+       # 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"
+}
+
+function test_per_pid ()
+{
+       local metadata
+       local metadata_env
+       local metadata_path
+       local testapp_pid
+       local value
+       local value2
+
+       local expected_path="${TRACE_PATH}/lttng-traces"
+       local session_name="per-pid"
+
+       metadata=$(mktemp)
+       metadata_env=$(mktemp)
+
+       diag "Test UST metadata env field in per-pid mode"
+       create_lttng_session_ok "$session_name"
+       enable_ust_lttng_channel_ok "$session_name" channel "--buffers-pid"
+       enable_ust_lttng_event_ok "$session_name" $EVENT_NAME channel
+       start_lttng_tracing_ok "$session_name"
+
+       $TESTAPP_BIN "$NR_ITER" "$NR_USEC_WAIT" &
+       testapp_pid=$!
+       wait $testapp_pid
+
+       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}" 1> "$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}"
+
+       # Buffering scheme
+       value=$(get_env_value "$metadata_env" tracer_buffering_scheme)
+       ok $? "Extracting tracer_buffering_scheme from env metadata"
+       expected_path="${expected_path}/${value}"
+
+       # Procname
+       value=$(get_env_value "$metadata_env" procname)
+       ok $? "Extracting procname from env metadata"
+       expected_path="${expected_path}/${value}"
+
+       # vpid and tracer_buffering_id should be the same here.
+       # "vpid =" is used since other key have vpid in them.
+       value=$(get_env_value "$metadata_env" "vpid =")
+       ok $? "Extracting vpid from env metadata"
+
+       value2=$(get_env_value "$metadata_env" tracer_buffering_id)
+       ok $? "Extracting tracer_buffering_id from env metadata"
+       expected_path="${expected_path}-${value2}"
+
+       is "$value" "$value2" "vpid and tracer_buffering_id are identical"
+       is "$testapp_pid" "$value" "vpid and known testapp pid are identical"
+       is "$testapp_pid" "$value2" "tracer_buffering_id and known testapp pid are identical"
+
+       # vpid_datetime
+       value=$(get_env_value "$metadata_env" vpid_datetime)
+       ok $? "Extracting vpid_datetime from env metadata"
+       value=$(iso8601_to_lttng_dir_datetime "$value")
+       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"
+
+# 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_per_uid test_per_pid )
+
+for fct_test in "${tests[@]}";
+do
+       ${fct_test}
+done
+
+stop_lttng_sessiond
+unset LTTNG_HOME
+
+rm -rf "$TRACE_PATH"
diff --git a/tests/regression/tools/metadata/utils.sh b/tests/regression/tools/metadata/utils.sh
new file mode 100644 (file)
index 0000000..89fa772
--- /dev/null
@@ -0,0 +1,59 @@
+#!/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
+
+function get_env_value ()
+{
+       local env_file=$1
+       local key=$2
+       local result
+       local ret
+
+       result=$(grep "$key" < "$env_file")
+       ret=$?
+       if [ $ret -eq 1 ]; then
+               echo "invalid_value_extraction"
+               return 1
+       else
+               # Strip the key using bash substring removal.
+               # This remove all leading chars until the actual value.
+               result=${result#* = }
+
+               # Remove the trailing ';'
+               result=${result:0:-1}
+
+               # Remove enclosing '"' if present
+               if [ "${result:0:1}" == '"' ]; then
+                       result=${result:1:-1}
+               fi
+
+               echo "$result"
+               return 0
+       fi
+}
+
+function iso8601_to_lttng_dir_datetime ()
+{
+       local result=$1
+
+       result=${result/T/-}
+
+       # Remove trailing timezone information including the '-'.
+       result=${result:0:-5}
+
+       echo "$result"
+       return 0
+}
index d156f17dad99b81685c2c0f36760767c485f618b..c17eb221c5a6e085fc1b443227eda49361c30b5f 100644 (file)
@@ -900,7 +900,14 @@ function create_lttng_session ()
        local trace_path=$4
        local opt=$5
 
-       $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path $opt > $OUTPUT_DEST
+       if [ -z "$trace_path" ]; then
+               # Use lttng-sessiond default output.
+               trace_path=""
+       else
+               trace_path="-o $trace_path"
+       fi
+
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN create "$sess_name" $trace_path $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
        ret=$?
        if [ $expected_to_fail -eq "1" ]; then
                test "$ret" -ne "0"
This page took 0.04677 seconds and 4 git commands to generate.