sessiond: Extract `{setup,teardown}_tracer_notifier()` functions
[lttng-tools.git] / tests / regression / tools / notification / test_notification_multi_app
CommitLineData
434f8068
JR
1#!/bin/bash
2#
9d16b343 3# Copyright (C) 2017 Jonathan Rajotte <jonathan.rajotte-julien@efficiso.com>>
434f8068 4#
9d16b343 5# SPDX-License-Identifier: LGPL-2.1-only
434f8068
JR
6
7TEST_DESC="Notification"
8
9CURDIR=$(dirname $0)/
10TESTDIR=$CURDIR/../../../
11
434f8068
JR
12TESTPOINT=$(readlink -f ${CURDIR}/.libs/libpause_consumer.so)
13
14TESTAPP_PATH="$TESTDIR/utils/testapp"
15TESTAPP_NAME="gen-ust-events"
16TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
854382b8 17TESTAPP_STATE_FILE="$(mktemp -u)"
434f8068 18
854382b8 19NR_ITER=1000
434f8068
JR
20NR_USEC_WAIT=5
21
22SESSION_NAME="my_session"
854382b8 23CHANNEL_NAME="my_channel"
434f8068 24
434f8068 25
434f8068
JR
26DIR=$(readlink -f $TESTDIR)
27
1bd26228
JG
28PAGE_SIZE=$(getconf PAGE_SIZE)
29
854382b8
JR
30NUM_TEST_UST=50
31NUM_TEST_KERNEL=50
32NUM_TESTS=$(($NUM_TEST_UST + $NUM_TEST_KERNEL))
434f8068
JR
33
34source $TESTDIR/utils/utils.sh
25cb2044 35source $CURDIR/util_event_generator.sh
434f8068
JR
36
37consumerd_pipe=()
38file_sync_after_first_event=$(mktemp -u)
39
40# MUST set TESTDIR before calling those functions
41plan_tests $NUM_TESTS
42
43print_test_banner "$TEST_DESC"
44
45app_pids=()
867313e2 46
434f8068
JR
47function start_client {
48 local pid=-1
49 local output_file=$1
50 local session_name=$2
51 local channel_name=$3
52 local domain_type=$4
53 local buffer_usage_type=$5
54 local buffer_usage_threshold_type=$6
55 local buffer_usage_threshold_value=$7
56 local nr_expected_notification=$8
57
58 ${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} &
59 pid=$!
60
61 app_pids+=("$pid")
62}
63
64function wait_for_message ()
65{
345ed219
JR
66 local directory=$1
67 local file_pattern=$2
68 local message=$3
434f8068 69
345ed219 70 for file in $directory/${file_pattern}*; do
434f8068
JR
71 while(true); do
72 # Check for "error" message
73 grep -q "error:" ${file}
74 app_error=$?
75 if [ $app_error -eq "0" ] ; then
76 # An error occurred
77 fail "Waiting message: error logged see file content: ${message}, ${file}"
78 return 1
79 fi
80
81 grep -q "${message}" ${file}
82 if [[ "$?" -ne "0" ]]; then
83 # Lookup failed restart loop
84 diag "Lookup failed sleep and retry grep for: ${message}, ${file}"
85 sleep 0.25
86 continue
87 fi
88 break
89 done
90 done
91 pass "Message received: ${message}"
92 return 0
93}
94
95function print_errors ()
96{
345ed219
JR
97 local directory=$1
98 local file_pattern=$2
434f8068 99
345ed219 100 for file in $directory/${file_pattern}*; do
434f8068
JR
101 # Check for "error" message
102 error_message=$(grep "error:" ${file})
867313e2 103 if [[ "${error_message}x" != "x" ]]; then
434f8068
JR
104 diag "Errors for application ${file}:"
105 diag "${error_message}"
106 fi
107 done
108}
109
110function comm_consumerd ()
111{
112 local message=$1
113 local pipe=$2
114 echo -ne "${message}" > "${pipe}"
434f8068
JR
115}
116
117function stop_consumerd ()
118{
119 local pipe=$1
120 comm_consumerd "1" "$pipe"
434f8068
JR
121}
122
123function resume_consumerd ()
124{
125 local pipe=$1
126 comm_consumerd "\0" "$pipe"
434f8068
JR
127}
128
129function test_multi_app ()
130{
854382b8
JR
131 local domain_type=$1
132 local event_generator_pid=$2
133
434f8068
JR
134 local app_pids=()
135 local low_output_file_pattern="low_app_output_file_"
136 local high_output_file_pattern="high_app_output_file_"
345ed219 137 local output_dir=$(mktemp -d)
434f8068 138
345ed219 139 local testpoint_base_path=$(readlink -f "$output_dir/lttng.t_p_n_multi_app")
6a1eee92
JR
140 local testpoint_pipe_path=$(mktemp -u "${testpoint_base_path}.XXXXXX")
141
142 local nr_notification_expected=5
143 local nr_client_app=50
854382b8
JR
144 local domain_string=""
145 local event_name=""
146
147 case $domain_type in
148 ust)
149 domain_string=LTTNG_DOMAIN_UST
150 event_name="tp:tptest"
151 ;;
152 kernel)
153 domain_string=LTTNG_DOMAIN_KERNEL
154 event_name="lttng_test_filter_event"
155 ;;
156 *)
157 fail "Invalid domain type"
158 exit 1
159 ;;
160 esac
6a1eee92 161
434f8068 162 # Setup
6a1eee92 163 LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}"
434f8068
JR
164 start_lttng_sessiond
165
434f8068 166 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
854382b8
JR
167 enable_${domain_type}_lttng_channel_ok $SESSION_NAME $CHANNEL_NAME --subbuf-size=$PAGE_SIZE
168 enable_${domain_type}_lttng_event_ok $SESSION_NAME $event_name $CHANNEL_NAME
434f8068
JR
169
170 # Fetch consumerd testpoint pipe information
171 # This is needed since the testpoint create a pipe with the consumer type suffixed
345ed219
JR
172 consumerd_pipe=()
173 for f in "$testpoint_pipe_path"*; do
434f8068
JR
174 consumerd_pipe+=("$f")
175 done
176
6a1eee92 177 for (( i = 0; i < $nr_client_app; i++ )); do
345ed219
JR
178 low_app_output_file=$output_dir/${low_output_file_pattern}${i}
179 high_app_output_file=$output_dir/${high_output_file_pattern}${i}
854382b8
JR
180 start_client $low_app_output_file $SESSION_NAME $CHANNEL_NAME $domain_string LOW RATIO 0.0 $nr_notification_expected
181 start_client $high_app_output_file $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO 0.420 $nr_notification_expected
434f8068
JR
182 done
183
345ed219
JR
184 wait_for_message $output_dir "${low_output_file_pattern}" "sync: ready"
185 wait_for_message $output_dir "${high_output_file_pattern}" "sync: ready"
434f8068
JR
186
187 # Test notification reception
6a1eee92 188 for (( i = 0; i < $nr_notification_expected; i++ )); do
434f8068
JR
189
190 # Stop consumerd consumption to force high notification
191 start_lttng_tracing_ok $SESSION_NAME
192 for pipe in "${consumerd_pipe[@]}"; do
193 stop_consumerd "${pipe}"
194 done
195
345ed219 196 wait_for_message $output_dir "${high_output_file_pattern}" "notification: high $i"
434f8068 197
854382b8
JR
198 # Put application in suspend mode to prevent double low
199 # notification and synchronize on state file.
200 kill -s SIGUSR1 $event_generator_pid
201 while [ ! -f "${TESTAPP_STATE_FILE}" ]; do
202 sleep 0.5
203 done
204
434f8068
JR
205 # Resume consumerd
206 for pipe in "${consumerd_pipe[@]}"; do
207 resume_consumerd "${pipe}"
208 done
209 # Stop tracing forcing full buffer consumption
7fe98a98 210 stop_lttng_tracing_ok $SESSION_NAME
434f8068
JR
211
212 # Check for notifications reception
345ed219 213 wait_for_message $output_dir "${low_output_file_pattern}" "notification: low $i"
434f8068
JR
214 ret=$?
215 ok $ret "Notifications $i received"
216 if [[ $ret -ne "0" ]]; then
217 # Error occurred bail out
218 break;
219 fi
854382b8
JR
220
221 # Put application in active mode and synchronize on state file.
222 kill -s SIGUSR1 $event_generator_pid
223 while [ -f "${TESTAPP_STATE_FILE}" ]; do
224 sleep 0.5
225 done
434f8068
JR
226 done
227
345ed219 228 wait_for_message $output_dir "${low_output_file_pattern}" "exit: 0"
434f8068
JR
229 ret=$?
230 ok $ret "Application for low notification terminated normally"
345ed219
JR
231 if [[ $ret -ne "0" ]]; then
232 print_errors $output_dir "${low_output_file_pattern}"
434f8068
JR
233 fi
234
345ed219 235 wait_for_message $output_dir "${high_output_file_pattern}" "exit: 0"
434f8068
JR
236 ret=$?
237 ok $ret "Application for high notification terminated normally"
345ed219
JR
238 if [[ $ret -ne "0" ]]; then
239 print_errors $output_dir "${high_output_file_pattern}"
434f8068
JR
240 fi
241
345ed219 242
854382b8 243 destroy_lttng_session_ok $SESSION_NAME
434f8068 244 stop_lttng_sessiond
854382b8
JR
245
246 for pipe in "${consumerd_pipe[@]}"; do
247 rm -rf "${pipe}"
248 done
81665716
JR
249
250 rm -rf $output_dir
854382b8
JR
251}
252
253function test_multi_app_ust ()
254{
255 diag "Multi client app UST notification"
25cb2044 256 ust_event_generator "$TESTAPP_BIN" "$TESTAPP_STATE_FILE" &
854382b8
JR
257 local generator_pid=$!
258
259 test_multi_app ust $generator_pid
260
25cb2044 261 kill -s SIGUSR2 $generator_pid 2> /dev/null
854382b8
JR
262 wait $generator_pid 2> /dev/null
263 rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null
264}
265
266function test_multi_app_kernel ()
267{
268 diag "Multi client app kernel notification"
269 modprobe lttng-test
270
25cb2044 271 kernel_event_generator generate_filter_events $TESTAPP_STATE_FILE &
854382b8
JR
272 local generator_pid=$!
273
274 test_multi_app kernel $generator_pid
275
276
25cb2044 277 kill -s SIGUSR2 $generator_pid 2> /dev/null
854382b8
JR
278 wait $generator_pid 2> /dev/null
279 rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null
280
d0e263e7 281 modprobe --remove lttng-test
854382b8
JR
282}
283
284function test_on_register_evaluation_ust ()
285{
286 diag "On register notification UST"
287
288 # Start app in infinite loop
25cb2044 289 ust_event_generator "$TESTAPP_BIN" "$TESTAPP_STATE_FILE" &
854382b8
JR
290 local generator_pid=$!
291
292 test_on_register_evaluation ust $generator_pid
293
25cb2044 294 kill -s SIGUSR2 $generator_pid 2> /dev/null
854382b8
JR
295 wait $generator_pid 2> /dev/null
296 rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null
297
298}
299
300function test_on_register_evaluation_kernel()
301{
302 diag "On register notification kernel"
303
304 modprobe lttng-test
305
25cb2044 306 kernel_event_generator generate_filter_events $TESTAPP_STATE_FILE &
854382b8
JR
307 local generator_pid=$!
308
309 test_on_register_evaluation kernel $generator_pid
310
311
25cb2044 312 kill -s SIGUSR2 $generator_pid 2> /dev/null
854382b8
JR
313 wait $generator_pid 2> /dev/null
314 rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null
315
d0e263e7 316 modprobe --remove lttng-test
434f8068
JR
317}
318
867313e2
JR
319function test_on_register_evaluation ()
320{
854382b8
JR
321 local domain_type=$1
322 local event_generator_pid=$2
323
867313e2
JR
324 local app_pids=()
325 local high_output_file_pattern="high_app_output_file_on_register_evaluation"
326
345ed219
JR
327 local output_dir=$(mktemp -d)
328 local testpoint_base_path=$(readlink -f "$output_dir/lttng.t_p_n_register_evaluation")
867313e2 329 local testpoint_pipe_path=$(mktemp -u "${testpoint_base_path}.XXXXXX")
854382b8
JR
330 local domain_string=""
331 local event_name=""
867313e2 332
854382b8
JR
333 case $domain_type in
334 ust)
335 domain_string=LTTNG_DOMAIN_UST
336 event_name="tp:tptest"
337 ;;
338 kernel)
339 domain_string=LTTNG_DOMAIN_KERNEL
340 event_name="lttng_test_filter_event"
341 ;;
342 *)
343 fail "Invalid domain type"
344 exit 1
345 ;;
346 esac
347
867313e2
JR
348 # Setup
349 LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}"
350 start_lttng_sessiond
351
867313e2 352 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
854382b8
JR
353 enable_${domain_type}_lttng_channel_ok $SESSION_NAME $CHANNEL_NAME --subbuf-size=$PAGE_SIZE
354 enable_${domain_type}_lttng_event_ok $SESSION_NAME $event_name $CHANNEL_NAME
867313e2
JR
355
356 # Fetch consumerd testpoint pipe information
357 # This is needed since the testpoint create a pipe with the consumer type suffixed
345ed219
JR
358 consumerd_pipe=()
359 for f in "$testpoint_pipe_path"*; do
867313e2
JR
360 consumerd_pipe+=("$f")
361 done
362
363 high_app_output_file=${high_output_file_pattern}.first_receiver
345ed219 364 high_app_output_path=$output_dir/${high_app_output_file}
854382b8 365 start_client $high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO 0.420 1
867313e2 366
345ed219 367 wait_for_message $output_dir "${high_app_output_file}" "sync: ready"
867313e2
JR
368
369 # Stop consumerd consumption to force high notification
370 start_lttng_tracing_ok $SESSION_NAME
371
372 for pipe in "${consumerd_pipe[@]}"; do
373 stop_consumerd "${pipe}"
374 done
375
345ed219 376 wait_for_message $output_dir "${high_app_output_file}" "notification: high 0"
867313e2
JR
377
378 # Start a second receiver, the receiver should receive a high
379 # notification on subscription
380 high_app_output_file=${high_output_file_pattern}.second_receiver
345ed219 381 high_app_output_path=$output_dir/${high_app_output_file}
854382b8 382 start_client $high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO 0.420 1
345ed219
JR
383 wait_for_message $output_dir "${high_app_output_file}" "sync: ready"
384 wait_for_message $output_dir "${high_app_output_file}" "notification: high 0"
867313e2
JR
385
386 # Resume consumerd
387 for pipe in "${consumerd_pipe[@]}"; do
388 resume_consumerd "${pipe}"
389 done
390
345ed219 391 wait_for_message $output_dir "${high_output_file_pattern}" "exit: 0"
867313e2
JR
392 ret=$?
393 ok $ret "Application for high notification terminated normally"
345ed219 394 if [[ $ret -ne "0" ]]; then
867313e2
JR
395 # Keep the file
396 print_errors "${high_output_file_pattern}"
397 fi
398
345ed219 399
854382b8 400 destroy_lttng_session_ok $SESSION_NAME
867313e2
JR
401 stop_lttng_sessiond
402
25cb2044 403 kill -s SIGUSR2 $generator_pid 2> /dev/null
854382b8
JR
404 wait $generator_pid 2> /dev/null
405
406 for pipe in "${consumerd_pipe[@]}"; do
407 rm -rf "${pipe}"
408 done
409
81665716 410 rm -rf "$output_dir"
867313e2
JR
411}
412
434f8068
JR
413
414TESTS=(
854382b8
JR
415 test_multi_app_ust
416 test_on_register_evaluation_ust
434f8068
JR
417)
418
854382b8 419if [ "$(id -u)" == "0" ]; then
fb180e6e 420 validate_lttng_modules_present
854382b8
JR
421 TESTS+=(
422 test_multi_app_kernel
423 test_on_register_evaluation_kernel
424)
425else
426 skip 0 "Root access is needed. Skipping all kernel multi-app notification tests." $NUM_TEST_KERNEL
427fi
428
429
434f8068
JR
430for fct_test in ${TESTS[@]};
431do
432 TRACE_PATH=$(mktemp -d)
433
434 ${fct_test}
435 if [ $? -ne 0 ]; then
436 break;
437 fi
438
439 # Only delete if successful
440 rm -rf $TRACE_PATH
441done
This page took 0.050501 seconds and 4 git commands to generate.