sessiond: kernel triggers: add infrastructure to create event notifiers
[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 TRACE_PATH=$(mktemp -d)
44 SESSION_NAME="ust_perf"
45 CHAN_NAME="mychan"
46 EVENT_NAME="tp:tptest"
47 PMU="UNHALTED_REFERENCE_CYCLES"
48 PERFID=$($CURDIR/find_event $PMU)
49 test $? -eq "0"
50 ok $? "Find PMU $PMU"
51
52 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
53
54 enable_ust_lttng_channel_ok $SESSION_NAME $CHAN_NAME
55
56 enable_ust_lttng_event_per_chan $SESSION_NAME $EVENT_NAME $CHAN_NAME
57
58 add_context_ust_ok $SESSION_NAME $CHAN_NAME "perf:thread:raw:${PERFID}:test"
59
60 start_lttng_tracing_ok
61
62 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT >/dev/null 2>&1
63
64 stop_lttng_tracing_ok
65
66 destroy_lttng_session_ok $SESSION_NAME
67
68 validate_trace "perf_thread_raw_${PERFID}_test" $TRACE_PATH
69
70 rm -rf $TRACE_PATH
71 }
72
73 function test_kernel_raw()
74 {
75 TRACE_PATH=$(mktemp -d)
76 SESSION_NAME="kernel_perf"
77 CHAN_NAME="mychan"
78 EVENT_NAME="lttng_test_filter_event"
79 PMU="UNHALTED_REFERENCE_CYCLES"
80 PERFID=$($CURDIR/find_event $PMU)
81 test $? -eq "0"
82 ok $? "Find PMU $PMU"
83
84 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
85
86 lttng_enable_kernel_channel_ok $SESSION_NAME $CHAN_NAME
87
88 enable_kernel_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHAN_NAME
89
90 add_context_kernel_ok $SESSION_NAME $CHAN_NAME "perf:cpu:raw:${PERFID}:test"
91
92 start_lttng_tracing_ok
93
94 echo -n 10 > /proc/lttng-test-filter-event
95
96 stop_lttng_tracing_ok
97
98 destroy_lttng_session_ok $SESSION_NAME
99
100 validate_trace "perf_cpu_raw_${PERFID}_test" $TRACE_PATH
101
102 rm -rf $TRACE_PATH
103 }
104
105 if [ "$(id -u)" == "0" ]; then
106 isroot=1
107 else
108 isroot=0
109 fi
110
111 # MUST set TESTDIR before calling those functions
112 plan_tests $NUM_TESTS
113
114 print_test_banner "$TEST_DESC"
115
116 start_lttng_sessiond
117
118 have_libpfm
119
120 test_ust_raw
121
122 skip $isroot "Root access is needed for kernel testing, skipping." 9 ||
123 {
124 modprobe lttng-test
125 test_kernel_raw
126 modprobe --remove lttng-test
127 }
128
129 stop_lttng_sessiond
This page took 0.044692 seconds and 4 git commands to generate.