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