tests: mi for clear command
[lttng-tools.git] / tests / perf / test_perf_raw.in
1 #!/bin/bash
2 #
3 # Copyright (C) - 2016 Julien Desfossez <jdesfossez@efficios.com>
4 #
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License, version 2 only, as
7 # published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 # more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc., 51
16 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 TEST_DESC="Perf counters"
19
20 CURDIR=$(dirname $0)/
21 TESTDIR=$CURDIR/..
22 LTTNG_BIN="lttng"
23 SESSION_NAME="perf_counters"
24 NUM_TESTS=21
25 NR_ITER=1
26 NR_USEC_WAIT=1
27 TESTAPP_PATH="$TESTDIR/utils/testapp"
28 TESTAPP_NAME="gen-ust-events"
29 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
30 # Empty if libpfm is installed, "#" otherwise
31 HAVE_LIBPFM="@LTTNG_TOOLS_BUILD_WITH_LIBPFM_TRUE@"
32
33 source $TESTDIR/utils/utils.sh
34
35 function enable_ust_lttng_event_per_chan()
36 {
37 sess_name="$1"
38 event_name="$2"
39 chan_name="$3"
40
41 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -c $chan_name -u >/dev/null 2>&1
42 ok $? "Enable event $event_name for session $sess_name in channel $chan_name"
43 }
44
45 function have_libpfm()
46 {
47 test -z $HAVE_LIBPFM
48 ok $? "Have libpfm installed"
49 }
50
51 function test_ust_raw()
52 {
53 TRACE_PATH=$(mktemp -d)
54 SESSION_NAME="ust_perf"
55 CHAN_NAME="mychan"
56 EVENT_NAME="tp:tptest"
57 PMU="UNHALTED_REFERENCE_CYCLES"
58 PERFID=$($CURDIR/find_event $PMU)
59 test $? -eq "0"
60 ok $? "Find PMU $PMU"
61
62 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
63
64 enable_ust_lttng_channel_ok $SESSION_NAME $CHAN_NAME
65
66 enable_ust_lttng_event_per_chan $SESSION_NAME $EVENT_NAME $CHAN_NAME
67
68 add_context_ust_ok $SESSION_NAME $CHAN_NAME "perf:thread:raw:${PERFID}:test"
69
70 start_lttng_tracing_ok
71
72 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT >/dev/null 2>&1
73
74 stop_lttng_tracing_ok
75
76 destroy_lttng_session_ok $SESSION_NAME
77
78 validate_trace "perf_thread_raw_${PERFID}_test" $TRACE_PATH
79
80 rm -rf $TRACE_PATH
81 }
82
83 function test_kernel_raw()
84 {
85 TRACE_PATH=$(mktemp -d)
86 SESSION_NAME="kernel_perf"
87 CHAN_NAME="mychan"
88 EVENT_NAME="lttng_test_filter_event"
89 PMU="UNHALTED_REFERENCE_CYCLES"
90 PERFID=$($CURDIR/find_event $PMU)
91 test $? -eq "0"
92 ok $? "Find PMU $PMU"
93
94 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
95
96 lttng_enable_kernel_channel_ok $SESSION_NAME $CHAN_NAME
97
98 enable_kernel_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHAN_NAME
99
100 add_context_kernel_ok $SESSION_NAME $CHAN_NAME "perf:cpu:raw:${PERFID}:test"
101
102 start_lttng_tracing_ok
103
104 echo -n 10 > /proc/lttng-test-filter-event
105
106 stop_lttng_tracing_ok
107
108 destroy_lttng_session_ok $SESSION_NAME
109
110 validate_trace "perf_cpu_raw_${PERFID}_test" $TRACE_PATH
111
112 rm -rf $TRACE_PATH
113 }
114
115 if [ "$(id -u)" == "0" ]; then
116 isroot=1
117 else
118 isroot=0
119 fi
120
121 # MUST set TESTDIR before calling those functions
122 plan_tests $NUM_TESTS
123
124 print_test_banner "$TEST_DESC"
125
126 start_lttng_sessiond
127
128 have_libpfm
129
130 test_ust_raw
131
132 skip $isroot "Root access is needed for kernel testing, skipping." 9 ||
133 {
134 modprobe lttng-test
135 test_kernel_raw
136 rmmod lttng-test
137 }
138
139 stop_lttng_sessiond
This page took 0.037994 seconds and 5 git commands to generate.