X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=tests%2Fregression%2Ftools%2Fsnapshots%2Ftest_kernel;h=870c437b217fc2ed0eb339628fff428e220312fd;hb=2a05e025c52eda43f8ebafdbe6f47dc0e80efa77;hp=6910b0e62b8c6469278a033083f20e6c1ed44d20;hpb=07b86b528dc279d59cdf16e6cb946c144fe773f2;p=lttng-tools.git diff --git a/tests/regression/tools/snapshots/test_kernel b/tests/regression/tools/snapshots/test_kernel index 6910b0e62..870c437b2 100755 --- a/tests/regression/tools/snapshots/test_kernel +++ b/tests/regression/tools/snapshots/test_kernel @@ -1,59 +1,41 @@ #!/bin/bash # -# Copyright (C) - 2013 Julien Desfossez +# Copyright (C) 2013 Julien Desfossez # -# This library is free software; you can redistribute it and/or modify it under -# the terms of the GNU Lesser General Public License as published by the Free -# Software Foundation; version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -# details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this library; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# SPDX-License-Identifier: LGPL-2.1-only + TEST_DESC="Snapshots - Kernel tracing" CURDIR=$(dirname $0)/ TESTDIR=$CURDIR/../../.. EVENT_NAME="sched_switch" -PID_RELAYD=0 SESSION_NAME="" CHANNEL_NAME="snapchan" -TRACE_PATH=$(mktemp -d) +TRACE_PATH=$(mktemp -d -t tmp.test_snapshots_kernel_trace_path.XXXXXX) -NUM_TESTS=2040 +NUM_TESTS=2061 source $TESTDIR/utils/utils.sh -# LTTng kernel modules check -out=`ls /lib/modules/$(uname -r)/extra | grep lttng` -if [ -z "$out" ]; then - BAIL_OUT "LTTng modules not detected." -fi - function test_kernel_local_snapshot () { diag "Test local kernel snapshots" create_lttng_session_no_output $SESSION_NAME enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME - start_lttng_tracing $SESSION_NAME - lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH + start_lttng_tracing_ok $SESSION_NAME + lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH lttng_snapshot_record $SESSION_NAME - stop_lttng_tracing $SESSION_NAME - destroy_lttng_session $SESSION_NAME + stop_lttng_tracing_ok $SESSION_NAME + destroy_lttng_session_ok $SESSION_NAME # Validate test - validate_trace $EVENT_NAME $TRACE_PATH/snapshot/ + validate_trace_path_kernel_snapshot "$TRACE_PATH" "" "snapshot-1" 0 "" + validate_trace $EVENT_NAME $TRACE_PATH/ if [ $? -eq 0 ]; then # Only delete if successful rm -rf $TRACE_PATH - else - break fi } @@ -63,42 +45,38 @@ function test_kernel_local_snapshot_after_stop () create_lttng_session_no_output $SESSION_NAME enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME - start_lttng_tracing $SESSION_NAME - stop_lttng_tracing $SESSION_NAME - lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH + start_lttng_tracing_ok $SESSION_NAME + stop_lttng_tracing_ok $SESSION_NAME + lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH lttng_snapshot_record $SESSION_NAME - destroy_lttng_session $SESSION_NAME + destroy_lttng_session_ok $SESSION_NAME # Validate test - validate_trace $EVENT_NAME $TRACE_PATH/snapshot/ + validate_trace $EVENT_NAME $TRACE_PATH/ if [ $? -eq 0 ]; then # Only delete if successful rm -rf $TRACE_PATH - else - break fi } function test_kernel_local_snapshot_append_to_metadata () { - EVENT1=sched_switch - EVENT2=sched_process_exec + local EVENT1=sched_switch + local EVENT2=sched_process_exit diag "Test local kernel snapshots with one event $EVENT1" create_lttng_session_no_output $SESSION_NAME enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME lttng_enable_kernel_event $SESSION_NAME $EVENT1 $CHANNEL_NAME - start_lttng_tracing $SESSION_NAME - lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH + start_lttng_tracing_ok $SESSION_NAME + lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH # first snapshot with only 1 event lttng_snapshot_record $SESSION_NAME - validate_trace $EVENT_NAME $TRACE_PATH/snapshot/ + validate_trace $EVENT_NAME $TRACE_PATH/ if [ $? -eq 0 ]; then # Only delete if successful rm -rf $TRACE_PATH - else - break fi diag "Adding event $EVENT2" @@ -106,16 +84,108 @@ function test_kernel_local_snapshot_append_to_metadata () lttng_enable_kernel_event $SESSION_NAME $EVENT2 $CHANNEL_NAME rm -rf $TRACE_PATH/snapshot/* 2>/dev/null lttng_snapshot_record $SESSION_NAME - validate_trace "${EVENT1},${EVENT2}" $TRACE_PATH/snapshot/ + validate_trace "${EVENT1},${EVENT2}" $TRACE_PATH/ if [ $? -eq 0 ]; then # Only delete if successful rm -rf $TRACE_PATH + fi + + stop_lttng_tracing_ok $SESSION_NAME + destroy_lttng_session_ok $SESSION_NAME +} + +function generate_filter_events_cpu0() +{ + # Generate many events (fill buffers) on a single CPU + taskset --cpu-list "$(get_any_available_cpu)" /bin/echo -n "$1" > /proc/lttng-test-filter-event 2> /dev/null +} + +function test_kernel_local_snapshot_discard () +{ + diag "Test local kernel snapshots with small discard buffers" + + local event_name="lttng_test_filter_event" + + modprobe lttng-test + create_lttng_session_no_output $SESSION_NAME + enable_lttng_mmap_discard_small_kernel_channel $SESSION_NAME \ + $CHANNEL_NAME + enable_kernel_lttng_event_ok $SESSION_NAME $event_name $CHANNEL_NAME + start_lttng_tracing_ok $SESSION_NAME + lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH + + generate_filter_events_cpu0 10000 + + # Take first snapshot, remember first line. + lttng_snapshot_record $SESSION_NAME + FIRST_LINE="$(trace_first_line $TRACE_PATH/)" + diag "First line (1st snapshot): $FIRST_LINE" + + rm -rf $TRACE_PATH + + # Fill CPU 0's buffer and overwrite previous contents + generate_filter_events_cpu0 10000 + + # Take 2nd snapshot, compare first line. In discard mode, they + # should still be the same. + lttng_snapshot_record $SESSION_NAME + FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)" + diag "First line (2nd snapshot): $FIRST_LINE" + rm -rf $TRACE_PATH + + if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then + fail "First snapshot event do not match" + else + pass "First snapshot event match" + fi + + stop_lttng_tracing_ok $SESSION_NAME + destroy_lttng_session_ok $SESSION_NAME + modprobe --remove lttng-test +} + +function test_kernel_local_snapshot_overwrite_small_buffers () +{ + diag "Test local kernel snapshot with small overwrite buffers" + + local event_name="lttng_test_filter_event" + + modprobe lttng-test + create_lttng_session_no_output $SESSION_NAME + enable_lttng_mmap_overwrite_small_kernel_channel $SESSION_NAME \ + $CHANNEL_NAME + enable_kernel_lttng_event_ok $SESSION_NAME $event_name $CHANNEL_NAME + start_lttng_tracing_ok $SESSION_NAME + lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH + + generate_filter_events_cpu0 10000 + + # Take first snapshot, remember first line. + lttng_snapshot_record $SESSION_NAME + FIRST_LINE="$(trace_first_line $TRACE_PATH/)" + diag "First line (1st snapshot): $FIRST_LINE" + + rm -rf $TRACE_PATH + + # Fill CPU 0's buffer and overwrite previous contents + generate_filter_events_cpu0 10000 + + # Take 2nd snapshot, compare first line. In overwrite mode, they + # WILL be different. + lttng_snapshot_record $SESSION_NAME + FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)" + diag "First line (2nd snapshot): $FIRST_LINE_2" + rm -rf $TRACE_PATH + + if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then + pass "First snapshot event do not match" else - break + fail "First snapshot event match" fi - stop_lttng_tracing $SESSION_NAME - destroy_lttng_session $SESSION_NAME + stop_lttng_tracing_ok $SESSION_NAME + destroy_lttng_session_ok $SESSION_NAME + modprobe --remove lttng-test } function test_kernel_1000_local_snapshots () @@ -126,14 +196,14 @@ function test_kernel_1000_local_snapshots () create_lttng_session_no_output $SESSION_NAME enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME - start_lttng_tracing $SESSION_NAME - lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH + start_lttng_tracing_ok $SESSION_NAME + lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH for i in $(seq 1 $NB_SNAP); do diag "Snapshot $i/$NB_SNAP" rm -rf $TRACE_PATH/snapshot/* 2>/dev/null lttng_snapshot_record $SESSION_NAME # Validate test - validate_trace $EVENT_NAME $TRACE_PATH/snapshot/ + validate_trace $EVENT_NAME $TRACE_PATH/ if [ $? -eq 0 ]; then # Only delete if successful rm -rf $TRACE_PATH @@ -141,26 +211,38 @@ function test_kernel_1000_local_snapshots () break fi done - stop_lttng_tracing $SESSION_NAME - destroy_lttng_session $SESSION_NAME + stop_lttng_tracing_ok $SESSION_NAME + destroy_lttng_session_ok $SESSION_NAME } plan_tests $NUM_TESTS print_test_banner "$TEST_DESC" +bail_out_if_no_babeltrace + + if [ "$(id -u)" == "0" ]; then isroot=1 else isroot=0 fi -skip $isroot "Root access is needed. Skipping all kernel snapshot tests." $NUM_TESTS || +skip $isroot "Root access is needed. Skipping all kernel snapshot tests" $NUM_TESTS || { + + validate_lttng_modules_present + start_lttng_sessiond #tests=( test_kernel_1000_local_snapshots ) - tests=( test_kernel_local_snapshot test_kernel_local_snapshot_after_stop test_kernel_local_snapshot_append_to_metadata test_kernel_1000_local_snapshots ) + tests=( test_kernel_local_snapshot + test_kernel_local_snapshot_after_stop + test_kernel_local_snapshot_append_to_metadata + test_kernel_local_snapshot_discard + test_kernel_local_snapshot_overwrite_small_buffers + test_kernel_1000_local_snapshots + ) for fct_test in ${tests[@]}; do