[lttng-dev] [PATCH lttng-tools] Test lttng-modules clock override plugin

Jérémie Galarneau jeremie.galarneau at efficios.com
Sat May 14 20:56:44 UTC 2016


Merged in master and stable-2.8. I have added the test to the
root_regression test suite.

Thanks!
Jérémie

On Wed, May 11, 2016 at 1:15 PM, Mathieu Desnoyers
<mathieu.desnoyers at efficios.com> wrote:
> [ For both master and stable-2.8 branches. ]
>
> Fixes: #939
>
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
> ---
>  tests/regression/kernel/Makefile.am         |   2 +-
>  tests/regression/kernel/test_clock_override | 209 ++++++++++++++++++++++++++++
>  2 files changed, 210 insertions(+), 1 deletion(-)
>  create mode 100755 tests/regression/kernel/test_clock_override
>
> diff --git a/tests/regression/kernel/Makefile.am b/tests/regression/kernel/Makefile.am
> index 36ff6ee..ca73ed4 100644
> --- a/tests/regression/kernel/Makefile.am
> +++ b/tests/regression/kernel/Makefile.am
> @@ -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
> index 0000000..c52ddf1
> --- /dev/null
> +++ b/tests/regression/kernel/test_clock_override
> @@ -0,0 +1,209 @@
> +#!/bin/bash
> +#
> +# Copyright (C) - 2013 Christian Babeux <christian.babeux at efficios.com>
> +# Copyright (C) - 2014, 2016 Mathieu Desnoyers <mathieu.desnoyers at 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
> +}
> --
> 2.1.4
>



-- 
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com


More information about the lttng-dev mailing list