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 TRACE_PATH
=$
(mktemp
-d)
39 DIR
=$
(readlink
-f $TESTDIR)
41 PAGE_SIZE
=$
(getconf PAGE_SIZE
)
45 NUM_TESTS
=$
(($NUM_TEST_UST + $NUM_TEST_KERNEL))
47 source $TESTDIR/utils
/utils.sh
50 file_sync_after_first_event
=$
(mktemp
-u)
52 # MUST set TESTDIR before calling those functions
55 print_test_banner
"$TEST_DESC"
59 function kernel_event_generator_toogle_state
61 kernel_event_generator_suspended
=$
((kernel_event_generator_suspended
==0))
64 function kernel_event_generator
67 kernel_event_generator_suspended
=0
68 trap kernel_event_generator_toogle_state SIGUSR1
69 trap "exit" SIGTERM SIGINT
71 if [[ $kernel_event_generator_suspended -eq "1" ]]; then
75 if [[ -f $state_file ]]; then
76 rm $state_file 2> /dev
/null
78 echo -n "1000" > /proc
/lttng-test-filter-event
83 function ust_event_generator_toogle_state
85 ust_event_generator_suspended
=$
((ust_event_generator_suspended
==0))
88 function ust_event_generator
91 ust_event_generator_suspended
=0
92 trap ust_event_generator_toogle_state SIGUSR1
93 trap "exit" SIGTERM SIGINT
95 if [[ $ust_event_generator_suspended -eq "1" ]]; then
99 if [[ -f $state_file ]]; then
100 rm $state_file 2> /dev
/null
102 taskset
-c 0 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT > /dev
/null
2>&1
107 function start_client
{
110 local session_name
=$2
111 local channel_name
=$3
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
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} &
124 function wait_for_message
()
126 local file_pattern
=$1
129 for file in $CURDIR/${file_pattern}*; do
131 # Check for "error" message
132 grep -q "error:" ${file}
134 if [ $app_error -eq "0" ] ; then
136 fail
"Waiting message: error logged see file content: ${message}, ${file}"
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}"
150 pass
"Message received: ${message}"
154 function print_errors
()
156 local file_pattern
=$1
158 for file in $CURDIR/${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_"
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")
199 local nr_notification_expected
=5
200 local nr_client_app
=50
201 local domain_string
=""
206 domain_string
=LTTNG_DOMAIN_UST
207 event_name
="tp:tptest"
210 domain_string
=LTTNG_DOMAIN_KERNEL
211 event_name
="lttng_test_filter_event"
214 fail
"Invalid domain type"
220 rm ${CURDIR}/${low_output_file_pattern}* 2> /dev
/null
221 rm ${CURDIR}/${high_output_file_pattern}* 2> /dev
/null
224 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}"
227 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
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
231 # Fetch consumerd testpoint pipe information
232 # This is needed since the testpoint create a pipe with the consumer type suffixed
233 for f
in "$testpoint_base_path"*; do
234 consumerd_pipe
+=("$f")
237 for (( i
= 0; i
< $nr_client_app; i
++ )); do
238 low_app_output_file
=$CURDIR/${low_output_file_pattern}${i}
239 high_app_output_file
=$CURDIR/${high_output_file_pattern}${i}
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
244 wait_for_message
"${low_output_file_pattern}" "sync: ready"
245 wait_for_message
"${high_output_file_pattern}" "sync: ready"
247 # Test notification reception
248 for (( i
= 0; i
< $nr_notification_expected; i
++ )); do
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}"
256 wait_for_message
"${high_output_file_pattern}" "notification: high $i"
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
266 for pipe
in "${consumerd_pipe[@]}"; do
267 resume_consumerd
"${pipe}"
269 # Stop tracing forcing full buffer consumption
270 stop_lttng_tracing
$SESSION_NAME
272 # Check for notifications reception
273 wait_for_message
"${low_output_file_pattern}" "notification: low $i"
275 ok
$ret "Notifications $i received"
276 if [[ $ret -ne "0" ]]; then
277 # Error occurred bail out
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
288 wait_for_message
"${low_output_file_pattern}" "exit: 0"
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
295 print_errors
"${low_output_file_pattern}"
298 wait_for_message
"${high_output_file_pattern}" "exit: 0"
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
305 print_errors
"${high_output_file_pattern}"
308 destroy_lttng_session_ok
$SESSION_NAME
311 for pipe
in "${consumerd_pipe[@]}"; do
316 function test_multi_app_ust
()
318 diag
"Multi client app UST notification"
319 ust_event_generator
$TESTAPP_STATE_FILE &
320 local generator_pid
=$
!
322 test_multi_app ust
$generator_pid
324 kill -9 $generator_pid 2> /dev
/null
325 wait $generator_pid 2> /dev
/null
326 rm -rf ${TESTAPP_STATE_FILE} 2> /dev
/null
329 function test_multi_app_kernel
()
331 diag
"Multi client app kernel notification"
334 kernel_event_generator
$TESTAPP_STATE_FILE &
335 local generator_pid
=$
!
337 test_multi_app kernel
$generator_pid
340 kill -9 $generator_pid 2>/dev
/null
341 wait $generator_pid 2> /dev
/null
342 rm -rf ${TESTAPP_STATE_FILE} 2> /dev
/null
347 function test_on_register_evaluation_ust
()
349 diag
"On register notification UST"
351 # Start app in infinite loop
352 ust_event_generator
$TESTAPP_STATE_FILE &
353 local generator_pid
=$
!
355 test_on_register_evaluation ust
$generator_pid
357 kill -9 $generator_pid 2> /dev
/null
358 wait $generator_pid 2> /dev
/null
359 rm -rf ${TESTAPP_STATE_FILE} 2> /dev
/null
363 function test_on_register_evaluation_kernel
()
365 diag
"On register notification kernel"
369 kernel_event_generator
$TESTAPP_STATE_FILE &
370 local generator_pid
=$
!
372 test_on_register_evaluation kernel
$generator_pid
375 kill -9 $generator_pid 2> /dev
/null
376 wait $generator_pid 2> /dev
/null
377 rm -rf ${TESTAPP_STATE_FILE} 2> /dev
/null
382 function test_on_register_evaluation
()
385 local event_generator_pid
=$2
388 local high_output_file_pattern
="high_app_output_file_on_register_evaluation"
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")
392 local domain_string
=""
396 rm ${CURDIR}/${high_output_file_pattern}* 2> /dev
/null
400 domain_string
=LTTNG_DOMAIN_UST
401 event_name
="tp:tptest"
404 domain_string
=LTTNG_DOMAIN_KERNEL
405 event_name
="lttng_test_filter_event"
408 fail
"Invalid domain type"
414 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}"
417 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
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
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")
427 high_app_output_file
=${high_output_file_pattern}.first_receiver
428 high_app_output_path
=$CURDIR/${high_app_output_file}
429 start_client
$high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO
0.420 1
431 wait_for_message
"${high_app_output_file}" "sync: ready"
433 # Stop consumerd consumption to force high notification
434 start_lttng_tracing_ok
$SESSION_NAME
436 for pipe
in "${consumerd_pipe[@]}"; do
437 stop_consumerd
"${pipe}"
440 wait_for_message
"${high_app_output_file}" "notification: high 0"
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}
446 start_client
$high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO
0.420 1
447 wait_for_message
"${high_app_output_file}" "sync: ready"
448 wait_for_message
"${high_app_output_file}" "notification: high 0"
451 for pipe
in "${consumerd_pipe[@]}"; do
452 resume_consumerd
"${pipe}"
455 wait_for_message
"${high_output_file_pattern}" "exit: 0"
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
462 print_errors
"${high_output_file_pattern}"
465 destroy_lttng_session_ok
$SESSION_NAME
468 kill -9 $generator_pid
469 wait $generator_pid 2> /dev
/null
471 for pipe
in "${consumerd_pipe[@]}"; do
480 test_on_register_evaluation_ust
483 if [ "$(id -u)" == "0" ]; then
485 test_multi_app_kernel
486 test_on_register_evaluation_kernel
489 skip
0 "Root access is needed. Skipping all kernel multi-app notification tests." $NUM_TEST_KERNEL
493 for fct_test
in ${TESTS[@]};
495 TRACE_PATH
=$
(mktemp
-d)
498 if [ $?
-ne 0 ]; then
502 # Only delete if successful