Commit | Line | Data |
---|---|---|
bb8ec90d JD |
1 | #!/bin/bash |
2 | # | |
9d16b343 MJ |
3 | # Copyright (C) 2013 Christian Babeux <christian.babeux@efficios.com> |
4 | # Copyright (C) 2014 Julien Desfossez <jdesfossez@efficios.com> | |
bb8ec90d | 5 | # |
9d16b343 | 6 | # SPDX-License-Identifier: GPL-2.0-only |
bb8ec90d JD |
7 | |
8 | TEST_DESC="UST tracer - Perf counters" | |
9 | ||
10 | CURDIR=$(dirname $0)/ | |
11 | TESTDIR=$CURDIR/../.. | |
bb8ec90d JD |
12 | SESSION_NAME="perf_counters" |
13 | EVENT_NAME="tp:tptest" | |
7cd988f0 | 14 | NUM_TESTS=24 |
bb8ec90d JD |
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 | ||
21 | source $TESTDIR/utils/utils.sh | |
22 | ||
23 | function enable_ust_lttng_event_per_chan() | |
24 | { | |
25 | sess_name="$1" | |
26 | event_name="$2" | |
27 | chan_name="$3" | |
28 | ||
29 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -c $chan_name -u >/dev/null 2>&1 | |
30 | ok $? "Enable event $event_name for session $sess_name in channel $chan_name" | |
31 | } | |
32 | ||
db3db2cb MJ |
33 | function add_context_ust_skip_ok() |
34 | { | |
35 | local session_name=$1 | |
36 | local channel_name=$2 | |
37 | local context_name=$3 | |
38 | local skip_num=$4 | |
39 | ||
40 | local ret | |
41 | ||
42 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" add-context -u \ | |
43 | -s "$session_name" -c "$channel_name" \ | |
44 | -t "$context_name" 1>"$OUTPUT_DEST" 2>"$ERROR_OUTPUT_DEST" | |
45 | ret=$? | |
46 | ||
47 | if [ "$ret" == "4" ]; then | |
48 | skip 0 "Current UST lib doesn't implement '$context_name' context" "$skip_num" | |
49 | else | |
50 | ok $ret "Add context command for type: $context_name" | |
51 | fi | |
52 | ||
53 | return $ret | |
54 | } | |
55 | ||
7cd988f0 JD |
56 | # Only test parsing of the enabling by raw ID |
57 | function test_parsing_raw() | |
bb8ec90d | 58 | { |
8d5a3312 | 59 | TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX") |
7cd988f0 JD |
60 | SESSION_NAME="ust_event_basic" |
61 | CHAN_NAME="mychan" | |
62 | ||
63 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
64 | ||
65 | enable_ust_lttng_channel_ok $SESSION_NAME $CHAN_NAME | |
66 | ||
67 | enable_ust_lttng_event_per_chan $SESSION_NAME $EVENT_NAME $CHAN_NAME | |
bb8ec90d | 68 | |
db3db2cb | 69 | add_context_ust_skip_ok $SESSION_NAME $CHAN_NAME "perf:thread:raw:r0110:test" 1 |
7cd988f0 JD |
70 | add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw:rZZZ:test" |
71 | add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw:b0110:test" | |
72 | add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw:r0110:" | |
73 | add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw:r0110::" | |
74 | add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw:r:test" | |
75 | add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw:r::" | |
76 | add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw::" | |
77 | add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw" | |
78 | add_context_ust_fail $SESSION_NAME $CHAN_NAME "perf:thread:raw:r0110:test:wrong" | |
79 | ||
80 | destroy_lttng_session_ok $SESSION_NAME | |
81 | ||
82 | rm -rf $TRACE_PATH | |
bb8ec90d JD |
83 | } |
84 | ||
85 | function test_event_basic() | |
86 | { | |
8d5a3312 | 87 | TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX") |
bb8ec90d JD |
88 | SESSION_NAME="ust_event_basic" |
89 | CHAN_NAME="mychan" | |
90 | ||
db3db2cb MJ |
91 | local ret |
92 | ||
bf6ae429 | 93 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
bb8ec90d | 94 | |
827caf52 | 95 | enable_ust_lttng_channel_ok $SESSION_NAME $CHAN_NAME |
bb8ec90d JD |
96 | |
97 | enable_ust_lttng_event_per_chan $SESSION_NAME $EVENT_NAME $CHAN_NAME | |
98 | ||
db3db2cb MJ |
99 | add_context_ust_skip_ok $SESSION_NAME $CHAN_NAME "perf:thread:page-fault" 4 |
100 | ret=$? | |
bb8ec90d | 101 | |
db3db2cb MJ |
102 | if [ "$ret" != "4" ]; then |
103 | start_lttng_tracing_ok | |
bb8ec90d | 104 | |
6c4a91d6 | 105 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT >/dev/null 2>&1 |
bb8ec90d | 106 | |
db3db2cb MJ |
107 | stop_lttng_tracing_ok |
108 | ||
109 | validate_trace "perf_thread_page_fault" "$TRACE_PATH" | |
110 | fi | |
bb8ec90d | 111 | |
67b4c664 | 112 | destroy_lttng_session_ok $SESSION_NAME |
bb8ec90d | 113 | |
db3db2cb | 114 | rm -rf "$TRACE_PATH" |
bb8ec90d JD |
115 | } |
116 | ||
117 | # MUST set TESTDIR before calling those functions | |
118 | plan_tests $NUM_TESTS | |
119 | ||
120 | print_test_banner "$TEST_DESC" | |
121 | ||
c125de8f FD |
122 | bail_out_if_no_babeltrace |
123 | ||
bc2d01d2 MD |
124 | if [ "$(id -u)" == "0" ]; then |
125 | isroot=1 | |
126 | else | |
127 | isroot=0 | |
128 | fi | |
129 | ||
7cd988f0 | 130 | start_lttng_sessiond |
bb8ec90d | 131 | |
7cd988f0 | 132 | test_parsing_raw |
bb8ec90d | 133 | |
7cd988f0 JD |
134 | skip $isroot "Root access is needed. Skipping UST perf tests." 8 || |
135 | { | |
136 | test_event_basic | |
bc2d01d2 | 137 | } |
7cd988f0 JD |
138 | |
139 | stop_lttng_sessiond |