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"
32 SESSION_NAME
="my_session"
33 UST_CHANNEL_NAME
="my_ust_channel"
34 EVENT_NAME
="tp:tptest"
37 TRACE_PATH
=$
(mktemp
-d)
39 DIR
=$
(readlink
-f $TESTDIR)
41 PAGE_SIZE
=$
(getconf PAGE_SIZE
)
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"
56 function start_client
{
62 local buffer_usage_type
=$5
63 local buffer_usage_threshold_type
=$6
64 local buffer_usage_threshold_value
=$7
65 local nr_expected_notification
=$8
67 ${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} &
73 function wait_for_message
()
78 for file in $CURDIR/${file_pattern}*; do
80 # Check for "error" message
81 grep -q "error:" ${file}
83 if [ $app_error -eq "0" ] ; then
85 fail
"Waiting message: error logged see file content: ${message}, ${file}"
89 grep -q "${message}" ${file}
90 if [[ "$?" -ne "0" ]]; then
91 # Lookup failed restart loop
92 diag
"Lookup failed sleep and retry grep for: ${message}, ${file}"
99 pass
"Message received: ${message}"
103 function print_errors
()
105 local file_pattern
=$1
107 for file in $CURDIR/${file_pattern}*; do
108 # Check for "error" message
109 error_message
=$
(grep "error:" ${file})
110 if [[ "${error_message}" -ne "" ]]; then
111 diag
"Errors for application ${file}:"
112 diag
"${error_message}"
117 function comm_consumerd
()
121 echo -ne "${message}" > "${pipe}"
125 function stop_consumerd
()
128 comm_consumerd
"1" "$pipe"
129 ok $?
"Stopping consumption consumerd"
132 function resume_consumerd
()
135 comm_consumerd
"\0" "$pipe"
136 ok $?
"Resuming consumerd"
139 function test_multi_app
()
142 local low_output_file_pattern
="low_app_output_file_"
143 local high_output_file_pattern
="high_app_output_file_"
145 local testpoint_base_path
=$
(readlink
-f "$CURDIR/lttng.t_p_n_multi_app")
146 local testpoint_pipe_path
=$
(mktemp
-u "${testpoint_base_path}.XXXXXX")
148 local nr_notification_expected
=5
149 local nr_client_app
=50
152 rm ${CURDIR}/${low_output_file_pattern}* 2> /dev
/null
153 rm ${CURDIR}/${high_output_file_pattern}* 2> /dev
/null
156 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}"
159 # Start app in infinite loop
160 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $file_sync_after_first_event &
162 # Pin to CPU zero to force specific sub buffer usage
163 taskset
-p -c 0 $app_pid > /dev
/null
2>&1
165 # Wait for sync with app
166 while [ ! -f "${file_sync_after_first_event}" ]; do
169 rm ${file_sync_after_first_event}
171 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
172 enable_ust_lttng_channel_ok
$SESSION_NAME $UST_CHANNEL_NAME --subbuf-size=$PAGE_SIZE
173 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $UST_CHANNEL_NAME
175 # Fetch consumerd testpoint pipe information
176 # This is needed since the testpoint create a pipe with the consumer type suffixed
177 for f
in "$testpoint_base_path"*; do
178 consumerd_pipe
+=("$f")
181 for (( i
= 0; i
< $nr_client_app; i
++ )); do
182 low_app_output_file
=$CURDIR/${low_output_file_pattern}${i}
183 high_app_output_file
=$CURDIR/${high_output_file_pattern}${i}
184 start_client
$low_app_output_file $SESSION_NAME $UST_CHANNEL_NAME LTTNG_DOMAIN_UST LOW RATIO
0.0 $nr_notification_expected
185 start_client
$high_app_output_file $SESSION_NAME $UST_CHANNEL_NAME LTTNG_DOMAIN_UST HIGH RATIO
0.420 $nr_notification_expected
188 wait_for_message
"${low_output_file_pattern}" "sync: ready"
189 wait_for_message
"${high_output_file_pattern}" "sync: ready"
191 # Test notification reception
192 for (( i
= 0; i
< $nr_notification_expected; i
++ )); do
194 # Stop consumerd consumption to force high notification
195 start_lttng_tracing_ok
$SESSION_NAME
196 for pipe
in "${consumerd_pipe[@]}"; do
197 stop_consumerd
"${pipe}"
200 wait_for_message
"${high_output_file_pattern}" "notification: high $i"
203 for pipe
in "${consumerd_pipe[@]}"; do
204 resume_consumerd
"${pipe}"
206 # Stop tracing forcing full buffer consumption
207 stop_lttng_tracing
$SESSION_NAME
209 # Check for notifications reception
210 wait_for_message
"${low_output_file_pattern}" "notification: low $i"
212 ok
$ret "Notifications $i received"
213 if [[ $ret -ne "0" ]]; then
214 # Error occurred bail out
219 wait_for_message
"${low_output_file_pattern}" "exit: 0"
221 ok
$ret "Application for low notification terminated normally"
222 if [[ $ret -eq "0" ]]; then
223 rm ${CURDIR}/${low_output_file_pattern}* 2> /dev
/null
226 print_errors
"${low_output_file_pattern}"
229 wait_for_message
"${high_output_file_pattern}" "exit: 0"
231 ok
$ret "Application for high notification terminated normally"
232 if [[ $ret -eq "0" ]]; then
233 rm ${CURDIR}/${high_output_file_pattern}* 2> /dev
/null
236 print_errors
"${high_output_file_pattern}"
240 wait $app_pid 2> /dev
/null
250 for fct_test
in ${TESTS[@]};
252 TRACE_PATH
=$
(mktemp
-d)
255 if [ $?
-ne 0 ]; then
259 # Only delete if successful