0a451ce63500d97a0bd938e3f860973b4fd399ba
[lttng-tools.git] / tests / perf / test_perf_raw.in
1 #!/bin/bash
2 #
3 # Copyright (C) 2016 Julien Desfossez <jdesfossez@efficios.com>
4 #
5 # SPDX-License-Identifier: GPL-2.0-only
6 #
7
8 TEST_DESC="Perf counters"
9
10 CURDIR=$(dirname $0)/
11 TESTDIR=$CURDIR/..
12 LTTNG_BIN="lttng"
13 SESSION_NAME="perf_counters"
14 NUM_TESTS=21
15 NR_ITER=1
16 NR_USEC_WAIT=1
17 TESTAPP_PATH="$TESTDIR/utils/testapp"
18 TESTAPP_NAME="gen-ust-events"
19 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
20 # Empty if libpfm is installed, "#" otherwise
21 HAVE_LIBPFM="@LTTNG_TOOLS_BUILD_WITH_LIBPFM_TRUE@"
22
23 source $TESTDIR/utils/utils.sh
24
25 function enable_ust_lttng_event_per_chan()
26 {
27 sess_name="$1"
28 event_name="$2"
29 chan_name="$3"
30
31 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -c $chan_name -u >/dev/null 2>&1
32 ok $? "Enable event $event_name for session $sess_name in channel $chan_name"
33 }
34
35 function have_libpfm()
36 {
37 test -z $HAVE_LIBPFM
38 ok $? "Have libpfm installed"
39 }
40
41 function test_ust_raw()
42 {
43 local SESSION_NAME="ust_perf"
44 local CHAN_NAME="mychan"
45 local EVENT_NAME="tp:tptest"
46 local PMU="UNHALTED_REFERENCE_CYCLES"
47 local tests_to_skip=9
48 local ret
49 local TRACE_PATH
50
51 # Find the raw perf id of the event.
52 PERFID=$("$CURDIR/find_event" "$PMU")
53 ret=$?
54 if [ "$ret" -eq "0" ]; then
55 pass "Find PMU $PMU"
56 elif [ "$ret" -eq "1" ]; then
57 skip 0 "PMU event not found." $tests_to_skip
58 return
59 elif [ "$ret" -eq "2" ]; then
60 skip 0 "PMU event not actionable." $tests_to_skip
61 return
62 else
63 fail "find_event returned $ret."
64 return
65 fi
66
67 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
68
69 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
70
71 enable_ust_lttng_channel_ok $SESSION_NAME $CHAN_NAME
72
73 enable_ust_lttng_event_per_chan $SESSION_NAME $EVENT_NAME $CHAN_NAME
74
75 add_context_ust_ok $SESSION_NAME $CHAN_NAME "perf:thread:raw:${PERFID}:test"
76
77 start_lttng_tracing_ok
78
79 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT >/dev/null 2>&1
80
81 stop_lttng_tracing_ok
82
83 destroy_lttng_session_ok $SESSION_NAME
84
85 validate_trace "perf_thread_raw_${PERFID}_test" $TRACE_PATH
86
87 rm -rf $TRACE_PATH
88 }
89
90 function test_kernel_raw()
91 {
92 local SESSION_NAME="kernel_perf"
93 local CHAN_NAME="mychan"
94 local EVENT_NAME="lttng_test_filter_event"
95 local PMU="UNHALTED_REFERENCE_CYCLES"
96 local PERFID=""
97 local tests_to_skip=9
98 local ret
99 local TRACE_PATH
100
101 # Find the raw perf id of the event.
102 PERFID=$("$CURDIR/find_event" "$PMU")
103 ret=$?
104 if [ "$ret" -eq "0" ]; then
105 pass "Find PMU $PMU"
106 elif [ "$ret" -eq "1" ]; then
107 skip 0 "PMU event not found." $tests_to_skip
108 return
109 elif [ "$ret" -eq "2" ]; then
110 skip 0 "PMU event not actionable." $tests_to_skip
111 return
112 else
113 fail "find_event returned $ret."
114 return
115 fi
116
117 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
118
119 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
120
121 lttng_enable_kernel_channel_ok $SESSION_NAME $CHAN_NAME
122
123 enable_kernel_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHAN_NAME
124
125 add_context_kernel_ok $SESSION_NAME $CHAN_NAME "perf:cpu:raw:${PERFID}:test"
126
127 start_lttng_tracing_ok
128
129 echo -n 10 > /proc/lttng-test-filter-event
130
131 stop_lttng_tracing_ok
132
133 destroy_lttng_session_ok $SESSION_NAME
134
135 validate_trace "perf_cpu_raw_${PERFID}_test" $TRACE_PATH
136
137 rm -rf $TRACE_PATH
138 }
139
140 if [ "$(id -u)" == "0" ]; then
141 isroot=1
142 else
143 isroot=0
144 fi
145
146 # MUST set TESTDIR before calling those functions
147 plan_tests $NUM_TESTS
148
149 print_test_banner "$TEST_DESC"
150
151 start_lttng_sessiond
152
153 have_libpfm
154
155 test_ust_raw
156
157 skip $isroot "Root access is needed for kernel testing, skipping." 9 ||
158 {
159 modprobe lttng-test
160 test_kernel_raw
161 modprobe --remove lttng-test
162 }
163
164 stop_lttng_sessiond
This page took 0.034136 seconds and 4 git commands to generate.