[lttng-dev] [PATCH lttng-tools 5/6] Tests for the regenerate statedump command
Mathieu Desnoyers
mathieu.desnoyers at efficios.com
Thu Jun 30 18:30:08 UTC 2016
----- On Jun 30, 2016, at 12:36 PM, Julien Desfossez jdesfossez at efficios.com wrote:
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
> Signed-off-by: Julien Desfossez <jdesfossez at efficios.com>
> ---
> configure.ac | 1 +
> tests/fast_regression | 1 +
> tests/regression/tools/Makefile.am | 2 +-
> tests/regression/tools/regen-statedump/Makefile.am | 16 ++++
> tests/regression/tools/regen-statedump/test_kernel | 80 +++++++++++++++++++
> tests/regression/tools/regen-statedump/test_ust | 89 ++++++++++++++++++++++
> tests/root_regression | 1 +
> tests/utils/utils.sh | 54 +++++++++++++
> 8 files changed, 243 insertions(+), 1 deletion(-)
> create mode 100644 tests/regression/tools/regen-statedump/Makefile.am
> create mode 100755 tests/regression/tools/regen-statedump/test_kernel
> create mode 100755 tests/regression/tools/regen-statedump/test_ust
>
> diff --git a/configure.ac b/configure.ac
> index 89a7858..6222e2b 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -981,6 +981,7 @@ AC_CONFIG_FILES([
> tests/regression/tools/wildcard/Makefile
> tests/regression/tools/crash/Makefile
> tests/regression/tools/regen-metadata/Makefile
> + tests/regression/tools/regen-statedump/Makefile
> tests/regression/ust/Makefile
> tests/regression/ust/nprocesses/Makefile
> tests/regression/ust/high-throughput/Makefile
> diff --git a/tests/fast_regression b/tests/fast_regression
> index 262c846..8edbeca 100644
> --- a/tests/fast_regression
> +++ b/tests/fast_regression
> @@ -17,6 +17,7 @@ regression/tools/mi/test_mi
> regression/tools/wildcard/test_event_wildcard
> regression/tools/crash/test_crash
> regression/tools/regen-metadata/test_ust
> +regression/tools/regen-statedump/test_ust
> regression/ust/before-after/test_before_after
> regression/ust/buffers-pid/test_buffers_pid
> regression/ust/multi-session/test_multi_session
> diff --git a/tests/regression/tools/Makefile.am
> b/tests/regression/tools/Makefile.am
> index 91820ad..76374c7 100644
> --- a/tests/regression/tools/Makefile.am
> +++ b/tests/regression/tools/Makefile.am
> @@ -1,2 +1,2 @@
> SUBDIRS = streaming filtering health tracefile-limits snapshots live exclusion
> save-load mi \
> - wildcard crash regen-metadata
> + wildcard crash regen-metadata regen-statedump
> diff --git a/tests/regression/tools/regen-statedump/Makefile.am
> b/tests/regression/tools/regen-statedump/Makefile.am
> new file mode 100644
> index 0000000..d4a92eb
> --- /dev/null
> +++ b/tests/regression/tools/regen-statedump/Makefile.am
> @@ -0,0 +1,16 @@
> +noinst_SCRIPTS = test_ust test_kernel
> +EXTRA_DIST = test_ust test_kernel
> +
> +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/regen-statedump/test_kernel
> b/tests/regression/tools/regen-statedump/test_kernel
> new file mode 100755
> index 0000000..85afe76
> --- /dev/null
> +++ b/tests/regression/tools/regen-statedump/test_kernel
> @@ -0,0 +1,80 @@
> +#!/bin/bash
> +#
> +# Copyright (C) - 2016 Julien Desfossez <jdesfossez at 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="Regenerate the statedump - Kernel tracing"
> +
> +CURDIR=$(dirname $0)/
> +TESTDIR=$CURDIR/../../..
> +EVENT_NAME="lttng_test_filter_event"
> +PID_RELAYD=0
> +SESSION_NAME=""
> +EVENT_NAME="lttng_statedump_start,lttng_statedump_end"
> +
> +TRACE_PATH=$(mktemp -d)
> +
> +NUM_TESTS=11
> +
> +source $TESTDIR/utils/utils.sh
> +
> +# LTTng kernel modules check
> +out=`ls /lib/modules/$(uname -r)/extra | grep lttng`
> +if [ -z "$out" ]; then
> + BAIL_OUT "LTTng modules not detected."
> +fi
> +
> +function test_kernel_local ()
> +{
> + diag "Test kernel local with statedump regeneration"
> + create_lttng_session_ok $SESSION_NAME $TRACE_PATH
> + lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME
> + start_lttng_tracing_ok $SESSION_NAME
> + echo -n "100" > /proc/lttng-test-filter-event
> + regenerate_statedump_ok $SESSION_NAME
> + stop_lttng_tracing_ok $SESSION_NAME
> + validate_trace_count $EVENT_NAME $TRACE_PATH 4
> + if [ $? -eq 0 ]; then
> + # Only delete if successful
> + rm -rf $TRACE_PATH
> + fi
> + destroy_lttng_session_ok $SESSION_NAME
> +}
> +
> +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 streaming tests."
> $NUM_TESTS ||
> +{
> + start_lttng_sessiond
> + modprobe lttng-test
> +
> + tests=( test_kernel_local )
> +
> + for fct_test in ${tests[@]};
> + do
> + SESSION_NAME=$(randstring 16 0)
> + ${fct_test}
> + done
> +
> + rmmod lttng-test
> + stop_lttng_sessiond
> +}
> diff --git a/tests/regression/tools/regen-statedump/test_ust
> b/tests/regression/tools/regen-statedump/test_ust
> new file mode 100755
> index 0000000..486b9a5
> --- /dev/null
> +++ b/tests/regression/tools/regen-statedump/test_ust
> @@ -0,0 +1,89 @@
> +#!/bin/bash
> +#
> +# Copyright (C) - 2016 Julien Desfossez <jdesfossez at 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="Regenerate the statedump - User-space tracing"
> +
> +CURDIR=$(dirname $0)/
> +TESTDIR=$CURDIR/../../..
> +NR_ITER=10
> +NR_USEC_WAIT=0
> +TESTAPP_PATH="$TESTDIR/utils/testapp"
> +TESTAPP_NAME="gen-ust-events"
> +TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
> +SESSION_NAME="stream"
> +EVENT_NAME="lttng_ust_statedump:start,lttng_ust_statedump:end"
> +PID_RELAYD=0
> +
> +TRACE_PATH=$(mktemp -d)
> +
> +NUM_TESTS=11
> +
> +source $TESTDIR/utils/utils.sh
> +
> +if [ ! -x "$TESTAPP_BIN" ]; then
> + BAIL_OUT "No UST events binary detected."
> +fi
> +
> +function test_ust_local ()
> +{
> + local file_sync_after_first=$(mktemp -u)
> + local file_sync_before_last=$(mktemp -u)
> +
> + diag "Test UST local with statedump regeneration"
> + create_lttng_session_ok $SESSION_NAME $TRACE_PATH
> + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
> +
> + $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first}
> ${file_sync_before_last} /dev/null 2>&1 &
> +
> + start_lttng_tracing_ok $SESSION_NAME
> +
> + while [ ! -f "${file_sync_after_first}" ]; do
> + sleep 0.5
> + done
> +
> + regenerate_statedump_ok $SESSION_NAME
> +
> + touch ${file_sync_before_last}
> +
> + stop_lttng_tracing_ok $SESSION_NAME
> + destroy_lttng_session_ok $SESSION_NAME
> + # Validate test
> + validate_trace_count $EVENT_NAME $TRACE_PATH 4
> + if [ $? -eq 0 ]; then
> + # Only delete if successful
> + rm -rf $TRACE_PATH
> + fi
> + rm -f ${file_sync_after_first}
> + rm -f ${file_sync_before_last}
> +}
> +
> +plan_tests $NUM_TESTS
> +
> +print_test_banner "$TEST_DESC"
> +
> +start_lttng_sessiond
> +
> +tests=( test_ust_local )
> +
> +for fct_test in ${tests[@]};
> +do
> + SESSION_NAME=$(randstring 16 0)
> + ${fct_test}
> +done
> +
> +stop_lttng_sessiond
> +
> +exit $out
> diff --git a/tests/root_regression b/tests/root_regression
> index d0fad04..d3eaf23 100644
> --- a/tests/root_regression
> +++ b/tests/root_regression
> @@ -15,4 +15,5 @@ regression/tools/filtering/test_unsupported_op
> regression/tools/filtering/test_valid_filter
> regression/tools/wildcard/test_event_wildcard
> regression/tools/regen-metadata/test_kernel
> +regression/tools/regen-statedump/test_kernel
> regression/ust/test_event_perf
> diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh
> index 3d744e2..c56a8aa 100644
> --- a/tests/utils/utils.sh
> +++ b/tests/utils/utils.sh
> @@ -1294,6 +1294,35 @@ function validate_trace
> return $ret
> }
>
> +function validate_trace_count
> +{
> + local event_name=$1
> + local trace_path=$2
> + local expected_count=$3
> +
> + which $BABELTRACE_BIN >/dev/null
> + if [ $? -ne 0 ]; then
> + skip 0 "Babeltrace binary not found. Skipping trace validation"
> + fi
> +
> + cnt=0
> + OLDIFS=$IFS
> + IFS=","
> + for i in $event_name; do
> + traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l)
> + if [ "$traced" -ne 0 ]; then
> + pass "Validate trace for event $i, $traced events"
> + else
> + fail "Validate trace for event $i"
> + diag "Found $traced occurences of $i"
> + fi
> + cnt=$(($cnt + $traced))
> + done
> + IFS=$OLDIFS
> + test $cnt -eq $expected_count
> + ok $? "Read a total of $cnt events, expected $expected_count"
> +}
> +
> function trace_first_line
> {
> local trace_path=$1
> @@ -1391,6 +1420,31 @@ function regenerate_metadata_fail ()
> regenerate_metadata 1 "$@"
> }
>
> +function regenerate_statedump ()
> +{
> + local expected_to_fail=$1
> + local sess_name=$2
> +
> + $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate statedump -s $sess_name 1>
> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
> + ret=$?
> + if [[ $expected_to_fail -eq "1" ]]; then
> + test "$ret" -ne "0"
> + ok $? "Expected fail on regenerate statedump $sess_name"
> + else
> + ok $ret "Metadata regenerate $sess_name"
> + fi
> +}
> +
> +function regenerate_statedump_ok ()
> +{
> + regenerate_statedump 0 "$@"
> +}
> +
> +function regenerate_statedump_fail ()
> +{
> + regenerate_statedump 1 "$@"
> +}
> +
> function destructive_tests_enabled ()
> {
> if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then
> --
> 1.9.1
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
More information about the lttng-dev
mailing list