From d8b7ee901bab38f2c8c080b418100111a0ef247f Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Mon, 8 Apr 2019 14:08:36 -0400 Subject: [PATCH] Test: clear: local, streaming, live, tracefile rotation This is the base testsuite for the lttng clear command. The following scenarios are validated: local local with tracefilei rotation streaming streaming with tracefile rotation live with viewer attach while clear is issued live with viewer attach after clear is issued live with viewer attach while clear is issued and tracefile rotation active These tests are performed for kernel and userspace domain. When testing in userspace the following scenarios are also tested: Per pid and clear: this should fail. It is not supported yet. relayd disallow clear: clear must fail when relayd does not allow it For the test using a viewer a testpoint was added to lttng-relayd live protocol to give a synchronization point between babeltrace and the test script. The common_test script is a bit convoluted due to the reuse of the same script for both ust and kernel testing. The alternative is to have almost the same code (90%) in two separate files. Signed-off-by: Jonathan Rajotte --- src/bin/lttng-relayd/live.c | 9 + src/bin/lttng-relayd/testpoint.h | 1 + tests/regression/tools/clear/Makefile.am | 23 +- tests/regression/tools/clear/common_test | 651 ++++++++++++++++++ .../tools/clear/relayd_state_testpoint.c | 62 ++ tests/regression/tools/clear/test_kernel | 156 +---- tests/regression/tools/clear/test_ust | 224 +----- tests/regression/tools/crash/test_crash | 4 +- .../notification/test_notification_multi_app | 2 +- tests/utils/utils.sh | 60 +- 10 files changed, 796 insertions(+), 396 deletions(-) create mode 100755 tests/regression/tools/clear/common_test create mode 100644 tests/regression/tools/clear/relayd_state_testpoint.c diff --git a/src/bin/lttng-relayd/live.c b/src/bin/lttng-relayd/live.c index d682d3b09..c06b38cb7 100644 --- a/src/bin/lttng-relayd/live.c +++ b/src/bin/lttng-relayd/live.c @@ -1098,6 +1098,15 @@ int viewer_attach_session(struct relay_connection *conn) goto send_reply; } + if (testpoint(relayd_viewer_session_attach)) { + ERR("Viewer session attach testpoint failed"); + send_streams = 0; + response.streams_count = 0; + response.status = htobe32(LTTNG_VIEWER_ATTACH_UNK); + goto send_reply; + } + + send_reply: health_code_update(); ret = send_response(conn->sock, &response, sizeof(response)); diff --git a/src/bin/lttng-relayd/testpoint.h b/src/bin/lttng-relayd/testpoint.h index ceece09e3..297b0f773 100644 --- a/src/bin/lttng-relayd/testpoint.h +++ b/src/bin/lttng-relayd/testpoint.h @@ -28,5 +28,6 @@ TESTPOINT_DECL(relayd_thread_listener); TESTPOINT_DECL(relayd_thread_live_dispatcher); TESTPOINT_DECL(relayd_thread_live_worker); TESTPOINT_DECL(relayd_thread_live_listener); +TESTPOINT_DECL(relayd_viewer_session_attach); #endif /* SESSIOND_TESTPOINT_H */ diff --git a/tests/regression/tools/clear/Makefile.am b/tests/regression/tools/clear/Makefile.am index aa700f172..890974e59 100644 --- a/tests/regression/tools/clear/Makefile.am +++ b/tests/regression/tools/clear/Makefile.am @@ -1,5 +1,23 @@ -noinst_SCRIPTS = test_kernel test_ust -EXTRA_DIST = test_kernel test_ust +AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(srcdir) +AM_LDFLAGS = + +if NO_SHARED + +CLEANFILES = librelayd_state.so librelayd_state.so.debug +EXTRA_DIST = test_kernel test_ust common_test relayd_state_testpoint.c + +else +# The testpoint library must be built as .so to be able to LD_PRELOAD it. +FORCE_SHARED_LIB_OPTIONS = -module -shared -avoid-version \ + -rpath $(abs_builddir) + +librelayd_state_la_SOURCES = relayd_state_testpoint.c +librelayd_state_la_LIBADD = $(top_builddir)/src/common/libcommon.la $(DL_LIBS) +librelayd_state_la_LDFLAGS = $(FORCE_SHARED_LIB_OPTIONS) +noinst_LTLIBRARIES = librelayd_state.la + +noinst_SCRIPTS = test_kernel test_ust common_test +EXTRA_DIST = test_kernel test_ust common_test all-local: @if [ x"$(srcdir)" != x"$(builddir)" ]; then \ @@ -14,3 +32,4 @@ clean-local: rm -f $(builddir)/$$script; \ done; \ fi +endif diff --git a/tests/regression/tools/clear/common_test b/tests/regression/tools/clear/common_test new file mode 100755 index 000000000..ede709bdf --- /dev/null +++ b/tests/regression/tools/clear/common_test @@ -0,0 +1,651 @@ +#!/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 + +# This is a common test for kernel and ust. DOMAIN must be set. + + +TEST_DESC="Clear - ${DOMAIN} tracing" + +CURDIR=$(dirname "$0")/ +TESTDIR=$CURDIR/../../.. +SESSION_NAME="" +TESTAPP_PATH="$TESTDIR/utils/testapp" +TESTAPP_NAME="gen-ust-events" +TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" +TESTPOINT=$(readlink -f "${CURDIR}/.libs/librelayd_state.so") + +NUM_CPUS=$(nproc) +PAGE_SIZE=$(getconf PAGE_SIZE) + + +source "$TESTDIR/utils/utils.sh" + +if [ "x$DOMAIN" == "x" ]; then + BAIL_OUT "This script must be called with DOMAIN set." +fi + +function clean_path () +{ + local trace_path=$1 + rm -rf "${trace_path:?}"/* +} + +function generate_events () +{ + local cpu=$1 + local nb=$2 + if [ "$DOMAIN" == "kernel" ]; then + taskset -c "$cpu" echo -n "$nb" > /proc/lttng-test-filter-event + else + taskset -c "$cpu" "$TESTAPP_BIN" -i "$nb" + fi +} + +function is_viewer_alive () +{ + local viewer_pid=$1 + jobs -p | grep "$viewer_pid" > /dev/null + return $? +} + +function sync_attach_viewer () +{ + local viewer_pid=$1 + local state_path=$2 + local sync_msg="Viewer attached" + + while ! grep -q "$sync_msg" "$state_path"; do + if ! is_viewer_alive "$viewer_pid"; then + break + fi + diag "Waiting for viewer to attach" + sleep 0.5 + done +} + +function saturate_tracefile_rotation () +{ + local session_name="$1" + local channel_name="$2" + local tracefile_count="$3" + + local path="$TRACE_PATH" + local num_cpus="$NUM_CPUS" + local events_per_call=1000 + local saturation_count=$((( tracefile_count * num_cpus ))) + local file_pattern="${channel_name}_*" + + # The number of event generation necessary to fill a single tracefile. + # We will use this to ensure that the tracefile rotation wrapped around. + local minimum_iteration_rotate=-1 + + local current_tracefile_count=0 + counter=0 + while [ "$current_tracefile_count" -lt "$saturation_count" ]; do + for i in $(seq 0 $(((num_cpus - 1)))); do + generate_events "$i" "$events_per_call" + done + # We need to stop & start to ensure that all data touch disk. + # This is useful in streaming mode where we do not have + # confirmation that data is present on disk otherwise. + stop_lttng_tracing_notap "$session_name" + start_lttng_tracing_notap "$session_name" + current_tracefile_count=$(find "$path" -name "$file_pattern" -type f \( ! -iname "*.idx" \) | wc -l) + if [ "$minimum_iteration_rotate" -eq "-1" ] && \ + [ "$current_tracefile_count" -ge $(((2 * num_cpus))) ]; then + minimum_iteration_rotate="$counter" + fi + (( counter= counter + 1 )) + diag "Saturating tracefile rotation: $counter" + done + + # Ensure that we wrap around. + for j in $(seq 0 "$minimum_iteration_rotate"); do + for i in $(seq 0 $(((num_cpus - 1)))); do + generate_events "$i" "$events_per_call" + done + diag "Saturating tracefile rotation wrap around: $j" + done + stop_lttng_tracing_notap "$session_name" + start_lttng_tracing_notap "$session_name" + +} + +# The session must be configured and started before calling this session. +# The clear command will be issued before the stop command. +function do_uid () +{ + local session_name=$1 + local trace_path=$2 + local event_name=$3 + local nb_iters=$4 + local nb_events_per_iter=$5 + + # Generate nb_events_per_iter events that will be flushed to disk on + # stop, we want to validate that tracing works. They will also validate + # that cleaning of file on disks works. + generate_events 0 "$nb_events_per_iter" + stop_lttng_tracing_ok "$session_name" + validate_trace_count "$event_name" "$trace_path" "$nb_events_per_iter" + + local i=0 + while [[ "$i" -lt "$nb_iters" ]]; do + start_lttng_tracing_ok "$session_name" + # Generate $nb_events_per_iter events that will sit in the + # buffer. In live mode we cannot control the flushing still we + # expect the trace to be empty on the relayd. In case of live we + # expect all event to be present on the viewer side. + generate_events 0 "$nb_events_per_iter" + + # Clear the session while active, this take care of both the + # buffers and data on disks. Expect an empty trace. + lttng_clear_session_ok "$session_name" + stop_lttng_tracing_ok "$session_name" + validate_trace_empty "$trace_path" + ((i = i + 1)) + done + + # Validate that tracing still works. + start_lttng_tracing_ok "$session_name" + generate_events 0 "$nb_events_per_iter" + stop_lttng_tracing_ok "$session_name" + validate_trace_count "$event_name" "$trace_path" "$nb_events_per_iter" + + # Validate that clear while stopped works. + lttng_clear_session_ok "$session_name" + validate_trace_empty "$trace_path" +} + +function test_streaming () +{ + diag "Test ${DOMAIN} streaming clear" + create_lttng_session_uri "$SESSION_NAME" net://localhost + enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" + start_lttng_tracing_ok "$SESSION_NAME" + do_uid "$SESSION_NAME" "$TRACE_PATH" "$EVENT_NAME" 100 10 + destroy_lttng_session_ok "$SESSION_NAME" +} + +# We cannot user babeltrace to validate live reception or buffer clearing when +# the session is active due to the timing of the live timer that could influence +# the number of event the viewer sees or not. +function test_streaming_live_with_viewer () +{ + local babeltrace_stdout + local babeltrace_stderr + local nb_iter=100 + local nb_event_per_iter=1000 + local events_expected=$(((2 + nb_iter) * nb_event_per_iter)) + local url="net://127.0.0.1/host/${HOSTNAME}/${SESSION_NAME}" + local ret + local events_seen + + babeltrace_stdout=$(mktemp) + babeltrace_stderr=$(mktemp) + + diag "Test ${DOMAIN} streaming live clear hook viewer before clear" + create_lttng_session_uri "$SESSION_NAME" net://localhost "--live" + enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" + start_lttng_tracing_ok "$SESSION_NAME" + # We use a testpoint inside lttng-relayd as a sync point to validate + # that the viewer is attached. We are looking for a string inside + # RELAYD_STATE_PATH. We need to bailout if the string is not found and + # babeltrace exited. Trash the stdout of babeltrace since we cannot + # infer anything from it. + $BABELTRACE_BIN -i lttng-live "$url" 1> /dev/null 2> "$babeltrace_stderr" & + babeltrace_pid=$! + + sync_attach_viewer "$babeltrace_pid" "$RELAYD_STATE_PATH" + + do_uid "$SESSION_NAME" "$TRACE_PATH" \ + "$EVENT_NAME" \ + "$nb_iter" \ + "$nb_event_per_iter" + + # Validate that the viewer is still alive + is_viewer_alive "$babeltrace_pid" + ok $? "Viewer is still alive" + + # The viewer should detach itself on session destroy + destroy_lttng_session_ok "$SESSION_NAME" + + wait "$babeltrace_pid" + ret=$? + ok $ret "Babeltrace exited with no error" + if [ "$ret" -ne "0" ]; then + diag "$(cat "$babeltrace_stderr")" + fi + + rm -f "$babeltrace_stderr" +} + +function test_streaming_live_attach_viewer_after_clear () +{ + local babeltrace_stdout + local babeltrace_stderr + local ret + local events_seen + local nb_iter=10 + local nb_event_per_iter=100 + local events_expected=$nb_event_per_iter + local url="net://127.0.0.1/host/${HOSTNAME}/${SESSION_NAME}" + + babeltrace_stdout=$(mktemp) + babeltrace_stderr=$(mktemp) + + diag "Test ${DOMAIN} streaming live hook viewer after clear" + create_lttng_session_uri "$SESSION_NAME" net://localhost "--live" + enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" + start_lttng_tracing_ok "$SESSION_NAME" + do_uid "$SESSION_NAME" "$TRACE_PATH" \ + "$EVENT_NAME" \ + "$nb_iter" \ + "$nb_event_per_iter" + + "$BABELTRACE_BIN" -i lttng-live "$url" 1> "$babeltrace_stdout" 2> "$babeltrace_stderr" & + babeltrace_pid=$! + sync_attach_viewer "$babeltrace_pid" "$RELAYD_STATE_PATH" + + start_lttng_tracing_ok "$SESSION_NAME" + + # We only expect these last events. + generate_events 0 "$nb_event_per_iter" + + stop_lttng_tracing_ok "$session_name" + destroy_lttng_session_ok "$SESSION_NAME" + + wait "$babeltrace_pid" + ret=$? + ok $ret "Babeltrace exited with no error" + if [ "$ret" -ne "0" ]; then + diag "$(cat "$babeltrace_stderr")" + fi + + # TODO: sometime the viewer does not see 100 events... not sure why yet. + # Does not seems related to clear. + #events_seen=$(cat "$babeltrace_stdout" | wc -l) + #test $events_seen -eq $events_expected + #ok $? "Viewer saw the expected number of event: ${events_seen}/${events_expected}" + + rm -f "$babeltrace_stdout" + rm -f "$babeltrace_stderr" +} + +function test_local () +{ + diag "Test ${DOMAIN} local" + create_lttng_session_ok "$SESSION_NAME" "$TRACE_PATH" + enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" + start_lttng_tracing_ok "$SESSION_NAME" + do_uid "$SESSION_NAME" "$TRACE_PATH" "$EVENT_NAME" 100 10 + destroy_lttng_session_ok "$SESSION_NAME" +} + +function do_snapshot () +{ + local session_name=$1 + local trace_path=$2 + + enable_"$DOMAIN"_lttng_event_ok "$session_name" "$EVENT_NAME" + start_lttng_tracing_ok "$session_name" + + # Generate 10 events that will sit in the buffers. + generate_events 0 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" + + lttng_clear_session_ok "$session_name" + + # 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. + generate_events 0 10 + lttng_snapshot_record "$session_name" + stop_lttng_tracing_ok "$session_name" + validate_trace_count "$EVENT_NAME" "$trace_path" 10 +} + +function test_streaming_snapshot () +{ + diag "Test $DOMAIN streaming snapshot clear" + + create_lttng_session_uri "$SESSION_NAME" net://localhost "--snapshot" + do_snapshot "$SESSION_NAME" "$TRACE_PATH" + destroy_lttng_session_ok "$SESSION_NAME" +} + +function test_local_snapshot () +{ + diag "Test $DOMAIN local snapshot clear" + + create_lttng_session_ok "$SESSION_NAME" "$TRACE_PATH" "--snapshot" + do_snapshot "$SESSION_NAME" "$TRACE_PATH" + destroy_lttng_session_ok "$SESSION_NAME" +} + +function test_ust_local_snapshot_per_pid () +{ + local file_sync_before_last + local file_sync_before_last_touch + local file_sync_before_exit + local file_sync_before_exit_touch + local channel_name="channel0" + + file_sync_before_last=$(mktemp -u) + file_sync_before_last_touch=$(mktemp -u) + file_sync_before_exit=$(mktemp -u) + file_sync_before_exit_touch=$(mktemp -u) + + diag "Test ust local snapshot clear per pid " + + create_lttng_session_ok "$SESSION_NAME" "$TRACE_PATH" "--snapshot" + enable_ust_lttng_channel_ok "$SESSION_NAME" "$channel_name" "--buffers-pid" + 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" + + lttng_clear_session_ok "$SESSION_NAME" + + # 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_relayd_dissalow_clear () +{ + diag "Test lttng-relayd disallow clear" + start_lttng_relayd "-o $TRACE_PATH --disallow-clear" + start_lttng_sessiond + + create_lttng_session_uri "$SESSION_NAME" net://localhost "--live" + enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" + start_lttng_tracing_ok "$SESSION_NAME" + + generate_events 0 1 + + lttng_clear_session_fail "$SESSION_NAME" + + destroy_lttng_session_ok "$SESSION_NAME" + + stop_lttng_sessiond + stop_lttng_relayd +} + +function test_per_pid () +{ + local channel_name=chan + diag "Test clear on per-pid session" + create_lttng_session_ok "$SESSION_NAME" "$TRACE_PATH" + enable_"$DOMAIN"_lttng_channel_ok "$SESSION_NAME" $channel_name --buffers-pid + enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" $channel_name + start_lttng_tracing_ok "$SESSION_NAME" + + # Per pid is not supported in this version. Clear must fail. + lttng_clear_session_fail "$SESSION_NAME" + + destroy_lttng_session_ok "$SESSION_NAME" +} + +function test_local_tracefile_rotation () +{ + local channel_name="over9000" + local tracefile_count=6 + local tracefile_size=$(((3 * PAGE_SIZE))) + local iteration=5 + + diag "Test ${DOMAIN} local with tracefile rotation" + create_lttng_session_ok "$SESSION_NAME" "$TRACE_PATH" + enable_"$DOMAIN"_lttng_channel_ok "$SESSION_NAME" $channel_name \ + "--tracefile-count $tracefile_count --tracefile-size $tracefile_size --overwrite" + enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" $channel_name + start_lttng_tracing_ok "$SESSION_NAME" + + # Saturate the tracefile. + for i in $(seq 0 $iteration); do + saturate_tracefile_rotation "$SESSION_NAME" "$channel_name" "$tracefile_count" + lttng_clear_session_ok "$session_name" + stop_lttng_tracing_ok "$session_name" + validate_trace_empty "$TRACE_PATH" + lttng_clear_session_ok "$session_name" + start_lttng_tracing_ok "$session_name" + done + + destroy_lttng_session_ok "$SESSION_NAME" +} + +function test_streaming_tracefile_rotation () +{ + local channel_name="over9000" + local tracefile_count=6 + local tracefile_size=$(((3 * PAGE_SIZE))) + local iteration=5 + + diag "Test ${DOMAIN} streamin with tracefile rotation" + create_lttng_session_uri "$SESSION_NAME" net://localhost + enable_"$DOMAIN"_lttng_channel_ok "$SESSION_NAME" "$channel_name" \ + "--tracefile-count $tracefile_count --tracefile-size $tracefile_size --overwrite" + enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" "$channel_name" + start_lttng_tracing_ok "$SESSION_NAME" + + # Saturate the tracefile. + for i in $(seq 0 $iteration); do + saturate_tracefile_rotation "$SESSION_NAME" "$channel_name" "$tracefile_count" + lttng_clear_session_ok "$session_name" + stop_lttng_tracing_ok "$session_name" + validate_trace_empty "$TRACE_PATH" + lttng_clear_session_ok "$session_name" + start_lttng_tracing_ok "$session_name" + done + + destroy_lttng_session_ok "$SESSION_NAME" +} + +function test_streaming_live_tracefile_rotation_with_viewer () +{ + local babeltrace_stderr + local channel_name="over9000" + local tracefile_count=6 + local tracefile_size=$(((3 * PAGE_SIZE))) + local iteration=2 + local babeltrace_pid + local url="net://127.0.0.1/host/${HOSTNAME}/${SESSION_NAME}" + + babeltrace_stderr=$(mktemp) + + + diag "Test ${DOMAIN} streaming live with tracefile rotation viewer attached" + create_lttng_session_uri "$SESSION_NAME" net://localhost "--live" + enable_"$DOMAIN"_lttng_channel_ok "$SESSION_NAME" "$channel_name" \ + "--tracefile-count $tracefile_count --tracefile-size $tracefile_size --overwrite" + enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" "$channel_name" + start_lttng_tracing_ok "$SESSION_NAME" + + $BABELTRACE_BIN -i lttng-live "$url" 1> /dev/null 2> "$babeltrace_stderr" & + babeltrace_pid=$! + + sync_attach_viewer "$babeltrace_pid" "$RELAYD_STATE_PATH" + + # Saturate the tracefile. + for i in $(seq 0 $iteration); do + saturate_tracefile_rotation "$SESSION_NAME" "$channel_name" "$tracefile_count" + lttng_clear_session_ok "$session_name" + stop_lttng_tracing_ok "$session_name" + validate_trace_empty "$TRACE_PATH" + lttng_clear_session_ok "$session_name" + start_lttng_tracing_ok "$session_name" + done + + # Validate that the viewer is still alive. + is_viewer_alive "$babeltrace_pid" + ok $? "Viewer is still alive" + + # The viewer should detach on destroy. + destroy_lttng_session_ok "$SESSION_NAME" + + wait "$babeltrace_pid" + ret=$? + ok "$ret" "Babeltrace exited with no error" + if [ "$ret" -ne "0" ]; then + diag "$(cat "$babeltrace_stderr")" + fi + + rm -f "$babeltrace_stderr" +} + +if [ "$DOMAIN" == "ust" ]; then + NUM_TESTS=1438 +elif [ "$DOMAIN" == "kernel" ]; then + NUM_TESTS=1429 +else + BAIL_OUT "Invalid domain: $DOMAIN" +fi + +plan_tests $NUM_TESTS + +print_test_banner "$TEST_DESC" + +tests=( + test_local + test_local_snapshot + test_local_tracefile_rotation + test_streaming + test_streaming_snapshot + test_streaming_tracefile_rotation + test_streaming_live_with_viewer + test_streaming_live_attach_viewer_after_clear + test_streaming_live_tracefile_rotation_with_viewer +) + +if [ "$DOMAIN" == "ust" ]; then + if [ ! -x "$TESTAPP_BIN" ]; then + BAIL_OUT "No UST events binary detected." + fi + test+=( + test_ust_local_snapshot_per_pid + test_per_pid + ) + EVENT_NAME="tp:tptest" +else + # Kernel domain + if [ "$(id -u)" -ne "0" ]; then + skip 0 "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS && exit 0 + fi + validate_lttng_modules_present + EVENT_NAME="lttng_test_filter_event" +fi + + +TRACE_PATH=$(mktemp -d) +RELAYD_STATE_PATH=$(mktemp) +TESTPOINT_ARGS="RELAYD_STATE_PATH=${RELAYD_STATE_PATH} LTTNG_TESTPOINT_ENABLE=1" +LTTNG_RELAYD_ENV_VARS="$TESTPOINT_ARGS LD_PRELOAD=$TESTPOINT" + +start_lttng_relayd "-o $TRACE_PATH" +start_lttng_sessiond + +if [ "$DOMAIN" == "kernel" ]; then + modprobe lttng-test +fi + + +for fct_test in "${tests[@]}"; +do + SESSION_NAME=$(randstring 16 0) + ${fct_test} + clean_path "$TRACE_PATH" + # Truncate the RELAYD_STATE_PATH file + : > "$RELAYD_STATE_PATH" +done + +if [ "$DOMAIN" == "kernel" ]; then + rmmod lttng-test +fi + +stop_lttng_sessiond +stop_lttng_relayd + +if [ "$DOMAIN" == "ust" ]; then + # This test control how lttng-relayd is started. Do it after everything else. + test_relayd_dissalow_clear +fi + +rm -f "$RELAYD_STATE_PATH" diff --git a/tests/regression/tools/clear/relayd_state_testpoint.c b/tests/regression/tools/clear/relayd_state_testpoint.c new file mode 100644 index 000000000..b6a39b5fc --- /dev/null +++ b/tests/regression/tools/clear/relayd_state_testpoint.c @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2017 - Jérémie Galarneau + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License, version 2 only, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +int lttng_opt_verbose; +int lttng_opt_mi; +int lttng_opt_quiet; + +int __testpoint_relayd_viewer_session_attach(void) +{ + int ret = 0; + const char *state_file_path; + int state_fd = -1; + + state_file_path = lttng_secure_getenv( + "RELAYD_STATE_PATH"); + if (!state_file_path) { + ERR("RELAYD_STATE_PATH getenv"); + ret = -1; + goto end; + } + + state_fd = open(state_file_path, O_WRONLY | O_APPEND | O_SYNC); + if (state_fd == -1) { + ERR("RELAYD_STATE_PATH open"); + ret = -1; + goto end; + } + + dprintf(state_fd, "Viewer attached\n"); +end: + if(state_fd > -1) { + (void) close(state_fd); + } + return ret; +} diff --git a/tests/regression/tools/clear/test_kernel b/tests/regression/tools/clear/test_kernel index d3e17fe7a..bf181bd4f 100755 --- a/tests/regression/tools/clear/test_kernel +++ b/tests/regression/tools/clear/test_kernel @@ -15,157 +15,9 @@ # 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") +COMMON_TEST="$CURDIR/common_test" -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../../.. -EVENT_NAME="lttng_test_filter_event" +export DOMAIN="kernel" -TRACE_PATH=$(mktemp -d) - -NUM_TESTS=55 - -source $TESTDIR/utils/utils.sh - -function clean_path () -{ - local trace_path=$1 - set -u - rm -rf $trace_path/* - set +u -} - -function test_kernel_streaming () -{ - diag "Test kernel streaming clear" - create_lttng_session_uri $SESSION_NAME net://localhost - lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME - start_lttng_tracing_ok $SESSION_NAME - # TODO: place holder, support for streaming MUST be implemented - # This validate that for now we fail correctly - lttng_clear_session_fail $SESSION_NAME - - destroy_lttng_session_ok $SESSION_NAME -} - -function test_kernel_streaming_live () -{ - diag "Test kernel streaming live clear" - create_lttng_session_uri $SESSION_NAME net://localhost "--live" - lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME - start_lttng_tracing_ok $SESSION_NAME - # TODO: place holder, support for streaming MUST be implemented - # This validate that for now we fail correctly - lttng_clear_session_fail $SESSION_NAME - - destroy_lttng_session_ok $SESSION_NAME -} - -function test_kernel_local () -{ - diag "Test kernel local" - create_lttng_session_ok $SESSION_NAME $TRACE_PATH - lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME - start_lttng_tracing_ok $SESSION_NAME - # TODO: place holder, support for local MUST be implemented - lttng_clear_session_fail $SESSION_NAME - # TODO: validate that the previous chunk IS no more present - - destroy_lttng_session_ok $SESSION_NAME -} - -function do_kernel_snapshot () -{ - local session_name=$1 - local trace_path=$2 - - 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 - - lttng_clear_session_ok $session_name - - # 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 () -{ - diag "Test kernel streaming snapshot clear" - - create_lttng_session_uri $SESSION_NAME net://localhost "--snapshot" - do_kernel_snapshot $SESSION_NAME $TRACE_PATH - destroy_lttng_session_ok $SESSION_NAME -} - -function test_kernel_local_snapshot () -{ - diag "Test kernel local snapshot clear" - - create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot" - do_kernel_snapshot $SESSION_NAME $TRACE_PATH - 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 - -tests=( test_kernel_streaming - test_kernel_streaming_live - test_kernel_local - test_kernel_streaming_snapshot - test_kernel_local_snapshot -) - -skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS || -{ - validate_lttng_modules_present - - start_lttng_relayd "-o $TRACE_PATH" - start_lttng_sessiond - modprobe lttng-test - - for fct_test in ${tests[@]}; - do - SESSION_NAME=$(randstring 16 0) - ${fct_test} - clean_path $TRACE_PATH - done - - rmmod lttng-test - stop_lttng_sessiond - stop_lttng_relayd -} - -clean_path $TRACE_PATH +$COMMON_TEST diff --git a/tests/regression/tools/clear/test_ust b/tests/regression/tools/clear/test_ust index a20eaa9c5..9930a5c5c 100755 --- a/tests/regression/tools/clear/test_ust +++ b/tests/regression/tools/clear/test_ust @@ -15,225 +15,9 @@ # 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") +COMMON_TEST="$CURDIR/common_test" -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" +export DOMAIN="ust" -NUM_TESTS=74 - -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 test_ust_streaming () -{ - diag "Test ust streaming clear" - create_lttng_session_uri $SESSION_NAME net://localhost - enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME - start_lttng_tracing_ok $SESSION_NAME - # TODO: place holder, support for streaming MUST be implemented - # This validate that for now we fail correctly - lttng_clear_session_fail $SESSION_NAME - - destroy_lttng_session_ok $SESSION_NAME -} - -function test_ust_streaming_live () -{ - diag "Test ust streaming live clear" - create_lttng_session_uri $SESSION_NAME net://localhost "--live" - enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME - start_lttng_tracing_ok $SESSION_NAME - # TODO: place holder, support for streaming MUST be implemented - # This validate that for now we fail correctly - lttng_clear_session_fail $SESSION_NAME - - destroy_lttng_session_ok $SESSION_NAME -} - -function test_ust_local () -{ - diag "Test ust local" - create_lttng_session_ok $SESSION_NAME $TRACE_PATH - enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME - start_lttng_tracing_ok $SESSION_NAME - # TODO: place holder, support for local MUST be implemented - lttng_clear_session_fail $SESSION_NAME - # TODO: validate that the previous chunk IS no more present - - destroy_lttng_session_ok $SESSION_NAME -} - -function do_ust_snapshot () -{ - local session_name=$1 - local trace_path=$2 - - enable_ust_lttng_event_ok $session_name $EVENT_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 - - lttng_clear_session_ok $session_name - - # 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 () -{ - diag "Test ust streaming snapshot clear" - - create_lttng_session_uri $SESSION_NAME net://localhost "--snapshot" - do_ust_snapshot $SESSION_NAME $TRACE_PATH - destroy_lttng_session_ok $SESSION_NAME -} - -function test_ust_local_snapshot () -{ - diag "Test ust local snapshot clear" - - create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot" - do_ust_snapshot $SESSION_NAME $TRACE_PATH - destroy_lttng_session_ok $SESSION_NAME -} - -function test_ust_local_snapshot_per_pid () -{ - diag "Test ust local snapshot clear per pid " - 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) - - create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot" - enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-pid - 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 - - lttng_clear_session_ok $SESSION_NAME - - # 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} -} - -plan_tests $NUM_TESTS - -print_test_banner "$TEST_DESC" - - -tests=( - test_ust_streaming - test_ust_streaming_live - test_ust_local - test_ust_streaming_snapshot - test_ust_local_snapshot - test_ust_local_snapshot_per_pid -) - -start_lttng_relayd "-o $TRACE_PATH" -start_lttng_sessiond - -for fct_test in ${tests[@]}; -do - SESSION_NAME=$(randstring 16 0) - ${fct_test} - clean_path $TRACE_PATH -done - -stop_lttng_sessiond -stop_lttng_relayd +$COMMON_TEST diff --git a/tests/regression/tools/crash/test_crash b/tests/regression/tools/crash/test_crash index 97b94a8a9..7b24764c2 100755 --- a/tests/regression/tools/crash/test_crash +++ b/tests/regression/tools/crash/test_crash @@ -233,7 +233,7 @@ function test_lttng_crash() # Generate 10 events $TESTAPP_BIN -i 10 -w 0 - stop_lttng_tracing + stop_lttng_tracing_ok crash_recup_count=$($LTTNG_CRASH $shm_path | wc -l) test $crash_recup_count -eq "10" @@ -271,7 +271,7 @@ function test_lttng_crash_extraction() start_lttng_tracing_ok $session_name # Generate 10 events $TESTAPP_BIN -i 10 -w 0 - stop_lttng_tracing + stop_lttng_tracing_ok $LTTNG_CRASH -x $extraction_path $shm_path ok $? "Extraction of crashed buffers to path" diff --git a/tests/regression/tools/notification/test_notification_multi_app b/tests/regression/tools/notification/test_notification_multi_app index ff3c82d6d..379d2537a 100755 --- a/tests/regression/tools/notification/test_notification_multi_app +++ b/tests/regression/tools/notification/test_notification_multi_app @@ -265,7 +265,7 @@ function test_multi_app () resume_consumerd "${pipe}" done # Stop tracing forcing full buffer consumption - stop_lttng_tracing $SESSION_NAME + stop_lttng_tracing_ok $SESSION_NAME # Check for notifications reception wait_for_message $output_dir "${low_output_file_pattern}" "notification: low $i" diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index affed6166..a63efdf63 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -343,11 +343,17 @@ function start_lttng_relayd_opt() { local withtap=$1 local opt=$2 + local env_vars="" DIR=$(readlink -f $TESTDIR) + # Check for env. variable. Allow the use of LD_PRELOAD etc. + if [[ "x${LTTNG_RELAYD_ENV_VARS}" != "x" ]]; then + env_vars=${LTTNG_RELAYD_ENV_VARS} + fi + if [ -z $(pgrep $RELAYD_MATCH) ]; then - $DIR/../src/bin/lttng-relayd/$RELAYD_BIN -b $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST + env $env_vars $DIR/../src/bin/lttng-relayd/$RELAYD_BIN -b $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 & if [ $? -eq 1 ]; then if [ $withtap -eq "1" ]; then @@ -1082,52 +1088,68 @@ function disable_python_lttng_event () function start_lttng_tracing () { - local expected_to_fail=$1 - local sess_name=$2 + local withtap=$1 + local expected_to_fail=$2 + local sess_name=$3 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST ret=$? - if [[ $expected_to_fail -eq "1" ]]; then - test "$ret" -ne "0" - ok $? "Start tracing for session $sess_name failed as expected" - else - ok $ret "Start tracing for session $sess_name" + if [ $withtap -eq "1" ]; then + if [[ $expected_to_fail -eq "1" ]]; then + test "$ret" -ne "0" + ok $? "Start tracing for session $sess_name failed as expected" + else + ok $ret "Start tracing for session $sess_name" + fi fi } function start_lttng_tracing_ok () { - start_lttng_tracing 0 "$@" + start_lttng_tracing 1 0 "$@" } function start_lttng_tracing_fail () { - start_lttng_tracing 1 "$@" + start_lttng_tracing 1 1 "$@" +} + +function start_lttng_tracing_notap () +{ + start_lttng_tracing 0 0 "$@" } function stop_lttng_tracing () { - local expected_to_fail=$1 - local sess_name=$2 + local withtap=$1 + local expected_to_fail=$2 + local sess_name=$3 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST ret=$? - if [[ $expected_to_fail -eq "1" ]]; then - test "$ret" -ne "0" - ok $? "Stop lttng tracing for session $sess_name failed as expected" - else - ok $ret "Stop lttng tracing for session $sess_name" + if [ $withtap -eq "1" ]; then + if [[ $expected_to_fail -eq "1" ]]; then + test "$ret" -ne "0" + ok $? "Stop lttng tracing for session $sess_name failed as expected" + else + ok $ret "Stop lttng tracing for session $sess_name" + fi fi } function stop_lttng_tracing_ok () { - stop_lttng_tracing 0 "$@" + stop_lttng_tracing 1 0 "$@" } function stop_lttng_tracing_fail () { - stop_lttng_tracing 1 "$@" + stop_lttng_tracing 1 1 "$@" +} + +function stop_lttng_tracing_notap () +{ + stop_lttng_tracing 0 0 "$@" } function destroy_lttng_session () -- 2.34.1