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)
50 source $TESTDIR/utils
/utils.sh
53 file_sync_after_first_event
=$
(mktemp
-u)
55 # MUST set TESTDIR before calling those functions
58 print_test_banner
"$TEST_DESC"
61 function start_client
{
67 local buffer_usage_type
=$5
68 local buffer_usage_threshold_type
=$6
69 local buffer_usage_threshold_value
=$7
70 local nr_expected_notification
=$8
72 ${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} &
78 function wait_for_message
()
83 for file in $CURDIR/${file_pattern}*; do
85 # Check for "error" message
86 grep -q "error:" ${file}
88 if [ $app_error -eq "0" ] ; then
90 fail
"Waiting message: error logged see file content: ${message}, ${file}"
94 grep -q "${message}" ${file}
95 if [[ "$?" -ne "0" ]]; then
96 # Lookup failed restart loop
97 diag
"Lookup failed sleep and retry grep for: ${message}, ${file}"
104 pass
"Message received: ${message}"
108 function print_errors
()
110 local file_pattern
=$1
112 for file in $CURDIR/${file_pattern}*; do
113 # Check for "error" message
114 error_message
=$
(grep "error:" ${file})
115 if [[ "${error_message}" -ne "" ]]; then
116 diag
"Errors for application ${file}:"
117 diag
"${error_message}"
122 function comm_consumerd
()
126 echo -ne "${message}" > "${pipe}"
130 function stop_consumerd
()
133 comm_consumerd
"1" "$pipe"
134 ok $?
"Stopping consumption consumerd"
137 function resume_consumerd
()
140 comm_consumerd
"\0" "$pipe"
141 ok $?
"Resuming consumerd"
144 function test_multi_app
()
147 local low_output_file_pattern
="low_app_output_file_"
148 local high_output_file_pattern
="high_app_output_file_"
151 rm ${CURDIR}/${low_output_file_pattern}* 2> /dev
/null
152 rm ${CURDIR}/${high_output_file_pattern}* 2> /dev
/null
155 LTTNG_SESSIOND_ENV_VARS
="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} LD_PRELOAD=${TESTPOINT}"
158 # Start app in infinite loop
159 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $file_sync_after_first_event &
161 # Pin to CPU zero to force specific sub buffer usage
162 taskset
-p -c 0 $app_pid > /dev
/null
2>&1
164 # Wait for sync with app
165 while [ ! -f "${file_sync_after_first_event}" ]; do
168 rm ${file_sync_after_first_event}
170 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
171 enable_ust_lttng_channel_ok
$SESSION_NAME $UST_CHANNEL_NAME --subbuf-size=4096
172 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME $UST_CHANNEL_NAME
174 # Fetch consumerd testpoint pipe information
175 # This is needed since the testpoint create a pipe with the consumer type suffixed
176 for f
in "$TESTPOINT_BASE_PATH"*; do
177 consumerd_pipe
+=("$f")
180 for (( i
= 0; i
< $NR_CLIENT_APP; i
++ )); do
181 low_app_output_file
=$CURDIR/${low_output_file_pattern}${i}
182 high_app_output_file
=$CURDIR/${high_output_file_pattern}${i}
183 start_client
$low_app_output_file $SESSION_NAME $UST_CHANNEL_NAME LTTNG_DOMAIN_UST LOW RATIO
0.0 $NR_NOTIFICATION_EXPECTED
184 start_client
$high_app_output_file $SESSION_NAME $UST_CHANNEL_NAME LTTNG_DOMAIN_UST HIGH RATIO
0.420 $NR_NOTIFICATION_EXPECTED
187 wait_for_message
"${low_output_file_pattern}" "sync: ready"
188 wait_for_message
"${high_output_file_pattern}" "sync: ready"
190 # Test notification reception
191 for (( i
= 0; i
< $NR_NOTIFICATION_EXPECTED; i
++ )); do
193 # Stop consumerd consumption to force high notification
194 start_lttng_tracing_ok
$SESSION_NAME
195 for pipe
in "${consumerd_pipe[@]}"; do
196 stop_consumerd
"${pipe}"
199 wait_for_message
"${high_output_file_pattern}" "notification: high $i"
202 for pipe
in "${consumerd_pipe[@]}"; do
203 resume_consumerd
"${pipe}"
205 # Stop tracing forcing full buffer consumption
206 stop_lttng_tracing
$SESSION_NAME
208 # Check for notifications reception
209 wait_for_message
"${low_output_file_pattern}" "notification: low $i"
211 ok
$ret "Notifications $i received"
212 if [[ $ret -ne "0" ]]; then
213 # Error occurred bail out
218 wait_for_message
"${low_output_file_pattern}" "exit: 0"
220 ok
$ret "Application for low notification terminated normally"
221 if [[ $ret -eq "0" ]]; then
222 rm ${CURDIR}/${low_output_file_pattern}* 2> /dev
/null
225 print_errors
"${low_output_file_pattern}"
228 wait_for_message
"${high_output_file_pattern}" "exit: 0"
230 ok
$ret "Application for high notification terminated normally"
231 if [[ $ret -eq "0" ]]; then
232 rm ${CURDIR}/${high_output_file_pattern}* 2> /dev
/null
235 print_errors
"${high_output_file_pattern}"
239 wait $app_pid 2> /dev
/null
249 for fct_test
in ${TESTS[@]};
251 TRACE_PATH
=$
(mktemp
-d)
254 if [ $?
-ne 0 ]; then
258 # Only delete if successful