Commit | Line | Data |
---|---|---|
dc890bff JR |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) - 2017 Jonathan Rajotte <jonathan.rajotte-julien@efficiso.com>> | |
4 | # | |
5 | # This library is free software; you can redistribute it and/or modify it under | |
6 | # the terms of the GNU Lesser General Public License as published by the Free | |
7 | # Software Foundation; version 2.1 of the License. | |
8 | # | |
9 | # This library is distributed in the hope that it will be useful, but WITHOUT | |
10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
11 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
12 | # details. | |
13 | # | |
14 | # You should have received a copy of the GNU Lesser General Public License | |
15 | # along with this library; if not, write to the Free Software Foundation, Inc., | |
16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | ||
18 | TEST_DESC="Notification" | |
19 | ||
20 | CURDIR=$(dirname $0)/ | |
21 | TESTDIR=$CURDIR/../../../ | |
22 | ||
dc890bff JR |
23 | TESTPOINT=$(readlink -f ${CURDIR}/.libs/libpause_consumer.so) |
24 | ||
25 | TESTAPP_PATH="$TESTDIR/utils/testapp" | |
26 | TESTAPP_NAME="gen-ust-events" | |
27 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
60c78fd5 | 28 | TESTAPP_STATE_FILE="$(mktemp -u)" |
dc890bff | 29 | |
60c78fd5 | 30 | NR_ITER=1000 |
dc890bff JR |
31 | NR_USEC_WAIT=5 |
32 | ||
33 | SESSION_NAME="my_session" | |
60c78fd5 | 34 | CHANNEL_NAME="my_channel" |
dc890bff | 35 | |
dc890bff JR |
36 | |
37 | TRACE_PATH=$(mktemp -d) | |
38 | ||
39 | DIR=$(readlink -f $TESTDIR) | |
40 | ||
c9b9deb7 JG |
41 | PAGE_SIZE=$(getconf PAGE_SIZE) |
42 | ||
60c78fd5 JR |
43 | NUM_TEST_UST=50 |
44 | NUM_TEST_KERNEL=50 | |
45 | NUM_TESTS=$(($NUM_TEST_UST + $NUM_TEST_KERNEL)) | |
dc890bff JR |
46 | |
47 | source $TESTDIR/utils/utils.sh | |
48 | ||
49 | consumerd_pipe=() | |
50 | file_sync_after_first_event=$(mktemp -u) | |
51 | ||
52 | # MUST set TESTDIR before calling those functions | |
53 | plan_tests $NUM_TESTS | |
54 | ||
55 | print_test_banner "$TEST_DESC" | |
56 | ||
57 | app_pids=() | |
13934c8d | 58 | |
60c78fd5 JR |
59 | function kernel_event_generator_toogle_state |
60 | { | |
61 | kernel_event_generator_suspended=$((kernel_event_generator_suspended==0)) | |
62 | ||
63 | } | |
64 | function kernel_event_generator | |
65 | { | |
66 | state_file=$1 | |
67 | kernel_event_generator_suspended=0 | |
68 | trap kernel_event_generator_toogle_state SIGUSR1 | |
69 | trap "exit" SIGTERM SIGINT | |
70 | while (true); do | |
71 | if [[ $kernel_event_generator_suspended -eq "1" ]]; then | |
72 | touch $state_file | |
73 | sleep 0.5 | |
74 | else | |
75 | if [[ -f $state_file ]]; then | |
76 | rm $state_file 2> /dev/null | |
77 | fi | |
78 | echo -n "1000" > /proc/lttng-test-filter-event | |
79 | fi | |
80 | done | |
81 | } | |
82 | ||
83 | function ust_event_generator_toogle_state | |
84 | { | |
85 | ust_event_generator_suspended=$((ust_event_generator_suspended==0)) | |
86 | ||
87 | } | |
88 | function ust_event_generator | |
89 | { | |
90 | state_file=$1 | |
91 | ust_event_generator_suspended=0 | |
92 | trap ust_event_generator_toogle_state SIGUSR1 | |
93 | trap "exit" SIGTERM SIGINT | |
94 | while (true); do | |
95 | if [[ $ust_event_generator_suspended -eq "1" ]]; then | |
96 | touch $state_file | |
97 | sleep 0.5 | |
98 | else | |
99 | if [[ -f $state_file ]]; then | |
100 | rm $state_file 2> /dev/null | |
101 | fi | |
102 | taskset -c 0 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT > /dev/null 2>&1 | |
103 | fi | |
104 | done | |
105 | } | |
106 | ||
dc890bff JR |
107 | function start_client { |
108 | local pid=-1 | |
109 | local output_file=$1 | |
110 | local session_name=$2 | |
111 | local channel_name=$3 | |
112 | local domain_type=$4 | |
113 | local buffer_usage_type=$5 | |
114 | local buffer_usage_threshold_type=$6 | |
115 | local buffer_usage_threshold_value=$7 | |
116 | local nr_expected_notification=$8 | |
117 | ||
118 | ${CURDIR}/base_client ${session_name} ${channel_name} ${domain_type} ${buffer_usage_type} ${buffer_usage_threshold_type} ${buffer_usage_threshold_value} ${nr_expected_notification} > ${output_file} & | |
119 | pid=$! | |
120 | ||
121 | app_pids+=("$pid") | |
122 | } | |
123 | ||
124 | function wait_for_message () | |
125 | { | |
126 | local file_pattern=$1 | |
127 | local message=$2 | |
128 | ||
129 | for file in $CURDIR/${file_pattern}*; do | |
130 | while(true); do | |
131 | # Check for "error" message | |
132 | grep -q "error:" ${file} | |
133 | app_error=$? | |
134 | if [ $app_error -eq "0" ] ; then | |
135 | # An error occurred | |
136 | fail "Waiting message: error logged see file content: ${message}, ${file}" | |
137 | return 1 | |
138 | fi | |
139 | ||
140 | grep -q "${message}" ${file} | |
141 | if [[ "$?" -ne "0" ]]; then | |
142 | # Lookup failed restart loop | |
143 | diag "Lookup failed sleep and retry grep for: ${message}, ${file}" | |
144 | sleep 0.25 | |
145 | continue | |
146 | fi | |
147 | break | |
148 | done | |
149 | done | |
150 | pass "Message received: ${message}" | |
151 | return 0 | |
152 | } | |
153 | ||
154 | function print_errors () | |
155 | { | |
156 | local file_pattern=$1 | |
157 | ||
158 | for file in $CURDIR/${file_pattern}*; do | |
159 | # Check for "error" message | |
160 | error_message=$(grep "error:" ${file}) | |
13934c8d | 161 | if [[ "${error_message}x" != "x" ]]; then |
dc890bff JR |
162 | diag "Errors for application ${file}:" |
163 | diag "${error_message}" | |
164 | fi | |
165 | done | |
166 | } | |
167 | ||
168 | function comm_consumerd () | |
169 | { | |
170 | local message=$1 | |
171 | local pipe=$2 | |
172 | echo -ne "${message}" > "${pipe}" | |
dc890bff JR |
173 | } |
174 | ||
175 | function stop_consumerd () | |
176 | { | |
177 | local pipe=$1 | |
178 | comm_consumerd "1" "$pipe" | |
dc890bff JR |
179 | } |
180 | ||
181 | function resume_consumerd () | |
182 | { | |
183 | local pipe=$1 | |
184 | comm_consumerd "\0" "$pipe" | |
dc890bff JR |
185 | } |
186 | ||
187 | function test_multi_app () | |
188 | { | |
60c78fd5 JR |
189 | local domain_type=$1 |
190 | local event_generator_pid=$2 | |
191 | ||
dc890bff JR |
192 | local app_pids=() |
193 | local low_output_file_pattern="low_app_output_file_" | |
194 | local high_output_file_pattern="high_app_output_file_" | |
195 | ||
aa397ecd JR |
196 | local testpoint_base_path=$(readlink -f "$CURDIR/lttng.t_p_n_multi_app") |
197 | local testpoint_pipe_path=$(mktemp -u "${testpoint_base_path}.XXXXXX") | |
198 | ||
199 | local nr_notification_expected=5 | |
200 | local nr_client_app=50 | |
60c78fd5 JR |
201 | local domain_string="" |
202 | local event_name="" | |
203 | ||
204 | case $domain_type in | |
205 | ust) | |
206 | domain_string=LTTNG_DOMAIN_UST | |
207 | event_name="tp:tptest" | |
208 | ;; | |
209 | kernel) | |
210 | domain_string=LTTNG_DOMAIN_KERNEL | |
211 | event_name="lttng_test_filter_event" | |
212 | ;; | |
213 | *) | |
214 | fail "Invalid domain type" | |
215 | exit 1 | |
216 | ;; | |
217 | esac | |
aa397ecd | 218 | |
dc890bff JR |
219 | # Cleanup |
220 | rm ${CURDIR}/${low_output_file_pattern}* 2> /dev/null | |
221 | rm ${CURDIR}/${high_output_file_pattern}* 2> /dev/null | |
222 | ||
223 | # Setup | |
aa397ecd | 224 | LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}" |
dc890bff JR |
225 | start_lttng_sessiond |
226 | ||
dc890bff | 227 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
60c78fd5 JR |
228 | enable_${domain_type}_lttng_channel_ok $SESSION_NAME $CHANNEL_NAME --subbuf-size=$PAGE_SIZE |
229 | enable_${domain_type}_lttng_event_ok $SESSION_NAME $event_name $CHANNEL_NAME | |
dc890bff JR |
230 | |
231 | # Fetch consumerd testpoint pipe information | |
232 | # This is needed since the testpoint create a pipe with the consumer type suffixed | |
aa397ecd | 233 | for f in "$testpoint_base_path"*; do |
dc890bff JR |
234 | consumerd_pipe+=("$f") |
235 | done | |
236 | ||
aa397ecd | 237 | for (( i = 0; i < $nr_client_app; i++ )); do |
dc890bff JR |
238 | low_app_output_file=$CURDIR/${low_output_file_pattern}${i} |
239 | high_app_output_file=$CURDIR/${high_output_file_pattern}${i} | |
60c78fd5 JR |
240 | start_client $low_app_output_file $SESSION_NAME $CHANNEL_NAME $domain_string LOW RATIO 0.0 $nr_notification_expected |
241 | start_client $high_app_output_file $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO 0.420 $nr_notification_expected | |
dc890bff JR |
242 | done |
243 | ||
244 | wait_for_message "${low_output_file_pattern}" "sync: ready" | |
245 | wait_for_message "${high_output_file_pattern}" "sync: ready" | |
246 | ||
247 | # Test notification reception | |
aa397ecd | 248 | for (( i = 0; i < $nr_notification_expected; i++ )); do |
dc890bff JR |
249 | |
250 | # Stop consumerd consumption to force high notification | |
251 | start_lttng_tracing_ok $SESSION_NAME | |
252 | for pipe in "${consumerd_pipe[@]}"; do | |
253 | stop_consumerd "${pipe}" | |
254 | done | |
255 | ||
256 | wait_for_message "${high_output_file_pattern}" "notification: high $i" | |
257 | ||
60c78fd5 JR |
258 | # Put application in suspend mode to prevent double low |
259 | # notification and synchronize on state file. | |
260 | kill -s SIGUSR1 $event_generator_pid | |
261 | while [ ! -f "${TESTAPP_STATE_FILE}" ]; do | |
262 | sleep 0.5 | |
263 | done | |
264 | ||
dc890bff JR |
265 | # Resume consumerd |
266 | for pipe in "${consumerd_pipe[@]}"; do | |
267 | resume_consumerd "${pipe}" | |
268 | done | |
269 | # Stop tracing forcing full buffer consumption | |
270 | stop_lttng_tracing $SESSION_NAME | |
271 | ||
272 | # Check for notifications reception | |
273 | wait_for_message "${low_output_file_pattern}" "notification: low $i" | |
274 | ret=$? | |
275 | ok $ret "Notifications $i received" | |
276 | if [[ $ret -ne "0" ]]; then | |
277 | # Error occurred bail out | |
278 | break; | |
279 | fi | |
60c78fd5 JR |
280 | |
281 | # Put application in active mode and synchronize on state file. | |
282 | kill -s SIGUSR1 $event_generator_pid | |
283 | while [ -f "${TESTAPP_STATE_FILE}" ]; do | |
284 | sleep 0.5 | |
285 | done | |
dc890bff JR |
286 | done |
287 | ||
288 | wait_for_message "${low_output_file_pattern}" "exit: 0" | |
289 | ret=$? | |
290 | ok $ret "Application for low notification terminated normally" | |
291 | if [[ $ret -eq "0" ]]; then | |
292 | rm ${CURDIR}/${low_output_file_pattern}* 2> /dev/null | |
293 | else | |
294 | # Keep the file | |
295 | print_errors "${low_output_file_pattern}" | |
296 | fi | |
297 | ||
298 | wait_for_message "${high_output_file_pattern}" "exit: 0" | |
299 | ret=$? | |
300 | ok $ret "Application for high notification terminated normally" | |
301 | if [[ $ret -eq "0" ]]; then | |
302 | rm ${CURDIR}/${high_output_file_pattern}* 2> /dev/null | |
303 | else | |
304 | # Keep the file | |
305 | print_errors "${high_output_file_pattern}" | |
306 | fi | |
307 | ||
60c78fd5 | 308 | destroy_lttng_session_ok $SESSION_NAME |
dc890bff | 309 | stop_lttng_sessiond |
60c78fd5 JR |
310 | |
311 | for pipe in "${consumerd_pipe[@]}"; do | |
312 | rm -rf "${pipe}" | |
313 | done | |
314 | } | |
315 | ||
316 | function test_multi_app_ust () | |
317 | { | |
318 | diag "Multi client app UST notification" | |
319 | ust_event_generator $TESTAPP_STATE_FILE & | |
320 | local generator_pid=$! | |
321 | ||
322 | test_multi_app ust $generator_pid | |
323 | ||
324 | kill -9 $generator_pid 2> /dev/null | |
325 | wait $generator_pid 2> /dev/null | |
326 | rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null | |
327 | } | |
328 | ||
329 | function test_multi_app_kernel () | |
330 | { | |
331 | diag "Multi client app kernel notification" | |
332 | modprobe lttng-test | |
333 | ||
334 | kernel_event_generator $TESTAPP_STATE_FILE & | |
335 | local generator_pid=$! | |
336 | ||
337 | test_multi_app kernel $generator_pid | |
338 | ||
339 | ||
340 | kill -9 $generator_pid 2>/dev/null | |
341 | wait $generator_pid 2> /dev/null | |
342 | rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null | |
343 | ||
344 | rmmod lttng-test | |
345 | } | |
346 | ||
347 | function test_on_register_evaluation_ust () | |
348 | { | |
349 | diag "On register notification UST" | |
350 | ||
351 | # Start app in infinite loop | |
352 | ust_event_generator $TESTAPP_STATE_FILE & | |
353 | local generator_pid=$! | |
354 | ||
355 | test_on_register_evaluation ust $generator_pid | |
356 | ||
357 | kill -9 $generator_pid 2> /dev/null | |
358 | wait $generator_pid 2> /dev/null | |
359 | rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null | |
360 | ||
361 | } | |
362 | ||
363 | function test_on_register_evaluation_kernel() | |
364 | { | |
365 | diag "On register notification kernel" | |
366 | ||
367 | modprobe lttng-test | |
368 | ||
369 | kernel_event_generator $TESTAPP_STATE_FILE & | |
370 | local generator_pid=$! | |
371 | ||
372 | test_on_register_evaluation kernel $generator_pid | |
373 | ||
374 | ||
375 | kill -9 $generator_pid 2> /dev/null | |
376 | wait $generator_pid 2> /dev/null | |
377 | rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null | |
378 | ||
379 | rmmod lttng-test | |
dc890bff JR |
380 | } |
381 | ||
13934c8d JR |
382 | function test_on_register_evaluation () |
383 | { | |
60c78fd5 JR |
384 | local domain_type=$1 |
385 | local event_generator_pid=$2 | |
386 | ||
13934c8d JR |
387 | local app_pids=() |
388 | local high_output_file_pattern="high_app_output_file_on_register_evaluation" | |
389 | ||
390 | local testpoint_base_path=$(readlink -f "$CURDIR/lttng.t_p_n_register_evaluation") | |
391 | local testpoint_pipe_path=$(mktemp -u "${testpoint_base_path}.XXXXXX") | |
60c78fd5 JR |
392 | local domain_string="" |
393 | local event_name="" | |
13934c8d JR |
394 | |
395 | # Cleanup | |
396 | rm ${CURDIR}/${high_output_file_pattern}* 2> /dev/null | |
397 | ||
60c78fd5 JR |
398 | case $domain_type in |
399 | ust) | |
400 | domain_string=LTTNG_DOMAIN_UST | |
401 | event_name="tp:tptest" | |
402 | ;; | |
403 | kernel) | |
404 | domain_string=LTTNG_DOMAIN_KERNEL | |
405 | event_name="lttng_test_filter_event" | |
406 | ;; | |
407 | *) | |
408 | fail "Invalid domain type" | |
409 | exit 1 | |
410 | ;; | |
411 | esac | |
412 | ||
13934c8d JR |
413 | # Setup |
414 | LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}" | |
415 | start_lttng_sessiond | |
416 | ||
13934c8d | 417 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
60c78fd5 JR |
418 | enable_${domain_type}_lttng_channel_ok $SESSION_NAME $CHANNEL_NAME --subbuf-size=$PAGE_SIZE |
419 | enable_${domain_type}_lttng_event_ok $SESSION_NAME $event_name $CHANNEL_NAME | |
13934c8d JR |
420 | |
421 | # Fetch consumerd testpoint pipe information | |
422 | # This is needed since the testpoint create a pipe with the consumer type suffixed | |
423 | for f in "$testpoint_base_path"*; do | |
424 | consumerd_pipe+=("$f") | |
425 | done | |
426 | ||
427 | high_app_output_file=${high_output_file_pattern}.first_receiver | |
428 | high_app_output_path=$CURDIR/${high_app_output_file} | |
60c78fd5 | 429 | start_client $high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO 0.420 1 |
13934c8d JR |
430 | |
431 | wait_for_message "${high_app_output_file}" "sync: ready" | |
432 | ||
433 | # Stop consumerd consumption to force high notification | |
434 | start_lttng_tracing_ok $SESSION_NAME | |
435 | ||
436 | for pipe in "${consumerd_pipe[@]}"; do | |
437 | stop_consumerd "${pipe}" | |
438 | done | |
439 | ||
440 | wait_for_message "${high_app_output_file}" "notification: high 0" | |
441 | ||
442 | # Start a second receiver, the receiver should receive a high | |
443 | # notification on subscription | |
444 | high_app_output_file=${high_output_file_pattern}.second_receiver | |
445 | high_app_output_path=$CURDIR/${high_app_output_file} | |
60c78fd5 | 446 | start_client $high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO 0.420 1 |
13934c8d JR |
447 | wait_for_message "${high_app_output_file}" "sync: ready" |
448 | wait_for_message "${high_app_output_file}" "notification: high 0" | |
449 | ||
450 | # Resume consumerd | |
451 | for pipe in "${consumerd_pipe[@]}"; do | |
452 | resume_consumerd "${pipe}" | |
453 | done | |
454 | ||
455 | wait_for_message "${high_output_file_pattern}" "exit: 0" | |
456 | ret=$? | |
457 | ok $ret "Application for high notification terminated normally" | |
458 | if [[ $ret -eq "0" ]]; then | |
459 | rm ${CURDIR}/${high_output_file_pattern}* 2> /dev/null | |
460 | else | |
461 | # Keep the file | |
462 | print_errors "${high_output_file_pattern}" | |
463 | fi | |
464 | ||
60c78fd5 | 465 | destroy_lttng_session_ok $SESSION_NAME |
13934c8d JR |
466 | stop_lttng_sessiond |
467 | ||
60c78fd5 JR |
468 | kill -9 $generator_pid |
469 | wait $generator_pid 2> /dev/null | |
470 | ||
471 | for pipe in "${consumerd_pipe[@]}"; do | |
472 | rm -rf "${pipe}" | |
473 | done | |
474 | ||
13934c8d JR |
475 | } |
476 | ||
dc890bff JR |
477 | |
478 | TESTS=( | |
60c78fd5 JR |
479 | test_multi_app_ust |
480 | test_on_register_evaluation_ust | |
dc890bff JR |
481 | ) |
482 | ||
60c78fd5 JR |
483 | if [ "$(id -u)" == "0" ]; then |
484 | TESTS+=( | |
485 | test_multi_app_kernel | |
486 | test_on_register_evaluation_kernel | |
487 | ) | |
488 | else | |
489 | skip 0 "Root access is needed. Skipping all kernel multi-app notification tests." $NUM_TEST_KERNEL | |
490 | fi | |
491 | ||
492 | ||
dc890bff JR |
493 | for fct_test in ${TESTS[@]}; |
494 | do | |
495 | TRACE_PATH=$(mktemp -d) | |
496 | ||
497 | ${fct_test} | |
498 | if [ $? -ne 0 ]; then | |
499 | break; | |
500 | fi | |
501 | ||
502 | # Only delete if successful | |
503 | rm -rf $TRACE_PATH | |
504 | done |