a6b158230f4cb4cedd5793a413101508e8948812
[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 fi
110 }
111
112 function test_uri_switch_file_network
113 {
114 IPVER=$1
115 echo ""
116 echo -e "=== Testing switch file -> network ($IPVER)"
117
118 TMP_PATH=$(mktemp -d)
119 FILE_URI="file://$TMP_PATH"
120
121 if [ "$IPVER" == "IPv6" ]; then
122 NETWORK_URIS=("net6://localhost" "net6://[::1]")
123 else
124 NETWORK_URIS=("net://localhost" "net://127.0.0.1")
125 fi
126
127 NET_PATHS=("foo/bar" "OohEehOohAhAahTingTangWallaWallaBingBang" ".")
128
129 for NETWORK_URI in ${NETWORK_URIS[@]};
130 do
131 for NET_PATH in ${NET_PATHS[@]};
132 do
133 SESSION_NAME=$(randstring 16 0)
134 echo ""
135 echo "$FILE_URI -> $NETWORK_URI/$NET_PATH"
136
137 lttng_create_session $FILE_URI
138 lttng_enable_consumer "$NETWORK_URI/$NET_PATH"
139 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
140 start_tracing $SESSION_NAME
141 run_apps
142 wait_apps
143 stop_tracing $SESSION_NAME
144 destroy_lttng_session $SESSION_NAME
145 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$NET_PATH
146
147 if [ $? -eq 0 ]; then
148 # Only delete if successful
149 rm -rf $TRACE_PATH
150 else
151 break
152 fi
153 done
154 done
155 rm -rf $TMP_PATH
156 }
157
158 function test_uri_switch_network_file
159 {
160 IPVER=$1
161 echo ""
162 echo -e "=== Testing switch network ($IPVER) -> file"
163
164 if [ "$IPVER" == "IPv6" ]; then
165 NETWORK_URI="net6://localhost"
166 else
167 NETWORK_URI="net://localhost"
168 fi
169
170 FILE_PATHS=("." "foo/bar" "42")
171
172 for FILE_PATH in ${FILE_PATHS[@]};
173 do
174 TMP_PATH=$(mktemp -d)
175 FILE_URI="file://$TMP_PATH"
176 SESSION_NAME=$(randstring 16 0)
177
178 echo ""
179 echo "$NETWORK_URI -> $FILE_URI/$FILE_PATH"
180
181 lttng_create_session $NETWORK_URI
182 lttng_enable_consumer "$FILE_URI/$FILE_PATH"
183 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
184 start_tracing $SESSION_NAME
185 run_apps
186 wait_apps
187 stop_tracing $SESSION_NAME
188 destroy_lttng_session $SESSION_NAME
189 validate_trace $EVENT_NAME $TMP_PATH/$FILE_PATH
190
191 if [ $? -eq 0 ]; then
192 # Only delete if successful
193 rm -rf $TMP_PATH
194 else
195 break
196 fi
197 done
198 }
199
200
201 start_sessiond
202
203 echo ""
204 echo "=== Testing with IPv4"
205 lttng_start_relayd "-o $TRACE_PATH"
206 test_uri_switch_localhost_folder "IPv4"
207 test_uri_switch_file_network "IPv4"
208 test_uri_switch_network_file "IPv4"
209 lttng_stop_relayd
210
211 echo ""
212 echo "=== Testing with IPv6"
213 lttng_start_relayd "-o $TRACE_PATH -C tcp6://localhost:5342 -D tcp6://localhost:5343"
214 test_uri_switch_localhost_folder "IPv6"
215 test_uri_switch_file_network "IPv6"
216 test_uri_switch_network_file "IPv6"
217 lttng_stop_relayd
218
219 stop_sessiond
This page took 0.033587 seconds and 3 git commands to generate.