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
35 source $CURDIR/util_event_generator.sh
38 file_sync_after_first_event
=$
(mktemp
-u)
40 # MUST set TESTDIR before calling those functions
43 print_test_banner
"$TEST_DESC"
47 function start_client
{
53 local buffer_usage_type
=$5
54 local buffer_usage_threshold_type
=$6
55 local buffer_usage_threshold_value
=$7
56 local nr_expected_notification
=$8
58 ${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} &
64 function wait_for_message
()
70 for file in $directory/${file_pattern}*; do
72 # Check for "error" message
73 grep -q "error:" ${file}
75 if [ $app_error -eq "0" ] ; then
77 fail
"Waiting message: error logged see file content: ${message}, ${file}"
81 grep -q "${message}" ${file}
82 if [[ "$?" -ne "0" ]]; then
83 # Lookup failed restart loop
84 diag
"Lookup failed sleep and retry grep for: ${message}, ${file}"
91 pass
"Message received: ${message}"
95 function print_errors
()
100 for file in $directory/${file_pattern}*; do
101 # Check for "error" message
102 error_message
=$
(grep "error:" ${file})
103 if [[ "${error_message}x" != "x" ]]; then
104 diag
"Errors for application ${file}:"
105 diag
"${error_message}"
110 function comm_consumerd
()
114 echo -ne "${message}" > "${pipe}"
117 function stop_consumerd
()
120 comm_consumerd
"1" "$pipe"
123 function resume_consumerd
()
126 comm_consumerd
"\0" "$pipe"
129 function test_multi_app
()
132 local event_generator_pid
=$2
135 local low_output_file_pattern
="low_app_output_file_"
136 local high_output_file_pattern
="high_app_output_file_"
137 local output_dir
=$
(mktemp
-d)
139 local testpoint_base_path
=$
(readlink
-f "$output_dir/lttng.t_p_n_multi_app")
140 local testpoint_pipe_path
=$
(mktemp
-u "${testpoint_base_path}.XXXXXX")
142 local nr_notification_expected
=5
143 local nr_client_app
=50
144 local domain_string
=""
149 domain_string
=LTTNG_DOMAIN_UST
150 event_name
="tp:tptest"
153 domain_string
=LTTNG_DOMAIN_KERNEL
154 event_name
="lttng_test_filter_event"
157 fail
"Invalid domain type"
163 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}"
166 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
167 enable_
${domain_type}_lttng_channel_ok
$SESSION_NAME $CHANNEL_NAME --subbuf-size=$PAGE_SIZE
168 enable_
${domain_type}_lttng_event_ok
$SESSION_NAME $event_name $CHANNEL_NAME
170 # Fetch consumerd testpoint pipe information
171 # This is needed since the testpoint create a pipe with the consumer type suffixed
173 for f
in "$testpoint_pipe_path"*; do
174 consumerd_pipe
+=("$f")
177 for (( i
= 0; i
< $nr_client_app; i
++ )); do
178 low_app_output_file
=$output_dir/${low_output_file_pattern}${i}
179 high_app_output_file
=$output_dir/${high_output_file_pattern}${i}
180 start_client
$low_app_output_file $SESSION_NAME $CHANNEL_NAME $domain_string LOW RATIO
0.0 $nr_notification_expected
181 start_client
$high_app_output_file $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO
0.420 $nr_notification_expected
184 wait_for_message
$output_dir "${low_output_file_pattern}" "sync: ready"
185 wait_for_message
$output_dir "${high_output_file_pattern}" "sync: ready"
187 # Test notification reception
188 for (( i
= 0; i
< $nr_notification_expected; i
++ )); do
190 # Stop consumerd consumption to force high notification
191 start_lttng_tracing_ok
$SESSION_NAME
192 for pipe
in "${consumerd_pipe[@]}"; do
193 stop_consumerd
"${pipe}"
196 wait_for_message
$output_dir "${high_output_file_pattern}" "notification: high $i"
198 # Put application in suspend mode to prevent double low
199 # notification and synchronize on state file.
200 kill -s SIGUSR1
$event_generator_pid
201 while [ ! -f "${TESTAPP_STATE_FILE}" ]; do
206 for pipe
in "${consumerd_pipe[@]}"; do
207 resume_consumerd
"${pipe}"
209 # Stop tracing forcing full buffer consumption
210 stop_lttng_tracing_ok
$SESSION_NAME
212 # Check for notifications reception
213 wait_for_message
$output_dir "${low_output_file_pattern}" "notification: low $i"
215 ok
$ret "Notifications $i received"
216 if [[ $ret -ne "0" ]]; then
217 # Error occurred bail out
221 # Put application in active mode and synchronize on state file.
222 kill -s SIGUSR1
$event_generator_pid
223 while [ -f "${TESTAPP_STATE_FILE}" ]; do
228 wait_for_message
$output_dir "${low_output_file_pattern}" "exit: 0"
230 ok
$ret "Application for low notification terminated normally"
231 if [[ $ret -ne "0" ]]; then
232 print_errors
$output_dir "${low_output_file_pattern}"
235 wait_for_message
$output_dir "${high_output_file_pattern}" "exit: 0"
237 ok
$ret "Application for high notification terminated normally"
238 if [[ $ret -ne "0" ]]; then
239 print_errors
$output_dir "${high_output_file_pattern}"
243 destroy_lttng_session_ok
$SESSION_NAME
246 for pipe
in "${consumerd_pipe[@]}"; do
253 function test_multi_app_ust
()
255 diag
"Multi client app UST notification"
256 ust_event_generator
"$TESTAPP_BIN" "$TESTAPP_STATE_FILE" &
257 local generator_pid
=$
!
259 test_multi_app ust
$generator_pid
261 kill -s SIGUSR2
$generator_pid 2> /dev
/null
262 wait $generator_pid 2> /dev
/null
263 rm -rf ${TESTAPP_STATE_FILE} 2> /dev
/null
266 function test_multi_app_kernel
()
268 diag
"Multi client app kernel notification"
271 kernel_event_generator generate_filter_events
$TESTAPP_STATE_FILE &
272 local generator_pid
=$
!
274 test_multi_app kernel
$generator_pid
277 kill -s SIGUSR2
$generator_pid 2> /dev
/null
278 wait $generator_pid 2> /dev
/null
279 rm -rf ${TESTAPP_STATE_FILE} 2> /dev
/null
281 modprobe
--remove lttng-test
284 function test_on_register_evaluation_ust
()
286 diag
"On register notification UST"
288 # Start app in infinite loop
289 ust_event_generator
"$TESTAPP_BIN" "$TESTAPP_STATE_FILE" &
290 local generator_pid
=$
!
292 test_on_register_evaluation ust
$generator_pid
294 kill -s SIGUSR2
$generator_pid 2> /dev
/null
295 wait $generator_pid 2> /dev
/null
296 rm -rf ${TESTAPP_STATE_FILE} 2> /dev
/null
300 function test_on_register_evaluation_kernel
()
302 diag
"On register notification kernel"
306 kernel_event_generator generate_filter_events
$TESTAPP_STATE_FILE &
307 local generator_pid
=$
!
309 test_on_register_evaluation kernel
$generator_pid
312 kill -s SIGUSR2
$generator_pid 2> /dev
/null
313 wait $generator_pid 2> /dev
/null
314 rm -rf ${TESTAPP_STATE_FILE} 2> /dev
/null
316 modprobe
--remove lttng-test
319 function test_on_register_evaluation
()
322 local event_generator_pid
=$2
325 local high_output_file_pattern
="high_app_output_file_on_register_evaluation"
327 local output_dir
=$
(mktemp
-d)
328 local testpoint_base_path
=$
(readlink
-f "$output_dir/lttng.t_p_n_register_evaluation")
329 local testpoint_pipe_path
=$
(mktemp
-u "${testpoint_base_path}.XXXXXX")
330 local domain_string
=""
335 domain_string
=LTTNG_DOMAIN_UST
336 event_name
="tp:tptest"
339 domain_string
=LTTNG_DOMAIN_KERNEL
340 event_name
="lttng_test_filter_event"
343 fail
"Invalid domain type"
349 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}"
352 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
353 enable_
${domain_type}_lttng_channel_ok
$SESSION_NAME $CHANNEL_NAME --subbuf-size=$PAGE_SIZE
354 enable_
${domain_type}_lttng_event_ok
$SESSION_NAME $event_name $CHANNEL_NAME
356 # Fetch consumerd testpoint pipe information
357 # This is needed since the testpoint create a pipe with the consumer type suffixed
359 for f
in "$testpoint_pipe_path"*; do
360 consumerd_pipe
+=("$f")
363 high_app_output_file
=${high_output_file_pattern}.first_receiver
364 high_app_output_path
=$output_dir/${high_app_output_file}
365 start_client
$high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO
0.420 1
367 wait_for_message
$output_dir "${high_app_output_file}" "sync: ready"
369 # Stop consumerd consumption to force high notification
370 start_lttng_tracing_ok
$SESSION_NAME
372 for pipe
in "${consumerd_pipe[@]}"; do
373 stop_consumerd
"${pipe}"
376 wait_for_message
$output_dir "${high_app_output_file}" "notification: high 0"
378 # Start a second receiver, the receiver should receive a high
379 # notification on subscription
380 high_app_output_file
=${high_output_file_pattern}.second_receiver
381 high_app_output_path
=$output_dir/${high_app_output_file}
382 start_client
$high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO
0.420 1
383 wait_for_message
$output_dir "${high_app_output_file}" "sync: ready"
384 wait_for_message
$output_dir "${high_app_output_file}" "notification: high 0"
387 for pipe
in "${consumerd_pipe[@]}"; do
388 resume_consumerd
"${pipe}"
391 wait_for_message
$output_dir "${high_output_file_pattern}" "exit: 0"
393 ok
$ret "Application for high notification terminated normally"
394 if [[ $ret -ne "0" ]]; then
396 print_errors
"${high_output_file_pattern}"
400 destroy_lttng_session_ok
$SESSION_NAME
403 kill -s SIGUSR2
$generator_pid 2> /dev
/null
404 wait $generator_pid 2> /dev
/null
406 for pipe
in "${consumerd_pipe[@]}"; do
416 test_on_register_evaluation_ust
419 if [ "$(id -u)" == "0" ]; then
420 validate_lttng_modules_present
422 test_multi_app_kernel
423 test_on_register_evaluation_kernel
426 skip
0 "Root access is needed. Skipping all kernel multi-app notification tests." $NUM_TEST_KERNEL
430 for fct_test
in ${TESTS[@]};
432 TRACE_PATH
=$
(mktemp
-d)
435 if [ $?
-ne 0 ]; then
439 # Only delete if successful