Tests: Add runner script for UST regression tests
[lttng-tools.git] / tests / regression / 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
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
9ac429ef 29source $TESTDIR/utils/utils.sh
983875b1 30
c38b5107 31print_test_banner "$TEST_DESC"
983875b1
CB
32
33if [ ! -x "$CURDIR/$BIN_NAME" ]; then
34 echo -e "No UST nevents binary detected. Skipping."
35 exit 0
36fi
37
38function 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
45function 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
52function 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
61function 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
71function 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
110function 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
156function test_uri_switch_network_file
157{
158IPVER=$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 199start_lttng_sessiond
983875b1
CB
200
201echo ""
202echo "=== Testing with IPv4"
fb3268e3 203start_lttng_relayd "-o $TRACE_PATH"
983875b1
CB
204test_uri_switch_localhost_folder "IPv4"
205test_uri_switch_file_network "IPv4"
206test_uri_switch_network_file "IPv4"
fb3268e3 207stop_lttng_relayd
983875b1
CB
208
209echo ""
210echo "=== Testing with IPv6"
fb3268e3 211start_lttng_relayd "-o $TRACE_PATH -C tcp6://localhost:5342 -D tcp6://localhost:5343"
983875b1
CB
212test_uri_switch_localhost_folder "IPv6"
213test_uri_switch_file_network "IPv6"
214test_uri_switch_network_file "IPv6"
fb3268e3 215stop_lttng_relayd
983875b1 216
fb3268e3 217stop_lttng_sessiond
This page took 0.034774 seconds and 5 git commands to generate.