New URI switching tests
[lttng-tools.git] / tests / tools / streaming / uri_switch
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
19 CURDIR=$(dirname $0)/
20 TESTDIR=$CURDIR/../..
21 BIN_NAME="gen-ust-events"
22 SESSION_NAME="stream"
23 EVENT_NAME="tp:tptest"
24 PID_RELAYD=0
25
26 TRACE_PATH=$(mktemp -d)
27
28 source $TESTDIR/utils.sh
29
30 echo -e "\n"
31 echo -e "---------------------------"
32 echo -e " Streaming - URI switching "
33 echo -e "---------------------------"
34
35 if [ ! -x "$CURDIR/$BIN_NAME" ]; then
36 echo -e "No UST nevents binary detected. Skipping."
37 exit 0
38 fi
39
40 function lttng_create_session
41 {
42 URI=$1
43 # Create session with custom URI
44 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create -U $URI $SESSION_NAME >/dev/null 2>&1
45 }
46
47 function lttng_enable_consumer
48 {
49 URI=$1
50 # Create session with custom URI
51 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-consumer -u $URI >/dev/null 2>&1
52 }
53
54 function run_apps
55 {
56 # Run 5 times with a 1 second delay
57 COUNT=5
58 APP_DELAY=1000000
59 ./$CURDIR/$BIN_NAME $COUNT $APP_DELAY >/dev/null 2>&1 &
60
61 }
62
63 function wait_apps
64 {
65 echo -n "Waiting for applications to end"
66 while [ -n "$(pidof $BIN_NAME)" ]; do
67 echo -n "."
68 sleep 0.5
69 done
70 echo ""
71 }
72
73 function test_uri_switch_localhost_folder
74 {
75 IPVER=$1
76 echo -e "\n=== Testing switch of localhost folder ($IPVER)\n"
77
78 if [ "$IPVER" == "IPv6" ]; then
79 BASE_URI="net6://localhost"
80 else
81 BASE_URI="net://localhost"
82 fi
83
84 RANDCOUNT=10
85 RAND=""
86 i=1
87
88 lttng_create_session $BASE_URI
89
90 echo -e "Randomizing output folder on $BASE_URI..."
91 while [ "$i" -le $RANDCOUNT ]
92 do
93 RAND=$(randstring 16 0)
94 lttng_enable_consumer "$BASE_URI/$RAND"
95 let "i += 1"
96 done
97
98 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
99 start_tracing $SESSION_NAME
100 run_apps
101 wait_apps
102 stop_tracing $SESSION_NAME
103 destroy_lttng_session $SESSION_NAME
104 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$RAND
105
106 if [ $? -eq 0 ]; then
107 # Only delete if successful
108 rm -rf $TRACE_PATH
109 else
110 break
111 fi
112 }
113
114 function test_uri_switch_file_network
115 {
116 IPVER=$1
117 echo ""
118 echo -e "=== Testing switch file -> network ($IPVER)"
119
120 TMP_PATH=$(mktemp -d)
121 FILE_URI="file://$TMP_PATH"
122
123 if [ "$IPVER" == "IPv6" ]; then
124 NETWORK_URIS=("net6://localhost" "net6://[::1]")
125 else
126 NETWORK_URIS=("net://localhost" "net://127.0.0.1")
127 fi
128
129 NET_PATHS=("foo/bar" "OohEehOohAhAahTingTangWallaWallaBingBang" ".")
130
131 for NETWORK_URI in ${NETWORK_URIS[@]};
132 do
133 for NET_PATH in ${NET_PATHS[@]};
134 do
135 SESSION_NAME=$(randstring 16 0)
136 echo ""
137 echo "$FILE_URI -> $NETWORK_URI/$NET_PATH"
138
139 lttng_create_session $FILE_URI
140 lttng_enable_consumer "$NETWORK_URI/$NET_PATH"
141 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
142 start_tracing $SESSION_NAME
143 run_apps
144 wait_apps
145 stop_tracing $SESSION_NAME
146 destroy_lttng_session $SESSION_NAME
147 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$NET_PATH
148
149 if [ $? -eq 0 ]; then
150 # Only delete if successful
151 rm -rf $TRACE_PATH
152 else
153 break
154 fi
155 done
156 done
157 rm -rf $TMP_PATH
158 }
159
160 function test_uri_switch_network_file
161 {
162 IPVER=$1
163 echo ""
164 echo -e "=== Testing switch network ($IPVER) -> file"
165
166 if [ "$IPVER" == "IPv6" ]; then
167 NETWORK_URI="net6://localhost"
168 else
169 NETWORK_URI="net://localhost"
170 fi
171
172 FILE_PATHS=("." "foo/bar" "42")
173
174 for FILE_PATH in ${FILE_PATHS[@]};
175 do
176 TMP_PATH=$(mktemp -d)
177 FILE_URI="file://$TMP_PATH"
178 SESSION_NAME=$(randstring 16 0)
179
180 echo ""
181 echo "$NETWORK_URI -> $FILE_URI/$FILE_PATH"
182
183 lttng_create_session $NETWORK_URI
184 lttng_enable_consumer "$FILE_URI/$FILE_PATH"
185 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
186 start_tracing $SESSION_NAME
187 run_apps
188 wait_apps
189 stop_tracing $SESSION_NAME
190 destroy_lttng_session $SESSION_NAME
191 validate_trace $EVENT_NAME $TMP_PATH/$FILE_PATH
192
193 if [ $? -eq 0 ]; then
194 # Only delete if successful
195 rm -rf $TMP_PATH
196 else
197 break
198 fi
199 done
200 }
201
202
203 start_sessiond
204
205 echo ""
206 echo "=== Testing with IPv4"
207 lttng_start_relayd "-o $TRACE_PATH"
208 test_uri_switch_localhost_folder "IPv4"
209 test_uri_switch_file_network "IPv4"
210 test_uri_switch_network_file "IPv4"
211 lttng_stop_relayd
212
213 echo ""
214 echo "=== Testing with IPv6"
215 lttng_start_relayd "-o $TRACE_PATH -C tcp6://localhost:5342 -D tcp6://localhost:5343"
216 test_uri_switch_localhost_folder "IPv6"
217 test_uri_switch_file_network "IPv6"
218 test_uri_switch_network_file "IPv6"
219 lttng_stop_relayd
220
221 stop_sessiond
This page took 0.033807 seconds and 4 git commands to generate.