sessiond: split event notifier error counter CLI options
[lttng-tools.git] / tests / regression / tools / notification / test_notification_notifier_discarded_count
1 #!/bin/bash
2 #
3 # Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
4 #
5 # SPDX-License-Identifier: LGPL-2.1-only
6
7 CURDIR=$(dirname "$0")/
8 TESTDIR=$CURDIR/../../../
9
10 TMPDIR=$(mktemp -d)
11
12 TESTAPP_PATH="$TESTDIR/utils/testapp"
13 TESTAPP_NAME="gen-ust-events"
14 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
15
16 TESTPOINT_BASE_PATH=$(readlink -f "$TMPDIR/lttng.t_p_n")
17 TESTPOINT_PIPE_PATH=$(mktemp -u "${TESTPOINT_BASE_PATH}.XXXXXX")
18 TESTPOINT=$(readlink -f "${CURDIR}/.libs/libpause_sessiond.so")
19
20 SH_TAP=1
21
22 # shellcheck source=../../../utils/utils.sh
23 source "$TESTDIR/utils/utils.sh"
24 # shellcheck source=./util_event_generator.sh
25 source "$CURDIR/util_event_generator.sh"
26
27 FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
28 FULL_LTTNG_SESSIOND_BIN="${TESTDIR}/../src/bin/lttng-sessiond/lttng-sessiond"
29
30 UST_NUM_TESTS=18
31 KERNEL_NUM_TESTS=17
32 NUM_TESTS=$(($UST_NUM_TESTS + $KERNEL_NUM_TESTS))
33
34 plan_tests $NUM_TESTS
35
36 function test_kernel_notifier_discarded_count
37 {
38 local sessiond_pipe=()
39 local trigger_name="my_trigger"
40 local list_triggers_stdout=$(mktemp -t list_triggers_stdout.XXXXXX)
41
42 # Used on sessiond launch.
43 LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \
44 NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
45 LD_PRELOAD=${TESTPOINT}"
46
47 diag "Kernel event notifer error counter"
48
49 start_lttng_sessiond_notap
50
51 # This is needed since the testpoint creates a pipe with the sessiond
52 # type suffixed.
53 for f in "$TESTPOINT_BASE_PATH"*; do
54 sessiond_pipe+=("$f")
55 done
56
57 lttng_add_trigger_ok "$trigger_name" \
58 --condition on-event --kernel lttng_test_filter_event \
59 --action notify
60
61 "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout"
62
63 # Confirm that the discarded notification line is not present.
64 cat "$list_triggers_stdout" | grep -v --quiet "discarded tracer messages"
65 ok $? "No discarded tracer notification message"
66
67 tail -n 1 "$list_triggers_stdout" | grep --quiet "errors: none"
68 ok $? "Trigger 'errors: none' notification message"
69
70 # Stop consumption of notifier tracer notifications.
71 diag "Pause consumption of tracer messages"
72 echo -n 1 > $sessiond_pipe
73
74 # The notifier ring buffer configuration is currently made of 16 4096
75 # bytes subbuffers. Each kernel notification is at least 42 bytes long.
76 # To fill it, we need to generate (16 * 4096)/42 = 1561 notifications.
77 # That number is a bit larger than what we need since some of the space
78 # is lost in subbuffer boundaries.
79 echo -n "2000" > /proc/lttng-test-filter-event
80
81 "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout"
82
83 # Confirm that the discarded notification line is present. To avoid
84 # false positives.
85 cat "$list_triggers_stdout" | grep --quiet "discarded tracer messages"
86 ok $? "Tracer notification discarded line printed"
87
88 # Confirm that the number of dicarded tracer messages is not zero.
89 cat "$list_triggers_stdout" | grep --quiet "discarded tracer messages: 0"
90 isnt $? 0 "Discarded tracer notification number non-zero as expected"
91
92 lttng_remove_trigger_ok "$trigger_name"
93
94 # Confirm that no notifier is enabled.
95 list_triggers_line_count=$("$FULL_LTTNG_BIN" list-triggers | wc -l)
96 is "$list_triggers_line_count" "0" "No \`on-event\` kernel notifier enabled as expected"
97
98 # Enable another notifier and list it to confirm the counter was cleared.
99 lttng_add_trigger_ok "$trigger_name" \
100 --condition on-event --kernel lttng_test_filter_event \
101 --action notify
102
103 "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout"
104
105 # Confirm that the discarded notification line is not present.
106 cat "$list_triggers_stdout" | grep -v --quiet "discarded tracer messages"
107 ok $? "No discarded tracer notification message"
108
109 tail -n 1 "$list_triggers_stdout" | grep --quiet "errors: none"
110 ok $? "Trigger 'errors: none' notification message"
111
112 lttng_remove_trigger_ok "$trigger_name"
113
114 stop_lttng_sessiond_notap
115
116 unset LTTNG_SESSIOND_ENV_VARS
117
118 rm -f "$list_triggers_stdout"
119 }
120
121 function test_kernel_notifier_discarded_count_max_bucket
122 {
123 start_lttng_sessiond "" "--event-notifier-error-buffer-size-kernel=3"
124
125 diag "Kernel event notifer error counter bucket limit"
126 for i in $(seq 3); do
127 lttng_add_trigger_ok "$i" \
128 --condition on-event --kernel my_event_that_doesnt_need_to_really_exist_$i \
129 --action notify
130 done
131
132 for i in $(seq 4 5); do
133 lttng_add_trigger_fail "$i" \
134 --condition on-event --kernel my_event_that_doesnt_need_to_really_exist_$i \
135 --action notify
136 done
137
138 stop_lttng_sessiond_notap
139 }
140
141 function test_ust_notifier_discarded_count
142 {
143 local sessiond_pipe=()
144 local trigger_name="my_trigger"
145 local list_triggers_stdout=$(mktemp -t list_triggers_stdout.XXXXXX)
146 local NR_USEC_WAIT=0
147 local PIPE_SIZE
148 local NR_ITER
149
150 diag "UST event notifer error counter"
151
152 PIPE_SIZE=$("$CURDIR"/default_pipe_size_getter)
153 if [ $? -ne 0 ]; then
154 BAIL_OUT "Failed to get system default pipe size"
155 else
156 diag "Default system pipe size: $PIPE_SIZE bytes"
157 fi
158
159 # Find the number of events needed to overflow the event notification
160 # pipe buffer. Each LTTng-UST notification is at least 42 bytes long.
161 # Double that number to ensure enough events are created to overflow
162 # the buffer.
163 NR_ITER=$(( (PIPE_SIZE / 42) * 2 ))
164 diag "Test application will emit $NR_ITER events"
165
166 # Used on sessiond launch.
167 LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \
168 NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
169 LD_PRELOAD=${TESTPOINT}"
170
171 start_lttng_sessiond_notap
172
173 # This is needed since the testpoint create a pipe with the sessiond
174 # type suffixed.
175 for f in "$TESTPOINT_BASE_PATH"*; do
176 sessiond_pipe+=("$f")
177 done
178
179 lttng_add_trigger_ok "$trigger_name" \
180 --condition on-event --userspace tp:tptest \
181 --action notify
182
183 "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout"
184
185 # Confirm that the discarded notification line is not present.
186 cat "$list_triggers_stdout" | grep -v --quiet "discarded tracer messages"
187 ok $? "No discarded tracer notification message"
188
189 tail -n 1 "$list_triggers_stdout" | grep --quiet "errors: none"
190 ok $? "Trigger 'errors: none' notification message"
191
192 # Stop consumption of notifier tracer notifications.
193 diag "Pause consumption of tracer messages"
194 echo -n 1 > $sessiond_pipe
195
196 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT
197 ok $? "Generating $NR_ITER tracer notifications"
198
199 "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout"
200
201 # Confirm that the discarded notification line is present. To avoid
202 # false positive.
203 cat "$list_triggers_stdout" | grep --quiet "discarded tracer messages"
204 ok $? "Tracer notification discarded line printed"
205
206 # Confirm that the number of discarded tracer messages is not zero.
207 cat "$list_triggers_stdout" | grep --quiet "discarded tracer messages: 0"
208 isnt $? 0 "Discarded tracer notification number non-zero as expected"
209
210 # Remove the notifier.
211 lttng_remove_trigger_ok "$trigger_name"
212
213 # Confirm that no notifier is enabled.
214 list_triggers_line_count=$("$FULL_LTTNG_BIN" list-triggers | wc -l)
215 is "$list_triggers_line_count" "0" "No \`on-event\` userspace notifier enabled as expected"
216
217 # Enable another notifier and list it to confirm the counter was cleared.
218 lttng_add_trigger_ok "$trigger_name" \
219 --condition on-event --userspace tp:tptest \
220 --action notify
221
222 # Confirm that the discarded notification line is not present.
223 "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout"
224
225 # Confirm that the discarded notification line is not present.
226 cat "$list_triggers_stdout" | grep -v --quiet "discarded tracer messages"
227 ok $? "No discarded tracer notification message"
228
229 tail -n 1 "$list_triggers_stdout" | grep --quiet "errors: none"
230 ok $? "Trigger 'errors: none' notification message"
231
232 lttng_remove_trigger_ok "$trigger_name"
233
234 stop_lttng_sessiond_notap
235
236 unset LTTNG_SESSIOND_ENV_VARS
237
238 rm -f "$list_triggers_stdout"
239 }
240 function test_ust_notifier_discarded_count_max_bucket
241 {
242 start_lttng_sessiond "" "--event-notifier-error-buffer-size-userspace=3"
243
244 diag "UST event notifer error counter bucket limit"
245 for i in $(seq 3); do
246 lttng_add_trigger_ok "$i" \
247 --condition on-event --userspace my_event_that_doesnt_need_to_really_exist_$i \
248 --action notify
249 done
250
251 for i in $(seq 4 5); do
252 lttng_add_trigger_fail "$i" \
253 --condition on-event --userspace my_event_that_doesnt_need_to_really_exist_$i \
254 --action notify
255 done
256
257 stop_lttng_sessiond_notap
258 }
259
260 test_ust_notifier_discarded_count
261 test_ust_notifier_discarded_count_max_bucket
262
263 if [ "$(id -u)" == "0" ]; then
264
265 validate_lttng_modules_present
266
267 modprobe lttng-test
268
269 test_kernel_notifier_discarded_count
270
271 test_kernel_notifier_discarded_count_max_bucket
272
273 modprobe --remove lttng-test
274
275 rm -rf "${sessiond_pipe[@]}" 2> /dev/null
276 else
277 # Kernel tests are skipped.
278 skip 0 "Root access is needed. Skipping all kernel notification tests." $KERNEL_NUM_TESTS
279 fi
280
281 rm -rf "$TMPDIR"
This page took 0.03617 seconds and 5 git commands to generate.