Commit | Line | Data |
---|---|---|
983875b1 CB |
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 | |
c38b5107 | 18 | TEST_DESC="Streaming - URI switching" |
983875b1 CB |
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 | ||
c38b5107 | 31 | print_test_banner "$TEST_DESC" |
983875b1 CB |
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 | |
fb3268e3 | 97 | start_lttng_tracing $SESSION_NAME |
983875b1 CB |
98 | run_apps |
99 | wait_apps | |
fb3268e3 | 100 | stop_lttng_tracing $SESSION_NAME |
983875b1 CB |
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 | |
983875b1 CB |
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 | |
fb3268e3 | 138 | start_lttng_tracing $SESSION_NAME |
983875b1 CB |
139 | run_apps |
140 | wait_apps | |
fb3268e3 | 141 | stop_lttng_tracing $SESSION_NAME |
983875b1 CB |
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 | |
fb3268e3 | 182 | start_lttng_tracing $SESSION_NAME |
983875b1 CB |
183 | run_apps |
184 | wait_apps | |
fb3268e3 | 185 | stop_lttng_tracing $SESSION_NAME |
983875b1 CB |
186 | destroy_lttng_session $SESSION_NAME |
187 | validate_trace $EVENT_NAME $TMP_PATH/$FILE_PATH | |
188 | ||
189 | if [ $? -eq 0 ]; then | |
d007b9c3 DG |
190 | # Only delete if successful |
191 | rm -rf $TMP_PATH | |
983875b1 | 192 | else |
d007b9c3 | 193 | break |
983875b1 CB |
194 | fi |
195 | done | |
196 | } | |
197 | ||
198 | ||
fb3268e3 | 199 | start_lttng_sessiond |
983875b1 CB |
200 | |
201 | echo "" | |
202 | echo "=== Testing with IPv4" | |
fb3268e3 | 203 | start_lttng_relayd "-o $TRACE_PATH" |
983875b1 CB |
204 | test_uri_switch_localhost_folder "IPv4" |
205 | test_uri_switch_file_network "IPv4" | |
206 | test_uri_switch_network_file "IPv4" | |
fb3268e3 | 207 | stop_lttng_relayd |
983875b1 CB |
208 | |
209 | echo "" | |
210 | echo "=== Testing with IPv6" | |
fb3268e3 | 211 | start_lttng_relayd "-o $TRACE_PATH -C tcp6://localhost:5342 -D tcp6://localhost:5343" |
983875b1 CB |
212 | test_uri_switch_localhost_folder "IPv6" |
213 | test_uri_switch_file_network "IPv6" | |
214 | test_uri_switch_network_file "IPv6" | |
fb3268e3 | 215 | stop_lttng_relayd |
983875b1 | 216 | |
fb3268e3 | 217 | stop_lttng_sessiond |