3 # Copyright (C) 2017 Jonathan Rajotte <jonathan.rajotte-julien@efficiso.com>>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 TEST_DESC
="Notification"
10 TESTDIR
=$CURDIR/..
/..
/..
/
12 TESTPOINT
=$
(readlink
-f ${CURDIR}/.libs
/libpause_consumer.so
)
14 TESTAPP_PATH
="$TESTDIR/utils/testapp"
15 TESTAPP_NAME
="gen-ust-events"
16 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
17 TESTAPP_STATE_FILE
="$(mktemp -u)"
22 SESSION_NAME
="my_session"
23 CHANNEL_NAME
="my_channel"
26 DIR
=$
(readlink
-f $TESTDIR)
28 PAGE_SIZE
=$
(getconf PAGE_SIZE
)
32 NUM_TESTS
=$
(($NUM_TEST_UST + $NUM_TEST_KERNEL))
34 source $TESTDIR/utils
/utils.sh
37 file_sync_after_first_event
=$
(mktemp
-u)
39 # MUST set TESTDIR before calling those functions
42 print_test_banner
"$TEST_DESC"
46 function kernel_event_generator_toggle_state
48 kernel_event_generator_suspended
=$
((kernel_event_generator_suspended
==0))
51 function kernel_event_generator
54 kernel_event_generator_suspended
=0
55 trap kernel_event_generator_toggle_state SIGUSR1
58 if [[ $kernel_event_generator_suspended -eq "1" ]]; then
62 if [[ -f $state_file ]]; then
63 rm $state_file 2> /dev
/null
65 echo -n "1000" > /proc
/lttng-test-filter-event
70 function ust_event_generator_toggle_state
72 ust_event_generator_suspended
=$
((ust_event_generator_suspended
==0))
75 function ust_event_generator
78 ust_event_generator_suspended
=0
79 trap ust_event_generator_toggle_state SIGUSR1
80 trap "exit" SIGTERM SIGINT
82 if [[ $ust_event_generator_suspended -eq "1" ]]; then
86 if [[ -f $state_file ]]; then
87 rm $state_file 2> /dev
/null
89 taskset
-c 0 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT > /dev
/null
2>&1
94 function start_client
{
100 local buffer_usage_type
=$5
101 local buffer_usage_threshold_type
=$6
102 local buffer_usage_threshold_value
=$7
103 local nr_expected_notification
=$8
105 ${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} &
111 function wait_for_message
()
114 local file_pattern
=$2
117 for file in $directory/${file_pattern}*; do
119 # Check for "error" message
120 grep -q "error:" ${file}
122 if [ $app_error -eq "0" ] ; then
124 fail
"Waiting message: error logged see file content: ${message}, ${file}"
128 grep -q "${message}" ${file}
129 if [[ "$?" -ne "0" ]]; then
130 # Lookup failed restart loop
131 diag
"Lookup failed sleep and retry grep for: ${message}, ${file}"
138 pass
"Message received: ${message}"
142 function print_errors
()
145 local file_pattern
=$2
147 for file in $directory/${file_pattern}*; do
148 # Check for "error" message
149 error_message
=$
(grep "error:" ${file})
150 if [[ "${error_message}x" != "x" ]]; then
151 diag
"Errors for application ${file}:"
152 diag
"${error_message}"
157 function comm_consumerd
()
161 echo -ne "${message}" > "${pipe}"
164 function stop_consumerd
()
167 comm_consumerd
"1" "$pipe"
170 function resume_consumerd
()
173 comm_consumerd
"\0" "$pipe"
176 function test_multi_app
()
179 local event_generator_pid
=$2
182 local low_output_file_pattern
="low_app_output_file_"
183 local high_output_file_pattern
="high_app_output_file_"
184 local output_dir
=$
(mktemp
-d)
186 local testpoint_base_path
=$
(readlink
-f "$output_dir/lttng.t_p_n_multi_app")
187 local testpoint_pipe_path
=$
(mktemp
-u "${testpoint_base_path}.XXXXXX")
189 local nr_notification_expected
=5
190 local nr_client_app
=50
191 local domain_string
=""
196 domain_string
=LTTNG_DOMAIN_UST
197 event_name
="tp:tptest"
200 domain_string
=LTTNG_DOMAIN_KERNEL
201 event_name
="lttng_test_filter_event"
204 fail
"Invalid domain type"
210 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}"
213 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
214 enable_
${domain_type}_lttng_channel_ok
$SESSION_NAME $CHANNEL_NAME --subbuf-size=$PAGE_SIZE
215 enable_
${domain_type}_lttng_event_ok
$SESSION_NAME $event_name $CHANNEL_NAME
217 # Fetch consumerd testpoint pipe information
218 # This is needed since the testpoint create a pipe with the consumer type suffixed
220 for f
in "$testpoint_pipe_path"*; do
221 consumerd_pipe
+=("$f")
224 for (( i
= 0; i
< $nr_client_app; i
++ )); do
225 low_app_output_file
=$output_dir/${low_output_file_pattern}${i}
226 high_app_output_file
=$output_dir/${high_output_file_pattern}${i}
227 start_client
$low_app_output_file $SESSION_NAME $CHANNEL_NAME $domain_string LOW RATIO
0.0 $nr_notification_expected
228 start_client
$high_app_output_file $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO
0.420 $nr_notification_expected
231 wait_for_message
$output_dir "${low_output_file_pattern}" "sync: ready"
232 wait_for_message
$output_dir "${high_output_file_pattern}" "sync: ready"
234 # Test notification reception
235 for (( i
= 0; i
< $nr_notification_expected; i
++ )); do
237 # Stop consumerd consumption to force high notification
238 start_lttng_tracing_ok
$SESSION_NAME
239 for pipe
in "${consumerd_pipe[@]}"; do
240 stop_consumerd
"${pipe}"
243 wait_for_message
$output_dir "${high_output_file_pattern}" "notification: high $i"
245 # Put application in suspend mode to prevent double low
246 # notification and synchronize on state file.
247 kill -s SIGUSR1
$event_generator_pid
248 while [ ! -f "${TESTAPP_STATE_FILE}" ]; do
253 for pipe
in "${consumerd_pipe[@]}"; do
254 resume_consumerd
"${pipe}"
256 # Stop tracing forcing full buffer consumption
257 stop_lttng_tracing_ok
$SESSION_NAME
259 # Check for notifications reception
260 wait_for_message
$output_dir "${low_output_file_pattern}" "notification: low $i"
262 ok
$ret "Notifications $i received"
263 if [[ $ret -ne "0" ]]; then
264 # Error occurred bail out
268 # Put application in active mode and synchronize on state file.
269 kill -s SIGUSR1
$event_generator_pid
270 while [ -f "${TESTAPP_STATE_FILE}" ]; do
275 wait_for_message
$output_dir "${low_output_file_pattern}" "exit: 0"
277 ok
$ret "Application for low notification terminated normally"
278 if [[ $ret -ne "0" ]]; then
279 print_errors
$output_dir "${low_output_file_pattern}"
282 wait_for_message
$output_dir "${high_output_file_pattern}" "exit: 0"
284 ok
$ret "Application for high notification terminated normally"
285 if [[ $ret -ne "0" ]]; then
286 print_errors
$output_dir "${high_output_file_pattern}"
290 destroy_lttng_session_ok
$SESSION_NAME
293 for pipe
in "${consumerd_pipe[@]}"; do
300 function test_multi_app_ust
()
302 diag
"Multi client app UST notification"
303 ust_event_generator
$TESTAPP_STATE_FILE &
304 local generator_pid
=$
!
306 test_multi_app ust
$generator_pid
308 kill -s SIGTERM
$generator_pid 2> /dev
/null
309 wait $generator_pid 2> /dev
/null
310 rm -rf ${TESTAPP_STATE_FILE} 2> /dev
/null
313 function test_multi_app_kernel
()
315 diag
"Multi client app kernel notification"
318 kernel_event_generator
$TESTAPP_STATE_FILE &
319 local generator_pid
=$
!
321 test_multi_app kernel
$generator_pid
324 kill -s SIGTERM
$generator_pid 2> /dev
/null
325 wait $generator_pid 2> /dev
/null
326 rm -rf ${TESTAPP_STATE_FILE} 2> /dev
/null
331 function test_on_register_evaluation_ust
()
333 diag
"On register notification UST"
335 # Start app in infinite loop
336 ust_event_generator
$TESTAPP_STATE_FILE &
337 local generator_pid
=$
!
339 test_on_register_evaluation ust
$generator_pid
341 kill -s SIGTERM
$generator_pid 2> /dev
/null
342 wait $generator_pid 2> /dev
/null
343 rm -rf ${TESTAPP_STATE_FILE} 2> /dev
/null
347 function test_on_register_evaluation_kernel
()
349 diag
"On register notification kernel"
353 kernel_event_generator
$TESTAPP_STATE_FILE &
354 local generator_pid
=$
!
356 test_on_register_evaluation kernel
$generator_pid
359 kill -s SIGTERM
$generator_pid 2> /dev
/null
360 wait $generator_pid 2> /dev
/null
361 rm -rf ${TESTAPP_STATE_FILE} 2> /dev
/null
366 function test_on_register_evaluation
()
369 local event_generator_pid
=$2
372 local high_output_file_pattern
="high_app_output_file_on_register_evaluation"
374 local output_dir
=$
(mktemp
-d)
375 local testpoint_base_path
=$
(readlink
-f "$output_dir/lttng.t_p_n_register_evaluation")
376 local testpoint_pipe_path
=$
(mktemp
-u "${testpoint_base_path}.XXXXXX")
377 local domain_string
=""
382 domain_string
=LTTNG_DOMAIN_UST
383 event_name
="tp:tptest"
386 domain_string
=LTTNG_DOMAIN_KERNEL
387 event_name
="lttng_test_filter_event"
390 fail
"Invalid domain type"
396 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}"
399 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
400 enable_
${domain_type}_lttng_channel_ok
$SESSION_NAME $CHANNEL_NAME --subbuf-size=$PAGE_SIZE
401 enable_
${domain_type}_lttng_event_ok
$SESSION_NAME $event_name $CHANNEL_NAME
403 # Fetch consumerd testpoint pipe information
404 # This is needed since the testpoint create a pipe with the consumer type suffixed
406 for f
in "$testpoint_pipe_path"*; do
407 consumerd_pipe
+=("$f")
410 high_app_output_file
=${high_output_file_pattern}.first_receiver
411 high_app_output_path
=$output_dir/${high_app_output_file}
412 start_client
$high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO
0.420 1
414 wait_for_message
$output_dir "${high_app_output_file}" "sync: ready"
416 # Stop consumerd consumption to force high notification
417 start_lttng_tracing_ok
$SESSION_NAME
419 for pipe
in "${consumerd_pipe[@]}"; do
420 stop_consumerd
"${pipe}"
423 wait_for_message
$output_dir "${high_app_output_file}" "notification: high 0"
425 # Start a second receiver, the receiver should receive a high
426 # notification on subscription
427 high_app_output_file
=${high_output_file_pattern}.second_receiver
428 high_app_output_path
=$output_dir/${high_app_output_file}
429 start_client
$high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO
0.420 1
430 wait_for_message
$output_dir "${high_app_output_file}" "sync: ready"
431 wait_for_message
$output_dir "${high_app_output_file}" "notification: high 0"
434 for pipe
in "${consumerd_pipe[@]}"; do
435 resume_consumerd
"${pipe}"
438 wait_for_message
$output_dir "${high_output_file_pattern}" "exit: 0"
440 ok
$ret "Application for high notification terminated normally"
441 if [[ $ret -ne "0" ]]; then
443 print_errors
"${high_output_file_pattern}"
447 destroy_lttng_session_ok
$SESSION_NAME
450 kill -s SIGTERM
$generator_pid 2> /dev
/null
451 wait $generator_pid 2> /dev
/null
453 for pipe
in "${consumerd_pipe[@]}"; do
463 test_on_register_evaluation_ust
466 if [ "$(id -u)" == "0" ]; then
467 validate_lttng_modules_present
469 test_multi_app_kernel
470 test_on_register_evaluation_kernel
473 skip
0 "Root access is needed. Skipping all kernel multi-app notification tests." $NUM_TEST_KERNEL
477 for fct_test
in ${TESTS[@]};
479 TRACE_PATH
=$
(mktemp
-d)
482 if [ $?
-ne 0 ]; then
486 # Only delete if successful