| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) - 2012 Christian Babeux <christian.babeux@efficios.com> |
| 4 | # David Goulet <dgoulet@efficios.com> |
| 5 | # |
| 6 | # This library is free software; you can redistribute it and/or modify it under |
| 7 | # the terms of the GNU Lesser General Public License as published by the Free |
| 8 | # Software Foundation; version 2.1 of the License. |
| 9 | # |
| 10 | # This library is distributed in the hope that it will be useful, but WITHOUT |
| 11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 12 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 13 | # details. |
| 14 | # |
| 15 | # You should have received a copy of the GNU Lesser General Public License |
| 16 | # along with this library; if not, write to the Free Software Foundation, Inc., |
| 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | TEST_DESC="Streaming - URI switching" |
| 19 | |
| 20 | CURDIR=$(dirname $0)/ |
| 21 | TESTDIR=$CURDIR/../.. |
| 22 | BIN_NAME="gen-ust-events" |
| 23 | SESSION_NAME="stream" |
| 24 | EVENT_NAME="tp:tptest" |
| 25 | PID_RELAYD=0 |
| 26 | |
| 27 | TRACE_PATH=$(mktemp -d) |
| 28 | |
| 29 | source $TESTDIR/utils.sh |
| 30 | |
| 31 | print_test_banner "$TEST_DESC" |
| 32 | |
| 33 | if [ ! -x "$CURDIR/$BIN_NAME" ]; then |
| 34 | echo -e "No UST nevents binary detected. Skipping." |
| 35 | exit 0 |
| 36 | fi |
| 37 | |
| 38 | function lttng_create_session |
| 39 | { |
| 40 | URI=$1 |
| 41 | # Create session with custom URI |
| 42 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create -U $URI $SESSION_NAME >/dev/null 2>&1 |
| 43 | } |
| 44 | |
| 45 | function lttng_enable_consumer |
| 46 | { |
| 47 | URI=$1 |
| 48 | # Create session with custom URI |
| 49 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-consumer -u $URI >/dev/null 2>&1 |
| 50 | } |
| 51 | |
| 52 | function run_apps |
| 53 | { |
| 54 | # Run 5 times with a 1 second delay |
| 55 | COUNT=5 |
| 56 | APP_DELAY=1000000 |
| 57 | ./$CURDIR/$BIN_NAME $COUNT $APP_DELAY >/dev/null 2>&1 & |
| 58 | |
| 59 | } |
| 60 | |
| 61 | function wait_apps |
| 62 | { |
| 63 | echo -n "Waiting for applications to end" |
| 64 | while [ -n "$(pidof $BIN_NAME)" ]; do |
| 65 | echo -n "." |
| 66 | sleep 0.5 |
| 67 | done |
| 68 | echo "" |
| 69 | } |
| 70 | |
| 71 | function test_uri_switch_localhost_folder |
| 72 | { |
| 73 | IPVER=$1 |
| 74 | echo -e "\n=== Testing switch of localhost folder ($IPVER)\n" |
| 75 | |
| 76 | if [ "$IPVER" == "IPv6" ]; then |
| 77 | BASE_URI="net6://localhost" |
| 78 | else |
| 79 | BASE_URI="net://localhost" |
| 80 | fi |
| 81 | |
| 82 | RANDCOUNT=10 |
| 83 | RAND="" |
| 84 | i=1 |
| 85 | |
| 86 | lttng_create_session $BASE_URI |
| 87 | |
| 88 | echo -e "Randomizing output folder on $BASE_URI..." |
| 89 | while [ "$i" -le $RANDCOUNT ] |
| 90 | do |
| 91 | RAND=$(randstring 16 0) |
| 92 | lttng_enable_consumer "$BASE_URI/$RAND" |
| 93 | let "i += 1" |
| 94 | done |
| 95 | |
| 96 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME |
| 97 | start_lttng_tracing $SESSION_NAME |
| 98 | run_apps |
| 99 | wait_apps |
| 100 | stop_lttng_tracing $SESSION_NAME |
| 101 | destroy_lttng_session $SESSION_NAME |
| 102 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$RAND |
| 103 | |
| 104 | if [ $? -eq 0 ]; then |
| 105 | # Only delete if successful |
| 106 | rm -rf $TRACE_PATH |
| 107 | fi |
| 108 | } |
| 109 | |
| 110 | function test_uri_switch_file_network |
| 111 | { |
| 112 | IPVER=$1 |
| 113 | echo "" |
| 114 | echo -e "=== Testing switch file -> network ($IPVER)" |
| 115 | |
| 116 | TMP_PATH=$(mktemp -d) |
| 117 | FILE_URI="file://$TMP_PATH" |
| 118 | |
| 119 | if [ "$IPVER" == "IPv6" ]; then |
| 120 | NETWORK_URIS=("net6://localhost" "net6://[::1]") |
| 121 | else |
| 122 | NETWORK_URIS=("net://localhost" "net://127.0.0.1") |
| 123 | fi |
| 124 | |
| 125 | NET_PATHS=("foo/bar" "OohEehOohAhAahTingTangWallaWallaBingBang" ".") |
| 126 | |
| 127 | for NETWORK_URI in ${NETWORK_URIS[@]}; |
| 128 | do |
| 129 | for NET_PATH in ${NET_PATHS[@]}; |
| 130 | do |
| 131 | SESSION_NAME=$(randstring 16 0) |
| 132 | echo "" |
| 133 | echo "$FILE_URI -> $NETWORK_URI/$NET_PATH" |
| 134 | |
| 135 | lttng_create_session $FILE_URI |
| 136 | lttng_enable_consumer "$NETWORK_URI/$NET_PATH" |
| 137 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME |
| 138 | start_lttng_tracing $SESSION_NAME |
| 139 | run_apps |
| 140 | wait_apps |
| 141 | stop_lttng_tracing $SESSION_NAME |
| 142 | destroy_lttng_session $SESSION_NAME |
| 143 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$NET_PATH |
| 144 | |
| 145 | if [ $? -eq 0 ]; then |
| 146 | # Only delete if successful |
| 147 | rm -rf $TRACE_PATH |
| 148 | else |
| 149 | break |
| 150 | fi |
| 151 | done |
| 152 | done |
| 153 | rm -rf $TMP_PATH |
| 154 | } |
| 155 | |
| 156 | function test_uri_switch_network_file |
| 157 | { |
| 158 | IPVER=$1 |
| 159 | echo "" |
| 160 | echo -e "=== Testing switch network ($IPVER) -> file" |
| 161 | |
| 162 | if [ "$IPVER" == "IPv6" ]; then |
| 163 | NETWORK_URI="net6://localhost" |
| 164 | else |
| 165 | NETWORK_URI="net://localhost" |
| 166 | fi |
| 167 | |
| 168 | FILE_PATHS=("." "foo/bar" "42") |
| 169 | |
| 170 | for FILE_PATH in ${FILE_PATHS[@]}; |
| 171 | do |
| 172 | TMP_PATH=$(mktemp -d) |
| 173 | FILE_URI="file://$TMP_PATH" |
| 174 | SESSION_NAME=$(randstring 16 0) |
| 175 | |
| 176 | echo "" |
| 177 | echo "$NETWORK_URI -> $FILE_URI/$FILE_PATH" |
| 178 | |
| 179 | lttng_create_session $NETWORK_URI |
| 180 | lttng_enable_consumer "$FILE_URI/$FILE_PATH" |
| 181 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME |
| 182 | start_lttng_tracing $SESSION_NAME |
| 183 | run_apps |
| 184 | wait_apps |
| 185 | stop_lttng_tracing $SESSION_NAME |
| 186 | destroy_lttng_session $SESSION_NAME |
| 187 | validate_trace $EVENT_NAME $TMP_PATH/$FILE_PATH |
| 188 | |
| 189 | if [ $? -eq 0 ]; then |
| 190 | # Only delete if successful |
| 191 | rm -rf $TMP_PATH |
| 192 | else |
| 193 | break |
| 194 | fi |
| 195 | done |
| 196 | } |
| 197 | |
| 198 | |
| 199 | start_lttng_sessiond |
| 200 | |
| 201 | echo "" |
| 202 | echo "=== Testing with IPv4" |
| 203 | start_lttng_relayd "-o $TRACE_PATH" |
| 204 | test_uri_switch_localhost_folder "IPv4" |
| 205 | test_uri_switch_file_network "IPv4" |
| 206 | test_uri_switch_network_file "IPv4" |
| 207 | stop_lttng_relayd |
| 208 | |
| 209 | echo "" |
| 210 | echo "=== Testing with IPv6" |
| 211 | start_lttng_relayd "-o $TRACE_PATH -C tcp6://localhost:5342 -D tcp6://localhost:5343" |
| 212 | test_uri_switch_localhost_folder "IPv6" |
| 213 | test_uri_switch_file_network "IPv6" |
| 214 | test_uri_switch_network_file "IPv6" |
| 215 | stop_lttng_relayd |
| 216 | |
| 217 | stop_lttng_sessiond |