Commit | Line | Data |
---|---|---|
38eb8a68 FD |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com> | |
4 | # | |
5 | # SPDX-License-Identifier: LGPL-2.1-only | |
6 | ||
7 | CURDIR=$(dirname "$0")/ | |
8 | TESTDIR=$CURDIR/../../../ | |
9 | ||
10 | TMPDIR=$(mktemp -d) | |
11 | ||
12 | TESTAPP_PATH="$TESTDIR/utils/testapp" | |
13 | TESTAPP_NAME="gen-ust-events" | |
14 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
15 | ||
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") | |
19 | ||
20 | SH_TAP=1 | |
21 | ||
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" | |
26 | ||
27 | FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}" | |
28 | FULL_LTTNG_SESSIOND_BIN="${TESTDIR}/../src/bin/lttng-sessiond/lttng-sessiond" | |
29 | ||
709fb83f JG |
30 | UST_NUM_TESTS=18 |
31 | KERNEL_NUM_TESTS=17 | |
38eb8a68 FD |
32 | NUM_TESTS=$(($UST_NUM_TESTS + $KERNEL_NUM_TESTS)) |
33 | ||
34 | plan_tests $NUM_TESTS | |
35 | ||
36 | function test_kernel_notifier_discarded_count | |
37 | { | |
38 | local sessiond_pipe=() | |
39 | local trigger_name="my_trigger" | |
40 | local list_triggers_stdout=$(mktemp -t list_triggers_stdout.XXXXXX) | |
41 | ||
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}" | |
46 | ||
47 | diag "Kernel event notifer error counter" | |
48 | ||
49 | start_lttng_sessiond_notap | |
50 | ||
51 | # This is needed since the testpoint creates a pipe with the sessiond | |
52 | # type suffixed. | |
53 | for f in "$TESTPOINT_BASE_PATH"*; do | |
54 | sessiond_pipe+=("$f") | |
55 | done | |
56 | ||
57 | lttng_add_trigger_ok "$trigger_name" \ | |
58 | --condition on-event --kernel lttng_test_filter_event \ | |
59 | --action notify | |
60 | ||
61 | "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" | |
62 | ||
709fb83f JG |
63 | # Confirm that the discarded notification line is not present. |
64 | cat "$list_triggers_stdout" | grep -v --quiet "discarded tracer messages" | |
65 | ok $? "No discarded tracer notification message" | |
66 | ||
67 | tail -n 1 "$list_triggers_stdout" | grep --quiet "errors: none" | |
68 | ok $? "Trigger 'errors: none' notification message" | |
38eb8a68 FD |
69 | |
70 | # Stop consumption of notifier tracer notifications. | |
709fb83f | 71 | diag "Pause consumption of tracer messages" |
38eb8a68 FD |
72 | echo -n 1 > $sessiond_pipe |
73 | ||
74 | # The notifier ring buffer configuration is currently made of 16 4096 | |
75 | # bytes subbuffers. Each kernel notification is at least 42 bytes long. | |
76 | # To fill it, we need to generate (16 * 4096)/42 = 1561 notifications. | |
77 | # That number is a bit larger than what we need since some of the space | |
78 | # is lost in subbuffer boundaries. | |
79 | echo -n "200000" > /proc/lttng-test-filter-event | |
80 | ||
81 | "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" | |
82 | ||
83 | # Confirm that the discarded notification line is present. To avoid | |
84 | # false positives. | |
709fb83f | 85 | cat "$list_triggers_stdout" | grep --quiet "dicarded tracer messages" |
38eb8a68 FD |
86 | ok $? "Tracer notification discarded line printed" |
87 | ||
709fb83f JG |
88 | # Confirm that the number of dicarded tracer messages is not zero. |
89 | cat "$list_triggers_stdout" | grep --quiet "dicarded tracer messages: 0" | |
38eb8a68 FD |
90 | isnt $? 0 "Discarded tracer notification number non-zero as expected" |
91 | ||
92 | lttng_remove_trigger_ok "$trigger_name" | |
93 | ||
94 | # Confirm that no notifier is enabled. | |
95 | list_triggers_line_count=$("$FULL_LTTNG_BIN" list-triggers | wc -l) | |
96 | is "$list_triggers_line_count" "0" "No \`on-event\` kernel notifier enabled as expected" | |
97 | ||
98 | # Enable another notifier and list it to confirm the counter was cleared. | |
99 | lttng_add_trigger_ok "$trigger_name" \ | |
100 | --condition on-event --kernel lttng_test_filter_event \ | |
101 | --action notify | |
102 | ||
709fb83f JG |
103 | # Confirm that the discarded notification line is not present. |
104 | cat "$list_triggers_stdout" | grep -v --quiet "discarded tracer messages" | |
105 | ok $? "No discarded tracer notification message" | |
106 | ||
107 | tail -n 1 "$list_triggers_stdout" | grep --quiet "errors: none" | |
108 | ok $? "Trigger 'errors: none' notification message" | |
38eb8a68 FD |
109 | |
110 | lttng_remove_trigger_ok "$trigger_name" | |
111 | ||
112 | stop_lttng_sessiond_notap | |
113 | ||
114 | unset LTTNG_SESSIOND_ENV_VARS | |
115 | ||
116 | rm -f "$list_triggers_stdout" | |
117 | } | |
118 | ||
119 | function test_kernel_notifier_discarded_count_max_bucket | |
120 | { | |
121 | start_lttng_sessiond "" "--event-notifier-error-number-of-bucket=3" | |
122 | ||
123 | diag "Kernel event notifer error counter bucket limit" | |
124 | for i in $(seq 3); do | |
125 | lttng_add_trigger_ok "$i" \ | |
126 | --condition on-event --kernel my_event_that_doesnt_need_to_really_exist_$i \ | |
127 | --action notify | |
128 | done | |
129 | ||
130 | for i in $(seq 4 5); do | |
131 | lttng_add_trigger_fail "$i" \ | |
132 | --condition on-event --kernel my_event_that_doesnt_need_to_really_exist_$i \ | |
133 | --action notify | |
134 | done | |
135 | ||
136 | stop_lttng_sessiond_notap | |
137 | } | |
138 | ||
139 | function test_ust_notifier_discarded_count | |
140 | { | |
141 | local sessiond_pipe=() | |
142 | local trigger_name="my_trigger" | |
143 | local list_triggers_stdout=$(mktemp -t list_triggers_stdout.XXXXXX) | |
144 | local NR_USEC_WAIT=0 | |
145 | local PIPE_SIZE | |
146 | local NR_ITER | |
147 | ||
148 | diag "UST event notifer error counter" | |
149 | ||
150 | PIPE_SIZE=$("$CURDIR"/default_pipe_size_getter) | |
151 | if [ $? -ne 0 ]; then | |
152 | BAIL_OUT "Failed to get system default pipe size" | |
153 | else | |
154 | diag "Default system pipe size: $PIPE_SIZE bytes" | |
155 | fi | |
156 | ||
157 | # Find the number of events needed to overflow the event notification | |
158 | # pipe buffer. Each LTTng-UST notification is at least 42 bytes long. | |
159 | # Double that number to ensure enough events are created to overflow | |
160 | # the buffer. | |
161 | NR_ITER=$(( (PIPE_SIZE / 42) * 2 )) | |
162 | diag "Test application will emit $NR_ITER events" | |
163 | ||
164 | # Used on sessiond launch. | |
165 | LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \ | |
166 | NOTIFIER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \ | |
167 | LD_PRELOAD=${TESTPOINT}" | |
168 | ||
169 | start_lttng_sessiond_notap | |
170 | ||
171 | # This is needed since the testpoint create a pipe with the sessiond | |
172 | # type suffixed. | |
173 | for f in "$TESTPOINT_BASE_PATH"*; do | |
174 | sessiond_pipe+=("$f") | |
175 | done | |
176 | ||
177 | lttng_add_trigger_ok "$trigger_name" \ | |
178 | --condition on-event --userspace tp:tptest \ | |
179 | --action notify | |
180 | ||
181 | "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" | |
182 | ||
709fb83f JG |
183 | # Confirm that the discarded notification line is not present. |
184 | cat "$list_triggers_stdout" | grep -v --quiet "discarded tracer messages" | |
185 | ok $? "No discarded tracer notification message" | |
186 | ||
187 | tail -n 1 "$list_triggers_stdout" | grep --quiet "errors: none" | |
188 | ok $? "Trigger 'errors: none' notification message" | |
38eb8a68 FD |
189 | |
190 | # Stop consumption of notifier tracer notifications. | |
709fb83f | 191 | diag "Pause consumption of tracer messages" |
38eb8a68 FD |
192 | echo -n 1 > $sessiond_pipe |
193 | ||
194 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT | |
195 | ok $? "Generating $NR_ITER tracer notifications" | |
196 | ||
197 | "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" | |
198 | ||
199 | # Confirm that the discarded notification line is present. To avoid | |
200 | # false positive. | |
709fb83f | 201 | cat "$list_triggers_stdout" | grep --quiet "discarded tracer messages" |
38eb8a68 FD |
202 | ok $? "Tracer notification discarded line printed" |
203 | ||
709fb83f JG |
204 | # Confirm that the number of discarded tracer messages is not zero. |
205 | cat "$list_triggers_stdout" | grep --quiet "discarded tracer messages: 0" | |
38eb8a68 FD |
206 | isnt $? 0 "Discarded tracer notification number non-zero as expected" |
207 | ||
208 | # Remove the notifier. | |
209 | lttng_remove_trigger_ok "$trigger_name" | |
210 | ||
211 | # Confirm that no notifier is enabled. | |
212 | list_triggers_line_count=$("$FULL_LTTNG_BIN" list-triggers | wc -l) | |
213 | is "$list_triggers_line_count" "0" "No \`on-event\` userspace notifier enabled as expected" | |
214 | ||
215 | # Enable another notifier and list it to confirm the counter was cleared. | |
216 | lttng_add_trigger_ok "$trigger_name" \ | |
217 | --condition on-event --userspace tp:tptest \ | |
218 | --action notify | |
219 | ||
709fb83f | 220 | # Confirm that the discarded notification line is not present. |
38eb8a68 | 221 | "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" |
709fb83f JG |
222 | |
223 | # Confirm that the discarded notification line is not present. | |
224 | cat "$list_triggers_stdout" | grep -v --quiet "discarded tracer messages" | |
225 | ok $? "No discarded tracer notification message" | |
226 | ||
227 | tail -n 1 "$list_triggers_stdout" | grep --quiet "errors: none" | |
228 | ok $? "Trigger 'errors: none' notification message" | |
38eb8a68 FD |
229 | |
230 | lttng_remove_trigger_ok "$trigger_name" | |
231 | ||
232 | stop_lttng_sessiond_notap | |
233 | ||
234 | unset LTTNG_SESSIOND_ENV_VARS | |
235 | ||
236 | rm -f "$list_triggers_stdout" | |
237 | } | |
238 | function test_ust_notifier_discarded_count_max_bucket | |
239 | { | |
240 | start_lttng_sessiond "" "--event-notifier-error-number-of-bucket=3" | |
241 | ||
242 | diag "UST event notifer error counter bucket limit" | |
243 | for i in $(seq 3); do | |
244 | lttng_add_trigger_ok "$i" \ | |
245 | --condition on-event --userspace my_event_that_doesnt_need_to_really_exist_$i \ | |
246 | --action notify | |
247 | done | |
248 | ||
249 | for i in $(seq 4 5); do | |
250 | lttng_add_trigger_fail "$i" \ | |
251 | --condition on-event --userspace my_event_that_doesnt_need_to_really_exist_$i \ | |
252 | --action notify | |
253 | done | |
254 | ||
255 | stop_lttng_sessiond_notap | |
256 | } | |
257 | ||
258 | test_ust_notifier_discarded_count | |
259 | test_ust_notifier_discarded_count_max_bucket | |
260 | ||
261 | if [ "$(id -u)" == "0" ]; then | |
262 | ||
263 | validate_lttng_modules_present | |
264 | ||
265 | modprobe lttng-test | |
266 | ||
267 | test_kernel_notifier_discarded_count | |
268 | ||
269 | test_kernel_notifier_discarded_count_max_bucket | |
270 | ||
271 | modprobe --remove lttng-test | |
272 | ||
273 | rm -rf "${sessiond_pipe[@]}" 2> /dev/null | |
274 | else | |
275 | # Kernel tests are skipped. | |
276 | skip 0 "Root access is needed. Skipping all kernel notification tests." $KERNEL_NUM_TESTS | |
277 | fi | |
278 | ||
279 | rm -rf "$TMPDIR" |