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"
57 function start_client
{
63 local buffer_usage_type
=$5
64 local buffer_usage_threshold_type
=$6
65 local buffer_usage_threshold_value
=$7
66 local nr_expected_notification
=$8
68 ${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} &
74 function wait_for_message
()
79 for file in $CURDIR/${file_pattern}*; do
81 # Check for "error" message
82 grep -q "error:" ${file}
84 if [ $app_error -eq "0" ] ; then
86 fail
"Waiting message: error logged see file content: ${message}, ${file}"
90 grep -q "${message}" ${file}
91 if [[ "$?" -ne "0" ]]; then
92 # Lookup failed restart loop
93 diag
"Lookup failed sleep and retry grep for: ${message}, ${file}"
100 pass
"Message received: ${message}"
104 function print_errors
()
106 local file_pattern
=$1
108 for file in $CURDIR/${file_pattern}*; do
109 # Check for "error" message
110 error_message
=$
(grep "error:" ${file})
111 if [[ "${error_message}x" != "x" ]]; then
112 diag
"Errors for application ${file}:"
113 diag
"${error_message}"
118 function comm_consumerd
()
122 echo -ne "${message}" > "${pipe}"
126 function stop_consumerd
()
129 comm_consumerd
"1" "$pipe"
130 ok $?
"Stopping consumption consumerd"
133 function resume_consumerd
()
136 comm_consumerd
"\0" "$pipe"
137 ok $?
"Resuming consumerd"
140 function test_multi_app
()
143 local low_output_file_pattern
="low_app_output_file_"
144 local high_output_file_pattern
="high_app_output_file_"
146 local testpoint_base_path
=$
(readlink
-f "$CURDIR/lttng.t_p_n_multi_app")
147 local testpoint_pipe_path
=$
(mktemp
-u "${testpoint_base_path}.XXXXXX")
149 local nr_notification_expected
=5
150 local nr_client_app
=50
153 rm ${CURDIR}/${low_output_file_pattern}* 2> /dev
/null
154 rm ${CURDIR}/${high_output_file_pattern}* 2> /dev
/null
157 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}"
160 # Start app in infinite loop
161 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $file_sync_after_first_event &
163 # Pin to CPU zero to force specific sub buffer usage
164 taskset
-p -c 0 $app_pid > /dev
/null
2>&1
166 # Wait for sync with app
167 while [ ! -f "${file_sync_after_first_event}" ]; do
170 rm ${file_sync_after_first_event}
172 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
173 enable_ust_lttng_channel_ok
$SESSION_NAME $UST_CHANNEL_NAME --subbuf-size=$PAGE_SIZE
174 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $UST_CHANNEL_NAME
176 # Fetch consumerd testpoint pipe information
177 # This is needed since the testpoint create a pipe with the consumer type suffixed
178 for f
in "$testpoint_base_path"*; do
179 consumerd_pipe
+=("$f")
182 for (( i
= 0; i
< $nr_client_app; i
++ )); do
183 low_app_output_file
=$CURDIR/${low_output_file_pattern}${i}
184 high_app_output_file
=$CURDIR/${high_output_file_pattern}${i}
185 start_client
$low_app_output_file $SESSION_NAME $UST_CHANNEL_NAME LTTNG_DOMAIN_UST LOW RATIO
0.0 $nr_notification_expected
186 start_client
$high_app_output_file $SESSION_NAME $UST_CHANNEL_NAME LTTNG_DOMAIN_UST HIGH RATIO
0.420 $nr_notification_expected
189 wait_for_message
"${low_output_file_pattern}" "sync: ready"
190 wait_for_message
"${high_output_file_pattern}" "sync: ready"
192 # Test notification reception
193 for (( i
= 0; i
< $nr_notification_expected; i
++ )); do
195 # Stop consumerd consumption to force high notification
196 start_lttng_tracing_ok
$SESSION_NAME
197 for pipe
in "${consumerd_pipe[@]}"; do
198 stop_consumerd
"${pipe}"
201 wait_for_message
"${high_output_file_pattern}" "notification: high $i"
204 for pipe
in "${consumerd_pipe[@]}"; do
205 resume_consumerd
"${pipe}"
207 # Stop tracing forcing full buffer consumption
208 stop_lttng_tracing
$SESSION_NAME
210 # Check for notifications reception
211 wait_for_message
"${low_output_file_pattern}" "notification: low $i"
213 ok
$ret "Notifications $i received"
214 if [[ $ret -ne "0" ]]; then
215 # Error occurred bail out
220 wait_for_message
"${low_output_file_pattern}" "exit: 0"
222 ok
$ret "Application for low notification terminated normally"
223 if [[ $ret -eq "0" ]]; then
224 rm ${CURDIR}/${low_output_file_pattern}* 2> /dev
/null
227 print_errors
"${low_output_file_pattern}"
230 wait_for_message
"${high_output_file_pattern}" "exit: 0"
232 ok
$ret "Application for high notification terminated normally"
233 if [[ $ret -eq "0" ]]; then
234 rm ${CURDIR}/${high_output_file_pattern}* 2> /dev
/null
237 print_errors
"${high_output_file_pattern}"
241 wait $app_pid 2> /dev
/null
246 function test_on_register_evaluation
()
249 local high_output_file_pattern
="high_app_output_file_on_register_evaluation"
251 local testpoint_base_path
=$
(readlink
-f "$CURDIR/lttng.t_p_n_register_evaluation")
252 local testpoint_pipe_path
=$
(mktemp
-u "${testpoint_base_path}.XXXXXX")
255 rm ${CURDIR}/${high_output_file_pattern}* 2> /dev
/null
258 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}"
261 # Start app in infinite loop
262 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $file_sync_after_first_event &
264 # Pin to CPU zero to force specific sub buffer usage
265 taskset
-p -c 0 $app_pid > /dev
/null
2>&1
267 # Wait for sync with app
268 while [ ! -f "${file_sync_after_first_event}" ]; do
271 rm ${file_sync_after_first_event}
273 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
274 enable_ust_lttng_channel_ok
$SESSION_NAME $UST_CHANNEL_NAME --subbuf-size=$PAGE_SIZE
275 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $UST_CHANNEL_NAME
277 # Fetch consumerd testpoint pipe information
278 # This is needed since the testpoint create a pipe with the consumer type suffixed
279 for f
in "$testpoint_base_path"*; do
280 consumerd_pipe
+=("$f")
283 high_app_output_file
=${high_output_file_pattern}.first_receiver
284 high_app_output_path
=$CURDIR/${high_app_output_file}
285 start_client
$high_app_output_path $SESSION_NAME $UST_CHANNEL_NAME LTTNG_DOMAIN_UST HIGH RATIO
0.420 1
287 wait_for_message
"${high_app_output_file}" "sync: ready"
289 # Stop consumerd consumption to force high notification
290 start_lttng_tracing_ok
$SESSION_NAME
292 for pipe
in "${consumerd_pipe[@]}"; do
293 stop_consumerd
"${pipe}"
296 wait_for_message
"${high_app_output_file}" "notification: high 0"
298 # Start a second receiver, the receiver should receive a high
299 # notification on subscription
300 high_app_output_file
=${high_output_file_pattern}.second_receiver
301 high_app_output_path
=$CURDIR/${high_app_output_file}
302 start_client
$high_app_output_path $SESSION_NAME $UST_CHANNEL_NAME LTTNG_DOMAIN_UST HIGH RATIO
0.420 1
303 wait_for_message
"${high_app_output_file}" "sync: ready"
304 wait_for_message
"${high_app_output_file}" "notification: high 0"
307 for pipe
in "${consumerd_pipe[@]}"; do
308 resume_consumerd
"${pipe}"
311 wait_for_message
"${high_output_file_pattern}" "exit: 0"
313 ok
$ret "Application for high notification terminated normally"
314 if [[ $ret -eq "0" ]]; then
315 rm ${CURDIR}/${high_output_file_pattern}* 2> /dev
/null
318 print_errors
"${high_output_file_pattern}"
324 wait $app_pid 2> /dev
/null
330 test_on_register_evaluation
333 for fct_test
in ${TESTS[@]};
335 TRACE_PATH
=$
(mktemp
-d)
338 if [ $?
-ne 0 ]; then
342 # Only delete if successful