Fix: lttng-snapshot: use after free of max size argument
[lttng-tools.git] / tests / perf / test_perf_raw.in
CommitLineData
6faa26ca
JD
1#!/bin/bash
2#
9d16b343 3# Copyright (C) 2016 Julien Desfossez <jdesfossez@efficios.com>
6faa26ca 4#
9d16b343 5# SPDX-License-Identifier: GPL-2.0-only
6faa26ca 6#
6faa26ca
JD
7
8TEST_DESC="Perf counters"
9
10CURDIR=$(dirname $0)/
11TESTDIR=$CURDIR/..
12LTTNG_BIN="lttng"
13SESSION_NAME="perf_counters"
95cdb5e3 14NUM_TESTS=21
6faa26ca
JD
15NR_ITER=1
16NR_USEC_WAIT=1
17TESTAPP_PATH="$TESTDIR/utils/testapp"
18TESTAPP_NAME="gen-ust-events"
19TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
20# Empty if libpfm is installed, "#" otherwise
21HAVE_LIBPFM="@LTTNG_TOOLS_BUILD_WITH_LIBPFM_TRUE@"
22
23source $TESTDIR/utils/utils.sh
24
25function 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
35function have_libpfm()
36{
37 test -z $HAVE_LIBPFM
38 ok $? "Have libpfm installed"
39}
40
41function test_ust_raw()
42{
65702b8f
JR
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
33e55711 49 local TRACE_PATH
65702b8f
JR
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
6faa26ca 66
33e55711
FD
67 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
68
6faa26ca
JD
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
6c4a91d6 79 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT >/dev/null 2>&1
6faa26ca
JD
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
90function test_kernel_raw()
91{
65702b8f
JR
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
33e55711 99 local TRACE_PATH
65702b8f
JR
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
6faa26ca 116
33e55711
FD
117 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
118
6faa26ca
JD
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
140if [ "$(id -u)" == "0" ]; then
141 isroot=1
142else
143 isroot=0
144fi
145
146# MUST set TESTDIR before calling those functions
147plan_tests $NUM_TESTS
148
149print_test_banner "$TEST_DESC"
150
151start_lttng_sessiond
152
153have_libpfm
154
155test_ust_raw
156
157skip $isroot "Root access is needed for kernel testing, skipping." 9 ||
158{
159 modprobe lttng-test
160 test_kernel_raw
d0e263e7 161 modprobe --remove lttng-test
6faa26ca
JD
162}
163
164stop_lttng_sessiond
This page took 0.062247 seconds and 4 git commands to generate.