From e02b109ba0132f2c715fdb9db55cbdf8f8203749 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Wed, 19 Mar 2014 16:19:04 -0400 Subject: [PATCH] Tests: add tests for the save and load feature This commit integrates the tests to the fast make check. Fixes #757 Signed-off-by: David Goulet --- configure.ac | 1 + tests/fast_regression | 2 + tests/regression/tools/Makefile.am | 2 +- .../tmp/tmp.eAJ1f0oCZE/test-42/save-42.lttng | 46 ++++++ tests/regression/tools/save-load/Makefile.am | 16 ++ .../tools/save-load/load-42-complex.lttng | 109 ++++++++++++ .../regression/tools/save-load/load-42.lttng | 46 ++++++ tests/regression/tools/save-load/test_load | 134 +++++++++++++++ tests/regression/tools/save-load/test_save | 156 ++++++++++++++++++ tests/utils/utils.sh | 17 ++ 10 files changed, 528 insertions(+), 1 deletion(-) create mode 100644 tests/regression/tools/save-load/ /tmp/tmp.eAJ1f0oCZE/test-42/save-42.lttng create mode 100644 tests/regression/tools/save-load/Makefile.am create mode 100644 tests/regression/tools/save-load/load-42-complex.lttng create mode 100644 tests/regression/tools/save-load/load-42.lttng create mode 100755 tests/regression/tools/save-load/test_load create mode 100755 tests/regression/tools/save-load/test_save diff --git a/configure.ac b/configure.ac index 26f286b06..ce46a753e 100644 --- a/configure.ac +++ b/configure.ac @@ -426,6 +426,7 @@ AC_CONFIG_FILES([ tests/regression/tools/snapshots/Makefile tests/regression/tools/live/Makefile tests/regression/tools/exclusion/Makefile + tests/regression/tools/save-load/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 40acf5cd7..e4ac615dc 100644 --- a/tests/fast_regression +++ b/tests/fast_regression @@ -11,6 +11,8 @@ regression/tools/tracefile-limits/test_tracefile_size regression/tools/exclusion/test_exclusion regression/tools/snapshots/test_ust_fast regression/tools/snapshots/test_ust_streaming +regression/tools/save-load/test_save +regression/tools/save-load/test_load 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 f3bdc25f4..84df80075 100644 --- a/tests/regression/tools/Makefile.am +++ b/tests/regression/tools/Makefile.am @@ -1 +1 @@ -SUBDIRS = streaming filtering health tracefile-limits snapshots live exclusion +SUBDIRS = streaming filtering health tracefile-limits snapshots live exclusion save-load diff --git a/tests/regression/tools/save-load/ /tmp/tmp.eAJ1f0oCZE/test-42/save-42.lttng b/tests/regression/tools/save-load/ /tmp/tmp.eAJ1f0oCZE/test-42/save-42.lttng new file mode 100644 index 000000000..be7545c72 --- /dev/null +++ b/tests/regression/tools/save-load/ /tmp/tmp.eAJ1f0oCZE/test-42/save-42.lttng @@ -0,0 +1,46 @@ + + + + save-42 + + + UST + PER_UID + + + chan1 + true + DISCARD + 131072 + 4 + 0 + 0 + MMAP + 0 + 0 + 0 + + + tp:tptest + true + TRACEPOINT + ALL + -1 + + + + + + + + false + + + true + + /tmp/tmp.eAJ1f0oCZE + + + + + diff --git a/tests/regression/tools/save-load/Makefile.am b/tests/regression/tools/save-load/Makefile.am new file mode 100644 index 000000000..72b3039f0 --- /dev/null +++ b/tests/regression/tools/save-load/Makefile.am @@ -0,0 +1,16 @@ +noinst_SCRIPTS = test_save test_load +EXTRA_DIST = $(noinst_SCRIPTS) + +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/save-load/load-42-complex.lttng b/tests/regression/tools/save-load/load-42-complex.lttng new file mode 100644 index 000000000..e8a360bab --- /dev/null +++ b/tests/regression/tools/save-load/load-42-complex.lttng @@ -0,0 +1,109 @@ + + + + load-42-complex + + + UST + PER_UID + + + chan3 + true + DISCARD + 262144 + 4 + 0 + 200000 + MMAP + 0 + 0 + 1000000 + + + uevent3* + true + TRACEPOINT + ALL + -1 + + uevent3-42 + + + + uevent3* + true + TRACEPOINT + ALL + -1 + + + + + + chan2 + true + DISCARD + 131072 + 4 + 0 + 0 + MMAP + 131072 + 14 + 1000000 + + + uevent2 + true + TRACEPOINT + RANGE + 6 + + + + + + chan1 + true + DISCARD + 131072 + 16 + 0 + 0 + MMAP + 0 + 0 + 1000000 + + + uevent1 + true + TRACEPOINT + ALL + -1 + $ctx.procname == "test" + + + + + + + + false + + 1000000 + + + + true + + + tcp4://127.0.0.1:8172/ + tcp4://127.0.0.1:9817/ + + + + + + diff --git a/tests/regression/tools/save-load/load-42.lttng b/tests/regression/tools/save-load/load-42.lttng new file mode 100644 index 000000000..a031aa0d4 --- /dev/null +++ b/tests/regression/tools/save-load/load-42.lttng @@ -0,0 +1,46 @@ + + + + load-42 + + + UST + PER_UID + + + channel0 + true + DISCARD + 131072 + 4 + 0 + 0 + MMAP + 0 + 0 + 0 + + + * + true + TRACEPOINT + ALL + -1 + + + + + + + + false + + + true + + /tmp/lttng/load-42-1 + + + + + diff --git a/tests/regression/tools/save-load/test_load b/tests/regression/tools/save-load/test_load new file mode 100755 index 000000000..a58c29967 --- /dev/null +++ b/tests/regression/tools/save-load/test_load @@ -0,0 +1,134 @@ +#!/bin/bash +# +# Copyright (C) - 2014 David Goulet +# +# 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="Load session(s)" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../../ +SESSIOND_BIN="lttng-sessiond" +RELAYD_BIN="lttng-relayd" +LTTNG_BIN="lttng" + +SESSION_NAME="load-42" +EVENT_NAME="tp:tptest" + +DIR=$(readlink -f $TESTDIR) + +NUM_TESTS=20 + +source $TESTDIR/utils/utils.sh + +# MUST set TESTDIR before calling those functions +plan_tests $NUM_TESTS + +print_test_banner "$TEST_DESC" + +function disable_event() +{ + local sess_name="$1" + local chan_name="$2" + local event_name="$3" + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -c $chan_name -u >/dev/null 2>&1 + ok $? "Disable event $event_name for session $sess_name" +} + +function test_basic_load() +{ + diag "Test basic load" + + lttng_load "-s $SESSION_NAME -i $CURDIR" + + destroy_lttng_session $SESSION_NAME +} + +function test_complex_load() +{ + local sess="$SESSION_NAME-complex" + diag "Test complex load" + + # Start relayd with localhost binding. The complex session uses those + # custom values. + start_lttng_relayd "-C tcp://localhost:8172 -D tcp://localhost:9817" + + lttng_load "-s $sess -i $CURDIR" + + # Once loaded, we are suppose to be able to disable certain events/channels + # thus having a confirmation that it's valid + disable_event $sess chan1 uevent1 + disable_event $sess chan2 uevent2 + disable_event $sess chan3 uevent3* + + disable_ust_lttng_channel $sess chan1 + disable_ust_lttng_channel $sess chan2 + disable_ust_lttng_channel $sess chan3 + + destroy_lttng_session $sess + + stop_lttng_relayd_nocheck +} + +function test_all_load() +{ + diag "Test load all sessions" + + # Start relayd with localhost binding. The complex session uses those + # custom values. + start_lttng_relayd "-C tcp://localhost:8172 -D tcp://localhost:9817" + + lttng_load "-a -i $CURDIR" + + destroy_lttng_session $SESSION_NAME + destroy_lttng_session "$SESSION_NAME-complex" + + stop_lttng_relayd_nocheck +} + +function test_overwrite() +{ + diag "Test load overwrite" + + lttng_load "-s $SESSION_NAME -i $CURDIR" + + # This one should succeed + lttng_load "-f -s $SESSION_NAME -i $CURDIR" + + destroy_lttng_session $SESSION_NAME +} + +start_lttng_sessiond + +TESTS=( + test_basic_load + test_complex_load + test_all_load + test_overwrite +) + +for fct_test in ${TESTS[@]}; +do + TRACE_PATH=$(mktemp -d) + + ${fct_test} + if [ $? -ne 0 ]; then + break; + fi + # Only delete if successful + rm -rf $TRACE_PATH +done + +stop_lttng_sessiond diff --git a/tests/regression/tools/save-load/test_save b/tests/regression/tools/save-load/test_save new file mode 100755 index 000000000..1f6bbbd5a --- /dev/null +++ b/tests/regression/tools/save-load/test_save @@ -0,0 +1,156 @@ +#!/bin/bash +# +# Copyright (C) - 2014 David Goulet +# +# 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="Save session(s)" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../../ +SESSIOND_BIN="lttng-sessiond" +RELAYD_BIN="lttng-relayd" +LTTNG_BIN="lttng" + +SESSION_NAME="save-42" +CHANNEL_NAME="chan-save" +EVENT_NAME="tp:tptest" + +DIR=$(readlink -f $TESTDIR) + +NUM_TESTS=37 + +source $TESTDIR/utils/utils.sh + +# MUST set TESTDIR before calling those functions +plan_tests $NUM_TESTS + +print_test_banner "$TEST_DESC" + +# Expected to fail +function save_lttng_fail() +{ + local sess_name=$1 + local opts=$2 + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts >/dev/null 2>&1 + if [ $? -ne 0 ]; then + ok 0 "Session failed to be saved. Expected!" + else + ok 1 "Session has been saved. NOT expected!" + fi +} + +function is_session_saved() +{ + local path=$1 + local name=$2 + + [ -f "$path/$name.lttng" ]; + ok $? "Session $name.lttng file found!" +} + +function test_basic_save() +{ + diag "Test basic save" + + create_lttng_session $SESSION_NAME $TRACE_PATH + enable_ust_lttng_channel $SESSION_NAME $CHANNEL_NAME + enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME + + lttng_save $SESSION_NAME "-o $TRACE_PATH" + + is_session_saved $TRACE_PATH $SESSION_NAME + + destroy_lttng_session $SESSION_NAME +} + +function test_basic_save_all() +{ + diag "Test basic save all" + + create_lttng_session $SESSION_NAME-1 $TRACE_PATH + create_lttng_session $SESSION_NAME-2 $TRACE_PATH + create_lttng_session $SESSION_NAME-3 $TRACE_PATH + + enable_ust_lttng_channel $SESSION_NAME-1 $CHANNEL_NAME + enable_ust_lttng_channel $SESSION_NAME-2 $CHANNEL_NAME + enable_ust_lttng_channel $SESSION_NAME-3 $CHANNEL_NAME + + enable_ust_lttng_event $SESSION_NAME-1 $EVENT_NAME $CHANNEL_NAME + enable_ust_lttng_event $SESSION_NAME-2 $EVENT_NAME $CHANNEL_NAME + enable_ust_lttng_event $SESSION_NAME-3 $EVENT_NAME $CHANNEL_NAME + + lttng_save "" "-a -o $TRACE_PATH" + + is_session_saved $TRACE_PATH $SESSION_NAME-1 + is_session_saved $TRACE_PATH $SESSION_NAME-2 + is_session_saved $TRACE_PATH $SESSION_NAME-3 + + destroy_lttng_session $SESSION_NAME-1 + destroy_lttng_session $SESSION_NAME-2 + destroy_lttng_session $SESSION_NAME-3 +} + +function test_overwrite() +{ + diag "Test overwrite session file" + + create_lttng_session $SESSION_NAME $TRACE_PATH + enable_ust_lttng_channel $SESSION_NAME $CHANNEL_NAME + enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME + + lttng_save $SESSION_NAME "-o $TRACE_PATH" + + is_session_saved $TRACE_PATH $SESSION_NAME + + destroy_lttng_session $SESSION_NAME + + # Create a new session with same name so we can force the overwrite + create_lttng_session $SESSION_NAME $TRACE_PATH + enable_ust_lttng_channel $SESSION_NAME $CHANNEL_NAME + enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME + + # This one MUST fail + save_lttng_fail $SESSION_NAME "-o $TRACE_PATH" + + # This one MUST succeed + lttng_save $SESSION_NAME "-f -o $TRACE_PATH" + + is_session_saved $TRACE_PATH $SESSION_NAME + + destroy_lttng_session $SESSION_NAME +} + +start_lttng_sessiond + +TESTS=( + test_basic_save + test_basic_save_all + test_overwrite +) + +for fct_test in ${TESTS[@]}; +do + TRACE_PATH=$(mktemp -d) + + ${fct_test} + if [ $? -ne 0 ]; then + break; + fi + # Only delete if successful + #rm -rf $TRACE_PATH +done + +stop_lttng_sessiond diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index 88304eb80..a1a26d9df 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -400,6 +400,23 @@ function lttng_snapshot_record () ok $? "Snapshot recorded" } +function lttng_save() +{ + local sess_name=$1 + local opts=$2 + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts >/dev/null 2>&1 + ok $? "Session successfully saved" +} + +function lttng_load() +{ + local opts=$1 + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts >/dev/null 2>&1 + ok $? "Load command successful" +} + function trace_matches () { event_name=$1 -- 2.34.1