c340bd597415115af33df022d10d06ab1240ac33
[lttng-tools.git] / tests / regression / tools / streaming / test_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 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 NUM_TESTS=186
30
31 source $TESTDIR/utils/utils.sh
32
33 print_test_banner "$TEST_DESC"
34
35 if [ ! -x "$CURDIR/$BIN_NAME" ]; then
36 BAIL_OUT "No UST nevents binary detected. Skipping."
37 fi
38
39 function lttng_create_session
40 {
41 URI=$1
42 # Create session with custom URI
43 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create -U $URI $SESSION_NAME >/dev/null 2>&1
44 ok $? "Create session with uri $URI"
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 ok $? "Enable consumer with uri $URI"
53 }
54
55 function run_apps
56 {
57 # Run 5 times with a 1 second delay
58 COUNT=5
59 APP_DELAY=1000000
60 ./$CURDIR/$BIN_NAME $COUNT $APP_DELAY >/dev/null 2>&1 &
61 }
62
63 function wait_apps
64 {
65 while [ -n "$(pidof $BIN_NAME)" ]; do
66 sleep 0.5
67 done
68 pass "Wait for applications to end"
69 }
70
71 function test_uri_switch_localhost_folder
72 {
73 IPVER=$1
74
75 diag "Test switch of localhost folder ($IPVER)"
76
77 if [ "$IPVER" == "IPv6" ]; then
78 BASE_URI="net6://localhost"
79 else
80 BASE_URI="net://localhost"
81 fi
82
83 RANDCOUNT=10
84 RAND=""
85 i=1
86
87 lttng_create_session $BASE_URI
88
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 pass "Randomize output folder on $BASE_URI"
97
98 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
99 start_lttng_tracing $SESSION_NAME
100 run_apps
101 wait_apps
102 stop_lttng_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
116 diag "Test 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 diag "$FILE_URI -> $NETWORK_URI/$NET_PATH"
135
136 lttng_create_session $FILE_URI
137 lttng_enable_consumer "$NETWORK_URI/$NET_PATH"
138 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
139 start_lttng_tracing $SESSION_NAME
140 run_apps
141 wait_apps
142 stop_lttng_tracing $SESSION_NAME
143 destroy_lttng_session $SESSION_NAME
144 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$NET_PATH
145
146 if [ $? -eq 0 ]; then
147 # Only delete if successful
148 rm -rf $TRACE_PATH
149 else
150 break
151 fi
152 done
153 done
154 rm -rf $TMP_PATH
155 }
156
157 function test_uri_switch_network_file
158 {
159 IPVER=$1
160 diag "Test 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 diag "$NETWORK_URI -> $FILE_URI/$FILE_PATH"
177
178 lttng_create_session $NETWORK_URI
179 lttng_enable_consumer "$FILE_URI/$FILE_PATH"
180 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
181 start_lttng_tracing $SESSION_NAME
182 run_apps
183 wait_apps
184 stop_lttng_tracing $SESSION_NAME
185 destroy_lttng_session $SESSION_NAME
186 validate_trace $EVENT_NAME $TMP_PATH/$FILE_PATH
187
188 if [ $? -eq 0 ]; then
189 # Only delete if successful
190 rm -rf $TMP_PATH
191 else
192 break
193 fi
194 done
195 }
196
197 plan_tests $NUM_TESTS
198
199 start_lttng_sessiond
200
201 diag "Test with IPv4"
202 start_lttng_relayd "-o $TRACE_PATH"
203 test_uri_switch_localhost_folder "IPv4"
204 test_uri_switch_file_network "IPv4"
205 test_uri_switch_network_file "IPv4"
206 stop_lttng_relayd
207
208 diag "Test with IPv6"
209 start_lttng_relayd "-o $TRACE_PATH -C tcp6://localhost:5342 -D tcp6://localhost:5343"
210 test_uri_switch_localhost_folder "IPv6"
211 test_uri_switch_file_network "IPv6"
212 test_uri_switch_network_file "IPv6"
213 stop_lttng_relayd
214
215 stop_lttng_sessiond
This page took 0.03418 seconds and 4 git commands to generate.