Test lttng-modules clock override plugin
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 11 May 2016 17:15:25 +0000 (13:15 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 14 May 2016 20:06:33 +0000 (16:06 -0400)
[ For both master and stable-2.8 branches. ]

Fixes: #939
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/regression/kernel/Makefile.am
tests/regression/kernel/test_clock_override [new file with mode: 0755]
tests/root_regression

index 36ff6eeac41759807994776e35aec6e9d022afca..ca73ed43ef6326ef663c423d0ba89409a9481c94 100644 (file)
@@ -1,4 +1,4 @@
-EXTRA_DIST = test_event_basic test_all_events test_syscall
+EXTRA_DIST = test_event_basic test_all_events test_syscall test_clock_override
 
 all-local:
        @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
diff --git a/tests/regression/kernel/test_clock_override b/tests/regression/kernel/test_clock_override
new file mode 100755 (executable)
index 0000000..c52ddf1
--- /dev/null
@@ -0,0 +1,209 @@
+#!/bin/bash
+#
+# Copyright (C) - 2013 Christian Babeux <christian.babeux@efficios.com>
+# Copyright (C) - 2014, 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License, version 2 only, as
+# published by the Free Software Foundation.
+#
+# This program 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 General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+TEST_DESC="Kernel tracer - Clock override plugin"
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/../..
+SESSION_NAME="clock_override"
+
+NUM_TESTS=30
+EVENT_NAME="lttng_test_filter_event"
+
+TESTCMD="echo -n 10 > /proc/lttng-test-filter-event"
+
+METADATA_CLOCK_START_TOKEN="clock {"
+METADATA_CLOCK_END_TOKEN="};"
+
+METADATA_TOKEN_LIST=(
+       "name"
+       "uuid"
+       "description"
+       "freq"
+)
+
+CLOCK_TOKEN_VALUE=(
+       "lttng_test_clock_override"
+       "83c63deb-7aa4-48fb-abda-946f400d76e6"
+       "Freeze time with 1KHz for regression test"
+       "1000"
+)
+
+source $TESTDIR/utils/utils.sh
+
+function signal_cleanup()
+{
+       diag "*** Exiting ***"
+       rmmod lttng-test
+       stop_lttng_sessiond
+       rmmod lttng-clock-plugin-test
+       rmmod lttng-clock
+       exit 1
+}
+
+function extract_clock_metadata()
+{
+       local metadata_file=$1
+       local clock_metadata_file_destination=$2
+       cat $metadata_file \
+               | sed -n "/$METADATA_CLOCK_START_TOKEN/,/$METADATA_CLOCK_END_TOKEN/p" \
+               > $clock_metadata_file_destination
+       ok $? "Clock metadata extraction"
+}
+
+function extract_clock_metadata_token()
+{
+       local clock_metadata_file=$1
+       local token=$2
+       # Look for token and get value between ""
+       cat $clock_metadata_file | grep $token | awk -F"= |;" '{print $2}' | tr -d '"'
+}
+
+function test_clock_override_metadata()
+{
+       local ctf_metadata_file=$(mktemp -p $TRACE_PATH ctf-metadata.XXXXX)
+       local clock_metadata_file=$(mktemp -p $TRACE_PATH clock-metadata.XXXXX)
+       local result=""
+
+       diag "Clock override plugin metadata test"
+
+       modprobe lttng-clock-plugin-test
+       start_lttng_sessiond
+       modprobe lttng-test
+
+       create_lttng_session_ok $SESSION_NAME $TRACE_PATH
+       enable_kernel_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
+       start_lttng_tracing_ok $SESSION_NAME
+       eval ${TESTCMD}
+       stop_lttng_tracing_ok $SESSION_NAME
+       destroy_lttng_session_ok $SESSION_NAME
+
+       rmmod lttng-test
+       stop_lttng_sessiond
+       rmmod lttng-clock-plugin-test
+       rmmod lttng-clock
+
+       $BABELTRACE_BIN -o ctf-metadata -w $ctf_metadata_file $TRACE_PATH
+       ok $? "Metadata extraction from babeltrace"
+
+       extract_clock_metadata $ctf_metadata_file $clock_metadata_file
+
+       test ${#METADATA_TOKEN_LIST[@]} -eq ${#CLOCK_TOKEN_VALUE[@]}
+       ok $? "Tokens to check(${#METADATA_TOKEN_LIST[@]}) and provided values(${#CLOCK_TOKEN_VALUE[@]}) count is equal"
+
+       local counter=0
+       while [ "$counter" -lt "${#METADATA_TOKEN_LIST[@]}" ]; do
+               result=$(extract_clock_metadata_token $clock_metadata_file \
+                       ${METADATA_TOKEN_LIST[$counter]})
+               test "$result" == "${CLOCK_TOKEN_VALUE[$counter]}"
+               ok $? "Token \"${METADATA_TOKEN_LIST[$counter]}\" expect:${CLOCK_TOKEN_VALUE[$counter]} got:$result"
+               let "counter++"
+       done
+       rm -rf $ctf_metadata_file
+       rm -rf $clock_metadata_file
+}
+
+function test_clock_override_timestamp()
+{
+       diag "Clock override test"
+
+       # Test without the plugin
+       diag "Plugin disabled"
+
+       start_lttng_sessiond
+       modprobe lttng-test
+
+       create_lttng_session_ok $SESSION_NAME $TRACE_PATH
+       enable_kernel_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
+       start_lttng_tracing_ok $SESSION_NAME
+       eval ${TESTCMD}
+       stop_lttng_tracing_ok $SESSION_NAME
+       destroy_lttng_session_ok $SESSION_NAME
+
+       # Use Babeltrace with "-n all" to give a comma separated list for
+       # easy extraction of timestamps.
+       unique_timestamps_count=$($BABELTRACE_BIN -n all $TRACE_PATH | \
+               cut -d, -f1 | uniq | wc -l)
+       test $unique_timestamps_count -gt 1
+       ok $? "Unique event timestamps without clock override: $unique_timestamps_count expect >1"
+       rmmod lttng-test
+       stop_lttng_sessiond
+
+       # Test with clock override plugin.
+       diag "Plugin enabled"
+
+       modprobe lttng-clock-plugin-test
+       start_lttng_sessiond
+       modprobe lttng-test
+
+       start_lttng_sessiond
+       create_lttng_session_ok $SESSION_NAME $TRACE_PATH
+       enable_kernel_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
+       start_lttng_tracing_ok $SESSION_NAME
+       eval ${TESTCMD}
+       stop_lttng_tracing_ok $SESSION_NAME
+       destroy_lttng_session_ok $SESSION_NAME
+
+       rmmod lttng-test
+       stop_lttng_sessiond
+       rmmod lttng-clock-plugin-test
+       rmmod lttng-clock
+
+       # Use Babeltrace with "-n all" to give a comma separated list for
+       # easy extraction of timestamps.
+       unique_timestamps_count=$($BABELTRACE_BIN -n all $TRACE_PATH | \
+               cut -d, -f1 | uniq | wc -l)
+       test $unique_timestamps_count -eq 1
+       ok $? "Unique event timestamps with clock override: $unique_timestamps_count expect 1"
+}
+
+# MUST set TESTDIR before calling those functions
+plan_tests $NUM_TESTS
+
+print_test_banner "$TEST_DESC"
+
+TESTS=(
+       "test_clock_override_metadata"
+       "test_clock_override_timestamp"
+)
+
+TEST_COUNT=${#TESTS[@]}
+i=0
+
+if [ "$(id -u)" == "0" ]; then
+       isroot=1
+else
+       isroot=0
+fi
+
+skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
+{
+       trap signal_cleanup SIGTERM SIGINT
+
+       while [ "$i" -lt "$TEST_COUNT" ]; do
+
+               TRACE_PATH=$(mktemp -d)
+
+               # Execute test
+               ${TESTS[$i]}
+
+               rm -rf $TRACE_PATH
+
+               let "i++"
+       done
+}
index 869c560cfdb12c159de94b74023698a15419b0a4..4655c091cd4c10e86144a606546b393b34bb9251 100644 (file)
@@ -1,6 +1,7 @@
 regression/kernel/test_all_events
 regression/kernel/test_event_basic
 regression/kernel/test_syscall
+regression/kernel/test_clock_override
 regression/tools/live/test_kernel
 regression/tools/live/test_lttng_kernel
 regression/tools/streaming/test_high_throughput_limits
This page took 0.06537 seconds and 4 git commands to generate.