Create a dedicated test suite for Perf
[lttng-tools.git] / tests / perf / test_perf_raw.in
diff --git a/tests/perf/test_perf_raw.in b/tests/perf/test_perf_raw.in
new file mode 100644 (file)
index 0000000..a5f9f55
--- /dev/null
@@ -0,0 +1,139 @@
+#!/bin/bash
+#
+# Copyright (C) - 2016 Julien Desfossez <jdesfossez@efficios.com>
+#
+# 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.
+
+TEST_DESC="Perf counters"
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/..
+LTTNG_BIN="lttng"
+SESSION_NAME="perf_counters"
+NUM_TESTS=20
+NR_ITER=1
+NR_USEC_WAIT=1
+TESTAPP_PATH="$TESTDIR/utils/testapp"
+TESTAPP_NAME="gen-ust-events"
+TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
+# Empty if libpfm is installed, "#" otherwise
+HAVE_LIBPFM="@LTTNG_TOOLS_BUILD_WITH_LIBPFM_TRUE@"
+
+source $TESTDIR/utils/utils.sh
+
+function enable_ust_lttng_event_per_chan()
+{
+       sess_name="$1"
+       event_name="$2"
+       chan_name="$3"
+
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -c $chan_name -u >/dev/null 2>&1
+       ok $? "Enable event $event_name for session $sess_name in channel $chan_name"
+}
+
+function have_libpfm()
+{
+       test -z $HAVE_LIBPFM
+       ok $? "Have libpfm installed"
+}
+
+function test_ust_raw()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="ust_perf"
+       CHAN_NAME="mychan"
+       EVENT_NAME="tp:tptest"
+       PMU="UNHALTED_REFERENCE_CYCLES"
+       PERFID=$($CURDIR/find_event $PMU)
+       test $? -eq "0"
+       ok $? "Find PMU $PMU"
+
+       create_lttng_session_ok $SESSION_NAME $TRACE_PATH
+
+       enable_ust_lttng_channel_ok $SESSION_NAME $CHAN_NAME
+
+       enable_ust_lttng_event_per_chan $SESSION_NAME $EVENT_NAME $CHAN_NAME
+
+       add_context_ust_ok $SESSION_NAME $CHAN_NAME "perf:thread:raw:${PERFID}:test"
+
+       start_lttng_tracing_ok
+
+       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev/null 2>&1
+
+       stop_lttng_tracing_ok
+
+       destroy_lttng_session_ok $SESSION_NAME
+
+       validate_trace "perf_thread_raw_${PERFID}_test" $TRACE_PATH
+
+       rm -rf $TRACE_PATH
+}
+
+function test_kernel_raw()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_perf"
+       CHAN_NAME="mychan"
+       EVENT_NAME="lttng_test_filter_event"
+       PMU="UNHALTED_REFERENCE_CYCLES"
+       PERFID=$($CURDIR/find_event $PMU)
+       test $? -eq "0"
+       ok $? "Find PMU $PMU"
+
+       create_lttng_session_ok $SESSION_NAME $TRACE_PATH
+
+       lttng_enable_kernel_channel_ok $SESSION_NAME $CHAN_NAME
+
+       enable_kernel_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHAN_NAME
+
+       add_context_kernel_ok $SESSION_NAME $CHAN_NAME "perf:cpu:raw:${PERFID}:test"
+
+       start_lttng_tracing_ok
+
+       echo -n 10 > /proc/lttng-test-filter-event
+
+       stop_lttng_tracing_ok
+
+       destroy_lttng_session_ok $SESSION_NAME
+
+       validate_trace "perf_cpu_raw_${PERFID}_test" $TRACE_PATH
+
+       rm -rf $TRACE_PATH
+}
+
+if [ "$(id -u)" == "0" ]; then
+       isroot=1
+else
+       isroot=0
+fi
+
+# MUST set TESTDIR before calling those functions
+plan_tests $NUM_TESTS
+
+print_test_banner "$TEST_DESC"
+
+start_lttng_sessiond
+
+have_libpfm
+
+test_ust_raw
+
+skip $isroot "Root access is needed for kernel testing, skipping." 9 ||
+{
+       modprobe lttng-test
+       test_kernel_raw
+       rmmod lttng-test
+}
+
+stop_lttng_sessiond
This page took 0.025415 seconds and 4 git commands to generate.