From c28fcefd993b7539716bb5cd9557a08a217ec463 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Wed, 13 Feb 2019 21:33:35 -0500 Subject: [PATCH] tests: lttng clear command MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonathan Rajotte Signed-off-by: Mathieu Desnoyers Change-Id: I96c837dfd65be76aa8995305e1e17a8b315b22af Signed-off-by: Jérémie Galarneau --- configure.ac | 1 + tests/regression/Makefile.am | 5 +- tests/regression/tools/Makefile.am | 2 +- tests/regression/tools/clear/Makefile.am | 16 + tests/regression/tools/clear/test_kernel | 641 ++++++++++++++++++ tests/regression/tools/clear/test_ust | 804 +++++++++++++++++++++++ tests/utils/utils.sh | 102 ++- 7 files changed, 1564 insertions(+), 7 deletions(-) create mode 100644 tests/regression/tools/clear/Makefile.am create mode 100755 tests/regression/tools/clear/test_kernel create mode 100755 tests/regression/tools/clear/test_ust diff --git a/configure.ac b/configure.ac index e1c7554bc..a08055f34 100644 --- a/configure.ac +++ b/configure.ac @@ -1130,6 +1130,7 @@ AC_CONFIG_FILES([ tests/regression/tools/metadata/Makefile tests/regression/tools/working-directory/Makefile tests/regression/tools/relayd-grouping/Makefile + tests/regression/tools/clear/Makefile tests/regression/ust/Makefile tests/regression/ust/nprocesses/Makefile tests/regression/ust/high-throughput/Makefile diff --git a/tests/regression/Makefile.am b/tests/regression/Makefile.am index 874e0c08b..a26580785 100644 --- a/tests/regression/Makefile.am +++ b/tests/regression/Makefile.am @@ -33,7 +33,10 @@ TESTS = tools/filtering/test_invalid_filter \ tools/rotation/test_save_load_mi \ tools/rotation/test_schedule_api \ tools/metadata/test_kernel \ - tools/working-directory/test_relayd_working_directory + tools/working-directory/test_relayd_working_directory \ + tools/notification/test_notification_multi_app \ + tools/clear/test_ust \ + tools/clear/test_kernel if HAVE_LIBLTTNG_UST_CTL SUBDIRS += ust diff --git a/tests/regression/tools/Makefile.am b/tests/regression/tools/Makefile.am index 032ade6e7..5acd34bc7 100644 --- a/tests/regression/tools/Makefile.am +++ b/tests/regression/tools/Makefile.am @@ -1,3 +1,3 @@ SUBDIRS = streaming filtering health tracefile-limits snapshots live exclusion save-load mi \ wildcard crash regen-metadata regen-statedump notification rotation \ - base-path metadata working-directory relayd-grouping + base-path metadata working-directory relayd-grouping clear diff --git a/tests/regression/tools/clear/Makefile.am b/tests/regression/tools/clear/Makefile.am new file mode 100644 index 000000000..aa700f172 --- /dev/null +++ b/tests/regression/tools/clear/Makefile.am @@ -0,0 +1,16 @@ +noinst_SCRIPTS = test_kernel test_ust +EXTRA_DIST = test_kernel test_ust + +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/clear/test_kernel b/tests/regression/tools/clear/test_kernel new file mode 100755 index 000000000..01232863f --- /dev/null +++ b/tests/regression/tools/clear/test_kernel @@ -0,0 +1,641 @@ +#!/bin/bash +# +# Copyright (C) - 2019 Jonathan Rajotte-Julien +# +# 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="Clear - Kernel tracing" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +EVENT_NAME="lttng_test_filter_event" + +PAGE_SIZE=$(getconf PAGE_SIZE) +TRACE_PATH=$(mktemp -d) + +NUM_TESTS=837 + +source $TESTDIR/utils/utils.sh + +function signal_cleanup () +{ + stop_lttng_sessiond + modprobe -r lttng-test + full_cleanup +} + +function clean_path () +{ + local trace_path=$1 + set -u + rm -rf $trace_path/* + set +u +} + +function cond_start_tracing () +{ + local session_name=$1 + local tracing_active=$2 + + if [[ $tracing_active -ne 1 ]]; then + start_lttng_tracing_ok $session_name + fi +} + +function cond_stop_tracing () +{ + local session_name=$1 + local tracing_active=$2 + + if [[ $tracing_active -ne 1 ]]; then + stop_lttng_tracing_ok $session_name + fi +} + +function do_clear_session () +{ + local session_name=$1 + local tracing_active=$2 + local clear_twice=$3 + local rotate_before=$4 + local rotate_after=$5 + + cond_stop_tracing $session_name $tracing_active + if [[ $rotate_before -eq 1 ]]; then + rotate_session_ok $SESSION_NAME + fi + lttng_clear_session_ok $SESSION_NAME + if [[ $clear_twice -eq 1 ]]; then + lttng_clear_session_ok $SESSION_NAME + fi + if [[ $rotate_after -eq 1 ]]; then + if [[ $tracing_active -eq 1 ]]; then + rotate_session_ok $SESSION_NAME + else + # Expect failure + rotate_session_fail $SESSION_NAME + fi + fi + cond_start_tracing $session_name $tracing_active +} + +function test_kernel_streaming () +{ + local tracing_active=$1 + local clear_twice=$2 + local rotate_before=$3 + local rotate_after=$4 + local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" + + diag "Test kernel streaming clear" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after" + create_lttng_session_uri $SESSION_NAME net://localhost + lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing_ok $SESSION_NAME + # Generate 10 events that will sit in the buffers. + echo -n "10" > /proc/lttng-test-filter-event + + do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after + + stop_lttng_tracing_ok $SESSION_NAME + + if [[ $rotate_before -eq 1 ]]; then + validate_trace_count $EVENT_NAME $local_path 10 + else + validate_trace_empty $local_path + fi + + destroy_lttng_session_ok $SESSION_NAME +} + +function test_kernel_streaming_rotate_clear () +{ + local tracing_active=$1 + local clear_twice=$2 + local rotate_before=$3 + local rotate_after=$4 + local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" + + diag "Test kernel streaming rotate-clear" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after" + create_lttng_session_uri $SESSION_NAME net://localhost + lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing_ok $SESSION_NAME + echo -n "1" > /proc/lttng-test-filter-event + rotate_session_ok $SESSION_NAME + echo -n "2" > /proc/lttng-test-filter-event + do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after + echo -n "3" > /proc/lttng-test-filter-event + + stop_lttng_tracing_ok $SESSION_NAME + + if [[ $rotate_before -eq 1 ]]; then + local expect_count=6 + else + local expect_count=4 + fi + validate_trace_count $EVENT_NAME $local_path $expect_count + + destroy_lttng_session_ok $SESSION_NAME +} + +function test_kernel_streaming_clear_rotate() +{ + local tracing_active=$1 + local clear_twice=$2 + local rotate_before=$3 + local rotate_after=$4 + local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" + + diag "Test kernel streaming clear-rotate" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after" + create_lttng_session_uri $SESSION_NAME net://localhost + lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing_ok $SESSION_NAME + echo -n "1" > /proc/lttng-test-filter-event + do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after + echo -n "2" > /proc/lttng-test-filter-event + rotate_session_ok $SESSION_NAME + echo -n "3" > /proc/lttng-test-filter-event + + stop_lttng_tracing_ok $SESSION_NAME + + if [[ $rotate_before -eq 1 ]]; then + local expect_count=6 + else + local expect_count=5 + fi + validate_trace_count $EVENT_NAME $local_path $expect_count + + destroy_lttng_session_ok $SESSION_NAME +} + +function test_kernel_streaming_live () +{ + local tracing_active=$1 + local clear_twice=$2 + local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" + + diag "Test kernel streaming live clear" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice" + create_lttng_session_uri $SESSION_NAME net://localhost "--live" + lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing_ok $SESSION_NAME + # Generate 10 events that will sit in the buffers. + echo -n "10" > /proc/lttng-test-filter-event + do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0 + stop_lttng_tracing_ok $SESSION_NAME + + validate_trace_empty $local_path + + destroy_lttng_session_ok $SESSION_NAME +} + +#no clear +function test_kernel_basic_streaming_live_viewer () +{ + local tracing_active=$1 + local clear_twice=$2 + # 3, 4 unused + local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" + local remote_trace_path="${HOSTNAME}/${SESSION_NAME}" + local channel_name="chan" + local bt_output_path=$(mktemp -u) + local file_sync_before_exit=$(mktemp -u) + + diag "Test kernel basic streaming live with viewer" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice" + create_lttng_session_uri $SESSION_NAME net://localhost "--live" + enable_kernel_lttng_channel_ok $SESSION_NAME $channel_name + enable_kernel_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name + start_lttng_tracing_ok $SESSION_NAME + + wait_live_trace_ready net://localhost + + # Connect a live viewer + $BABELTRACE_BIN -i lttng-live net://localhost/host/$remote_trace_path > $bt_output_path & + local viewer_pid=$! + + wait_live_viewer_connect net://localhost + + echo -n "10" > /proc/lttng-test-filter-event + + diag "Wait until viewer sees all 10 expected events" + local evcount=0 + while [ $evcount -ne 10 ]; do + evcount=$(cat $bt_output_path | wc -l) + sleep 0.5 + done + pass "Live viewer read $evcount events, expect 10" + + destroy_lttng_session_ok $SESSION_NAME + touch $file_sync_before_exit + diag "Wait for viewer to exit" + wait $viewer_pid + ok $? "Babeltrace succeeds" + pass "Wait for viewer to exit" + + rm -f $bt_output_path + rm -f $file_sync_before_exit +} + +function test_kernel_streaming_live_viewer () +{ + local tracing_active=$1 + local clear_twice=$2 + # 3, 4 unused + local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" + local remote_trace_path="${HOSTNAME}/${SESSION_NAME}" + local channel_name="chan" + local bt_output_path=$(mktemp -d)/bt-output.txt + + diag "Test kernel streaming live clear with viewer" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice" + create_lttng_session_uri $SESSION_NAME net://localhost "--live" + enable_kernel_lttng_channel_ok $SESSION_NAME $channel_name + enable_kernel_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name + start_lttng_tracing_ok $SESSION_NAME + + wait_live_trace_ready net://localhost + + # Connect a live viewer + $BABELTRACE_BIN -i lttng-live net://localhost/host/$remote_trace_path > $bt_output_path & + local viewer_pid=$! + + wait_live_viewer_connect net://localhost + + echo -n "10" > /proc/lttng-test-filter-event + do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0 + stop_lttng_tracing_ok $SESSION_NAME + + destroy_lttng_session_ok $SESSION_NAME + diag "Wait for viewer to exit" + wait $viewer_pid + ok $? "Babeltrace succeeds" + pass "Wait for viewer to exit" + + clean_path $bt_output_path +} + +function test_kernel_local () +{ + local tracing_active=$1 + local clear_twice=$2 + local rotate_before=$3 + local rotate_after=$4 + + diag "Test kernel local" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after" + create_lttng_session_ok $SESSION_NAME $TRACE_PATH + lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing_ok $SESSION_NAME + # Generate 10 events that will sit in the buffers. + echo -n "10" > /proc/lttng-test-filter-event + do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after + stop_lttng_tracing_ok $SESSION_NAME + + if [[ $rotate_before -eq 1 ]]; then + validate_trace_count $EVENT_NAME $TRACE_PATH 10 + else + validate_trace_empty $TRACE_PATH + fi + + destroy_lttng_session_ok $SESSION_NAME +} + +function test_kernel_local_rotate_clear () +{ + local tracing_active=$1 + local clear_twice=$2 + local rotate_before=$3 + local rotate_after=$4 + + diag "Test kernel local rotate-clear" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after" + create_lttng_session_ok $SESSION_NAME $TRACE_PATH + lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing_ok $SESSION_NAME + echo -n "1" > /proc/lttng-test-filter-event + rotate_session_ok $SESSION_NAME + echo -n "2" > /proc/lttng-test-filter-event + do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after + echo -n "3" > /proc/lttng-test-filter-event + stop_lttng_tracing_ok $SESSION_NAME + + if [[ $rotate_before -eq 1 ]]; then + local expect_count=6 + else + local expect_count=4 + fi + validate_trace_count $EVENT_NAME $TRACE_PATH $expect_count + + destroy_lttng_session_ok $SESSION_NAME +} + +function test_kernel_local_clear_rotate() +{ + local tracing_active=$1 + local clear_twice=$2 + local rotate_before=$3 + local rotate_after=$4 + + diag "Test kernel local clear-rotate" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after" + create_lttng_session_ok $SESSION_NAME $TRACE_PATH + lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing_ok $SESSION_NAME + echo -n "1" > /proc/lttng-test-filter-event + do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after + echo -n "2" > /proc/lttng-test-filter-event + rotate_session_ok $SESSION_NAME + echo -n "3" > /proc/lttng-test-filter-event + stop_lttng_tracing_ok $SESSION_NAME + + if [[ $rotate_before -eq 1 ]]; then + local expect_count=6 + else + local expect_count=5 + fi + validate_trace_count $EVENT_NAME $TRACE_PATH $expect_count + + destroy_lttng_session_ok $SESSION_NAME +} + +function do_kernel_snapshot () +{ + local session_name=$1 + local trace_path=$2 + local tracing_active=$3 + local clear_twice=$4 + local rotate_before=$5 + local rotate_after=$6 + + lttng_enable_kernel_event $session_name $EVENT_NAME + start_lttng_tracing_ok $session_name + + # Generate 10 events that will sit in the buffers. + echo -n "10" > /proc/lttng-test-filter-event + + # Take a first snapshot and validate that the events are present. + lttng_snapshot_record $session_name + stop_lttng_tracing_ok $session_name + validate_trace_count $EVENT_NAME $trace_path 10 + + # Clean the output path + clean_path $trace_path + start_lttng_tracing_ok $session_name + + do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0 + + # Make sure the subsequent snapshot is empty and valid. + lttng_snapshot_record $session_name + stop_lttng_tracing_ok $session_name + validate_trace_empty $trace_path + + # Clean the output path + clean_path $trace_path + start_lttng_tracing_ok $session_name + + # Make sure that everything still works, generate events and take a + # snapshot. + echo -n "10" > /proc/lttng-test-filter-event + lttng_snapshot_record $session_name + stop_lttng_tracing_ok $session_name + validate_trace_count $EVENT_NAME $trace_path 10 +} + +function test_kernel_streaming_snapshot () +{ + local tracing_active=$1 + local clear_twice=$2 + + diag "Test kernel streaming snapshot clear" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice" + + create_lttng_session_uri $SESSION_NAME net://localhost "--snapshot" + do_kernel_snapshot $SESSION_NAME $TRACE_PATH $tracing_active $clear_twice + destroy_lttng_session_ok $SESSION_NAME +} + +function test_kernel_local_snapshot () +{ + local tracing_active=$1 + local clear_twice=$2 + + diag "Test kernel local snapshot clear" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice" + + create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot" + do_kernel_snapshot $SESSION_NAME $TRACE_PATH $tracing_active $clear_twice + destroy_lttng_session_ok $SESSION_NAME +} + +function test_kernel_streaming_tracefile_rotation () +{ + local tracing_active=$1 + local clear_twice=$2 + local rotate_before=$3 + local rotate_after=$4 + local channel_name="rotchan" + local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" + + diag "Test kernel streaming clear with tracefile rotation" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after" + create_lttng_session_uri $SESSION_NAME net://localhost + enable_kernel_lttng_channel_ok $SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \ + --tracefile-size=$PAGE_SIZE --tracefile-count=2 + enable_kernel_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name + start_lttng_tracing_ok $SESSION_NAME + echo -n "10" > /proc/lttng-test-filter-event + do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after + stop_lttng_tracing_ok $SESSION_NAME + + if [[ $rotate_before -eq 1 ]]; then + validate_trace_count $EVENT_NAME $local_path 10 + else + validate_trace_empty $local_path + fi + + start_lttng_tracing_ok $SESSION_NAME + echo -n "20" > /proc/lttng-test-filter-event + stop_lttng_tracing_ok + + if [[ $rotate_before -eq 1 ]]; then + validate_trace_count $EVENT_NAME $local_path 30 + else + validate_trace_count $EVENT_NAME $local_path 20 + fi + + destroy_lttng_session_ok $SESSION_NAME +} + +# With 1 byte per event (as strict minimum), generating 200000 events +# guarantees filling up 2 files of 64k in size, which is the maximum +# page size known on Linux +function test_kernel_streaming_tracefile_rotation_overwrite_files () +{ + local tracing_active=$1 + local clear_twice=$2 + local rotate_before=$3 + local rotate_after=$4 + local channel_name="rotchan" + local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" + + diag "Test kernel streaming clear with tracefile rotation, overwrite files" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after" + create_lttng_session_uri $SESSION_NAME net://localhost + enable_kernel_lttng_channel_ok $SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \ + --tracefile-size=$PAGE_SIZE --tracefile-count=2 + enable_kernel_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name + start_lttng_tracing_ok $SESSION_NAME + taskset -c 0 echo -n "200000" > /proc/lttng-test-filter-event + do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after + stop_lttng_tracing_ok $SESSION_NAME + + if [[ $rotate_before -eq 1 ]]; then + validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 200000 + else + validate_trace_empty $local_path + fi + + start_lttng_tracing_ok $SESSION_NAME + taskset -c 0 echo -n "400000" > /proc/lttng-test-filter-event + stop_lttng_tracing_ok + + if [[ $rotate_before -eq 1 ]]; then + validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 600000 + else + validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 200000 + fi + + destroy_lttng_session_ok $SESSION_NAME +} + +function test_kernel_disallow_clear () +{ + diag "Test kernel disallow clear on relay daemon" + SESSION_NAME=$(randstring 16 0) + + LTTNG_RELAYD_DISALLOW_CLEAR=1 start_lttng_relayd "-o $TRACE_PATH" + + start_lttng_sessiond + + create_lttng_session_uri $SESSION_NAME net://localhost + enable_kernel_lttng_event_ok $SESSION_NAME $EVENT_NAME + start_lttng_tracing_ok $SESSION_NAME + lttng_clear_session_fail $SESSION_NAME + destroy_lttng_session_ok $SESSION_NAME + + stop_lttng_sessiond + stop_lttng_relayd + clean_path $TRACE_PATH +} + +plan_tests $NUM_TESTS + +print_test_banner "$TEST_DESC" + +if [ "$(id -u)" == "0" ]; then + isroot=1 +else + isroot=0 +fi + +streaming_tests=(test_kernel_streaming + test_kernel_streaming_rotate_clear + test_kernel_streaming_clear_rotate + test_kernel_streaming_tracefile_rotation + test_kernel_streaming_tracefile_rotation_overwrite_files +) + +live_tests=(test_kernel_streaming_live + test_kernel_basic_streaming_live_viewer + test_kernel_streaming_live_viewer +) + +local_tests=(test_kernel_local + test_kernel_local_rotate_clear + test_kernel_local_clear_rotate +) + +snapshot_tests=(test_kernel_streaming_snapshot + test_kernel_local_snapshot +) + +skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS || +{ + trap signal_cleanup SIGTERM SIGINT + + validate_lttng_modules_present + + start_lttng_relayd "-o $TRACE_PATH" + start_lttng_sessiond + modprobe lttng-test + + # Clear with tracing active, clear once + for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_tests[@]}; + do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 1 0 0 0 + clean_path $TRACE_PATH + done + + # Clear with tracing active, clear twice + for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_tests[@]}; + do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 1 1 0 0 + clean_path $TRACE_PATH + done + + # Clear with tracing inactive, clear once + for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_tests[@]}; + do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 0 0 0 0 + clean_path $TRACE_PATH + done + + # Clear with tracing inactive, clear twice + for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_tests[@]}; + do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 0 1 0 0 + clean_path $TRACE_PATH + done + + # Clear with tracing inactive, rotate-clear once + for fct_test in ${streaming_tests[@]} ${local_tests[@]}; + do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 0 0 1 0 + clean_path $TRACE_PATH + done + + # Clear with tracing inactive, clear once-rotate(fail) + for fct_test in ${streaming_tests[@]} ${local_tests[@]}; + do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 0 0 0 1 + clean_path $TRACE_PATH + done + + rmmod lttng-test + stop_lttng_sessiond + stop_lttng_relayd + + test_kernel_disallow_clear +} + +clean_path $TRACE_PATH diff --git a/tests/regression/tools/clear/test_ust b/tests/regression/tools/clear/test_ust new file mode 100755 index 000000000..0be3bd437 --- /dev/null +++ b/tests/regression/tools/clear/test_ust @@ -0,0 +1,804 @@ +#!/bin/bash +# +# Copyright (C) - 2019 Jonathan Rajotte-Julien +# +# 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="Clear - UST tracing" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +EVENT_NAME="tp:tptest" +SESSION_NAME="" +TESTAPP_PATH="$TESTDIR/utils/testapp" +TESTAPP_NAME="gen-ust-events" +TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" + +NUM_TESTS=1683 + +PAGE_SIZE=$(getconf PAGE_SIZE) +TRACE_PATH=$(mktemp -d) + +source $TESTDIR/utils/utils.sh + +if [ ! -x "$TESTAPP_BIN" ]; then + BAIL_OUT "No UST events binary detected." +fi + +function clean_path () +{ + local trace_path=$1 + set -u + rm -rf $trace_path/* + set +u +} + +function cond_start_tracing () +{ + local session_name=$1 + local tracing_active=$2 + + if [[ $tracing_active -ne 1 ]]; then + start_lttng_tracing_ok $session_name + fi +} + +function cond_stop_tracing () +{ + local session_name=$1 + local tracing_active=$2 + + if [[ $tracing_active -ne 1 ]]; then + stop_lttng_tracing_ok $session_name + fi +} + +function do_clear_session () +{ + local session_name=$1 + local tracing_active=$2 + local clear_twice=$3 + local rotate_before=$4 + local rotate_after=$5 + + cond_stop_tracing $session_name $tracing_active + if [[ $rotate_before -eq 1 ]]; then + rotate_session_ok $SESSION_NAME + fi + lttng_clear_session_ok $SESSION_NAME + if [[ $clear_twice -eq 1 ]]; then + lttng_clear_session_ok $SESSION_NAME + fi + if [[ $rotate_after -eq 1 ]]; then + if [[ $tracing_active -eq 1 ]]; then + rotate_session_ok $SESSION_NAME + else + # Expect failure + rotate_session_fail $SESSION_NAME + fi + fi + cond_start_tracing $session_name $tracing_active +} + +function test_ust_streaming () +{ + local tracing_active=$1 + local clear_twice=$2 + local rotate_before=$3 + local rotate_after=$4 + local buffer_type=$5 + local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" + local channel_name="chan" + + diag "Test ust streaming clear" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" + create_lttng_session_uri $SESSION_NAME net://localhost + enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name + start_lttng_tracing_ok $SESSION_NAME + $TESTAPP_BIN -i 10 + do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after + stop_lttng_tracing_ok $SESSION_NAME + + if [[ $rotate_before -eq 1 ]]; then + validate_trace_count $EVENT_NAME $local_path 10 + else + if [[ "$buffer_type" == "uid" ]]; then + validate_trace_empty $local_path + else # pid + validate_directory_empty $local_path + fi + fi + + destroy_lttng_session_ok $SESSION_NAME +} + +function test_ust_streaming_rotate_clear () +{ + local tracing_active=$1 + local clear_twice=$2 + local rotate_before=$3 + local rotate_after=$4 + local buffer_type=$5 + local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" + local channel_name="chan" + + diag "Test ust streaming rotate-clear" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" + create_lttng_session_uri $SESSION_NAME net://localhost + enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name + start_lttng_tracing_ok $SESSION_NAME + $TESTAPP_BIN -i 1 + rotate_session_ok $SESSION_NAME + $TESTAPP_BIN -i 2 + do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after + $TESTAPP_BIN -i 3 + stop_lttng_tracing_ok $SESSION_NAME + + if [[ $rotate_before -eq 1 ]]; then + local expect_count=6 + else + local expect_count=4 + fi + validate_trace_count $EVENT_NAME $local_path $expect_count + + destroy_lttng_session_ok $SESSION_NAME +} + +function test_ust_streaming_clear_rotate () +{ + local tracing_active=$1 + local clear_twice=$2 + local rotate_before=$3 + local rotate_after=$4 + local buffer_type=$5 + local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" + local channel_name="chan" + + diag "Test ust streaming clear-rotate" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" + create_lttng_session_uri $SESSION_NAME net://localhost + enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name + start_lttng_tracing_ok $SESSION_NAME + $TESTAPP_BIN -i 1 + do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after + $TESTAPP_BIN -i 2 + rotate_session_ok $SESSION_NAME + $TESTAPP_BIN -i 3 + stop_lttng_tracing_ok $SESSION_NAME + + if [[ $rotate_before -eq 1 ]]; then + local expect_count=6 + else + local expect_count=5 + fi + validate_trace_count $EVENT_NAME $local_path $expect_count + + destroy_lttng_session_ok $SESSION_NAME +} + +function test_ust_streaming_live () +{ + local tracing_active=$1 + local clear_twice=$2 + # 3, 4 unused + local buffer_type=$5 + local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" + local channel_name="chan" + + diag "Test ust streaming live clear" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" + create_lttng_session_uri $SESSION_NAME net://localhost "--live" + enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name + start_lttng_tracing_ok $SESSION_NAME + $TESTAPP_BIN -i 10 + do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0 + stop_lttng_tracing_ok $SESSION_NAME + + validate_directory_empty $local_path + + destroy_lttng_session_ok $SESSION_NAME +} + +#no clear +function test_ust_basic_streaming_live_viewer () +{ + local tracing_active=$1 + local clear_twice=$2 + # 3, 4 unused + local buffer_type=$5 + local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" + local remote_trace_path="${HOSTNAME}/${SESSION_NAME}" + local channel_name="chan" + local bt_output_path=$(mktemp -u) + local file_sync_before_exit=$(mktemp -u) + + diag "Test ust basic streaming live with viewer" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" + create_lttng_session_uri $SESSION_NAME net://localhost "--live" + enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name + start_lttng_tracing_ok $SESSION_NAME + + wait_live_trace_ready net://localhost + + # Connect a live viewer + $BABELTRACE_BIN -i lttng-live net://localhost/host/$remote_trace_path > $bt_output_path & + local viewer_pid=$! + + wait_live_viewer_connect net://localhost + + $TESTAPP_BIN -i 10 --sync-before-exit $file_sync_before_exit & + local app_pid=$! + + diag "Wait until viewer sees all 10 expected events" + local evcount=0 + while [ $evcount -ne 10 ]; do + evcount=$(cat $bt_output_path | wc -l) + sleep 0.5 + done + pass "Live viewer read $evcount events, expect 10" + + destroy_lttng_session_ok $SESSION_NAME + touch $file_sync_before_exit + diag "Wait for application to exit" + wait $app_pid + pass "Wait for application to exit" + diag "Wait for viewer to exit" + wait $viewer_pid + ok $? "Babeltrace succeeds" + pass "Wait for viewer to exit" + + rm -f $bt_output_path + rm -f $file_sync_before_exit +} + +function test_ust_streaming_live_viewer () +{ + local tracing_active=$1 + local clear_twice=$2 + # 3, 4 unused + local buffer_type=$5 + local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" + local remote_trace_path="${HOSTNAME}/${SESSION_NAME}" + local channel_name="chan" + local bt_output_path=$(mktemp -d)/bt-output.txt + + diag "Test ust streaming live clear with viewer" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" + create_lttng_session_uri $SESSION_NAME net://localhost "--live" + enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name + start_lttng_tracing_ok $SESSION_NAME + + wait_live_trace_ready net://localhost + + # Connect a live viewer + $BABELTRACE_BIN -i lttng-live net://localhost/host/$remote_trace_path > $bt_output_path & + local viewer_pid=$! + + wait_live_viewer_connect net://localhost + + $TESTAPP_BIN -i 10 + do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0 + stop_lttng_tracing_ok $SESSION_NAME + + destroy_lttng_session_ok $SESSION_NAME + diag "Wait for viewer to exit" + wait $viewer_pid + ok $? "Babeltrace succeeds" + pass "Wait for viewer to exit" + + clean_path $bt_output_path +} + +function test_ust_local () +{ + local tracing_active=$1 + local clear_twice=$2 + local rotate_before=$3 + local rotate_after=$4 + local buffer_type=$5 + local channel_name="chan" + + diag "Test ust local" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" + create_lttng_session_ok $SESSION_NAME $TRACE_PATH + enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name + start_lttng_tracing_ok $SESSION_NAME + $TESTAPP_BIN -i 10 + do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after + stop_lttng_tracing_ok $SESSION_NAME + + if [[ $rotate_before -eq 1 ]]; then + validate_trace_count $EVENT_NAME $TRACE_PATH 10 + else + if [[ "$buffer_type" == "uid" ]]; then + validate_trace_empty $TRACE_PATH + else # pid + validate_directory_empty $TRACE_PATH + fi + fi + + destroy_lttng_session_ok $SESSION_NAME +} + +function test_ust_local_rotate_clear () +{ + local tracing_active=$1 + local clear_twice=$2 + local rotate_before=$3 + local rotate_after=$4 + local buffer_type=$5 + local channel_name="chan" + + diag "Test ust local rotate-clear" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" + create_lttng_session_ok $SESSION_NAME $TRACE_PATH + enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name + start_lttng_tracing_ok $SESSION_NAME + $TESTAPP_BIN -i 1 + rotate_session_ok $SESSION_NAME + $TESTAPP_BIN -i 2 + do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after + $TESTAPP_BIN -i 3 + stop_lttng_tracing_ok $SESSION_NAME + + if [[ $rotate_before -eq 1 ]]; then + local expect_count=6 + else + local expect_count=4 + fi + validate_trace_count $EVENT_NAME $TRACE_PATH $expect_count + + destroy_lttng_session_ok $SESSION_NAME +} + +function test_ust_local_clear_rotate () +{ + local tracing_active=$1 + local clear_twice=$2 + local rotate_before=$3 + local rotate_after=$4 + local buffer_type=$5 + local channel_name="chan" + + diag "Test ust local clear-rotate" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" + create_lttng_session_ok $SESSION_NAME $TRACE_PATH + enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name + start_lttng_tracing_ok $SESSION_NAME + $TESTAPP_BIN -i 1 + do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after + $TESTAPP_BIN -i 2 + rotate_session_ok $SESSION_NAME + $TESTAPP_BIN -i 3 + stop_lttng_tracing_ok $SESSION_NAME + + if [[ $rotate_before -eq 1 ]]; then + local expect_count=6 + else + local expect_count=5 + fi + validate_trace_count $EVENT_NAME $TRACE_PATH $expect_count + + destroy_lttng_session_ok $SESSION_NAME +} + +function do_ust_snapshot () +{ + local session_name=$1 + local trace_path=$2 + local tracing_active=$3 + local clear_twice=$4 + local buffer_type=$5 + local channel_name="snapshot" + + enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type + enable_ust_lttng_event_ok $session_name $EVENT_NAME $channel_name + start_lttng_tracing_ok $session_name + + # Generate 10 events that will sit in the buffers. + $TESTAPP_BIN -i 10 + + # Take a first snapshot and validate that the events are present. + lttng_snapshot_record $session_name + stop_lttng_tracing_ok $session_name + validate_trace_count $EVENT_NAME $trace_path 10 + + # Clean the output path + clean_path $trace_path + start_lttng_tracing_ok $session_name + + do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0 + + # Make sure the subsequent snapshot is empty and valid. + lttng_snapshot_record $session_name + stop_lttng_tracing_ok $session_name + validate_trace_empty $trace_path + + # Clean the output path + clean_path $trace_path + start_lttng_tracing_ok $session_name + + # Make sure that everything still works, generate events and take a + # snapshot. + $TESTAPP_BIN -i 10 + lttng_snapshot_record $session_name + stop_lttng_tracing_ok $session_name + validate_trace_count $EVENT_NAME $trace_path 10 +} + +function test_ust_streaming_snapshot () +{ + local tracing_active=$1 + local clear_twice=$2 + # 3, 4 unused. + local buffer_type=$5 + + diag "Test ust streaming snapshot clear" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" + + create_lttng_session_uri $SESSION_NAME net://localhost "--snapshot" + do_ust_snapshot $SESSION_NAME $TRACE_PATH $tracing_active $clear_twice $buffer_type + destroy_lttng_session_ok $SESSION_NAME +} + +function test_ust_local_snapshot () +{ + local tracing_active=$1 + local clear_twice=$2 + # 3, 4 unused. + local buffer_type=$5 + + diag "Test ust local snapshot clear" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" + + create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot" + do_ust_snapshot $SESSION_NAME $TRACE_PATH $tracing_active $clear_twice $buffer_type + destroy_lttng_session_ok $SESSION_NAME +} + +# snapshot for per-pid is tested independently of the "buffer type" parameter +# because an application needs to be live to appear in a snapshot. +function test_ust_local_snapshot_per_pid () +{ + local tracing_active=$1 + local clear_twice=$2 + # 3, 4 unused. + local buffer_type=$5 + local channel_name="channel0" + local file_sync_before_last=$(mktemp -u) + local file_sync_before_last_touch=$(mktemp -u) + local file_sync_before_exit=$(mktemp -u) + local file_sync_before_exit_touch=$(mktemp -u) + + diag "Test ust local snapshot clear per pid" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" + + create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot" + enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name + start_lttng_tracing_ok $SESSION_NAME + + # Generate 10 events that will sit in the buffers. + $TESTAPP_BIN -i 10 -w 0 \ + --sync-before-last-event ${file_sync_before_last} \ + --sync-before-last-event-touch ${file_sync_before_last_touch} \ + --sync-before-exit ${file_sync_before_exit} \ + --sync-before-exit-touch ${file_sync_before_exit_touch} >/dev/null 2>&1 & + + # Continue only when there is only the last event remaining. + while [ ! -f "${file_sync_before_last_touch}" ]; do + sleep 0.5 + done + + # Take a first snapshot and validate that the events are present. + lttng_snapshot_record $SESSION_NAME + stop_lttng_tracing_ok $SESSION_NAME + validate_trace_count $EVENT_NAME $TRACE_PATH 9 + + # Clean the output path + clean_path $TRACE_PATH + start_lttng_tracing_ok $SESSION_NAME + + do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0 + + # Make sure the subsequent snapshot is empty and valid. + lttng_snapshot_record $SESSION_NAME + stop_lttng_tracing_ok $SESSION_NAME + validate_trace_empty $TRACE_PATH + + # Validate that tracing still works and subsequent snapshots are valid. + # Clean the output path. + clean_path $TRACE_PATH + start_lttng_tracing_ok $SESSION_NAME + + # Continue over the last event. + touch ${file_sync_before_last} + + # Wait for the before exit sync point. This ensure that we went over the + # last tracepoint. + while [ ! -f "${file_sync_before_exit_touch}" ]; do + sleep 0.5 + done + + # Make sure the snapshot contains the last event. + lttng_snapshot_record $SESSION_NAME + stop_lttng_tracing_ok $SESSION_NAME + validate_trace_count $EVENT_NAME $TRACE_PATH 1 + + # Release the application. + touch ${file_sync_before_exit} + wait + destroy_lttng_session_ok $SESSION_NAME + + rm -f ${file_sync_before_last} + rm -f ${file_sync_before_last_touch} + rm -f ${file_sync_before_exit} + rm -f ${file_sync_before_exit_touch} +} + +function test_ust_streaming_tracefile_rotation () +{ + local tracing_active=$1 + local clear_twice=$2 + local rotate_before=$3 + local rotate_after=$4 + local buffer_type=$5 + local channel_name="rotchan" + local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" + + diag "Test ust streaming clear with tracefile rotation" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" + create_lttng_session_uri $SESSION_NAME net://localhost + enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \ + --tracefile-size=$PAGE_SIZE --tracefile-count=2 --buffers-$buffer_type + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name + start_lttng_tracing_ok $SESSION_NAME + $TESTAPP_BIN -i 10 + do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after + stop_lttng_tracing_ok $SESSION_NAME + + if [[ $rotate_before -eq 1 ]]; then + validate_trace_count $EVENT_NAME $local_path 10 + else + if [[ "$buffer_type" == "uid" ]]; then + validate_trace_empty $local_path + else # pid + validate_directory_empty $local_path + fi + fi + + start_lttng_tracing_ok $SESSION_NAME + $TESTAPP_BIN -i 20 + stop_lttng_tracing_ok + + if [[ $rotate_before -eq 1 ]]; then + validate_trace_count $EVENT_NAME $local_path 30 + else + validate_trace_count $EVENT_NAME $local_path 20 + fi + + destroy_lttng_session_ok $SESSION_NAME +} + +# With 1 byte per event (as strict minimum), generating 200000 events +# guarantees filling up 2 files of 64k in size, which is the maximum +# page size known on Linux +function test_ust_streaming_tracefile_rotation_overwrite_files () +{ + local tracing_active=$1 + local clear_twice=$2 + local rotate_before=$3 + local rotate_after=$4 + local buffer_type=$5 + local channel_name="rotchan" + local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" + + diag "Test ust streaming clear with tracefile rotation, overwrite files" + diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" + create_lttng_session_uri $SESSION_NAME net://localhost + enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \ + --tracefile-size=$PAGE_SIZE --tracefile-count=2 --buffers-$buffer_type + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name + start_lttng_tracing_ok $SESSION_NAME + taskset -c 0 $TESTAPP_BIN -i 200000 + do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after + stop_lttng_tracing_ok $SESSION_NAME + + if [[ $rotate_before -eq 1 ]]; then + validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 200000 + else + if [[ "$buffer_type" == "uid" ]]; then + validate_trace_empty $local_path + else # pid + validate_directory_empty $local_path + fi + fi + + start_lttng_tracing_ok $SESSION_NAME + taskset -c 0 $TESTAPP_BIN -i 400000 + stop_lttng_tracing_ok + + if [[ $rotate_before -eq 1 ]]; then + validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 600000 + else + validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 200000 + fi + + destroy_lttng_session_ok $SESSION_NAME +} + +function test_ust_disallow_clear () +{ + diag "Test ust disallow clear on relay daemon" + SESSION_NAME=$(randstring 16 0) + + LTTNG_RELAYD_DISALLOW_CLEAR=1 start_lttng_relayd "-o $TRACE_PATH" + + start_lttng_sessiond + + create_lttng_session_uri $SESSION_NAME net://localhost + enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME + start_lttng_tracing_ok $SESSION_NAME + lttng_clear_session_fail $SESSION_NAME + destroy_lttng_session_ok $SESSION_NAME + + stop_lttng_sessiond + stop_lttng_relayd + clean_path $TRACE_PATH +} + +plan_tests $NUM_TESTS + +print_test_banner "$TEST_DESC" + +streaming_tests=(test_ust_streaming + test_ust_streaming_rotate_clear + test_ust_streaming_clear_rotate + test_ust_streaming_tracefile_rotation + test_ust_streaming_tracefile_rotation_overwrite_files +) + +live_tests=(test_ust_streaming_live + test_ust_basic_streaming_live_viewer + test_ust_streaming_live_viewer +) + +local_tests=(test_ust_local + test_ust_local_rotate_clear + test_ust_local_clear_rotate +) + +snapshot_uid_tests=(test_ust_streaming_snapshot + test_ust_local_snapshot +) + +snapshot_pid_tests=(test_ust_local_snapshot_per_pid) + +start_lttng_relayd "-o $TRACE_PATH" +start_lttng_sessiond + +# Per-UID buffers + +# Clear with tracing active, clear once +for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]}; +do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 1 0 0 0 uid + clean_path $TRACE_PATH +done + +# Clear with tracing active, clear twice +for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]}; +do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 1 1 0 0 uid + clean_path $TRACE_PATH +done + +# Clear with tracing inactive, clear once +for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]}; +do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 0 0 0 0 uid + clean_path $TRACE_PATH +done + +# Clear with tracing inactive, clear twice +for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]}; +do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 0 1 0 0 uid + clean_path $TRACE_PATH +done + +# Clear with tracing inactive, rotate-clear once +for fct_test in ${streaming_tests[@]} ${local_tests[@]}; +do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 0 0 1 0 uid + clean_path $TRACE_PATH +done + +# Clear with tracing inactive, clear once-rotate(fail) +for fct_test in ${streaming_tests[@]} ${local_tests[@]}; +do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 0 0 0 1 uid + clean_path $TRACE_PATH +done + + +# Per-PID buffers. + +# Clear with tracing active, clear once +for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]}; +do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 1 0 0 0 pid + clean_path $TRACE_PATH +done + +# Clear with tracing active, clear twice +for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]}; +do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 1 1 0 0 pid + clean_path $TRACE_PATH +done + +# Clear with tracing inactive, clear once +for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]}; +do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 0 0 0 0 pid + clean_path $TRACE_PATH +done + +# Clear with tracing inactive, clear twice +for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]}; +do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 0 1 0 0 pid + clean_path $TRACE_PATH +done + +# Clear with tracing inactive, rotate-clear once +for fct_test in ${streaming_tests[@]} ${local_tests[@]}; +do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 0 0 1 0 pid + clean_path $TRACE_PATH +done + +# Clear with tracing inactive, clear once-rotate(fail) +for fct_test in ${streaming_tests[@]} ${local_tests[@]}; +do + SESSION_NAME=$(randstring 16 0) + ${fct_test} 0 0 0 1 pid + clean_path $TRACE_PATH +done + +stop_lttng_sessiond +stop_lttng_relayd + +test_ust_disallow_clear diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index 9df9a0bf0..df2671eb6 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -331,9 +331,9 @@ function lttng_enable_kernel_channel() local expected_to_fail=$2 local sess_name=$3 local channel_name=$4 - local opt=$5 + local opts="${@:5}" - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST + $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST ret=$? if [[ $expected_to_fail -eq "1" ]]; then test "$ret" -ne "0" @@ -946,9 +946,9 @@ function enable_ust_lttng_channel () local expected_to_fail=$2 local sess_name=$3 local channel_name=$4 - local opt=$5 + local opts="${@:5}" - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST + $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST ret=$? if [[ $expected_to_fail -eq "1" ]]; then test "$ret" -ne "0" @@ -1420,7 +1420,6 @@ function lttng_snapshot_del_output_fail () function lttng_snapshot_record () { local sess_name=$1 - local trace_path=$2 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name $trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST ok $? "Snapshot recorded" @@ -1573,6 +1572,44 @@ function add_context_kernel_fail() add_context_lttng 1 -k "$@" } +function validate_directory_empty () +{ + local trace_path=$1 + + ls -A $local_path > /dev/null 2>&1 + if [ $? -eq 0 ]; then + pass "Directory empty" + else + fail "Directory empty" + fi +} + +function wait_live_trace_ready () +{ + local url=$1 + local zero_client_match=0 + + diag "Waiting for live trace at url: $url" + while [ $zero_client_match -eq 0 ]; do + zero_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "0 client(s) connected" | wc -l) + sleep 0.5 + done + pass "Waiting for live trace at url: $url" +} + +function wait_live_viewer_connect () +{ + local url=$1 + local one_client_match=0 + + diag "Waiting for live viewers on url: $url" + while [ $one_client_match -eq 0 ]; do + one_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "1 client(s) connected" | wc -l) + sleep 0.5 + done + pass "Waiting for live viewers on url: $url" +} + function validate_metadata_event () { local event_name=$1 @@ -1690,6 +1727,36 @@ function validate_trace_count ok $? "Read a total of $cnt events, expected $expected_count" } +function validate_trace_count_range_incl_min_excl_max +{ + local event_name=$1 + local trace_path=$2 + local expected_min=$3 + local expected_max=$4 + + 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" -ge $expected_min ]; 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 -lt $expected_max + ok $? "Read a total of $cnt events, expected between [$expected_min, $expected_max[" +} + function trace_first_line { local trace_path=$1 @@ -1904,3 +1971,28 @@ function lttng_enable_rotation_size_fail () { lttng_enable_rotation_size 1 $@ } + +function lttng_clear_session () +{ + local expected_to_fail=$1 + local sess_name=$2 + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN clear $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 clear session $sess_name" + else + ok $ret "Clear session $sess_name" + fi +} + +function lttng_clear_session_ok () +{ + lttng_clear_session 0 $@ +} + +function lttng_clear_session_fail () +{ + lttng_clear_session 1 $@ +} -- 2.34.1