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