Tests: regression testing for notification API
[lttng-tools.git] / tests / regression / tools / notification / test_notification_multi_app
1 #!/bin/bash
2 #
3 # Copyright (C) - 2017 Jonathan Rajotte <jonathan.rajotte-julien@efficiso.com>>
4 #
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.
8 #
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
12 # details.
13 #
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
17
18 TEST_DESC="Notification"
19
20 CURDIR=$(dirname $0)/
21 TESTDIR=$CURDIR/../../../
22
23 # This is needed since the testpoint creates a pipe with the consumerd domain
24 # suffixed
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)
29
30 TESTAPP_PATH="$TESTDIR/utils/testapp"
31 TESTAPP_NAME="gen-ust-events"
32 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
33
34 NR_ITER=-1
35 NR_USEC_WAIT=5
36
37 SESSION_NAME="my_session"
38 UST_CHANNEL_NAME="my_ust_channel"
39 EVENT_NAME="tp:tptest"
40
41 NR_NOTIFICATION_EXPECTED=5
42 NR_CLIENT_APP=50
43
44 TRACE_PATH=$(mktemp -d)
45
46 DIR=$(readlink -f $TESTDIR)
47
48 NUM_TESTS=46
49
50 source $TESTDIR/utils/utils.sh
51
52 consumerd_pipe=()
53 file_sync_after_first_event=$(mktemp -u)
54
55 # MUST set TESTDIR before calling those functions
56 plan_tests $NUM_TESTS
57
58 print_test_banner "$TEST_DESC"
59
60 app_pids=()
61 function start_client {
62 local pid=-1
63 local output_file=$1
64 local session_name=$2
65 local channel_name=$3
66 local domain_type=$4
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
71
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} &
73 pid=$!
74
75 app_pids+=("$pid")
76 }
77
78 function wait_for_message ()
79 {
80 local file_pattern=$1
81 local message=$2
82
83 for file in $CURDIR/${file_pattern}*; do
84 while(true); do
85 # Check for "error" message
86 grep -q "error:" ${file}
87 app_error=$?
88 if [ $app_error -eq "0" ] ; then
89 # An error occurred
90 fail "Waiting message: error logged see file content: ${message}, ${file}"
91 return 1
92 fi
93
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}"
98 sleep 0.25
99 continue
100 fi
101 break
102 done
103 done
104 pass "Message received: ${message}"
105 return 0
106 }
107
108 function print_errors ()
109 {
110 local file_pattern=$1
111
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}"
118 fi
119 done
120 }
121
122 function comm_consumerd ()
123 {
124 local message=$1
125 local pipe=$2
126 echo -ne "${message}" > "${pipe}"
127 return $?
128 }
129
130 function stop_consumerd ()
131 {
132 local pipe=$1
133 comm_consumerd "1" "$pipe"
134 ok $? "Stopping consumption consumerd"
135 }
136
137 function resume_consumerd ()
138 {
139 local pipe=$1
140 comm_consumerd "\0" "$pipe"
141 ok $? "Resuming consumerd"
142 }
143
144 function test_multi_app ()
145 {
146 local app_pids=()
147 local low_output_file_pattern="low_app_output_file_"
148 local high_output_file_pattern="high_app_output_file_"
149
150 # Cleanup
151 rm ${CURDIR}/${low_output_file_pattern}* 2> /dev/null
152 rm ${CURDIR}/${high_output_file_pattern}* 2> /dev/null
153
154 # Setup
155 LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} LD_PRELOAD=${TESTPOINT}"
156 start_lttng_sessiond
157
158 # Start app in infinite loop
159 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $file_sync_after_first_event &
160 app_pid=$!
161 # Pin to CPU zero to force specific sub buffer usage
162 taskset -p -c 0 $app_pid > /dev/null 2>&1
163
164 # Wait for sync with app
165 while [ ! -f "${file_sync_after_first_event}" ]; do
166 sleep 0.5
167 done
168 rm ${file_sync_after_first_event}
169
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
173
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")
178 done
179
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
185 done
186
187 wait_for_message "${low_output_file_pattern}" "sync: ready"
188 wait_for_message "${high_output_file_pattern}" "sync: ready"
189
190 # Test notification reception
191 for (( i = 0; i < $NR_NOTIFICATION_EXPECTED; i++ )); do
192
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}"
197 done
198
199 wait_for_message "${high_output_file_pattern}" "notification: high $i"
200
201 # Resume consumerd
202 for pipe in "${consumerd_pipe[@]}"; do
203 resume_consumerd "${pipe}"
204 done
205 # Stop tracing forcing full buffer consumption
206 stop_lttng_tracing $SESSION_NAME
207
208 # Check for notifications reception
209 wait_for_message "${low_output_file_pattern}" "notification: low $i"
210 ret=$?
211 ok $ret "Notifications $i received"
212 if [[ $ret -ne "0" ]]; then
213 # Error occurred bail out
214 break;
215 fi
216 done
217
218 wait_for_message "${low_output_file_pattern}" "exit: 0"
219 ret=$?
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
223 else
224 # Keep the file
225 print_errors "${low_output_file_pattern}"
226 fi
227
228 wait_for_message "${high_output_file_pattern}" "exit: 0"
229 ret=$?
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
233 else
234 # Keep the file
235 print_errors "${high_output_file_pattern}"
236 fi
237
238 kill -9 $app_pid
239 wait $app_pid 2> /dev/null
240
241 stop_lttng_sessiond
242 }
243
244
245 TESTS=(
246 test_multi_app
247 )
248
249 for fct_test in ${TESTS[@]};
250 do
251 TRACE_PATH=$(mktemp -d)
252
253 ${fct_test}
254 if [ $? -ne 0 ]; then
255 break;
256 fi
257
258 # Only delete if successful
259 rm -rf $TRACE_PATH
260 done
261
This page took 0.037003 seconds and 6 git commands to generate.