Commit | Line | Data |
---|---|---|
2463b787 JR |
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 | ||
30 | UST_NUM_TESTS=15 | |
31 | KERNEL_NUM_TESTS=14 | |
32 | NUM_TESTS=$(($UST_NUM_TESTS + $KERNEL_NUM_TESTS)) | |
33 | ||
34 | plan_tests $NUM_TESTS | |
35 | ||
36 | function test_kernel_trigger_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 | TRIGGER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \ | |
45 | LD_PRELOAD=${TESTPOINT}" | |
46 | ||
47 | start_lttng_sessiond_notap | |
48 | ||
49 | # This is needed since the testpoint create a pipe with the sessiond | |
50 | # type suffixed. | |
51 | for f in "$TESTPOINT_BASE_PATH"*; do | |
52 | sessiond_pipe+=("$f") | |
53 | done | |
54 | ||
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" | |
59 | ||
60 | "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" | |
61 | ||
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" | |
65 | ||
66 | # Stop consumption of trigger tracer notifications. | |
67 | echo -n 1 > $sessiond_pipe | |
68 | ||
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 | |
75 | ||
76 | "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" | |
77 | ||
78 | # Confirm that the discarded notification line is present. To avoid | |
79 | # false positive. | |
80 | cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded" | |
81 | ok $? "Tracer notification discarded line printed" | |
82 | ||
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" | |
86 | ||
87 | "$FULL_LTTNG_BIN" remove-trigger "$trigger_name" > /dev/null | |
88 | ok $? "Removing \`on-event\` kernel trigger successful" | |
89 | ||
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" | |
93 | ||
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" | |
99 | ||
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" | |
104 | ||
105 | "$FULL_LTTNG_BIN" remove-trigger "$trigger_name" > /dev/null | |
106 | ok $? "Removing \`on-event\` kernel trigger successful" | |
107 | ||
108 | ||
109 | stop_lttng_sessiond_notap | |
110 | ||
111 | unset LTTNG_SESSIOND_ENV_VARS | |
112 | ||
113 | rm -f "$list_triggers_stdout" | |
114 | } | |
115 | ||
116 | function test_kernel_trigger_discarded_count_max_bucket | |
117 | { | |
118 | "$FULL_LTTNG_SESSIOND_BIN" -d --trigger-error-number-of-bucket=3 | |
119 | ||
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" | |
125 | done | |
126 | ||
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" | |
132 | done | |
133 | ||
134 | stop_lttng_sessiond_notap | |
135 | } | |
136 | ||
137 | function test_ust_trigger_discarded_count | |
138 | { | |
139 | local sessiond_pipe=() | |
140 | local trigger_name="my_trigger" | |
141 | local list_triggers_stdout=$(mktemp -t list_triggers_stdout.XXXXXX) | |
142 | local NR_ITER=2000 | |
143 | local NR_USEC_WAIT=0 | |
144 | ||
145 | ||
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}" | |
150 | ||
151 | start_lttng_sessiond_notap | |
152 | ||
153 | # This is needed since the testpoint create a pipe with the sessiond | |
154 | # type suffixed. | |
155 | for f in "$TESTPOINT_BASE_PATH"*; do | |
156 | sessiond_pipe+=("$f") | |
157 | done | |
158 | ||
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" | |
163 | ||
164 | "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" | |
165 | ||
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" | |
169 | ||
170 | # Stop consumption of trigger tracer notifications. | |
171 | echo -n 1 > $sessiond_pipe | |
172 | ||
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" | |
180 | ||
181 | "$FULL_LTTNG_BIN" list-triggers > "$list_triggers_stdout" | |
182 | ||
183 | # Confirm that the discarded notification line is present. To avoid | |
184 | # false positive. | |
185 | cat "$list_triggers_stdout" | grep --quiet "tracer notifications discarded" | |
186 | ok $? "Tracer notification discarded line printed" | |
187 | ||
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" | |
191 | ||
192 | # Remove the trigger. | |
193 | "$FULL_LTTNG_BIN" remove-trigger "$trigger_name" > /dev/null | |
194 | ok $? "Removing \`on-event\` userspace trigger successful" | |
195 | ||
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" | |
199 | ||
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" | |
205 | ||
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" | |
210 | ||
211 | "$FULL_LTTNG_BIN" remove-trigger "$trigger_name" > /dev/null | |
212 | ok $? "Removing \`on-event\` userspace trigger successful" | |
213 | ||
214 | stop_lttng_sessiond_notap | |
215 | ||
216 | unset LTTNG_SESSIOND_ENV_VARS | |
217 | ||
218 | rm -f "$list_triggers_stdout" | |
219 | } | |
220 | function test_ust_trigger_discarded_count_max_bucket | |
221 | { | |
222 | "$FULL_LTTNG_SESSIOND_BIN" -d --trigger-error-number-of-bucket=3 | |
223 | ||
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" | |
229 | done | |
230 | ||
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" | |
236 | done | |
237 | ||
238 | stop_lttng_sessiond_notap | |
239 | } | |
240 | ||
241 | test_ust_trigger_discarded_count | |
242 | test_ust_trigger_discarded_count_max_bucket | |
243 | ||
244 | if [ "$(id -u)" == "0" ]; then | |
245 | ||
246 | validate_lttng_modules_present | |
247 | ||
248 | modprobe lttng-test | |
249 | ||
250 | test_kernel_trigger_discarded_count | |
251 | ||
252 | test_kernel_trigger_discarded_count_max_bucket | |
253 | ||
254 | modprobe --remove lttng-test | |
255 | ||
256 | rm -rf "${sessiond_pipe[@]}" 2> /dev/null | |
257 | else | |
258 | # Kernel tests are skipped. | |
259 | skip 0 "Root access is needed. Skipping all kernel notification tests." $KERNEL_NUM_TESTS | |
260 | fi | |
261 | ||
262 | rm -rf "$TMPDIR" |