X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=tests%2Fregression%2Ftools%2Fnotification%2Ftest_notification_multi_app;h=d8b6392259e96fe631496876949dc0db1ee94c60;hp=622a18aad37377f169012496787b8b9a899f9856;hb=33e557114a2ba28e26e220a833e8a449c78b8b65;hpb=854382b8a0f18fa77ba97eac55a61dd8d8d8cc85 diff --git a/tests/regression/tools/notification/test_notification_multi_app b/tests/regression/tools/notification/test_notification_multi_app index 622a18aad..d8b639225 100755 --- a/tests/regression/tools/notification/test_notification_multi_app +++ b/tests/regression/tools/notification/test_notification_multi_app @@ -1,19 +1,8 @@ #!/bin/bash # -# Copyright (C) - 2017 Jonathan Rajotte > +# Copyright (C) 2017 Jonathan Rajotte > # -# This library is free software; you can redistribute it and/or modify it under -# the terms of the GNU Lesser General Public License as published by the Free -# Software Foundation; version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -# details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this library; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# SPDX-License-Identifier: LGPL-2.1-only TEST_DESC="Notification" @@ -25,7 +14,7 @@ TESTPOINT=$(readlink -f ${CURDIR}/.libs/libpause_consumer.so) TESTAPP_PATH="$TESTDIR/utils/testapp" TESTAPP_NAME="gen-ust-events" TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" -TESTAPP_STATE_FILE="$(mktemp -u)" +TESTAPP_STATE_FILE="$(mktemp --tmpdir -u tmp.test_notification_multi_app_state_file.XXXXXX)" NR_ITER=1000 NR_USEC_WAIT=5 @@ -34,8 +23,6 @@ SESSION_NAME="my_session" CHANNEL_NAME="my_channel" -TRACE_PATH=$(mktemp -d) - DIR=$(readlink -f $TESTDIR) PAGE_SIZE=$(getconf PAGE_SIZE) @@ -45,9 +32,10 @@ NUM_TEST_KERNEL=50 NUM_TESTS=$(($NUM_TEST_UST + $NUM_TEST_KERNEL)) source $TESTDIR/utils/utils.sh +source $CURDIR/util_event_generator.sh consumerd_pipe=() -file_sync_after_first_event=$(mktemp -u) +file_sync_after_first_event=$(mktemp --tmpdir -u tmp.test_notification_multi_app_sync_after_first.XXXXXX) # MUST set TESTDIR before calling those functions plan_tests $NUM_TESTS @@ -56,54 +44,6 @@ print_test_banner "$TEST_DESC" app_pids=() -function kernel_event_generator_toogle_state -{ - kernel_event_generator_suspended=$((kernel_event_generator_suspended==0)) - -} -function kernel_event_generator -{ - state_file=$1 - kernel_event_generator_suspended=0 - trap kernel_event_generator_toogle_state SIGUSR1 - trap "exit" SIGTERM SIGINT - while (true); do - if [[ $kernel_event_generator_suspended -eq "1" ]]; then - touch $state_file - sleep 0.5 - else - if [[ -f $state_file ]]; then - rm $state_file 2> /dev/null - fi - echo -n "1000" > /proc/lttng-test-filter-event - fi - done -} - -function ust_event_generator_toogle_state -{ - ust_event_generator_suspended=$((ust_event_generator_suspended==0)) - -} -function ust_event_generator -{ - state_file=$1 - ust_event_generator_suspended=0 - trap ust_event_generator_toogle_state SIGUSR1 - trap "exit" SIGTERM SIGINT - while (true); do - if [[ $ust_event_generator_suspended -eq "1" ]]; then - touch $state_file - sleep 0.5 - else - if [[ -f $state_file ]]; then - rm $state_file 2> /dev/null - fi - taskset -c 0 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT > /dev/null 2>&1 - fi - done -} - function start_client { local pid=-1 local output_file=$1 @@ -114,8 +54,9 @@ function start_client { local buffer_usage_threshold_type=$6 local buffer_usage_threshold_value=$7 local nr_expected_notification=$8 + local use_action_list=$9 - ${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} & + ${CURDIR}/base_client ${session_name} ${channel_name} ${domain_type} ${buffer_usage_type} ${buffer_usage_threshold_type} ${buffer_usage_threshold_value} ${nr_expected_notification} ${use_action_list} > ${output_file} & pid=$! app_pids+=("$pid") @@ -123,10 +64,11 @@ function start_client { function wait_for_message () { - local file_pattern=$1 - local message=$2 + local directory=$1 + local file_pattern=$2 + local message=$3 - for file in $CURDIR/${file_pattern}*; do + for file in $directory/${file_pattern}*; do while(true); do # Check for "error" message grep -q "error:" ${file} @@ -153,9 +95,10 @@ function wait_for_message () function print_errors () { - local file_pattern=$1 + local directory=$1 + local file_pattern=$2 - for file in $CURDIR/${file_pattern}*; do + for file in $directory/${file_pattern}*; do # Check for "error" message error_message=$(grep "error:" ${file}) if [[ "${error_message}x" != "x" ]]; then @@ -192,9 +135,10 @@ function test_multi_app () local app_pids=() local low_output_file_pattern="low_app_output_file_" local high_output_file_pattern="high_app_output_file_" + local output_dir=$(mktemp --tmpdir -d "tmp.test_${FUNCNAME[0]}_output_dir.XXXXXX") - local testpoint_base_path=$(readlink -f "$CURDIR/lttng.t_p_n_multi_app") - local testpoint_pipe_path=$(mktemp -u "${testpoint_base_path}.XXXXXX") + local testpoint_base_path=$(readlink -f "$output_dir/lttng.t_p_n_multi_app") + local testpoint_pipe_path=$(mktemp --tmpdir="$output_dir" -u "lttng.t_p_n_multi_app.XXXXXX") local nr_notification_expected=5 local nr_client_app=50 @@ -216,10 +160,6 @@ function test_multi_app () ;; esac - # Cleanup - rm ${CURDIR}/${low_output_file_pattern}* 2> /dev/null - rm ${CURDIR}/${high_output_file_pattern}* 2> /dev/null - # Setup LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}" start_lttng_sessiond @@ -230,19 +170,20 @@ function test_multi_app () # Fetch consumerd testpoint pipe information # This is needed since the testpoint create a pipe with the consumer type suffixed - for f in "$testpoint_base_path"*; do + consumerd_pipe=() + for f in "$testpoint_pipe_path"*; do consumerd_pipe+=("$f") done for (( i = 0; i < $nr_client_app; i++ )); do - low_app_output_file=$CURDIR/${low_output_file_pattern}${i} - high_app_output_file=$CURDIR/${high_output_file_pattern}${i} - start_client $low_app_output_file $SESSION_NAME $CHANNEL_NAME $domain_string LOW RATIO 0.0 $nr_notification_expected - start_client $high_app_output_file $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO 0.420 $nr_notification_expected + low_app_output_file=$output_dir/${low_output_file_pattern}${i} + high_app_output_file=$output_dir/${high_output_file_pattern}${i} + start_client $low_app_output_file $SESSION_NAME $CHANNEL_NAME $domain_string LOW RATIO 0.0 $nr_notification_expected $(( $i % 2)) + start_client $high_app_output_file $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO 0.420 $nr_notification_expected $(( $i % 2)) done - wait_for_message "${low_output_file_pattern}" "sync: ready" - wait_for_message "${high_output_file_pattern}" "sync: ready" + wait_for_message $output_dir "${low_output_file_pattern}" "sync: ready" + wait_for_message $output_dir "${high_output_file_pattern}" "sync: ready" # Test notification reception for (( i = 0; i < $nr_notification_expected; i++ )); do @@ -253,7 +194,7 @@ function test_multi_app () stop_consumerd "${pipe}" done - wait_for_message "${high_output_file_pattern}" "notification: high $i" + wait_for_message $output_dir "${high_output_file_pattern}" "notification: high $i" # Put application in suspend mode to prevent double low # notification and synchronize on state file. @@ -267,10 +208,10 @@ function test_multi_app () resume_consumerd "${pipe}" done # Stop tracing forcing full buffer consumption - stop_lttng_tracing $SESSION_NAME + stop_lttng_tracing_ok $SESSION_NAME # Check for notifications reception - wait_for_message "${low_output_file_pattern}" "notification: low $i" + wait_for_message $output_dir "${low_output_file_pattern}" "notification: low $i" ret=$? ok $ret "Notifications $i received" if [[ $ret -ne "0" ]]; then @@ -285,43 +226,40 @@ function test_multi_app () done done - wait_for_message "${low_output_file_pattern}" "exit: 0" + wait_for_message $output_dir "${low_output_file_pattern}" "exit: 0" ret=$? ok $ret "Application for low notification terminated normally" - if [[ $ret -eq "0" ]]; then - rm ${CURDIR}/${low_output_file_pattern}* 2> /dev/null - else - # Keep the file - print_errors "${low_output_file_pattern}" + if [[ $ret -ne "0" ]]; then + print_errors $output_dir "${low_output_file_pattern}" fi - wait_for_message "${high_output_file_pattern}" "exit: 0" + wait_for_message $output_dir "${high_output_file_pattern}" "exit: 0" ret=$? ok $ret "Application for high notification terminated normally" - if [[ $ret -eq "0" ]]; then - rm ${CURDIR}/${high_output_file_pattern}* 2> /dev/null - else - # Keep the file - print_errors "${high_output_file_pattern}" + if [[ $ret -ne "0" ]]; then + print_errors $output_dir "${high_output_file_pattern}" fi + destroy_lttng_session_ok $SESSION_NAME stop_lttng_sessiond for pipe in "${consumerd_pipe[@]}"; do rm -rf "${pipe}" done + + rm -rf $output_dir } function test_multi_app_ust () { diag "Multi client app UST notification" - ust_event_generator $TESTAPP_STATE_FILE & + ust_event_generator "$TESTAPP_BIN" "$TESTAPP_STATE_FILE" & local generator_pid=$! test_multi_app ust $generator_pid - kill -9 $generator_pid 2> /dev/null + kill -s SIGUSR2 $generator_pid 2> /dev/null wait $generator_pid 2> /dev/null rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null } @@ -331,17 +269,17 @@ function test_multi_app_kernel () diag "Multi client app kernel notification" modprobe lttng-test - kernel_event_generator $TESTAPP_STATE_FILE & + kernel_event_generator generate_filter_events $TESTAPP_STATE_FILE & local generator_pid=$! test_multi_app kernel $generator_pid - kill -9 $generator_pid 2>/dev/null + kill -s SIGUSR2 $generator_pid 2> /dev/null wait $generator_pid 2> /dev/null rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null - rmmod lttng-test + modprobe --remove lttng-test } function test_on_register_evaluation_ust () @@ -349,12 +287,12 @@ function test_on_register_evaluation_ust () diag "On register notification UST" # Start app in infinite loop - ust_event_generator $TESTAPP_STATE_FILE & + ust_event_generator "$TESTAPP_BIN" "$TESTAPP_STATE_FILE" & local generator_pid=$! test_on_register_evaluation ust $generator_pid - kill -9 $generator_pid 2> /dev/null + kill -s SIGUSR2 $generator_pid 2> /dev/null wait $generator_pid 2> /dev/null rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null @@ -366,17 +304,17 @@ function test_on_register_evaluation_kernel() modprobe lttng-test - kernel_event_generator $TESTAPP_STATE_FILE & + kernel_event_generator generate_filter_events $TESTAPP_STATE_FILE & local generator_pid=$! test_on_register_evaluation kernel $generator_pid - kill -9 $generator_pid 2> /dev/null + kill -s SIGUSR2 $generator_pid 2> /dev/null wait $generator_pid 2> /dev/null rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null - rmmod lttng-test + modprobe --remove lttng-test } function test_on_register_evaluation () @@ -387,14 +325,12 @@ function test_on_register_evaluation () local app_pids=() local high_output_file_pattern="high_app_output_file_on_register_evaluation" - local testpoint_base_path=$(readlink -f "$CURDIR/lttng.t_p_n_register_evaluation") - local testpoint_pipe_path=$(mktemp -u "${testpoint_base_path}.XXXXXX") + local output_dir=$(mktemp --tmpdir -d "tmp.test_${FUNCNAME[0]}_output_dir.XXXXXX") + local testpoint_base_path=$(readlink -f "$output_dir/lttng.t_p_n_register_evaluation") + local testpoint_pipe_path=$(mktemp --tmpdir="$output_dir" -u "lttng.t_p_n_register_evaluation.XXXXXX") local domain_string="" local event_name="" - # Cleanup - rm ${CURDIR}/${high_output_file_pattern}* 2> /dev/null - case $domain_type in ust) domain_string=LTTNG_DOMAIN_UST @@ -420,15 +356,16 @@ function test_on_register_evaluation () # Fetch consumerd testpoint pipe information # This is needed since the testpoint create a pipe with the consumer type suffixed - for f in "$testpoint_base_path"*; do + consumerd_pipe=() + for f in "$testpoint_pipe_path"*; do consumerd_pipe+=("$f") done high_app_output_file=${high_output_file_pattern}.first_receiver - high_app_output_path=$CURDIR/${high_app_output_file} - start_client $high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO 0.420 1 + high_app_output_path=$output_dir/${high_app_output_file} + start_client $high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO 0.420 1 0 - wait_for_message "${high_app_output_file}" "sync: ready" + wait_for_message $output_dir "${high_app_output_file}" "sync: ready" # Stop consumerd consumption to force high notification start_lttng_tracing_ok $SESSION_NAME @@ -437,41 +374,41 @@ function test_on_register_evaluation () stop_consumerd "${pipe}" done - wait_for_message "${high_app_output_file}" "notification: high 0" + wait_for_message $output_dir "${high_app_output_file}" "notification: high 0" # Start a second receiver, the receiver should receive a high # notification on subscription high_app_output_file=${high_output_file_pattern}.second_receiver - high_app_output_path=$CURDIR/${high_app_output_file} - start_client $high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO 0.420 1 - wait_for_message "${high_app_output_file}" "sync: ready" - wait_for_message "${high_app_output_file}" "notification: high 0" + high_app_output_path=$output_dir/${high_app_output_file} + start_client $high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO 0.420 1 0 + wait_for_message $output_dir "${high_app_output_file}" "sync: ready" + wait_for_message $output_dir "${high_app_output_file}" "notification: high 0" # Resume consumerd for pipe in "${consumerd_pipe[@]}"; do resume_consumerd "${pipe}" done - wait_for_message "${high_output_file_pattern}" "exit: 0" + wait_for_message $output_dir "${high_output_file_pattern}" "exit: 0" ret=$? ok $ret "Application for high notification terminated normally" - if [[ $ret -eq "0" ]]; then - rm ${CURDIR}/${high_output_file_pattern}* 2> /dev/null - else + if [[ $ret -ne "0" ]]; then # Keep the file print_errors "${high_output_file_pattern}" fi + destroy_lttng_session_ok $SESSION_NAME stop_lttng_sessiond - kill -9 $generator_pid + kill -s SIGUSR2 $generator_pid 2> /dev/null wait $generator_pid 2> /dev/null for pipe in "${consumerd_pipe[@]}"; do rm -rf "${pipe}" done + rm -rf "$output_dir" } @@ -481,6 +418,7 @@ TESTS=( ) if [ "$(id -u)" == "0" ]; then + validate_lttng_modules_present TESTS+=( test_multi_app_kernel test_on_register_evaluation_kernel @@ -492,7 +430,7 @@ fi for fct_test in ${TESTS[@]}; do - TRACE_PATH=$(mktemp -d) + TRACE_PATH=$(mktemp --tmpdir -d tmp.test_notification_multi_app_trace_path.XXXXXX) ${fct_test} if [ $? -ne 0 ]; then