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/..
/..
/..
/
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 "$TMPDIR/lttng.t_p_n")
17 TESTPOINT_PIPE_PATH
=$
(mktemp
-u "${TESTPOINT_BASE_PATH}.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"
32 NUM_TESTS
=$
(($UST_NUM_TESTS + $KERNEL_NUM_TESTS))
36 function test_kernel_notifier_discarded_count
38 local sessiond_pipe
=()
39 local trigger_name
="my_trigger"
40 local list_triggers_stdout
=$
(mktemp
-t list_triggers_stdout.XXXXXX
)
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}"
47 diag
"Kernel event notifer error counter"
49 start_lttng_sessiond_notap
51 # This is needed since the testpoint create a pipe with the sessiond
53 for f
in "$TESTPOINT_BASE_PATH"*; do
57 lttng_add_trigger_ok
"$trigger_name" \
58 --condition on-event
--kernel lttng_test_filter_event \
61 "$FULL_LTTNG_BIN" list-triggers
> "$list_triggers_stdout"
63 # Confirm that the discarded notification line is present.
64 cat "$list_triggers_stdout" |
grep --quiet "tracer notifications discarded: 0"
65 ok $?
"No discarded tracer notification"
67 # Stop consumption of notifier tracer notifications.
68 echo -n 1 > $sessiond_pipe
70 # The notifier ring buffer configuration is currently made of 16 4096
71 # bytes subbuffers. Each kernel notification is at least 42 bytes long.
72 # To fill it, we need to generate (16 * 4096)/42 = 1561 notifications.
73 # That number is a bit larger than what we need since some of the space
74 # is lost in subbuffer boundaries.
75 echo -n "200000" > /proc
/lttng-test-filter-event
77 "$FULL_LTTNG_BIN" list-triggers
> "$list_triggers_stdout"
79 # Confirm that the discarded notification line is present. To avoid
81 cat "$list_triggers_stdout" |
grep --quiet "tracer notifications discarded"
82 ok $?
"Tracer notification discarded line printed"
84 # Confirm that the number of tracer notifications discarded is not zero.
85 cat "$list_triggers_stdout" |
grep --quiet "tracer notifications discarded: 0"
86 isnt $?
0 "Discarded tracer notification number non-zero as expected"
88 lttng_remove_trigger_ok
"$trigger_name"
90 # Confirm that no notifier is enabled.
91 list_triggers_line_count
=$
("$FULL_LTTNG_BIN" list-triggers |
wc -l)
92 is
"$list_triggers_line_count" "0" "No \`on-event\` kernel notifier enabled as expected"
94 # Enable another notifier and list it to confirm the counter was cleared.
95 lttng_add_trigger_ok
"$trigger_name" \
96 --condition on-event
--kernel lttng_test_filter_event \
99 # Confirm that the discarded notification line is present.
100 "$FULL_LTTNG_BIN" list-triggers
> "$list_triggers_stdout"
101 cat "$list_triggers_stdout" |
grep --quiet "tracer notifications discarded: 0"
102 ok $?
"No discarded tracer notification"
104 lttng_remove_trigger_ok
"$trigger_name"
106 stop_lttng_sessiond_notap
108 unset LTTNG_SESSIOND_ENV_VARS
110 rm -f "$list_triggers_stdout"
113 function test_kernel_notifier_discarded_count_max_bucket
115 start_lttng_sessiond
"" "--event-notifier-error-number-of-bucket=3"
117 diag
"Kernel event notifer error counter bucket limit"
118 for i
in $
(seq 3); do
119 lttng_add_trigger_ok
"$i" \
120 --condition on-event
--kernel my_event_that_doesnt_need_to_really_exist_
$i \
124 for i
in $
(seq 4 5); do
125 lttng_add_trigger_fail
"$i" \
126 --condition on-event
--kernel my_event_that_doesnt_need_to_really_exist_
$i \
130 stop_lttng_sessiond_notap
133 function test_ust_notifier_discarded_count
135 local sessiond_pipe
=()
136 local trigger_name
="my_trigger"
137 local list_triggers_stdout
=$
(mktemp
-t list_triggers_stdout.XXXXXX
)
142 diag
"UST event notifer error counter"
143 # Used on sessiond launch.
144 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 \
145 NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
146 LD_PRELOAD=${TESTPOINT}"
148 start_lttng_sessiond_notap
150 # This is needed since the testpoint create a pipe with the sessiond
152 for f
in "$TESTPOINT_BASE_PATH"*; do
153 sessiond_pipe
+=("$f")
156 lttng_add_trigger_ok
"$trigger_name" \
157 --condition on-event
--userspace tp
:tptest \
160 "$FULL_LTTNG_BIN" list-triggers
> "$list_triggers_stdout"
162 # Confirm that the discarded notification line is present.
163 cat "$list_triggers_stdout" |
grep --quiet "tracer notifications discarded: 0"
164 ok $?
"No discarded tracer notification"
166 # Stop consumption of notifier tracer notifications.
167 echo -n 1 > $sessiond_pipe
169 # The notifier ring buffer configuration is currently made of 16 4096
170 # bytes subbuffers. Each userspace notification is at least 42 bytes long.
171 # To fill it, we need to generate (16 * 4096)/42 = 1561 notifications.
172 # That number is a bit larger than what we need since some of the space
173 # is lost in subbuffer boundaries.
174 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT
175 ok $?
"Generating $NR_ITER tracer notifications"
177 "$FULL_LTTNG_BIN" list-triggers
> "$list_triggers_stdout"
179 # Confirm that the discarded notification line is present. To avoid
181 cat "$list_triggers_stdout" |
grep --quiet "tracer notifications discarded"
182 ok $?
"Tracer notification discarded line printed"
184 # Confirm that the number of tracer notifications discarded is not zero.
185 cat "$list_triggers_stdout" |
grep --quiet "tracer notifications discarded: 0"
186 isnt $?
0 "Discarded tracer notification number non-zero as expected"
188 # Remove the notifier.
189 lttng_remove_trigger_ok
"$trigger_name"
191 # Confirm that no notifier is enabled.
192 list_triggers_line_count
=$
("$FULL_LTTNG_BIN" list-triggers |
wc -l)
193 is
"$list_triggers_line_count" "0" "No \`on-event\` userspace notifier enabled as expected"
195 # Enable another notifier and list it to confirm the counter was cleared.
196 lttng_add_trigger_ok
"$trigger_name" \
197 --condition on-event
--userspace tp
:tptest \
200 # Confirm that the discarded notification line is present.
201 "$FULL_LTTNG_BIN" list-triggers
> "$list_triggers_stdout"
202 cat "$list_triggers_stdout" |
grep --quiet "tracer notifications discarded: 0"
203 ok $?
"No discarded tracer notification"
205 lttng_remove_trigger_ok
"$trigger_name"
207 stop_lttng_sessiond_notap
209 unset LTTNG_SESSIOND_ENV_VARS
211 rm -f "$list_triggers_stdout"
213 function test_ust_notifier_discarded_count_max_bucket
215 start_lttng_sessiond
"" "--event-notifier-error-number-of-bucket=3"
217 diag
"UST event notifer error counter bucket limit"
218 for i
in $
(seq 3); do
219 lttng_add_trigger_ok
"$i" \
220 --condition on-event
--userspace my_event_that_doesnt_need_to_really_exist_
$i \
224 for i
in $
(seq 4 5); do
225 lttng_add_trigger_fail
"$i" \
226 --condition on-event
--userspace my_event_that_doesnt_need_to_really_exist_
$i \
230 stop_lttng_sessiond_notap
233 test_ust_notifier_discarded_count
234 test_ust_notifier_discarded_count_max_bucket
236 if [ "$(id -u)" == "0" ]; then
238 validate_lttng_modules_present
242 test_kernel_notifier_discarded_count
244 test_kernel_notifier_discarded_count_max_bucket
246 modprobe
--remove lttng-test
248 rm -rf "${sessiond_pipe[@]}" 2> /dev
/null
250 # Kernel tests are skipped.
251 skip
0 "Root access is needed. Skipping all kernel notification tests." $KERNEL_NUM_TESTS