| 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 | 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" |
| 28 | |
| 29 | NR_ITER=-1 |
| 30 | NR_USEC_WAIT=5 |
| 31 | |
| 32 | SESSION_NAME="my_session" |
| 33 | UST_CHANNEL_NAME="my_ust_channel" |
| 34 | EVENT_NAME="tp:tptest" |
| 35 | |
| 36 | |
| 37 | TRACE_PATH=$(mktemp -d) |
| 38 | |
| 39 | DIR=$(readlink -f $TESTDIR) |
| 40 | |
| 41 | PAGE_SIZE=$(getconf PAGE_SIZE) |
| 42 | |
| 43 | NUM_TESTS=46 |
| 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=() |
| 56 | function start_client { |
| 57 | local pid=-1 |
| 58 | local output_file=$1 |
| 59 | local session_name=$2 |
| 60 | local channel_name=$3 |
| 61 | local domain_type=$4 |
| 62 | local buffer_usage_type=$5 |
| 63 | local buffer_usage_threshold_type=$6 |
| 64 | local buffer_usage_threshold_value=$7 |
| 65 | local nr_expected_notification=$8 |
| 66 | |
| 67 | ${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} & |
| 68 | pid=$! |
| 69 | |
| 70 | app_pids+=("$pid") |
| 71 | } |
| 72 | |
| 73 | function wait_for_message () |
| 74 | { |
| 75 | local file_pattern=$1 |
| 76 | local message=$2 |
| 77 | |
| 78 | for file in $CURDIR/${file_pattern}*; do |
| 79 | while(true); do |
| 80 | # Check for "error" message |
| 81 | grep -q "error:" ${file} |
| 82 | app_error=$? |
| 83 | if [ $app_error -eq "0" ] ; then |
| 84 | # An error occurred |
| 85 | fail "Waiting message: error logged see file content: ${message}, ${file}" |
| 86 | return 1 |
| 87 | fi |
| 88 | |
| 89 | grep -q "${message}" ${file} |
| 90 | if [[ "$?" -ne "0" ]]; then |
| 91 | # Lookup failed restart loop |
| 92 | diag "Lookup failed sleep and retry grep for: ${message}, ${file}" |
| 93 | sleep 0.25 |
| 94 | continue |
| 95 | fi |
| 96 | break |
| 97 | done |
| 98 | done |
| 99 | pass "Message received: ${message}" |
| 100 | return 0 |
| 101 | } |
| 102 | |
| 103 | function print_errors () |
| 104 | { |
| 105 | local file_pattern=$1 |
| 106 | |
| 107 | for file in $CURDIR/${file_pattern}*; do |
| 108 | # Check for "error" message |
| 109 | error_message=$(grep "error:" ${file}) |
| 110 | if [[ "${error_message}" -ne "" ]]; then |
| 111 | diag "Errors for application ${file}:" |
| 112 | diag "${error_message}" |
| 113 | fi |
| 114 | done |
| 115 | } |
| 116 | |
| 117 | function comm_consumerd () |
| 118 | { |
| 119 | local message=$1 |
| 120 | local pipe=$2 |
| 121 | echo -ne "${message}" > "${pipe}" |
| 122 | return $? |
| 123 | } |
| 124 | |
| 125 | function stop_consumerd () |
| 126 | { |
| 127 | local pipe=$1 |
| 128 | comm_consumerd "1" "$pipe" |
| 129 | ok $? "Stopping consumption consumerd" |
| 130 | } |
| 131 | |
| 132 | function resume_consumerd () |
| 133 | { |
| 134 | local pipe=$1 |
| 135 | comm_consumerd "\0" "$pipe" |
| 136 | ok $? "Resuming consumerd" |
| 137 | } |
| 138 | |
| 139 | function test_multi_app () |
| 140 | { |
| 141 | local app_pids=() |
| 142 | local low_output_file_pattern="low_app_output_file_" |
| 143 | local high_output_file_pattern="high_app_output_file_" |
| 144 | |
| 145 | local testpoint_base_path=$(readlink -f "$CURDIR/lttng.t_p_n_multi_app") |
| 146 | local testpoint_pipe_path=$(mktemp -u "${testpoint_base_path}.XXXXXX") |
| 147 | |
| 148 | local nr_notification_expected=5 |
| 149 | local nr_client_app=50 |
| 150 | |
| 151 | # Cleanup |
| 152 | rm ${CURDIR}/${low_output_file_pattern}* 2> /dev/null |
| 153 | rm ${CURDIR}/${high_output_file_pattern}* 2> /dev/null |
| 154 | |
| 155 | # Setup |
| 156 | LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}" |
| 157 | start_lttng_sessiond |
| 158 | |
| 159 | # Start app in infinite loop |
| 160 | $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $file_sync_after_first_event & |
| 161 | app_pid=$! |
| 162 | # Pin to CPU zero to force specific sub buffer usage |
| 163 | taskset -p -c 0 $app_pid > /dev/null 2>&1 |
| 164 | |
| 165 | # Wait for sync with app |
| 166 | while [ ! -f "${file_sync_after_first_event}" ]; do |
| 167 | sleep 0.5 |
| 168 | done |
| 169 | rm ${file_sync_after_first_event} |
| 170 | |
| 171 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 172 | enable_ust_lttng_channel_ok $SESSION_NAME $UST_CHANNEL_NAME --subbuf-size=$PAGE_SIZE |
| 173 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $UST_CHANNEL_NAME |
| 174 | |
| 175 | # Fetch consumerd testpoint pipe information |
| 176 | # This is needed since the testpoint create a pipe with the consumer type suffixed |
| 177 | for f in "$testpoint_base_path"*; do |
| 178 | consumerd_pipe+=("$f") |
| 179 | done |
| 180 | |
| 181 | for (( i = 0; i < $nr_client_app; i++ )); do |
| 182 | low_app_output_file=$CURDIR/${low_output_file_pattern}${i} |
| 183 | high_app_output_file=$CURDIR/${high_output_file_pattern}${i} |
| 184 | start_client $low_app_output_file $SESSION_NAME $UST_CHANNEL_NAME LTTNG_DOMAIN_UST LOW RATIO 0.0 $nr_notification_expected |
| 185 | start_client $high_app_output_file $SESSION_NAME $UST_CHANNEL_NAME LTTNG_DOMAIN_UST HIGH RATIO 0.420 $nr_notification_expected |
| 186 | done |
| 187 | |
| 188 | wait_for_message "${low_output_file_pattern}" "sync: ready" |
| 189 | wait_for_message "${high_output_file_pattern}" "sync: ready" |
| 190 | |
| 191 | # Test notification reception |
| 192 | for (( i = 0; i < $nr_notification_expected; i++ )); do |
| 193 | |
| 194 | # Stop consumerd consumption to force high notification |
| 195 | start_lttng_tracing_ok $SESSION_NAME |
| 196 | for pipe in "${consumerd_pipe[@]}"; do |
| 197 | stop_consumerd "${pipe}" |
| 198 | done |
| 199 | |
| 200 | wait_for_message "${high_output_file_pattern}" "notification: high $i" |
| 201 | |
| 202 | # Resume consumerd |
| 203 | for pipe in "${consumerd_pipe[@]}"; do |
| 204 | resume_consumerd "${pipe}" |
| 205 | done |
| 206 | # Stop tracing forcing full buffer consumption |
| 207 | stop_lttng_tracing $SESSION_NAME |
| 208 | |
| 209 | # Check for notifications reception |
| 210 | wait_for_message "${low_output_file_pattern}" "notification: low $i" |
| 211 | ret=$? |
| 212 | ok $ret "Notifications $i received" |
| 213 | if [[ $ret -ne "0" ]]; then |
| 214 | # Error occurred bail out |
| 215 | break; |
| 216 | fi |
| 217 | done |
| 218 | |
| 219 | wait_for_message "${low_output_file_pattern}" "exit: 0" |
| 220 | ret=$? |
| 221 | ok $ret "Application for low notification terminated normally" |
| 222 | if [[ $ret -eq "0" ]]; then |
| 223 | rm ${CURDIR}/${low_output_file_pattern}* 2> /dev/null |
| 224 | else |
| 225 | # Keep the file |
| 226 | print_errors "${low_output_file_pattern}" |
| 227 | fi |
| 228 | |
| 229 | wait_for_message "${high_output_file_pattern}" "exit: 0" |
| 230 | ret=$? |
| 231 | ok $ret "Application for high notification terminated normally" |
| 232 | if [[ $ret -eq "0" ]]; then |
| 233 | rm ${CURDIR}/${high_output_file_pattern}* 2> /dev/null |
| 234 | else |
| 235 | # Keep the file |
| 236 | print_errors "${high_output_file_pattern}" |
| 237 | fi |
| 238 | |
| 239 | kill -9 $app_pid |
| 240 | wait $app_pid 2> /dev/null |
| 241 | |
| 242 | stop_lttng_sessiond |
| 243 | } |
| 244 | |
| 245 | |
| 246 | TESTS=( |
| 247 | test_multi_app |
| 248 | ) |
| 249 | |
| 250 | for fct_test in ${TESTS[@]}; |
| 251 | do |
| 252 | TRACE_PATH=$(mktemp -d) |
| 253 | |
| 254 | ${fct_test} |
| 255 | if [ $? -ne 0 ]; then |
| 256 | break; |
| 257 | fi |
| 258 | |
| 259 | # Only delete if successful |
| 260 | rm -rf $TRACE_PATH |
| 261 | done |
| 262 | |