Add kernel snapshot support
[lttng-tools.git] / tests / regression / tools / snapshots / test_kernel
diff --git a/tests/regression/tools/snapshots/test_kernel b/tests/regression/tools/snapshots/test_kernel
new file mode 100755 (executable)
index 0000000..6910b0e
--- /dev/null
@@ -0,0 +1,173 @@
+#!/bin/bash
+#
+# Copyright (C) - 2013 Julien Desfossez <jdesfossez@efficios.com>
+#
+# 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="Snapshots - Kernel tracing"
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/../../..
+EVENT_NAME="sched_switch"
+PID_RELAYD=0
+SESSION_NAME=""
+CHANNEL_NAME="snapchan"
+
+TRACE_PATH=$(mktemp -d)
+
+NUM_TESTS=2040
+
+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
+       lttng_snapshot_record $SESSION_NAME
+       stop_lttng_tracing $SESSION_NAME
+       destroy_lttng_session $SESSION_NAME
+
+       # Validate test
+       validate_trace $EVENT_NAME $TRACE_PATH/snapshot/
+       if [ $? -eq 0 ]; then
+               # Only delete if successful
+               rm -rf $TRACE_PATH
+       else
+               break
+       fi
+}
+
+function test_kernel_local_snapshot_after_stop ()
+{
+       diag "Test local kernel snapshots 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
+       lttng_snapshot_record $SESSION_NAME
+       destroy_lttng_session $SESSION_NAME
+
+       # Validate test
+       validate_trace $EVENT_NAME $TRACE_PATH/snapshot/
+       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
+
+       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
+
+       # first snapshot with only 1 event
+       lttng_snapshot_record $SESSION_NAME
+       validate_trace $EVENT_NAME $TRACE_PATH/snapshot/
+       if [ $? -eq 0 ]; then
+               # Only delete if successful
+               rm -rf $TRACE_PATH
+       else
+               break
+       fi
+
+       diag "Adding event $EVENT2"
+       # second snapshot with 2 events
+       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/
+       if [ $? -eq 0 ]; then
+               # Only delete if successful
+               rm -rf $TRACE_PATH
+       else
+               break
+       fi
+
+       stop_lttng_tracing $SESSION_NAME
+       destroy_lttng_session $SESSION_NAME
+}
+
+function test_kernel_1000_local_snapshots ()
+{
+       NB_SNAP=1000
+
+       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
+       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/
+               if [ $? -eq 0 ]; then
+                       # Only delete if successful
+                       rm -rf $TRACE_PATH
+               else
+                       break
+               fi
+       done
+       stop_lttng_tracing $SESSION_NAME
+       destroy_lttng_session $SESSION_NAME
+}
+
+plan_tests $NUM_TESTS
+
+print_test_banner "$TEST_DESC"
+
+if [ "$(id -u)" == "0" ]; then
+       isroot=1
+else
+       isroot=0
+fi
+
+skip $isroot "Root access is needed. Skipping all kernel snapshot tests." $NUM_TESTS ||
+{
+       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 )
+
+       for fct_test in ${tests[@]};
+       do
+               SESSION_NAME=$(randstring 16 0)
+               ${fct_test}
+
+       done
+
+       stop_lttng_sessiond
+}
This page took 0.025446 seconds and 4 git commands to generate.