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_trigger_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 TRIGGER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
45 LD_PRELOAD=${TESTPOINT}"
47 start_lttng_sessiond_notap
49 # This is needed since the testpoint create a pipe with the sessiond
51 for f
in "$TESTPOINT_BASE_PATH"*; do
55 "$FULL_LTTNG_BIN" add-trigger
--id "$trigger_name" \
56 --condition on-event
--kernel lttng_test_filter_event \
57 --action notify
> /dev
/null
> /dev
/null
58 ok $?
"Adding \`on-event\` kernel trigger successful"
60 "$FULL_LTTNG_BIN" list-triggers
> "$list_triggers_stdout"
62 # Confirm that the discarded notification line is present.
63 cat "$list_triggers_stdout" |
grep --quiet "tracer notifications discarded: 0"
64 ok $?
"No discarded tracer notification"
66 # Stop consumption of trigger tracer notifications.
67 echo -n 1 > $sessiond_pipe
69 # The trigger ring buffer configuration is currently made of 16 4096
70 # bytes subbuffers. Each kernel notification is at least 42 bytes long.
71 # To fill it, we need to generate (16 * 4096)/42 = 1561 notifications.
72 # That number is a bit larger than what we need since some of the space
73 # is lost in subbuffer boundaries.
74 echo -n "200000" > /proc
/lttng-test-filter-event
76 "$FULL_LTTNG_BIN" list-triggers
> "$list_triggers_stdout"
78 # Confirm that the discarded notification line is present. To avoid
80 cat "$list_triggers_stdout" |
grep --quiet "tracer notifications discarded"
81 ok $?
"Tracer notification discarded line printed"
83 # Confirm that the number of tracer notifications discarded is not zero.
84 cat "$list_triggers_stdout" |
grep --quiet "tracer notifications discarded: 0"
85 isnt $?
0 "Discarded tracer notification number non-zero as expected"
87 "$FULL_LTTNG_BIN" remove-trigger
"$trigger_name" > /dev
/null
88 ok $?
"Removing \`on-event\` kernel trigger successful"
90 # Confirm that no trigger 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 trigger enabled as expected"
94 # Enable another trigger and list it to confirm the counter was cleared.
95 "$FULL_LTTNG_BIN" add-trigger
--id "$trigger_name" \
96 --condition on-event
--kernel lttng_test_filter_event \
97 --action notify
> /dev
/null
98 ok $?
"Adding another \`on-event\` kernel trigger successful"
100 # Confirm that the discarded notification line is present.
101 "$FULL_LTTNG_BIN" list-triggers
> "$list_triggers_stdout"
102 cat "$list_triggers_stdout" |
grep --quiet "tracer notifications discarded: 0"
103 ok $?
"No discarded tracer notification"
105 "$FULL_LTTNG_BIN" remove-trigger
"$trigger_name" > /dev
/null
106 ok $?
"Removing \`on-event\` kernel trigger successful"
109 stop_lttng_sessiond_notap
111 unset LTTNG_SESSIOND_ENV_VARS
113 rm -f "$list_triggers_stdout"
116 function test_kernel_trigger_discarded_count_max_bucket
118 "$FULL_LTTNG_SESSIOND_BIN" -d --trigger-error-number-of-bucket=3
120 for i
in $
(seq 3); do
121 "$FULL_LTTNG_BIN" add-trigger
--id "$i" \
122 --condition on-event
--kernel my_event_that_doesnt_need_to_really_exist_
$i \
123 --action notify
> /dev
/null
124 ok $?
"Enabling \`on-event\` kernel trigger $i succeeds"
127 for i
in $
(seq 4 5); do
128 "$FULL_LTTNG_BIN" add-trigger
--id "$i" \
129 --condition on-event
--kernel my_event_that_doesnt_need_to_really_exist_
$i \
130 --action notify
> /dev
/null
2>&1
131 isnt $?
0 "Enabling \`on-event\` kernel trigger $i fails as expected"
134 stop_lttng_sessiond_notap
137 function test_ust_trigger_discarded_count
139 local sessiond_pipe
=()
140 local trigger_name
="my_trigger"
141 local list_triggers_stdout
=$
(mktemp
-t list_triggers_stdout.XXXXXX
)
146 # Used on sessiond launch.
147 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 \
148 TRIGGER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
149 LD_PRELOAD=${TESTPOINT}"
151 start_lttng_sessiond_notap
153 # This is needed since the testpoint create a pipe with the sessiond
155 for f
in "$TESTPOINT_BASE_PATH"*; do
156 sessiond_pipe
+=("$f")
159 "$FULL_LTTNG_BIN" add-trigger
--id "$trigger_name" \
160 --condition on-event
--userspace tp
:tptest \
161 --action notify
> /dev
/null
162 ok $?
"Adding \`on-event\` userspace trigger successful"
164 "$FULL_LTTNG_BIN" list-triggers
> "$list_triggers_stdout"
166 # Confirm that the discarded notification line is present.
167 cat "$list_triggers_stdout" |
grep --quiet "tracer notifications discarded: 0"
168 ok $?
"No discarded tracer notification"
170 # Stop consumption of trigger tracer notifications.
171 echo -n 1 > $sessiond_pipe
173 # The trigger ring buffer configuration is currently made of 16 4096
174 # bytes subbuffers. Each userspace notification is at least 42 bytes long.
175 # To fill it, we need to generate (16 * 4096)/42 = 1561 notifications.
176 # That number is a bit larger than what we need since some of the space
177 # is lost in subbuffer boundaries.
178 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT
179 ok $?
"Generating $NR_ITER tracer notifications"
181 "$FULL_LTTNG_BIN" list-triggers
> "$list_triggers_stdout"
183 # Confirm that the discarded notification line is present. To avoid
185 cat "$list_triggers_stdout" |
grep --quiet "tracer notifications discarded"
186 ok $?
"Tracer notification discarded line printed"
188 # Confirm that the number of tracer notifications discarded is not zero.
189 cat "$list_triggers_stdout" |
grep --quiet "tracer notifications discarded: 0"
190 isnt $?
0 "Discarded tracer notification number non-zero as expected"
192 # Remove the trigger.
193 "$FULL_LTTNG_BIN" remove-trigger
"$trigger_name" > /dev
/null
194 ok $?
"Removing \`on-event\` userspace trigger successful"
196 # Confirm that no trigger is enabled.
197 list_triggers_line_count
=$
("$FULL_LTTNG_BIN" list-triggers |
wc -l)
198 is
"$list_triggers_line_count" "0" "No \`on-event\` userspace trigger enabled as expected"
200 # Enable another trigger and list it to confirm the counter was cleared.
201 "$FULL_LTTNG_BIN" add-trigger
--id "$trigger_name" \
202 --condition on-event
--userspace tp
:tptest \
203 --action notify
> /dev
/null
204 ok $?
"Adding another \`on-event\` userspace trigger successful"
206 # Confirm that the discarded notification line is present.
207 "$FULL_LTTNG_BIN" list-triggers
> "$list_triggers_stdout"
208 cat "$list_triggers_stdout" |
grep --quiet "tracer notifications discarded: 0"
209 ok $?
"No discarded tracer notification"
211 "$FULL_LTTNG_BIN" remove-trigger
"$trigger_name" > /dev
/null
212 ok $?
"Removing \`on-event\` userspace trigger successful"
214 stop_lttng_sessiond_notap
216 unset LTTNG_SESSIOND_ENV_VARS
218 rm -f "$list_triggers_stdout"
220 function test_ust_trigger_discarded_count_max_bucket
222 "$FULL_LTTNG_SESSIOND_BIN" -d --trigger-error-number-of-bucket=3
224 for i
in $
(seq 3); do
225 "$FULL_LTTNG_BIN" add-trigger
--id "$i" \
226 --condition on-event
--userspace my_event_that_doesnt_need_to_really_exist_
$i \
227 --action notify
> /dev
/null
228 ok $?
"Enabling \`on-event\` userspace trigger $i succeeds"
231 for i
in $
(seq 4 5); do
232 "$FULL_LTTNG_BIN" add-trigger
--id "$i" \
233 --condition on-event
--userspace my_event_that_doesnt_need_to_really_exist_
$i \
234 --action notify
> /dev
/null
2>&1
235 isnt $?
0 "Enabling \`on-event\` userspace trigger $i fails as expected"
238 stop_lttng_sessiond_notap
241 test_ust_trigger_discarded_count
242 test_ust_trigger_discarded_count_max_bucket
244 if [ "$(id -u)" == "0" ]; then
246 validate_lttng_modules_present
250 test_kernel_trigger_discarded_count
252 test_kernel_trigger_discarded_count_max_bucket
254 modprobe
--remove lttng-test
256 rm -rf "${sessiond_pipe[@]}" 2> /dev
/null
258 # Kernel tests are skipped.
259 skip
0 "Root access is needed. Skipping all kernel notification tests." $KERNEL_NUM_TESTS