3 # Copyright (C) - 2017 Jonathan Rajotte <jonathan.rajotte-julien@efficiso.com>>
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.
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
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
18 TEST_DESC
="Notification"
21 TESTDIR
=$CURDIR/..
/..
/..
/
23 TESTPOINT
=$
(readlink
-f ${CURDIR}/.libs
/libpause_consumer.so
)
25 TESTAPP_PATH
="$TESTDIR/utils/testapp"
26 TESTAPP_NAME
="gen-ust-events"
27 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
28 TESTAPP_STATE_FILE
="$(mktemp -u)"
33 SESSION_NAME
="my_session"
34 CHANNEL_NAME
="my_channel"
37 DIR
=$
(readlink
-f $TESTDIR)
39 PAGE_SIZE
=$
(getconf PAGE_SIZE
)
43 NUM_TESTS
=$
(($NUM_TEST_UST + $NUM_TEST_KERNEL))
45 source $TESTDIR/utils
/utils.sh
48 file_sync_after_first_event
=$
(mktemp
-u)
50 # MUST set TESTDIR before calling those functions
53 print_test_banner
"$TEST_DESC"
57 function kernel_event_generator_toogle_state
59 kernel_event_generator_suspended
=$
((kernel_event_generator_suspended
==0))
62 function kernel_event_generator
65 kernel_event_generator_suspended
=0
66 trap kernel_event_generator_toogle_state SIGUSR1
67 trap "exit" SIGTERM SIGINT
69 if [[ $kernel_event_generator_suspended -eq "1" ]]; then
73 if [[ -f $state_file ]]; then
74 rm $state_file 2> /dev
/null
76 echo -n "1000" > /proc
/lttng-test-filter-event
81 function ust_event_generator_toogle_state
83 ust_event_generator_suspended
=$
((ust_event_generator_suspended
==0))
86 function ust_event_generator
89 ust_event_generator_suspended
=0
90 trap ust_event_generator_toogle_state SIGUSR1
91 trap "exit" SIGTERM SIGINT
93 if [[ $ust_event_generator_suspended -eq "1" ]]; then
97 if [[ -f $state_file ]]; then
98 rm $state_file 2> /dev
/null
100 taskset
-c 0 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT > /dev
/null
2>&1
105 function start_client
{
108 local session_name
=$2
109 local channel_name
=$3
111 local buffer_usage_type
=$5
112 local buffer_usage_threshold_type
=$6
113 local buffer_usage_threshold_value
=$7
114 local nr_expected_notification
=$8
116 ${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} &
122 function wait_for_message
()
125 local file_pattern
=$2
128 for file in $directory/${file_pattern}*; do
130 # Check for "error" message
131 grep -q "error:" ${file}
133 if [ $app_error -eq "0" ] ; then
135 fail
"Waiting message: error logged see file content: ${message}, ${file}"
139 grep -q "${message}" ${file}
140 if [[ "$?" -ne "0" ]]; then
141 # Lookup failed restart loop
142 diag
"Lookup failed sleep and retry grep for: ${message}, ${file}"
149 pass
"Message received: ${message}"
153 function print_errors
()
156 local file_pattern
=$2
158 for file in $directory/${file_pattern}*; do
159 # Check for "error" message
160 error_message
=$
(grep "error:" ${file})
161 if [[ "${error_message}x" != "x" ]]; then
162 diag
"Errors for application ${file}:"
163 diag
"${error_message}"
168 function comm_consumerd
()
172 echo -ne "${message}" > "${pipe}"
175 function stop_consumerd
()
178 comm_consumerd
"1" "$pipe"
181 function resume_consumerd
()
184 comm_consumerd
"\0" "$pipe"
187 function test_multi_app
()
190 local event_generator_pid
=$2
193 local low_output_file_pattern
="low_app_output_file_"
194 local high_output_file_pattern
="high_app_output_file_"
195 local output_dir
=$
(mktemp
-d)
197 local testpoint_base_path
=$
(readlink
-f "$output_dir/lttng.t_p_n_multi_app")
198 local testpoint_pipe_path
=$
(mktemp
-u "${testpoint_base_path}.XXXXXX")
200 local nr_notification_expected
=5
201 local nr_client_app
=50
202 local domain_string
=""
207 domain_string
=LTTNG_DOMAIN_UST
208 event_name
="tp:tptest"
211 domain_string
=LTTNG_DOMAIN_KERNEL
212 event_name
="lttng_test_filter_event"
215 fail
"Invalid domain type"
221 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}"
224 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
225 enable_
${domain_type}_lttng_channel_ok
$SESSION_NAME $CHANNEL_NAME --subbuf-size=$PAGE_SIZE
226 enable_
${domain_type}_lttng_event_ok
$SESSION_NAME $event_name $CHANNEL_NAME
228 # Fetch consumerd testpoint pipe information
229 # This is needed since the testpoint create a pipe with the consumer type suffixed
231 for f
in "$testpoint_pipe_path"*; do
232 consumerd_pipe
+=("$f")
235 for (( i
= 0; i
< $nr_client_app; i
++ )); do
236 low_app_output_file
=$output_dir/${low_output_file_pattern}${i}
237 high_app_output_file
=$output_dir/${high_output_file_pattern}${i}
238 start_client
$low_app_output_file $SESSION_NAME $CHANNEL_NAME $domain_string LOW RATIO
0.0 $nr_notification_expected
239 start_client
$high_app_output_file $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO
0.420 $nr_notification_expected
242 wait_for_message
$output_dir "${low_output_file_pattern}" "sync: ready"
243 wait_for_message
$output_dir "${high_output_file_pattern}" "sync: ready"
245 # Test notification reception
246 for (( i
= 0; i
< $nr_notification_expected; i
++ )); do
248 # Stop consumerd consumption to force high notification
249 start_lttng_tracing_ok
$SESSION_NAME
250 for pipe
in "${consumerd_pipe[@]}"; do
251 stop_consumerd
"${pipe}"
254 wait_for_message
$output_dir "${high_output_file_pattern}" "notification: high $i"
256 # Put application in suspend mode to prevent double low
257 # notification and synchronize on state file.
258 kill -s SIGUSR1
$event_generator_pid
259 while [ ! -f "${TESTAPP_STATE_FILE}" ]; do
264 for pipe
in "${consumerd_pipe[@]}"; do
265 resume_consumerd
"${pipe}"
267 # Stop tracing forcing full buffer consumption
268 stop_lttng_tracing_ok
$SESSION_NAME
270 # Check for notifications reception
271 wait_for_message
$output_dir "${low_output_file_pattern}" "notification: low $i"
273 ok
$ret "Notifications $i received"
274 if [[ $ret -ne "0" ]]; then
275 # Error occurred bail out
279 # Put application in active mode and synchronize on state file.
280 kill -s SIGUSR1
$event_generator_pid
281 while [ -f "${TESTAPP_STATE_FILE}" ]; do
286 wait_for_message
$output_dir "${low_output_file_pattern}" "exit: 0"
288 ok
$ret "Application for low notification terminated normally"
289 if [[ $ret -ne "0" ]]; then
290 print_errors
$output_dir "${low_output_file_pattern}"
293 wait_for_message
$output_dir "${high_output_file_pattern}" "exit: 0"
295 ok
$ret "Application for high notification terminated normally"
296 if [[ $ret -ne "0" ]]; then
297 print_errors
$output_dir "${high_output_file_pattern}"
302 destroy_lttng_session_ok
$SESSION_NAME
305 for pipe
in "${consumerd_pipe[@]}"; do
310 function test_multi_app_ust
()
312 diag
"Multi client app UST notification"
313 ust_event_generator
$TESTAPP_STATE_FILE &
314 local generator_pid
=$
!
316 test_multi_app ust
$generator_pid
318 kill -s SIGTERM
$generator_pid 2> /dev
/null
319 wait $generator_pid 2> /dev
/null
320 rm -rf ${TESTAPP_STATE_FILE} 2> /dev
/null
323 function test_multi_app_kernel
()
325 diag
"Multi client app kernel notification"
328 kernel_event_generator
$TESTAPP_STATE_FILE &
329 local generator_pid
=$
!
331 test_multi_app kernel
$generator_pid
334 kill -s SIGTERM
$generator_pid 2> /dev
/null
335 wait $generator_pid 2> /dev
/null
336 rm -rf ${TESTAPP_STATE_FILE} 2> /dev
/null
341 function test_on_register_evaluation_ust
()
343 diag
"On register notification UST"
345 # Start app in infinite loop
346 ust_event_generator
$TESTAPP_STATE_FILE &
347 local generator_pid
=$
!
349 test_on_register_evaluation ust
$generator_pid
351 kill -s SIGTERM
$generator_pid 2> /dev
/null
352 wait $generator_pid 2> /dev
/null
353 rm -rf ${TESTAPP_STATE_FILE} 2> /dev
/null
357 function test_on_register_evaluation_kernel
()
359 diag
"On register notification kernel"
363 kernel_event_generator
$TESTAPP_STATE_FILE &
364 local generator_pid
=$
!
366 test_on_register_evaluation kernel
$generator_pid
369 kill -s SIGTERM
$generator_pid 2> /dev
/null
370 wait $generator_pid 2> /dev
/null
371 rm -rf ${TESTAPP_STATE_FILE} 2> /dev
/null
376 function test_on_register_evaluation
()
379 local event_generator_pid
=$2
382 local high_output_file_pattern
="high_app_output_file_on_register_evaluation"
384 local output_dir
=$
(mktemp
-d)
385 local testpoint_base_path
=$
(readlink
-f "$output_dir/lttng.t_p_n_register_evaluation")
386 local testpoint_pipe_path
=$
(mktemp
-u "${testpoint_base_path}.XXXXXX")
387 local domain_string
=""
392 domain_string
=LTTNG_DOMAIN_UST
393 event_name
="tp:tptest"
396 domain_string
=LTTNG_DOMAIN_KERNEL
397 event_name
="lttng_test_filter_event"
400 fail
"Invalid domain type"
406 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}"
409 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
410 enable_
${domain_type}_lttng_channel_ok
$SESSION_NAME $CHANNEL_NAME --subbuf-size=$PAGE_SIZE
411 enable_
${domain_type}_lttng_event_ok
$SESSION_NAME $event_name $CHANNEL_NAME
413 # Fetch consumerd testpoint pipe information
414 # This is needed since the testpoint create a pipe with the consumer type suffixed
416 for f
in "$testpoint_pipe_path"*; do
417 consumerd_pipe
+=("$f")
420 high_app_output_file
=${high_output_file_pattern}.first_receiver
421 high_app_output_path
=$output_dir/${high_app_output_file}
422 start_client
$high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO
0.420 1
424 wait_for_message
$output_dir "${high_app_output_file}" "sync: ready"
426 # Stop consumerd consumption to force high notification
427 start_lttng_tracing_ok
$SESSION_NAME
429 for pipe
in "${consumerd_pipe[@]}"; do
430 stop_consumerd
"${pipe}"
433 wait_for_message
$output_dir "${high_app_output_file}" "notification: high 0"
435 # Start a second receiver, the receiver should receive a high
436 # notification on subscription
437 high_app_output_file
=${high_output_file_pattern}.second_receiver
438 high_app_output_path
=$output_dir/${high_app_output_file}
439 start_client
$high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO
0.420 1
440 wait_for_message
$output_dir "${high_app_output_file}" "sync: ready"
441 wait_for_message
$output_dir "${high_app_output_file}" "notification: high 0"
444 for pipe
in "${consumerd_pipe[@]}"; do
445 resume_consumerd
"${pipe}"
448 wait_for_message
$output_dir "${high_output_file_pattern}" "exit: 0"
450 ok
$ret "Application for high notification terminated normally"
451 if [[ $ret -ne "0" ]]; then
453 print_errors
"${high_output_file_pattern}"
458 destroy_lttng_session_ok
$SESSION_NAME
461 kill -s SIGTERM
$generator_pid 2> /dev
/null
462 wait $generator_pid 2> /dev
/null
464 for pipe
in "${consumerd_pipe[@]}"; do
473 test_on_register_evaluation_ust
476 if [ "$(id -u)" == "0" ]; then
478 test_multi_app_kernel
479 test_on_register_evaluation_kernel
482 skip
0 "Root access is needed. Skipping all kernel multi-app notification tests." $NUM_TEST_KERNEL
486 for fct_test
in ${TESTS[@]};
488 TRACE_PATH
=$
(mktemp
-d)
491 if [ $?
-ne 0 ]; then
495 # Only delete if successful