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
=$
(get_pipe_max_size
)
160 # Find the number of events needed to overflow the event notification
161 # pipe buffer. Each LTTng-UST notification is at least 42 bytes long.
162 # Double that number to ensure enough events are created to overflow
164 NR_ITER
=$
(( (PIPE_SIZE
/ 42) * 2 ))
165 diag
"Test application will emit $NR_ITER events"
167 # Used on sessiond launch.
168 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 \
169 NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
170 LD_PRELOAD=${TESTPOINT}"
172 start_lttng_sessiond_notap
174 # This is needed since the testpoint create a pipe with the sessiond
176 for f
in "$TESTPOINT_BASE_PATH"*; do
177 sessiond_pipe
+=("$f")
180 lttng_add_trigger_ok
"$trigger_name" \
181 --condition event-rule-matches
--type=user
--name=tp
:tptest \
184 trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$trigger_name")
185 is
$trigger_discarded_nb 0 "No discarded tracer notification"
187 # Stop consumption of notifier tracer notifications.
188 diag
"Pause consumption of tracer messages"
189 echo -n 1 > $sessiond_pipe
191 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT
192 ok $?
"Generating $NR_ITER tracer notifications"
194 # Confirm that the number of tracer notifications discarded is non-zero.
195 trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$trigger_name")
196 isnt
$trigger_discarded_nb 0 "Discarded tracer notification number non-zero ($trigger_discarded_nb) as expected"
198 # Remove the notifier.
199 lttng_remove_trigger_ok
"$trigger_name"
201 # Confirm that no trigger is enabled.
202 list_triggers_line_count
=$
("$FULL_LTTNG_BIN" list-triggers |
wc -l)
203 is
"$list_triggers_line_count" "0" "No \`event-rule-matches\` userspace notifier enabled as expected"
205 # Enable another notifier and list it to confirm the counter was cleared.
206 lttng_add_trigger_ok
"$trigger_name" \
207 --condition event-rule-matches
--type=user
--name=tp
:tptest \
210 trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$trigger_name")
211 is
$trigger_discarded_nb 0 "No discarded tracer notification"
213 lttng_remove_trigger_ok
"$trigger_name"
215 stop_lttng_sessiond_notap
217 unset LTTNG_SESSIOND_ENV_VARS
220 function test_ust_notifier_discarded_count_max_bucket
222 start_lttng_sessiond
"" "--event-notifier-error-buffer-size-userspace=3"
224 diag
"UST event notifer error counter bucket limit"
225 for i
in $
(seq 3); do
226 lttng_add_trigger_ok
"$i" \
227 --condition event-rule-matches
--type=user
--name=my_event_that_doesnt_need_to_really_exist_
$i \
231 for i
in $
(seq 4 5); do
232 lttng_add_trigger_fail
"$i" \
233 --condition event-rule-matches
--type=user
--name=my_event_that_doesnt_need_to_really_exist_
$i \
237 stop_lttng_sessiond_notap
240 function test_ust_notifier_discarded_count_multi_uid
242 local sessiond_pipe
=()
243 local root_trigger_name
="root_trigger"
244 local user_trigger_name
="user_trigger"
245 local list_triggers_stdout
=$
(mktemp
-t "list_triggers_stdout.XXXXXX")
249 local new_user
="dummy_lttng_test_user"
251 diag
"UST event notifer error counter multiple UIDs"
253 # Create a dummy user to run test apps as.
254 useradd
--no-create-home "$new_user"
255 new_uid
=$
(id
-u "$new_user")
257 PIPE_SIZE
=$
(get_pipe_max_size
)
259 # Find the number of events needed to overflow the event notification
260 # pipe buffer. Each LTTng-UST notification is at least 42 bytes long.
261 # Double that number to ensure enough events are created to overflow
263 NR_ITER
=$
(( (PIPE_SIZE
/ 42) * 2 ))
264 diag
"Test applications will emit $NR_ITER events"
266 # Used on sessiond launch.
267 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 \
268 NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
269 LD_PRELOAD=${TESTPOINT}"
271 start_lttng_sessiond_notap
273 # This is needed since the testpoint create a pipe with the sessiond
275 for f
in "$TESTPOINT_BASE_PATH"*; do
276 sessiond_pipe
+=("$f")
279 lttng_add_trigger_ok
"$root_trigger_name" \
280 --condition event-rule-matches
--type=user
--name tp
:tptest \
283 lttng_add_trigger_ok
"$user_trigger_name" --owner-uid "$new_uid" \
284 --condition event-rule-matches
--type=user
--name tp
:tptest \
287 # Stop consumption of notifier tracer notifications.
288 echo -n 1 > $sessiond_pipe
290 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT
291 ok $?
"Generating $NR_ITER tracer notifications as UID: $(id -u)"
293 su
"$new_user" -c "$TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT"
294 ok $?
"Generating $NR_ITER tracer notifications as UID: $new_uid"
296 root_trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$root_trigger_name")
297 user_trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$user_trigger_name")
299 isnt
$root_trigger_discarded_nb 0 \
300 "Root trigger discarded notifications number ($root_trigger_discarded_nb) is non-zero"
301 isnt
$user_trigger_discarded_nb 0 \
302 "User trigger discarded notifications number ($user_trigger_discarded_nb) is non-zero"
304 lttng_remove_trigger_ok
"$root_trigger_name"
305 lttng_remove_trigger_ok
"$user_trigger_name" --owner-uid "$new_uid"
307 stop_lttng_sessiond_notap
309 unset LTTNG_SESSIOND_ENV_VARS
312 rm -f "$list_triggers_stdout"
315 function test_ust_notifier_discarded_regardless_trigger_owner
317 local sessiond_pipe
=()
318 local root_trigger_name
="root_trigger"
319 local user_trigger_name
="user_trigger"
320 local list_triggers_stdout
=$
(mktemp
-t "list_triggers_stdout.XXXXXX")
324 local new_user
="dummy_lttng_test_user"
326 PIPE_SIZE
=$
(get_pipe_max_size
)
328 # Find the number of events needed to overflow the event notification
329 # pipe buffer. Each LTTng-UST notification is at least 42 bytes long.
330 # Double that number to ensure enough events are created to overflow
332 NR_ITER
=$
(( (PIPE_SIZE
/ 42) * 2 ))
333 diag
"Test applications will emit $NR_ITER events"
335 diag
"UST event notifer error counter persists when a root trigger is present"
337 # Create a dummy user to run test apps as.
338 useradd
--no-create-home "$new_user"
339 new_uid
=$
(id
-u "$new_user")
341 # Used on sessiond launch.
342 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 \
343 NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
344 LD_PRELOAD=${TESTPOINT}"
346 start_lttng_sessiond_notap
348 # This is needed since the testpoint create a pipe with the sessiond
350 for f
in "$TESTPOINT_BASE_PATH"*; do
351 sessiond_pipe
+=("$f")
354 lttng_add_trigger_ok
"$root_trigger_name" \
355 --condition event-rule-matches
--type=user
--name tp
:tptest \
358 # Stop consumption of notifier tracer notifications.
359 echo -n 1 > $sessiond_pipe
361 su
"$new_user" -c "$TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT"
362 ok $?
"Generating $NR_ITER tracer notifications as UID: $new_uid"
364 root_trigger_discarded_nb
=$
(trigger_get_discarded_notif_number
"$root_trigger_name")
366 isnt
$root_trigger_discarded_nb 0 \
367 "Root trigger discarded notifications number ($root_trigger_discarded_nb) is non-zero"
369 lttng_remove_trigger_ok
"$root_trigger_name"
371 stop_lttng_sessiond_notap
373 unset LTTNG_SESSIOND_ENV_VARS
376 rm -f "$list_triggers_stdout"
379 test_ust_notifier_discarded_count
380 test_ust_notifier_discarded_count_max_bucket
382 check_skip_kernel_test
"$KERNEL_NUM_TESTS" "Skipping kernel notification tests." ||
385 validate_lttng_modules_present
389 test_kernel_notifier_discarded_count
390 test_kernel_notifier_discarded_count_max_bucket
392 if destructive_tests_enabled
; then
393 # Those tests add a new user on the system. Since it's a quite
394 # intrusive change to the system, we decide to only run it when
395 # the user knows what they are doing.
396 test_ust_notifier_discarded_count_multi_uid
397 test_ust_notifier_discarded_regardless_trigger_owner
399 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
402 modprobe
--remove lttng-test
404 rm -rf "${sessiond_pipe[@]}" 2> /dev
/null
408 rm -rf "$TEST_TMPDIR"