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 # This is needed since the testpoint creates a pipe with the consumerd domain
25 TESTPOINT_BASE_PATH
=$
(readlink
-f "$CURDIR/lttng.t_p_n")
26 TESTPOINT_PIPE_PATH
=$
(mktemp
-u "${TESTPOINT_BASE_PATH}.XXXXXX")
27 TESTPOIT_ARGS
="CONSUMER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} LTTNG_TESTPOINT_ENABLE=1"
28 TESTPOINT
=$
(readlink
-f ${CURDIR}/.libs
/libpause_consumer.so
)
30 TESTAPP_PATH
="$TESTDIR/utils/testapp"
31 TESTAPP_NAME
="gen-ust-events"
32 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
37 SESSION_NAME
="my_session"
38 UST_CHANNEL_NAME
="my_ust_channel"
39 EVENT_NAME
="tp:tptest"
41 NR_NOTIFICATION_EXPECTED
=5
44 TRACE_PATH
=$
(mktemp
-d)
46 DIR
=$
(readlink
-f $TESTDIR)
48 PAGE_SIZE
=$
(getconf PAGE_SIZE
)
52 source $TESTDIR/utils
/utils.sh
55 file_sync_after_first_event
=$
(mktemp
-u)
57 # MUST set TESTDIR before calling those functions
60 print_test_banner
"$TEST_DESC"
63 function start_client
{
69 local buffer_usage_type
=$5
70 local buffer_usage_threshold_type
=$6
71 local buffer_usage_threshold_value
=$7
72 local nr_expected_notification
=$8
74 ${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} &
80 function wait_for_message
()
85 for file in $CURDIR/${file_pattern}*; do
87 # Check for "error" message
88 grep -q "error:" ${file}
90 if [ $app_error -eq "0" ] ; then
92 fail
"Waiting message: error logged see file content: ${message}, ${file}"
96 grep -q "${message}" ${file}
97 if [[ "$?" -ne "0" ]]; then
98 # Lookup failed restart loop
99 diag
"Lookup failed sleep and retry grep for: ${message}, ${file}"
106 pass
"Message received: ${message}"
110 function print_errors
()
112 local file_pattern
=$1
114 for file in $CURDIR/${file_pattern}*; do
115 # Check for "error" message
116 error_message
=$
(grep "error:" ${file})
117 if [[ "${error_message}" -ne "" ]]; then
118 diag
"Errors for application ${file}:"
119 diag
"${error_message}"
124 function comm_consumerd
()
128 echo -ne "${message}" > "${pipe}"
132 function stop_consumerd
()
135 comm_consumerd
"1" "$pipe"
136 ok $?
"Stopping consumption consumerd"
139 function resume_consumerd
()
142 comm_consumerd
"\0" "$pipe"
143 ok $?
"Resuming consumerd"
146 function test_multi_app
()
149 local low_output_file_pattern
="low_app_output_file_"
150 local high_output_file_pattern
="high_app_output_file_"
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
251 for fct_test
in ${TESTS[@]};
253 TRACE_PATH
=$
(mktemp
-d)
256 if [ $?
-ne 0 ]; then
260 # Only delete if successful