| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) - 2012 David Goulet <dgoulet@efficios.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 | TEST_DESC="UST tracer - Tracing with per UID buffers and periodical flush" |
| 18 | |
| 19 | CURDIR=$(dirname $0)/ |
| 20 | TESTDIR=$CURDIR/../../.. |
| 21 | NR_ITER=100 |
| 22 | NR_USEC_WAIT=100000 |
| 23 | TESTAPP_PATH="$TESTDIR/utils/testapp" |
| 24 | TESTAPP_NAME="gen-ust-events" |
| 25 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" |
| 26 | SESSION_NAME="periodical-flush" |
| 27 | EVENT_NAME="tp:tptest" |
| 28 | BIN_NAME="gen-nevents" |
| 29 | NUM_TESTS=38 |
| 30 | APP_TMP_FILE="/tmp/lttng_test_ust.42.file" |
| 31 | |
| 32 | source $TESTDIR/utils/utils.sh |
| 33 | |
| 34 | if [ ! -x "$TESTAPP_BIN" ]; then |
| 35 | BAIL_OUT "No UST events binary detected." |
| 36 | fi |
| 37 | |
| 38 | # MUST set TESTDIR before calling those functions |
| 39 | |
| 40 | function enable_channel_per_uid() |
| 41 | { |
| 42 | local sess_name=$1 |
| 43 | local channel_name=$2 |
| 44 | |
| 45 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name --switch-timer 100000 >/dev/null 2>&1 |
| 46 | ok $? "Enable channel $channel_name per UID for session $sess_name" |
| 47 | } |
| 48 | |
| 49 | function enable_channel_per_pid() |
| 50 | { |
| 51 | local sess_name=$1 |
| 52 | local channel_name=$2 |
| 53 | |
| 54 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-pid -u $channel_name -s $sess_name --switch-timer 100000 >/dev/null 2>&1 |
| 55 | ok $? "Enable channel $channel_name per UID for session $sess_name" |
| 56 | } |
| 57 | |
| 58 | function enable_metadata_per_uid() |
| 59 | { |
| 60 | local sess_name=$1 |
| 61 | local channel_name="metadata" |
| 62 | |
| 63 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name --switch-timer 200000 >/dev/null 2>&1 |
| 64 | ok $? "Enable channel $channel_name per UID for session $sess_name" |
| 65 | } |
| 66 | |
| 67 | function enable_metadata_per_pid() |
| 68 | { |
| 69 | local sess_name=$1 |
| 70 | local channel_name="metadata" |
| 71 | |
| 72 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-pid -u $channel_name -s $sess_name --switch-timer 200000 >/dev/null 2>&1 |
| 73 | ok $? "Enable channel $channel_name per PID for session $sess_name" |
| 74 | } |
| 75 | |
| 76 | function wait_apps |
| 77 | { |
| 78 | diag "Waiting for applications to end..." |
| 79 | while [ -n "$(pidof $TESTAPP_NAME)" ]; do |
| 80 | sleep 1 |
| 81 | done |
| 82 | } |
| 83 | |
| 84 | function validate_trace() |
| 85 | { |
| 86 | local out |
| 87 | |
| 88 | out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l) |
| 89 | if [ $out -eq 0 ]; then |
| 90 | fail "Trace validation" |
| 91 | diag "No event(s) found. We are supposed to have at least one." |
| 92 | out=1 |
| 93 | else |
| 94 | pass "Trace validation" |
| 95 | diag "Found $out event(s). Coherent." |
| 96 | out=0 |
| 97 | fi |
| 98 | |
| 99 | return $out |
| 100 | } |
| 101 | |
| 102 | function check_app_tmp_file() |
| 103 | { |
| 104 | # Wait for the application file to appear indicating that at least one |
| 105 | # tracepoint has been fired. |
| 106 | while [ ! -f "$APP_TMP_FILE" ]; do |
| 107 | sleep 0.5 |
| 108 | done |
| 109 | diag "Removing test app temporary file $APP_TMP_FILE" |
| 110 | rm -f $APP_TMP_FILE |
| 111 | } |
| 112 | |
| 113 | function start_trace_app() |
| 114 | { |
| 115 | # Start application with a temporary file. |
| 116 | $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $APP_TMP_FILE & |
| 117 | ok $? "Start application to trace" |
| 118 | } |
| 119 | |
| 120 | function start_check_trace_app() |
| 121 | { |
| 122 | start_trace_app |
| 123 | check_app_tmp_file |
| 124 | } |
| 125 | |
| 126 | test_after_app_pid() { |
| 127 | local out |
| 128 | |
| 129 | diag "Start application AFTER tracing is started" |
| 130 | |
| 131 | create_lttng_session $SESSION_NAME $TRACE_PATH |
| 132 | enable_metadata_per_pid $SESSION_NAME |
| 133 | enable_channel_per_pid $SESSION_NAME "channel0" |
| 134 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0" |
| 135 | start_lttng_tracing $SESSION_NAME |
| 136 | |
| 137 | # Start application after tracing |
| 138 | start_check_trace_app |
| 139 | # After this point we are sure that at least one event has been hit. |
| 140 | |
| 141 | # Make sure the application does not generate any more data, |
| 142 | # thus ensuring that we are not flushing a packet concurrently |
| 143 | # with validate_trace. |
| 144 | killall -SIGSTOP -q $TESTAPP_NAME |
| 145 | |
| 146 | # Give time to the consumer to write inflight data. |
| 147 | sleep 2 |
| 148 | |
| 149 | validate_trace |
| 150 | out=$? |
| 151 | |
| 152 | stop_lttng_tracing $SESSION_NAME |
| 153 | destroy_lttng_session $SESSION_NAME |
| 154 | |
| 155 | killall -SIGKILL -q $TESTAPP_NAME |
| 156 | wait_apps |
| 157 | |
| 158 | return $out |
| 159 | } |
| 160 | |
| 161 | test_before_app_pid() { |
| 162 | local out |
| 163 | local tmp_file="/tmp/lttng_test_ust.42.file" |
| 164 | |
| 165 | diag "Start application BEFORE tracing is started" |
| 166 | |
| 167 | start_trace_app |
| 168 | |
| 169 | # Start application before tracing |
| 170 | create_lttng_session $SESSION_NAME $TRACE_PATH |
| 171 | enable_metadata_per_pid $SESSION_NAME |
| 172 | enable_channel_per_pid $SESSION_NAME "channel0" |
| 173 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0" |
| 174 | start_lttng_tracing $SESSION_NAME |
| 175 | |
| 176 | check_app_tmp_file |
| 177 | # Let the application at least perform a flush! |
| 178 | sleep 2 |
| 179 | |
| 180 | # Make sure the application does not generate any more data, |
| 181 | # thus ensuring that we are not flushing a packet concurrently |
| 182 | # with validate_trace. |
| 183 | killall -SIGSTOP -q $TESTAPP_NAME |
| 184 | |
| 185 | # Give time to the consumer to write inflight data. |
| 186 | sleep 2 |
| 187 | |
| 188 | validate_trace |
| 189 | out=$? |
| 190 | |
| 191 | stop_lttng_tracing $SESSION_NAME |
| 192 | destroy_lttng_session $SESSION_NAME |
| 193 | |
| 194 | killall -SIGKILL -q $TESTAPP_NAME |
| 195 | wait_apps |
| 196 | |
| 197 | return $out |
| 198 | } |
| 199 | |
| 200 | test_after_app_uid() { |
| 201 | local out |
| 202 | |
| 203 | diag "Start application AFTER tracing is started" |
| 204 | |
| 205 | create_lttng_session $SESSION_NAME $TRACE_PATH |
| 206 | enable_metadata_per_uid $SESSION_NAME |
| 207 | enable_channel_per_uid $SESSION_NAME "channel0" |
| 208 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0" |
| 209 | start_lttng_tracing $SESSION_NAME |
| 210 | |
| 211 | # Start application after tracing |
| 212 | start_check_trace_app |
| 213 | # After this point we are sure that at least one event has been hit. |
| 214 | |
| 215 | # Make sure the application does not generate any more data, |
| 216 | # thus ensuring that we are not flushing a packet concurrently |
| 217 | # with validate_trace. |
| 218 | killall -SIGSTOP -q $TESTAPP_NAME |
| 219 | |
| 220 | # Give time to the consumer to write inflight data. |
| 221 | sleep 2 |
| 222 | |
| 223 | validate_trace |
| 224 | out=$? |
| 225 | |
| 226 | stop_lttng_tracing $SESSION_NAME |
| 227 | destroy_lttng_session $SESSION_NAME |
| 228 | |
| 229 | killall -SIGKILL -q $TESTAPP_NAME |
| 230 | wait_apps |
| 231 | |
| 232 | return $out |
| 233 | } |
| 234 | |
| 235 | test_before_app_uid() { |
| 236 | local out |
| 237 | |
| 238 | diag "Start application BEFORE tracing is started" |
| 239 | |
| 240 | # Start application before tracing |
| 241 | start_trace_app |
| 242 | |
| 243 | create_lttng_session $SESSION_NAME $TRACE_PATH |
| 244 | enable_metadata_per_uid $SESSION_NAME |
| 245 | enable_channel_per_uid $SESSION_NAME "channel0" |
| 246 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0" |
| 247 | start_lttng_tracing $SESSION_NAME |
| 248 | |
| 249 | check_app_tmp_file |
| 250 | # Let the application at least perform a flush! |
| 251 | sleep 2 |
| 252 | |
| 253 | # Make sure the application does not generate any more data, |
| 254 | # thus ensuring that we are not flushing a packet concurrently |
| 255 | # with validate_trace. |
| 256 | killall -SIGSTOP -q $TESTAPP_NAME |
| 257 | |
| 258 | # Give time to the consumer to write inflight data. |
| 259 | sleep 2 |
| 260 | |
| 261 | validate_trace |
| 262 | out=$? |
| 263 | |
| 264 | stop_lttng_tracing $SESSION_NAME |
| 265 | destroy_lttng_session $SESSION_NAME |
| 266 | |
| 267 | killall -SIGKILL -q $TESTAPP_NAME |
| 268 | wait_apps |
| 269 | |
| 270 | return $out |
| 271 | } |
| 272 | |
| 273 | # MUST set TESTDIR before calling those functions |
| 274 | plan_tests $NUM_TESTS |
| 275 | |
| 276 | print_test_banner "$TEST_DESC" |
| 277 | |
| 278 | TESTS=( |
| 279 | "test_before_app_uid" |
| 280 | "test_after_app_uid" |
| 281 | "test_before_app_pid" |
| 282 | "test_after_app_pid" |
| 283 | ) |
| 284 | |
| 285 | TEST_COUNT=${#TESTS[@]} |
| 286 | i=0 |
| 287 | |
| 288 | start_lttng_sessiond |
| 289 | |
| 290 | while [ $i -lt $TEST_COUNT ]; do |
| 291 | TRACE_PATH=$(mktemp -d) |
| 292 | ${TESTS[$i]} |
| 293 | rm -rf $TRACE_PATH |
| 294 | let "i++" |
| 295 | done |
| 296 | |
| 297 | stop_lttng_sessiond |