Clean-up: sessiond: make some accesses to conditions const
[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 TRACE_PATH=$(mktemp -d)
44 local SESSION_NAME="ust_perf"
45 local CHAN_NAME="mychan"
46 local EVENT_NAME="tp:tptest"
47 local PMU="UNHALTED_REFERENCE_CYCLES"
48 local tests_to_skip=9
49 local ret
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
JD
66
67 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
68
69 enable_ust_lttng_channel_ok $SESSION_NAME $CHAN_NAME
70
71 enable_ust_lttng_event_per_chan $SESSION_NAME $EVENT_NAME $CHAN_NAME
72
73 add_context_ust_ok $SESSION_NAME $CHAN_NAME "perf:thread:raw:${PERFID}:test"
74
75 start_lttng_tracing_ok
76
6c4a91d6 77 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT >/dev/null 2>&1
6faa26ca
JD
78
79 stop_lttng_tracing_ok
80
81 destroy_lttng_session_ok $SESSION_NAME
82
83 validate_trace "perf_thread_raw_${PERFID}_test" $TRACE_PATH
84
85 rm -rf $TRACE_PATH
86}
87
88function test_kernel_raw()
89{
65702b8f
JR
90 local TRACE_PATH=$(mktemp -d)
91 local SESSION_NAME="kernel_perf"
92 local CHAN_NAME="mychan"
93 local EVENT_NAME="lttng_test_filter_event"
94 local PMU="UNHALTED_REFERENCE_CYCLES"
95 local PERFID=""
96 local tests_to_skip=9
97 local ret
98
99 # Find the raw perf id of the event.
100 PERFID=$("$CURDIR/find_event" "$PMU")
101 ret=$?
102 if [ "$ret" -eq "0" ]; then
103 pass "Find PMU $PMU"
104 elif [ "$ret" -eq "1" ]; then
105 skip 0 "PMU event not found." $tests_to_skip
106 return
107 elif [ "$ret" -eq "2" ]; then
108 skip 0 "PMU event not actionable." $tests_to_skip
109 return
110 else
111 fail "find_event returned $ret."
112 return
113 fi
6faa26ca
JD
114
115 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
116
117 lttng_enable_kernel_channel_ok $SESSION_NAME $CHAN_NAME
118
119 enable_kernel_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHAN_NAME
120
121 add_context_kernel_ok $SESSION_NAME $CHAN_NAME "perf:cpu:raw:${PERFID}:test"
122
123 start_lttng_tracing_ok
124
125 echo -n 10 > /proc/lttng-test-filter-event
126
127 stop_lttng_tracing_ok
128
129 destroy_lttng_session_ok $SESSION_NAME
130
131 validate_trace "perf_cpu_raw_${PERFID}_test" $TRACE_PATH
132
133 rm -rf $TRACE_PATH
134}
135
136if [ "$(id -u)" == "0" ]; then
137 isroot=1
138else
139 isroot=0
140fi
141
142# MUST set TESTDIR before calling those functions
143plan_tests $NUM_TESTS
144
145print_test_banner "$TEST_DESC"
146
147start_lttng_sessiond
148
149have_libpfm
150
151test_ust_raw
152
153skip $isroot "Root access is needed for kernel testing, skipping." 9 ||
154{
155 modprobe lttng-test
156 test_kernel_raw
d0e263e7 157 modprobe --remove lttng-test
6faa26ca
JD
158}
159
160stop_lttng_sessiond
This page took 0.036773 seconds and 4 git commands to generate.