From e7716c6aec4c7152bd4cb060b805d8cb7051c121 Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Thu, 21 Dec 2017 15:32:16 -0500 Subject: [PATCH] Tests for the session rotation feature MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Julien Desfossez Signed-off-by: Jérémie Galarneau --- tests/regression/tools/rotation/Makefile.am | 16 ++ .../regression/tools/rotation/rotate_utils.sh | 129 +++++++++ tests/regression/tools/rotation/test_kernel | 144 ++++++++++ .../tools/rotation/test_save_load_mi | 121 +++++++++ tests/regression/tools/rotation/test_ust | 247 ++++++++++++++++++ tests/utils/utils.sh | 77 ++++++ 6 files changed, 734 insertions(+) create mode 100644 tests/regression/tools/rotation/Makefile.am create mode 100644 tests/regression/tools/rotation/rotate_utils.sh create mode 100755 tests/regression/tools/rotation/test_kernel create mode 100755 tests/regression/tools/rotation/test_save_load_mi create mode 100755 tests/regression/tools/rotation/test_ust diff --git a/tests/regression/tools/rotation/Makefile.am b/tests/regression/tools/rotation/Makefile.am new file mode 100644 index 000000000..39cda7821 --- /dev/null +++ b/tests/regression/tools/rotation/Makefile.am @@ -0,0 +1,16 @@ +noinst_SCRIPTS = test_kernel test_kernel_streaming test_ust_fast test_ust_long ust_test test_ust_streaming +EXTRA_DIST = test_kernel test_kernel_streaming test_ust_fast test_ust_long ust_test test_ust_streaming + +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/rotation/rotate_utils.sh b/tests/regression/tools/rotation/rotate_utils.sh new file mode 100644 index 000000000..1a78c174b --- /dev/null +++ b/tests/regression/tools/rotation/rotate_utils.sh @@ -0,0 +1,129 @@ +function set_chunk_pattern () +{ + # Need to call this function after $today has been set. + + # YYYYMMDD-HHMMSS-YYYYMMDD-HHMMSS + export chunk_pattern="${today}-[0-9][0-9][0-9][0-9][0-9][0-9]-${today}-[0-9][0-9][0-9][0-9][0-9][0-9]" +} + +function validate_test_chunks () +{ + local_path=$1 + today=$2 + app_path=$3 + domain=$4 + per_pid=$5 + + set_chunk_pattern + + # Check if the 3 chunk folders exist and they contain a ${app_path}/metadata file. + ls $local_path/${chunk_pattern}-1/${app_path}/metadata >/dev/null + ok $? "Chunk 1 exists" + ls $local_path/${chunk_pattern}-2/${app_path}/metadata >/dev/null + ok $? "Chunk 2 exists" + ls $local_path/${chunk_pattern}-3/${domain} >/dev/null + ok $? "Chunk 3 exists" + + # Make sure we don't have anything else in the first 2 chunk directories + # besides the kernel folder. + nr_stale=$(\ls $local_path/${chunk_pattern}-1 | grep -v $domain | wc -l) + ok $nr_stale "No stale folders in chunk 1 directory" + nr_stale=$(\ls $local_path/${chunk_pattern}-2 | grep -v $domain | wc -l) + ok $nr_stale "No stale folders in chunk 2 directory" + + # We expect a session of 30 events + validate_trace_count $EVENT_NAME $local_path 30 + + # Chunk 1: 10 events + validate_trace_count $EVENT_NAME $local_path/${chunk_pattern}-1 10 + if [ $? -eq 0 ]; then + # Only delete if successful + rm -rf $local_path/${chunk_pattern}-1 + fi + + # Chunk 2: 20 events + validate_trace_count $EVENT_NAME $local_path/${chunk_pattern}-2 20 + if [ $? -eq 0 ]; then + # Only delete if successful + rm -rf $local_path/${chunk_pattern}-2 + fi + + # Chunk 3: 0 event + # Do not check in per-pid, because the folder is really empty, no metadata + # or stream files. + if test $per_pid = 1; then + rm -rf $local_path/${chunk_pattern}-3 + else + validate_trace_empty $local_path/${chunk_pattern}-3 + if [ $? -eq 0 ]; then + # Only delete if successful + rm -rf $local_path/${chunk_pattern}-3 + fi + fi + + # The session folder after all chunks have been removed is empty + test -z "$(\ls -A $local_path)" + empty=$? + ok $empty "Trace folder is now empty" + if [ $empty -eq 0 ]; then + # Only delete if successful + rm -rf $local_path/ + else + find $local_path + fi +} + +function rotate_timer_test () +{ + local_path=$1 + per_pid=$2 + + today=$(date +%Y%m%d) + nr=0 + nr_iter=0 + expected_chunks=3 + + # Wait for $expected_chunks to be generated, timeout after + # 3 * $expected_chunks * 0.5s. + # On a laptop with an empty session, a local rotation takes about 200ms, + # and a remote rotation takes about 600ms. + # We currently set the timeout to 6 seconds for 3 rotations, if we get + # errors, we can bump this value. + + until [ $nr -ge $expected_chunks ] || [ $nr_iter -ge $(($expected_chunks * 2 )) ]; do + nr=$(ls $local_path | wc -l) + nr_iter=$(($nr_iter+1)) + sleep 1 + done + test $nr -ge $expected_chunks + ok $? "Generated $nr chunks in $(($nr_iter))s" + stop_lttng_tracing_ok $SESSION_NAME + destroy_lttng_session_ok $SESSION_NAME + + now=$(date +%Y%m%d) + test $today = $now + ok $? "Date did not change during the test" + + # Make sure the 10 first chunks are valid empty traces + i=1 + set_chunk_pattern + + # In a per-pid setup, only the first chunk is a valid trace, the other + # chunks should be empty folders + if test $per_pid = 1; then + validate_trace_empty $local_path/${chunk_pattern}-1 + nr=$(ls $local_path/${chunk_pattern}-2/ust | wc -l) + test $nr = 0 + ok $? "Chunk 2 is empty" + nr=$(ls $local_path/${chunk_pattern}-3/ust | wc -l) + test $nr = 0 + ok $? "Chunk 3 is empty" + else + while [ $i -le $expected_chunks ]; do + validate_trace_empty $local_path/${chunk_pattern}-$i + i=$(($i+1)) + done +fi + + rm -rf $local_path +} diff --git a/tests/regression/tools/rotation/test_kernel b/tests/regression/tools/rotation/test_kernel new file mode 100755 index 000000000..93b3da1c0 --- /dev/null +++ b/tests/regression/tools/rotation/test_kernel @@ -0,0 +1,144 @@ +#!/bin/bash +# +# Copyright (C) - 2017 Julien Desfossez +# +# 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="Rotation - Kernel tracing" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +EVENT_NAME="lttng_test_filter_event" +PID_RELAYD=0 +SESSION_NAME="" + +TRACE_PATH=$(mktemp -d) + +NUM_TESTS=68 + +source $TESTDIR/utils/utils.sh +source $CURDIR/rotate_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 lttng_create_session_uri +{ + # Create session with default path + $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME -U net://localhost >/dev/null 2>&1 + + ok $? "Create session $SESSION_NAME" +} + +function rotate_kernel_test () +{ + local_path=$1 + + lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing_ok $SESSION_NAME + + today=$(date +%Y%m%d) + # First chunk contains 10 events. + echo -n "10" > /proc/lttng-test-filter-event + rotate_session_ok $SESSION_NAME + + # Second chunk contains 20 events. + echo -n "20" > /proc/lttng-test-filter-event + stop_lttng_tracing_ok $SESSION_NAME + + # Third chunk contains no event (rotate after stop). + rotate_session_ok $SESSION_NAME + + destroy_lttng_session_ok $SESSION_NAME + + # The tests on the chunk folder rely on the date staying the same during + # the duration of the test, if this fail we will now why the other checks + # fail afterwards. There is a short window of time where an automated test + # could fail because of that. + now=$(date +%Y%m%d) + test $today = $now + ok $? "Date did not change during the test" + + validate_test_chunks $local_path $today kernel kernel 0 +} + +function test_kernel_streaming () +{ + diag "Test kernel streaming with session rotation" + lttng_create_session_uri + rotate_kernel_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" + rm -rf ${TRACE_PATH}/${HOSTNAME} +} + +function test_kernel_local () +{ + diag "Test kernel local with session rotation" + create_lttng_session_ok $SESSION_NAME $TRACE_PATH + + rotate_kernel_test "${TRACE_PATH}" +} + +function test_kernel_local_timer () +{ + diag "Test kernel local with session rotation timer" + create_lttng_session_ok $SESSION_NAME $TRACE_PATH + lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME + lttng_enable_rotation_timer_ok $SESSION_NAME 500ms + start_lttng_tracing_ok $SESSION_NAME + + rotate_timer_test "${TRACE_PATH}" 0 +} + +function test_kernel_streaming_timer () +{ + diag "Test kernel remote with session rotation timer" + lttng_create_session_uri + lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME + lttng_enable_rotation_timer_ok $SESSION_NAME 500ms + start_lttng_tracing_ok $SESSION_NAME + + rotate_timer_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" 0 + rm -rf ${TRACE_PATH}/${HOSTNAME} +} + +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_relayd "-o $TRACE_PATH" + start_lttng_sessiond + modprobe lttng-test + + tests=( test_kernel_streaming test_kernel_local test_kernel_local_timer test_kernel_streaming_timer) + + for fct_test in ${tests[@]}; + do + SESSION_NAME=$(randstring 16 0) + ${fct_test} + done + + rmmod lttng-test + stop_lttng_sessiond + stop_lttng_relayd +} diff --git a/tests/regression/tools/rotation/test_save_load_mi b/tests/regression/tools/rotation/test_save_load_mi new file mode 100755 index 000000000..8e1772a13 --- /dev/null +++ b/tests/regression/tools/rotation/test_save_load_mi @@ -0,0 +1,121 @@ +#!/bin/bash +# +# Copyright (C) - 2017 Julien Desfossez +# +# 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="Rotation - Save/Load/List/MI" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +SESSION_NAME="stream" + +TRACE_PATH=$(mktemp -d) + +NUM_TESTS=14 + +source $TESTDIR/utils/utils.sh +source $CURDIR/rotate_utils.sh + +#Overwrite the lttng_bin to get mi output +LTTNG_BIN="lttng --mi xml" + +#Global declaration for simplification +LTTNG=$TESTDIR/../src/bin/lttng/$LTTNG_BIN + +XSD_PATH=$TESTDIR/../src/common/mi-lttng-3.0.xsd + +XML_VALIDATE="$TESTDIR/regression/tools/mi/validate_xml $XSD_PATH" +XML_EXTRACT="$TESTDIR/regression/tools/mi/extract_xml" + +XPATH_CMD_OUTPUT="//lttng:command/lttng:output" +XPATH_SESSION="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session" +XPATH_ROTATE_SETUP="$XPATH_CMD_OUTPUT/lttng:rotation_schedule" + +function test_save_load () +{ + tmp_xml_output=$(mktemp -u) + tmp_save_output=$(mktemp -d) + + diag "Test save/load/list/MI with rotation" + create_lttng_session_ok $SESSION_NAME $TRACE_PATH + enable_ust_lttng_event_ok $SESSION_NAME -a + + # Enable a rotation timer and check the MI output of the command + $LTTNG enable-rotation -s $SESSION_NAME --timer 500ms >${tmp_xml_output} + $XML_VALIDATE ${tmp_xml_output} + ok $? "Valid lttng enable-rotation timer XML" + value=$($XML_EXTRACT ${tmp_xml_output} ${XPATH_ROTATE_SETUP}/lttng:rotation_schedule_timer_period) + test $value = 500000 + ok $? "Found the right rotation timer value in XML" + + # Enable a rotation size and check the MI output of the command + $LTTNG enable-rotation -s $SESSION_NAME --size 500k >${tmp_xml_output} + $XML_VALIDATE ${tmp_xml_output} + ok $? "Valid lttng enable-rotation size XML" + value=$($XML_EXTRACT ${tmp_xml_output} ${XPATH_ROTATE_SETUP}/lttng:rotation_schedule_size) + test $value = 512000 + ok $? "Found the right rotation size value in XML" + + # Check the output of lttng list with the 2 rotation parameters + $LTTNG list $SESSION_NAME >${tmp_xml_output} + $XML_VALIDATE ${tmp_xml_output} + ok $? "Valid lttng list XML" + value=$($XML_EXTRACT ${tmp_xml_output} ${XPATH_SESSION}/lttng:rotation_schedule_timer_period) + test $value = 500000 + ok $? "Found the right rotation timer value in list XML" + value=$($XML_EXTRACT ${tmp_xml_output} ${XPATH_SESSION}/lttng:rotation_schedule_size) + test $value = 512000 + ok $? "Found the right rotation size value in list XML" + + # save, destroy and reload the same session + $LTTNG save -o $tmp_save_output$SESSION_NAME >/dev/null + $LTTNG destroy $SESSION_NAME >/dev/null + $LTTNG load -i $tmp_save_output$SESSION_NAME >/dev/null + + # Check the output of lttng list with the 2 rotation parameters after the load + $LTTNG list $SESSION_NAME >${tmp_xml_output} + $XML_VALIDATE ${tmp_xml_output} + ok $? "Valid lttng list XML after load" + value=$($XML_EXTRACT ${tmp_xml_output} ${XPATH_SESSION}/lttng:rotation_schedule_timer_period) + test $value = 500000 + ok $? "Found the right rotation timer value in list XML after load" + value=$($XML_EXTRACT ${tmp_xml_output} ${XPATH_SESSION}/lttng:rotation_schedule_size) + test $value = 512000 + ok $? "Found the right rotation size value in list XML after load" + + $LTTNG destroy $SESSION_NAME >/dev/null + + rm -rf ${TRACE_PATH} + rm $tmp_xml_output + rm -rf $tmp_save_output +} + +plan_tests $NUM_TESTS + +print_test_banner "$TEST_DESC" + +start_lttng_sessiond + +tests=( test_save_load ) + +for fct_test in ${tests[@]}; +do + SESSION_NAME=$(randstring 16 0) + ${fct_test} +done + +stop_lttng_sessiond + +exit $out diff --git a/tests/regression/tools/rotation/test_ust b/tests/regression/tools/rotation/test_ust new file mode 100755 index 000000000..89c4c969d --- /dev/null +++ b/tests/regression/tools/rotation/test_ust @@ -0,0 +1,247 @@ +#!/bin/bash +# +# Copyright (C) - 2017 Julien Desfossez +# +# 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="Rotation - User space tracing" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +NR_ITER=1 +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="tp:tptest" +PID_RELAYD=0 + +TRACE_PATH=$(mktemp -d) + +NUM_TESTS=146 + +source $TESTDIR/utils/utils.sh +source $CURDIR/rotate_utils.sh + +if [ ! -x "$TESTAPP_BIN" ]; then + BAIL_OUT "No UST events binary detected." +fi + +function enable_channel_per_pid() +{ + sess_name=$1 + channel_name=$2 + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-pid -u $channel_name -s $sess_name >/dev/null 2>&1 + ok $? "Enable channel $channel_name per PID for session $sess_name" +} + +function lttng_create_session_uri +{ + # Create session with default path + $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME -U net://localhost >/dev/null 2>&1 + + ok $? "Create session $SESSION_NAME" +} + +# MUST set TESTDIR before calling those functions + +function rotate_ust_test () +{ + local_path=$1 + app_path=$2 + per_pid=$3 + + start_lttng_tracing_ok $SESSION_NAME + today=$(date +%Y%m%d) + + $TESTAPP_BIN 10 $NR_USEC_WAIT /dev/null 2>&1 + rotate_session_ok $SESSION_NAME + + $TESTAPP_BIN 20 $NR_USEC_WAIT /dev/null 2>&1 + stop_lttng_tracing_ok $SESSION_NAME + + # Third chunk contains no event (rotate after stop). + rotate_session_ok $SESSION_NAME + + destroy_lttng_session_ok $SESSION_NAME + + # The tests on the chunk folder rely on the date staying the same during + # the duration of the test, if this fail we will now why the other checks + # fail afterwards. There is a short window of time where an automated test + # could fail because of that. + now=$(date +%Y%m%d) + test $today = $now + ok $? "Date did not change during the test" + + validate_test_chunks "${local_path}" $today $app_path ust $per_pid +} + +function test_ust_streaming_uid () +{ + diag "Test UST streaming with session rotation per UID" + lttng_create_session_uri + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME + + rotate_ust_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" "ust/uid/*/*/" 0 + rm -rf ${TRACE_PATH}/${HOSTNAME} +} + +function test_ust_local_uid () +{ + diag "Test UST local with session rotation per UID" + create_lttng_session_ok $SESSION_NAME $TRACE_PATH + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME + + rotate_ust_test "${TRACE_PATH}" "ust/uid/*/*/" 0 + rm -rf ${TRACE_PATH} +} + +function test_ust_streaming_pid () +{ + diag "Test UST streaming with session rotation per PID" + lttng_create_session_uri + enable_channel_per_pid $SESSION_NAME "channel0" + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" + + rotate_ust_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" "ust/pid/*/" 1 + rm -rf ${TRACE_PATH}/${HOSTNAME} +} + +function test_ust_local_pid () +{ + diag "Test UST local with session rotation per PID" + create_lttng_session_ok $SESSION_NAME $TRACE_PATH + enable_channel_per_pid $SESSION_NAME "channel0" + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" + + rotate_ust_test "${TRACE_PATH}" "ust/pid/*/" 1 + rm -rf ${TRACE_PATH} +} + +function test_ust_local_timer_uid () +{ + diag "Test ust local with session rotation timer per-uid" + create_lttng_session_ok $SESSION_NAME $TRACE_PATH + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME + lttng_enable_rotation_timer_ok $SESSION_NAME 500ms + start_lttng_tracing_ok $SESSION_NAME + # We just want the app to register, no event generated + $TESTAPP_BIN 0 0 /dev/null 2>&1 + + rotate_timer_test "${TRACE_PATH}" 0 + rm -rf ${TRACE_PATH} +} + +function test_ust_streaming_timer_uid () +{ + diag "Test ust remote with session rotation timer per-uid" + lttng_create_session_uri + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME + lttng_enable_rotation_timer_ok $SESSION_NAME 500ms + start_lttng_tracing_ok $SESSION_NAME + # We just want the app to register, no event generated + $TESTAPP_BIN 0 0 /dev/null 2>&1 + + rotate_timer_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" 0 + rm -rf ${TRACE_PATH}/${HOSTNAME} +} + +function test_ust_local_timer_pid () +{ + diag "Test ust local with session rotation timer per-pid" + create_lttng_session_ok $SESSION_NAME $TRACE_PATH + enable_channel_per_pid $SESSION_NAME "channel0" + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" + lttng_enable_rotation_timer_ok $SESSION_NAME 500ms + start_lttng_tracing_ok $SESSION_NAME + # We just want the app to register, no event generated + $TESTAPP_BIN 0 0 /dev/null 2>&1 + + rotate_timer_test "${TRACE_PATH}" 1 + rm -rf ${TRACE_PATH} +} + +function test_ust_streaming_timer_pid () +{ + diag "Test ust remote with session rotation timer per-pid" + lttng_create_session_uri + enable_channel_per_pid $SESSION_NAME "channel0" + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" + lttng_enable_rotation_timer_ok $SESSION_NAME 500ms + start_lttng_tracing_ok $SESSION_NAME + # We just want the app to register, no event generated + $TESTAPP_BIN 0 0 /dev/null 2>&1 + + rotate_timer_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" 1 + rm -rf ${TRACE_PATH}/${HOSTNAME} +} + +function test_incompatible_sessions () +{ + diag "Check incompatible session types with rotation" + + diag "Live session with rotate timer" + # Should not be able to enable a rotation timer with a live session + $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --live >/dev/null 2>&1 + lttng_enable_rotation_timer_fail $SESSION_NAME 500ms + destroy_lttng_session_ok $SESSION_NAME + + diag "Snapshot session with rotate timer" + # Should not be able to enable a rotation timer with a snapshot session + $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --snapshot >/dev/null 2>&1 + lttng_enable_rotation_timer_fail $SESSION_NAME 500ms + destroy_lttng_session_ok $SESSION_NAME + + diag "Live session with rotate" + # Should not be able to rotate a live session + $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --live >/dev/null 2>&1 + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME + start_lttng_tracing_ok $SESSION_NAME + rotate_session_fail $SESSION_NAME + destroy_lttng_session_ok $SESSION_NAME + + diag "Snapshot session with rotate" + # Should not be able to rotate a snapshot session + $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --snapshot >/dev/null 2>&1 + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME + start_lttng_tracing_ok $SESSION_NAME + rotate_session_fail $SESSION_NAME + destroy_lttng_session_ok $SESSION_NAME + +} + +plan_tests $NUM_TESTS + +print_test_banner "$TEST_DESC" + +start_lttng_relayd "-o $TRACE_PATH" +start_lttng_sessiond + +tests=( test_ust_streaming_uid test_ust_local_uid \ + test_ust_streaming_pid test_ust_local_pid \ + test_ust_local_timer_uid test_ust_streaming_timer_uid \ + test_ust_local_timer_pid test_ust_streaming_timer_pid \ + test_incompatible_sessions ) + +for fct_test in ${tests[@]}; +do + SESSION_NAME=$(randstring 16 0) + ${fct_test} +done + +stop_lttng_sessiond +stop_lttng_relayd + +exit $out diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index 9980e8538..c88387dc7 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -1579,6 +1579,31 @@ function regenerate_statedump_fail () regenerate_statedump 1 "$@" } +function rotate_session () +{ + local expected_to_fail=$1 + local sess_name=$2 + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN rotate $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 rotate session $sess_name" + else + ok $ret "Rotate session $sess_name" + fi +} + +function rotate_session_ok () +{ + rotate_session 0 "$@" +} + +function rotate_session_fail () +{ + rotate_session 1 "$@" +} + function destructive_tests_enabled () { if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then @@ -1587,3 +1612,55 @@ function destructive_tests_enabled () return 1 fi } + +function lttng_enable_rotation_timer () +{ + local expected_to_fail=$1 + local sess_name=$2 + local period=$3 + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --timer $period 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST + ret=$? + if [[ $expected_to_fail -eq "1" ]]; then + test "$ret" -ne "0" + ok $? "Expected fail on rotate session $sess_name" + else + ok $ret "Rotate session $sess_name" + fi +} + +function lttng_enable_rotation_timer_ok () +{ + lttng_enable_rotation_timer 0 $@ +} + +function lttng_enable_rotation_timer_fail () +{ + lttng_enable_rotation_timer 1 $@ +} + +function lttng_enable_rotation_size () +{ + local expected_to_fail=$1 + local sess_name=$2 + local size=$3 + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --size $size 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST + ret=$? + if [[ $expected_to_fail -eq "1" ]]; then + test "$ret" -ne "0" + ok $? "Expected fail on rotate session $sess_name" + else + ok $ret "Rotate session $sess_name" + fi +} + +function lttng_enable_rotation_size_ok () +{ + lttng_enable_rotation_size 0 $@ +} + +function lttng_enable_rotation_size_fail () +{ + lttng_enable_rotation_size 1 $@ +} -- 2.34.1