Merge remote-tracking branch 'cbab-github/tests-cleanup' into cbab
[lttng-tools.git] / tests / regression / tools / streaming / test_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
c38b5107 18TEST_DESC="Streaming - URI switching"
983875b1
CB
19
20CURDIR=$(dirname $0)/
9ac429ef 21TESTDIR=$CURDIR/../../..
983875b1
CB
22BIN_NAME="gen-ust-events"
23SESSION_NAME="stream"
24EVENT_NAME="tp:tptest"
25PID_RELAYD=0
26
27TRACE_PATH=$(mktemp -d)
28
d346ccad
CB
29NUM_TESTS=186
30
9ac429ef 31source $TESTDIR/utils/utils.sh
983875b1 32
c38b5107 33print_test_banner "$TEST_DESC"
983875b1
CB
34
35if [ ! -x "$CURDIR/$BIN_NAME" ]; then
d346ccad 36 BAIL_OUT "No UST nevents binary detected. Skipping."
983875b1
CB
37fi
38
39function 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
d346ccad 44 ok $? "Create session with uri $URI"
983875b1
CB
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
d346ccad 52 ok $? "Enable consumer with uri $URI"
983875b1
CB
53}
54
55function 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 &
983875b1
CB
61}
62
63function wait_apps
64{
983875b1 65 while [ -n "$(pidof $BIN_NAME)" ]; do
983875b1
CB
66 sleep 0.5
67 done
d346ccad 68 pass "Wait for applications to end"
983875b1
CB
69}
70
71function test_uri_switch_localhost_folder
72{
73 IPVER=$1
d346ccad
CB
74
75 diag "Test switch of localhost folder ($IPVER)"
983875b1
CB
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
983875b1
CB
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
d346ccad
CB
96 pass "Randomize output folder on $BASE_URI"
97
983875b1 98 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
fb3268e3 99 start_lttng_tracing $SESSION_NAME
983875b1
CB
100 run_apps
101 wait_apps
fb3268e3 102 stop_lttng_tracing $SESSION_NAME
983875b1
CB
103 destroy_lttng_session $SESSION_NAME
104 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$RAND
105
106 if [ $? -eq 0 ]; then
d346ccad
CB
107 # Only delete if successful
108 rm -rf $TRACE_PATH
983875b1
CB
109 fi
110}
111
112function test_uri_switch_file_network
113{
114 IPVER=$1
d346ccad
CB
115
116 diag "Test switch file -> network ($IPVER)"
983875b1
CB
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)
d346ccad 134 diag "$FILE_URI -> $NETWORK_URI/$NET_PATH"
983875b1
CB
135
136 lttng_create_session $FILE_URI
137 lttng_enable_consumer "$NETWORK_URI/$NET_PATH"
138 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
fb3268e3 139 start_lttng_tracing $SESSION_NAME
983875b1
CB
140 run_apps
141 wait_apps
fb3268e3 142 stop_lttng_tracing $SESSION_NAME
983875b1
CB
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
157function test_uri_switch_network_file
158{
d346ccad
CB
159 IPVER=$1
160 diag "Test switch network ($IPVER) -> file"
983875b1
CB
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
d346ccad 176 diag "$NETWORK_URI -> $FILE_URI/$FILE_PATH"
983875b1
CB
177
178 lttng_create_session $NETWORK_URI
179 lttng_enable_consumer "$FILE_URI/$FILE_PATH"
180 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
fb3268e3 181 start_lttng_tracing $SESSION_NAME
983875b1
CB
182 run_apps
183 wait_apps
fb3268e3 184 stop_lttng_tracing $SESSION_NAME
983875b1
CB
185 destroy_lttng_session $SESSION_NAME
186 validate_trace $EVENT_NAME $TMP_PATH/$FILE_PATH
187
188 if [ $? -eq 0 ]; then
d007b9c3
DG
189 # Only delete if successful
190 rm -rf $TMP_PATH
983875b1 191 else
d007b9c3 192 break
983875b1
CB
193 fi
194 done
195}
196
d346ccad 197plan_tests $NUM_TESTS
983875b1 198
fb3268e3 199start_lttng_sessiond
983875b1 200
d346ccad 201diag "Test with IPv4"
fb3268e3 202start_lttng_relayd "-o $TRACE_PATH"
983875b1
CB
203test_uri_switch_localhost_folder "IPv4"
204test_uri_switch_file_network "IPv4"
205test_uri_switch_network_file "IPv4"
fb3268e3 206stop_lttng_relayd
983875b1 207
d346ccad 208diag "Test with IPv6"
fb3268e3 209start_lttng_relayd "-o $TRACE_PATH -C tcp6://localhost:5342 -D tcp6://localhost:5343"
983875b1
CB
210test_uri_switch_localhost_folder "IPv6"
211test_uri_switch_file_network "IPv6"
212test_uri_switch_network_file "IPv6"
fb3268e3 213stop_lttng_relayd
983875b1 214
fb3268e3 215stop_lttng_sessiond
This page took 0.034104 seconds and 4 git commands to generate.