3 # Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 CURDIR
=$
(dirname "$0")/
8 TESTDIR
=$CURDIR/..
/..
/..
/
10 TEST_TMPDIR
=$
(mktemp
--tmpdir -d tmp.test_notifier_discarded_count.XXXXXX
)
12 TESTAPP_PATH
="$TESTDIR/utils/testapp"
13 TESTAPP_NAME
="gen-ust-events"
14 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
16 TESTPOINT_BASE_PATH
=$
(readlink
-f "$TEST_TMPDIR/lttng.t_p_n")
17 TESTPOINT_PIPE_PATH
=$
(mktemp
-u --tmpdir="$TEST_TMPDIR" "lttng.t_p_n.XXXXXX")
18 TESTPOINT
=$
(readlink
-f "${CURDIR}/.libs/libpause_sessiond.so")
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"
27 FULL_LTTNG_BIN
="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
28 FULL_LTTNG_SESSIOND_BIN
="${TESTDIR}/../src/bin/lttng-sessiond/lttng-sessiond"
31 DESTRUCTIVE_TESTS_NUM
=12
32 KERNEL_NUM_TESTS
=$
((14 + $DESTRUCTIVE_TESTS_NUM))
33 NUM_TESTS
=$
(($UST_NUM_TESTS + $KERNEL_NUM_TESTS))
37 function trigger_get_discarded_notif_number
()
39 local trigger_name
="$1"
40 local list_triggers_stdout
=$
(mktemp
--tmpdir="$TEST_TMPDIR" "list_triggers_stdout.XXXXXX")
42 "$FULL_LTTNG_BIN" list-triggers
> "$list_triggers_stdout"
44 cat "$list_triggers_stdout" |
grep -A7 "$trigger_name" |
grep -A2 "event rule matches" |
tail -1 |
grep --quiet "errors: none"
47 if [ "$ret" -eq "0" ]; then
50 notif_nb
=$
(cat "$list_triggers_stdout" |
grep -A7 "$trigger_name" |
grep "discarded tracer messages" | cut
-d' ' -f10)
53 rm -f "$list_triggers_stdout"
55 # Printing the value to that the caller can get it back.
59 function test_kernel_notifier_discarded_count
61 local sessiond_pipe
=()
62 local trigger_name
="my_trigger"
63 local list_triggers_stdout
=$
(mktemp
--tmpdir="$TEST_TMPDIR" "list_triggers_stdout.XXXXXX")
65 # Used on sessiond launch.
66 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 \
67 NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
68 LD_PRELOAD=${TESTPOINT}"
70 diag
"Kernel event notifer error counter"
72 start_lttng_sessiond_notap
74 # This is needed since the testpoint creates a pipe with the sessiond
76 for f
in "$TESTPOINT_BASE_PATH"*; do
80 lttng_add_trigger_ok
"$trigger_name" \
81 --condition event-rule-matches
--type=kernel
--name=lttng_test_filter_event \
84 trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$trigger_name")
85 is
$trigger_discarded_nb 0 "No discarded tracer notification"
87 # Stop consumption of notifier tracer notifications.
88 diag
"Pause consumption of tracer messages"
89 echo -n 1 > $sessiond_pipe
91 # The notifier ring buffer configuration is currently made of 16 4096
92 # bytes subbuffers. Each kernel notification is at least 42 bytes long.
93 # To fill it, we need to generate (16 * 4096)/42 = 1561 notifications.
94 # That number is a bit larger than what we need since some of the space
95 # is lost in subbuffer boundaries.
96 echo -n "2000" > /proc
/lttng-test-filter-event
98 # Confirm that the number of tracer notifications discarded is non-zero.
99 trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$trigger_name")
100 isnt
$trigger_discarded_nb 0 "Discarded tracer notification number non-zero ($trigger_discarded_nb) as expected"
102 lttng_remove_trigger_ok
"$trigger_name"
104 # Confirm that no notifier is enabled.
105 list_triggers_line_count
=$
("$FULL_LTTNG_BIN" list-triggers |
wc -l)
106 is
"$list_triggers_line_count" "0" "No \`event-rule-matches\` kernel notifier enabled as expected"
108 # Enable another notifier and list it to confirm the counter was cleared.
109 lttng_add_trigger_ok
"$trigger_name" \
110 --condition event-rule-matches
--type=kernel
--name=lttng_test_filter_event \
113 trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$trigger_name")
114 is
$trigger_discarded_nb 0 "No discarded tracer notification"
116 lttng_remove_trigger_ok
"$trigger_name"
118 stop_lttng_sessiond_notap
120 unset LTTNG_SESSIOND_ENV_VARS
122 rm -f "$list_triggers_stdout"
125 function test_kernel_notifier_discarded_count_max_bucket
127 start_lttng_sessiond
"" "--event-notifier-error-buffer-size-kernel=3"
129 diag
"Kernel event notifer error counter bucket limit"
130 for i
in $
(seq 3); do
131 lttng_add_trigger_ok
"$i" \
132 --condition event-rule-matches
--type=kernel
--name=my_event_that_doesnt_need_to_really_exist_
$i \
136 for i
in $
(seq 4 5); do
137 lttng_add_trigger_fail
"$i" \
138 --condition event-rule-matches
--type=kernel
--name=my_event_that_doesnt_need_to_really_exist_
$i \
142 stop_lttng_sessiond_notap
145 function test_ust_notifier_discarded_count
147 local sessiond_pipe
=()
148 local trigger_name
="my_trigger"
153 diag
"UST event notifer error counter"
155 PIPE_SIZE
=$
("$CURDIR"/default_pipe_size_getter
)
156 if [ $?
-ne 0 ]; then
157 BAIL_OUT
"Failed to get system default pipe size"
159 diag
"Default system pipe size: $PIPE_SIZE bytes"
162 # Find the number of events needed to overflow the event notification
163 # pipe buffer. Each LTTng-UST notification is at least 42 bytes long.
164 # Double that number to ensure enough events are created to overflow
166 NR_ITER
=$
(( (PIPE_SIZE
/ 42) * 2 ))
167 diag
"Test application will emit $NR_ITER events"
169 # Used on sessiond launch.
170 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 \
171 NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
172 LD_PRELOAD=${TESTPOINT}"
174 start_lttng_sessiond_notap
176 # This is needed since the testpoint create a pipe with the sessiond
178 for f
in "$TESTPOINT_BASE_PATH"*; do
179 sessiond_pipe
+=("$f")
182 lttng_add_trigger_ok
"$trigger_name" \
183 --condition event-rule-matches
--type=user
--name=tp
:tptest \
186 trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$trigger_name")
187 is
$trigger_discarded_nb 0 "No discarded tracer notification"
189 # Stop consumption of notifier tracer notifications.
190 diag
"Pause consumption of tracer messages"
191 echo -n 1 > $sessiond_pipe
193 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT
194 ok $?
"Generating $NR_ITER tracer notifications"
196 # Confirm that the number of tracer notifications discarded is non-zero.
197 trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$trigger_name")
198 isnt
$trigger_discarded_nb 0 "Discarded tracer notification number non-zero ($trigger_discarded_nb) as expected"
200 # Remove the notifier.
201 lttng_remove_trigger_ok
"$trigger_name"
203 # Confirm that no trigger is enabled.
204 list_triggers_line_count
=$
("$FULL_LTTNG_BIN" list-triggers |
wc -l)
205 is
"$list_triggers_line_count" "0" "No \`event-rule-matches\` userspace notifier enabled as expected"
207 # Enable another notifier and list it to confirm the counter was cleared.
208 lttng_add_trigger_ok
"$trigger_name" \
209 --condition event-rule-matches
--type=user
--name=tp
:tptest \
212 trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$trigger_name")
213 is
$trigger_discarded_nb 0 "No discarded tracer notification"
215 lttng_remove_trigger_ok
"$trigger_name"
217 stop_lttng_sessiond_notap
219 unset LTTNG_SESSIOND_ENV_VARS
222 function test_ust_notifier_discarded_count_max_bucket
224 start_lttng_sessiond
"" "--event-notifier-error-buffer-size-userspace=3"
226 diag
"UST event notifer error counter bucket limit"
227 for i
in $
(seq 3); do
228 lttng_add_trigger_ok
"$i" \
229 --condition event-rule-matches
--type=user
--name=my_event_that_doesnt_need_to_really_exist_
$i \
233 for i
in $
(seq 4 5); do
234 lttng_add_trigger_fail
"$i" \
235 --condition event-rule-matches
--type=user
--name=my_event_that_doesnt_need_to_really_exist_
$i \
239 stop_lttng_sessiond_notap
242 function test_ust_notifier_discarded_count_multi_uid
244 local sessiond_pipe
=()
245 local root_trigger_name
="root_trigger"
246 local user_trigger_name
="user_trigger"
247 local list_triggers_stdout
=$
(mktemp
--tmpdir="$TEST_TMPDIR" "list_triggers_stdout.XXXXXX")
251 local new_user
="dummy_lttng_test_user"
253 diag
"UST event notifer error counter multiple UIDs"
255 # Create a dummy user to run test apps as.
256 useradd
--no-create-home "$new_user"
257 new_uid
=$
(id
-u "$new_user")
259 PIPE_SIZE
=$
("$CURDIR"/default_pipe_size_getter
)
260 if [ $?
-ne 0 ]; then
261 BAIL_OUT
"Failed to get system default pipe size"
263 diag
"Default system pipe size: $PIPE_SIZE bytes"
266 # Find the number of events needed to overflow the event notification
267 # pipe buffer. Each LTTng-UST notification is at least 42 bytes long.
268 # Double that number to ensure enough events are created to overflow
270 NR_ITER
=$
(( (PIPE_SIZE
/ 42) * 2 ))
271 diag
"Test applications will emit $NR_ITER events"
273 # Used on sessiond launch.
274 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 \
275 NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
276 LD_PRELOAD=${TESTPOINT}"
278 start_lttng_sessiond_notap
280 # This is needed since the testpoint create a pipe with the sessiond
282 for f
in "$TESTPOINT_BASE_PATH"*; do
283 sessiond_pipe
+=("$f")
286 lttng_add_trigger_ok
"$root_trigger_name" \
287 --condition event-rule-matches
--type=user
--name tp
:tptest \
290 lttng_add_trigger_ok
"$user_trigger_name" --owner-uid "$new_uid" \
291 --condition event-rule-matches
--type=user
--name tp
:tptest \
294 # Stop consumption of notifier tracer notifications.
295 echo -n 1 > $sessiond_pipe
297 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT
298 ok $?
"Generating $NR_ITER tracer notifications as UID: $(id -u)"
300 su
"$new_user" -c "$TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT"
301 ok $?
"Generating $NR_ITER tracer notifications as UID: $new_uid"
303 root_trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$root_trigger_name")
304 user_trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$user_trigger_name")
306 isnt
$root_trigger_discarded_nb 0 \
307 "Root trigger discarded notifications number ($root_trigger_discarded_nb) is non-zero"
308 isnt
$user_trigger_discarded_nb 0 \
309 "User trigger discarded notifications number ($user_trigger_discarded_nb) is non-zero"
311 lttng_remove_trigger_ok
"$root_trigger_name"
312 lttng_remove_trigger_ok
"$user_trigger_name" --owner-uid "$new_uid"
314 stop_lttng_sessiond_notap
316 unset LTTNG_SESSIOND_ENV_VARS
319 rm -f "$list_triggers_stdout"
322 function test_ust_notifier_discarded_regardless_trigger_owner
324 local sessiond_pipe
=()
325 local root_trigger_name
="root_trigger"
326 local user_trigger_name
="user_trigger"
327 local list_triggers_stdout
=$
(mktemp
--tmpdir="$TEST_TMPDIR" "list_triggers_stdout.XXXXXX")
331 local new_user
="dummy_lttng_test_user"
333 PIPE_SIZE
=$
("$CURDIR"/default_pipe_size_getter
)
334 if [ $?
-ne 0 ]; then
335 BAIL_OUT
"Failed to get system default pipe size"
337 diag
"Default system pipe size: $PIPE_SIZE bytes"
340 # Find the number of events needed to overflow the event notification
341 # pipe buffer. Each LTTng-UST notification is at least 42 bytes long.
342 # Double that number to ensure enough events are created to overflow
344 NR_ITER
=$
(( (PIPE_SIZE
/ 42) * 2 ))
345 diag
"Test applications will emit $NR_ITER events"
347 diag
"UST event notifer error counter persists when a root trigger is present"
349 # Create a dummy user to run test apps as.
350 useradd
--no-create-home "$new_user"
351 new_uid
=$
(id
-u "$new_user")
353 # Used on sessiond launch.
354 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 \
355 NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
356 LD_PRELOAD=${TESTPOINT}"
358 start_lttng_sessiond_notap
360 # This is needed since the testpoint create a pipe with the sessiond
362 for f
in "$TESTPOINT_BASE_PATH"*; do
363 sessiond_pipe
+=("$f")
366 lttng_add_trigger_ok
"$root_trigger_name" \
367 --condition event-rule-matches
--type=user
--name tp
:tptest \
370 # Stop consumption of notifier tracer notifications.
371 echo -n 1 > $sessiond_pipe
373 su
"$new_user" -c "$TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT"
374 ok $?
"Generating $NR_ITER tracer notifications as UID: $new_uid"
376 root_trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$root_trigger_name")
378 isnt
$root_trigger_discarded_nb 0 \
379 "Root trigger discarded notifications number ($root_trigger_discarded_nb) is non-zero"
381 lttng_remove_trigger_ok
"$root_trigger_name"
383 stop_lttng_sessiond_notap
385 unset LTTNG_SESSIOND_ENV_VARS
388 rm -f "$list_triggers_stdout"
391 test_ust_notifier_discarded_count
392 test_ust_notifier_discarded_count_max_bucket
394 if [ "$(id -u)" == "0" ]; then
396 validate_lttng_modules_present
400 test_kernel_notifier_discarded_count
401 test_kernel_notifier_discarded_count_max_bucket
403 if destructive_tests_enabled
; then
404 # Those tests add a new user on the system. Since it's a quite
405 # intrusive change to the system, we decide to only run it when
406 # the user knows what they are doing.
407 test_ust_notifier_discarded_count_multi_uid
408 test_ust_notifier_discarded_regardless_trigger_owner
410 skip
0 "You need to set the LTTNG_ENABLE_DESTRUCTIVE_TESTS environment variable to \"will-break-my-system\" to run this test" $DESTRUCTIVE_TESTS_NUM
413 modprobe
--remove lttng-test
415 rm -rf "${sessiond_pipe[@]}" 2> /dev
/null
417 # Kernel tests are skipped.
418 skip
0 "Root access is needed. Skipping all kernel notification tests." $KERNEL_NUM_TESTS
421 rm -rf "$TEST_TMPDIR"