New URI switching tests
[lttng-tools.git] / tests / tools / streaming / uri_switch
CommitLineData
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
18
19CURDIR=$(dirname $0)/
20TESTDIR=$CURDIR/../..
21BIN_NAME="gen-ust-events"
22SESSION_NAME="stream"
23EVENT_NAME="tp:tptest"
24PID_RELAYD=0
25
26TRACE_PATH=$(mktemp -d)
27
28source $TESTDIR/utils.sh
29
30echo -e "\n"
31echo -e "---------------------------"
32echo -e " Streaming - URI switching "
33echo -e "---------------------------"
34
35if [ ! -x "$CURDIR/$BIN_NAME" ]; then
36 echo -e "No UST nevents binary detected. Skipping."
37 exit 0
38fi
39
40function 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
47function 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
54function 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
63function 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
73function 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
114function 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
160function test_uri_switch_network_file
161{
162IPVER=$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
203start_sessiond
204
205echo ""
206echo "=== Testing with IPv4"
207lttng_start_relayd "-o $TRACE_PATH"
208test_uri_switch_localhost_folder "IPv4"
209test_uri_switch_file_network "IPv4"
210test_uri_switch_network_file "IPv4"
211lttng_stop_relayd
212
213echo ""
214echo "=== Testing with IPv6"
215lttng_start_relayd "-o $TRACE_PATH -C tcp6://localhost:5342 -D tcp6://localhost:5343"
216test_uri_switch_localhost_folder "IPv6"
217test_uri_switch_file_network "IPv6"
218test_uri_switch_network_file "IPv6"
219lttng_stop_relayd
220
221stop_sessiond
This page took 0.031348 seconds and 5 git commands to generate.