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
-d -t tmp.test_notifier_discarded_count.XXXXXX
)
12 # Set TMPDIR for further call to mktemp
13 export TMPDIR
="$TEST_TMPDIR"
15 TESTAPP_PATH
="$TESTDIR/utils/testapp"
16 TESTAPP_NAME
="gen-ust-events"
17 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
19 TESTPOINT_BASE_PATH
=$
(readlink
-f "$TEST_TMPDIR/lttng.t_p_n")
20 TESTPOINT_PIPE_PATH
=$
(mktemp
-u -t "lttng.t_p_n.XXXXXX")
21 TESTPOINT
=$
(readlink
-f "${CURDIR}/.libs/libpause_sessiond.so")
25 # shellcheck source=../../../utils/utils.sh
26 source "$TESTDIR/utils/utils.sh"
27 # shellcheck source=./util_event_generator.sh
28 source "$CURDIR/util_event_generator.sh"
30 FULL_LTTNG_BIN
="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
31 FULL_LTTNG_SESSIOND_BIN
="${TESTDIR}/../src/bin/lttng-sessiond/lttng-sessiond"
34 DESTRUCTIVE_TESTS_NUM
=12
35 KERNEL_NUM_TESTS
=$
((14 + $DESTRUCTIVE_TESTS_NUM))
36 NUM_TESTS
=$
(($UST_NUM_TESTS + $KERNEL_NUM_TESTS))
40 function trigger_get_discarded_notif_number
()
42 local trigger_name
="$1"
43 local list_triggers_stdout
=$
(mktemp
-t "list_triggers_stdout.XXXXXX")
45 "$FULL_LTTNG_BIN" list-triggers
> "$list_triggers_stdout"
47 cat "$list_triggers_stdout" |
grep -A7 "$trigger_name" |
grep -A2 "event rule matches" |
tail -1 |
grep --quiet "errors: none"
50 if [ "$ret" -eq "0" ]; then
53 notif_nb
=$
(cat "$list_triggers_stdout" |
grep -A7 "$trigger_name" |
grep "discarded tracer messages" | cut
-d' ' -f10)
56 rm -f "$list_triggers_stdout"
58 # Printing the value to that the caller can get it back.
62 function test_kernel_notifier_discarded_count
64 local sessiond_pipe
=()
65 local trigger_name
="my_trigger"
66 local list_triggers_stdout
=$
(mktemp
-t "list_triggers_stdout.XXXXXX")
68 # Used on sessiond launch.
69 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 \
70 NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
71 LD_PRELOAD=${TESTPOINT}"
73 diag
"Kernel event notifer error counter"
75 start_lttng_sessiond_notap
77 # This is needed since the testpoint creates a pipe with the sessiond
79 for f
in "$TESTPOINT_BASE_PATH"*; do
83 lttng_add_trigger_ok
"$trigger_name" \
84 --condition event-rule-matches
--type=kernel
--name=lttng_test_filter_event \
87 trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$trigger_name")
88 is
$trigger_discarded_nb 0 "No discarded tracer notification"
90 # Stop consumption of notifier tracer notifications.
91 diag
"Pause consumption of tracer messages"
92 echo -n 1 > $sessiond_pipe
94 # The notifier ring buffer configuration is currently made of 16 4096
95 # bytes subbuffers. Each kernel notification is at least 42 bytes long.
96 # To fill it, we need to generate (16 * 4096)/42 = 1561 notifications.
97 # That number is a bit larger than what we need since some of the space
98 # is lost in subbuffer boundaries.
99 echo -n "2000" > /proc
/lttng-test-filter-event
101 # Confirm that the number of tracer notifications discarded is non-zero.
102 trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$trigger_name")
103 isnt
$trigger_discarded_nb 0 "Discarded tracer notification number non-zero ($trigger_discarded_nb) as expected"
105 lttng_remove_trigger_ok
"$trigger_name"
107 # Confirm that no notifier is enabled.
108 list_triggers_line_count
=$
("$FULL_LTTNG_BIN" list-triggers |
wc -l)
109 is
"$list_triggers_line_count" "0" "No \`event-rule-matches\` kernel notifier enabled as expected"
111 # Enable another notifier and list it to confirm the counter was cleared.
112 lttng_add_trigger_ok
"$trigger_name" \
113 --condition event-rule-matches
--type=kernel
--name=lttng_test_filter_event \
116 trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$trigger_name")
117 is
$trigger_discarded_nb 0 "No discarded tracer notification"
119 lttng_remove_trigger_ok
"$trigger_name"
121 stop_lttng_sessiond_notap
123 unset LTTNG_SESSIOND_ENV_VARS
125 rm -f "$list_triggers_stdout"
128 function test_kernel_notifier_discarded_count_max_bucket
130 start_lttng_sessiond
"" "--event-notifier-error-buffer-size-kernel=3"
132 diag
"Kernel event notifer error counter bucket limit"
133 for i
in $
(seq 3); do
134 lttng_add_trigger_ok
"$i" \
135 --condition event-rule-matches
--type=kernel
--name=my_event_that_doesnt_need_to_really_exist_
$i \
139 for i
in $
(seq 4 5); do
140 lttng_add_trigger_fail
"$i" \
141 --condition event-rule-matches
--type=kernel
--name=my_event_that_doesnt_need_to_really_exist_
$i \
145 stop_lttng_sessiond_notap
148 function test_ust_notifier_discarded_count
150 local sessiond_pipe
=()
151 local trigger_name
="my_trigger"
156 diag
"UST event notifer error counter"
158 PIPE_SIZE
=$
("$CURDIR"/default_pipe_size_getter
)
159 if [ $?
-ne 0 ]; then
160 BAIL_OUT
"Failed to get system default pipe size"
162 diag
"Default system pipe size: $PIPE_SIZE bytes"
165 # Find the number of events needed to overflow the event notification
166 # pipe buffer. Each LTTng-UST notification is at least 42 bytes long.
167 # Double that number to ensure enough events are created to overflow
169 NR_ITER
=$
(( (PIPE_SIZE
/ 42) * 2 ))
170 diag
"Test application will emit $NR_ITER events"
172 # Used on sessiond launch.
173 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 \
174 NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
175 LD_PRELOAD=${TESTPOINT}"
177 start_lttng_sessiond_notap
179 # This is needed since the testpoint create a pipe with the sessiond
181 for f
in "$TESTPOINT_BASE_PATH"*; do
182 sessiond_pipe
+=("$f")
185 lttng_add_trigger_ok
"$trigger_name" \
186 --condition event-rule-matches
--type=user
--name=tp
:tptest \
189 trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$trigger_name")
190 is
$trigger_discarded_nb 0 "No discarded tracer notification"
192 # Stop consumption of notifier tracer notifications.
193 diag
"Pause consumption of tracer messages"
194 echo -n 1 > $sessiond_pipe
196 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT
197 ok $?
"Generating $NR_ITER tracer notifications"
199 # Confirm that the number of tracer notifications discarded is non-zero.
200 trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$trigger_name")
201 isnt
$trigger_discarded_nb 0 "Discarded tracer notification number non-zero ($trigger_discarded_nb) as expected"
203 # Remove the notifier.
204 lttng_remove_trigger_ok
"$trigger_name"
206 # Confirm that no trigger is enabled.
207 list_triggers_line_count
=$
("$FULL_LTTNG_BIN" list-triggers |
wc -l)
208 is
"$list_triggers_line_count" "0" "No \`event-rule-matches\` userspace notifier enabled as expected"
210 # Enable another notifier and list it to confirm the counter was cleared.
211 lttng_add_trigger_ok
"$trigger_name" \
212 --condition event-rule-matches
--type=user
--name=tp
:tptest \
215 trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$trigger_name")
216 is
$trigger_discarded_nb 0 "No discarded tracer notification"
218 lttng_remove_trigger_ok
"$trigger_name"
220 stop_lttng_sessiond_notap
222 unset LTTNG_SESSIOND_ENV_VARS
225 function test_ust_notifier_discarded_count_max_bucket
227 start_lttng_sessiond
"" "--event-notifier-error-buffer-size-userspace=3"
229 diag
"UST event notifer error counter bucket limit"
230 for i
in $
(seq 3); do
231 lttng_add_trigger_ok
"$i" \
232 --condition event-rule-matches
--type=user
--name=my_event_that_doesnt_need_to_really_exist_
$i \
236 for i
in $
(seq 4 5); do
237 lttng_add_trigger_fail
"$i" \
238 --condition event-rule-matches
--type=user
--name=my_event_that_doesnt_need_to_really_exist_
$i \
242 stop_lttng_sessiond_notap
245 function test_ust_notifier_discarded_count_multi_uid
247 local sessiond_pipe
=()
248 local root_trigger_name
="root_trigger"
249 local user_trigger_name
="user_trigger"
250 local list_triggers_stdout
=$
(mktemp
-t "list_triggers_stdout.XXXXXX")
254 local new_user
="dummy_lttng_test_user"
256 diag
"UST event notifer error counter multiple UIDs"
258 # Create a dummy user to run test apps as.
259 useradd
--no-create-home "$new_user"
260 new_uid
=$
(id
-u "$new_user")
262 PIPE_SIZE
=$
("$CURDIR"/default_pipe_size_getter
)
263 if [ $?
-ne 0 ]; then
264 BAIL_OUT
"Failed to get system default pipe size"
266 diag
"Default system pipe size: $PIPE_SIZE bytes"
269 # Find the number of events needed to overflow the event notification
270 # pipe buffer. Each LTTng-UST notification is at least 42 bytes long.
271 # Double that number to ensure enough events are created to overflow
273 NR_ITER
=$
(( (PIPE_SIZE
/ 42) * 2 ))
274 diag
"Test applications will emit $NR_ITER events"
276 # Used on sessiond launch.
277 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 \
278 NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
279 LD_PRELOAD=${TESTPOINT}"
281 start_lttng_sessiond_notap
283 # This is needed since the testpoint create a pipe with the sessiond
285 for f
in "$TESTPOINT_BASE_PATH"*; do
286 sessiond_pipe
+=("$f")
289 lttng_add_trigger_ok
"$root_trigger_name" \
290 --condition event-rule-matches
--type=user
--name tp
:tptest \
293 lttng_add_trigger_ok
"$user_trigger_name" --owner-uid "$new_uid" \
294 --condition event-rule-matches
--type=user
--name tp
:tptest \
297 # Stop consumption of notifier tracer notifications.
298 echo -n 1 > $sessiond_pipe
300 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT
301 ok $?
"Generating $NR_ITER tracer notifications as UID: $(id -u)"
303 su
"$new_user" -c "$TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT"
304 ok $?
"Generating $NR_ITER tracer notifications as UID: $new_uid"
306 root_trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$root_trigger_name")
307 user_trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$user_trigger_name")
309 isnt
$root_trigger_discarded_nb 0 \
310 "Root trigger discarded notifications number ($root_trigger_discarded_nb) is non-zero"
311 isnt
$user_trigger_discarded_nb 0 \
312 "User trigger discarded notifications number ($user_trigger_discarded_nb) is non-zero"
314 lttng_remove_trigger_ok
"$root_trigger_name"
315 lttng_remove_trigger_ok
"$user_trigger_name" --owner-uid "$new_uid"
317 stop_lttng_sessiond_notap
319 unset LTTNG_SESSIOND_ENV_VARS
322 rm -f "$list_triggers_stdout"
325 function test_ust_notifier_discarded_regardless_trigger_owner
327 local sessiond_pipe
=()
328 local root_trigger_name
="root_trigger"
329 local user_trigger_name
="user_trigger"
330 local list_triggers_stdout
=$
(mktemp
-t "list_triggers_stdout.XXXXXX")
334 local new_user
="dummy_lttng_test_user"
336 PIPE_SIZE
=$
("$CURDIR"/default_pipe_size_getter
)
337 if [ $?
-ne 0 ]; then
338 BAIL_OUT
"Failed to get system default pipe size"
340 diag
"Default system pipe size: $PIPE_SIZE bytes"
343 # Find the number of events needed to overflow the event notification
344 # pipe buffer. Each LTTng-UST notification is at least 42 bytes long.
345 # Double that number to ensure enough events are created to overflow
347 NR_ITER
=$
(( (PIPE_SIZE
/ 42) * 2 ))
348 diag
"Test applications will emit $NR_ITER events"
350 diag
"UST event notifer error counter persists when a root trigger is present"
352 # Create a dummy user to run test apps as.
353 useradd
--no-create-home "$new_user"
354 new_uid
=$
(id
-u "$new_user")
356 # Used on sessiond launch.
357 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 \
358 NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
359 LD_PRELOAD=${TESTPOINT}"
361 start_lttng_sessiond_notap
363 # This is needed since the testpoint create a pipe with the sessiond
365 for f
in "$TESTPOINT_BASE_PATH"*; do
366 sessiond_pipe
+=("$f")
369 lttng_add_trigger_ok
"$root_trigger_name" \
370 --condition event-rule-matches
--type=user
--name tp
:tptest \
373 # Stop consumption of notifier tracer notifications.
374 echo -n 1 > $sessiond_pipe
376 su
"$new_user" -c "$TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT"
377 ok $?
"Generating $NR_ITER tracer notifications as UID: $new_uid"
379 root_trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$root_trigger_name")
381 isnt
$root_trigger_discarded_nb 0 \
382 "Root trigger discarded notifications number ($root_trigger_discarded_nb) is non-zero"
384 lttng_remove_trigger_ok
"$root_trigger_name"
386 stop_lttng_sessiond_notap
388 unset LTTNG_SESSIOND_ENV_VARS
391 rm -f "$list_triggers_stdout"
394 test_ust_notifier_discarded_count
395 test_ust_notifier_discarded_count_max_bucket
397 if [ "$(id -u)" == "0" ]; then
399 validate_lttng_modules_present
403 test_kernel_notifier_discarded_count
404 test_kernel_notifier_discarded_count_max_bucket
406 if destructive_tests_enabled
; then
407 # Those tests add a new user on the system. Since it's a quite
408 # intrusive change to the system, we decide to only run it when
409 # the user knows what they are doing.
410 test_ust_notifier_discarded_count_multi_uid
411 test_ust_notifier_discarded_regardless_trigger_owner
413 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
416 modprobe
--remove lttng-test
418 rm -rf "${sessiond_pipe[@]}" 2> /dev
/null
420 # Kernel tests are skipped.
421 skip
0 "Root access is needed. Skipping all kernel notification tests." $KERNEL_NUM_TESTS
424 rm -rf "$TEST_TMPDIR"