Tests: Rename the tools tests runners to test_<test name>
[lttng-tools.git] / tests / regression / tools / streaming / test_high_throughput_limits
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
19 TEST_DESC="Streaming - High throughput with bandwidth limits"
20
21 CURDIR=$(dirname $0)/
22 TESTDIR=$CURDIR/../../..
23 NR_APP_ITER=10
24 NR_ITER=1000000
25 BIN_NAME="gen-ust-events"
26 SESSION_NAME="high-throughput"
27 EVENT_NAME="tp:tptest"
28 SESSIOND_CTRL_PORT=5342
29 SESSIOND_DATA_PORT=5343
30 DEFAULT_IF="lo"
31
32 TRACE_PATH=$(mktemp -d)
33
34 source $TESTDIR/utils/utils.sh
35
36 print_test_banner "$TEST_DESC"
37
38 if [ ! -x "$CURDIR/$BIN_NAME" ]; then
39 echo -e "No UST nevents binary detected. Passing."
40 exit 0
41 fi
42
43 if [ "$(id -u)" != "0" ]; then
44 echo "This test must be running as root to set bandwidth limits. Aborting"
45 # Exit status 0 so the tests can continue
46 exit 0
47 fi
48
49 function set_bw_limit
50 {
51 limit=$1
52 ctrlportlimit=$(($limit/10))
53 # failsafe to have at least 1kbit/s for control (in the case where $1 < 10)
54 [ $ctrlportlimit = 0 ] && ctrlportlimit=1
55 # if $1 < 10, we might bust the limit set here, but the
56 # parent qdisc (1:) will always limit us to the right max value
57 dataportlimit=$((9*${ctrlportlimit}))
58
59 echo -n "Setting bandwidth limits to ${limit}kbits, (${ctrlportlimit} for control and ${dataportlimit} for data)... "
60 tc qdisc add dev $DEFAULT_IF root handle 1: htb default 15 >/dev/null 2>&1
61
62 # the total bandwidth is the limit set by the user
63 tc class add dev $DEFAULT_IF parent 1: classid 1:1 htb rate ${limit}kbit ceil ${limit}kbit >/dev/null 2>&1
64 # 1/10 of the bandwidth guaranteed and traffic prioritized for the control port
65 tc class add dev $DEFAULT_IF parent 1:1 classid 1:10 htb rate ${ctrlportlimit}kbit ceil ${limit}kbit prio 1 >/dev/null 2>&1
66 # 9/10 of the bandwidth guaranteed and can borrow up to the total bandwidth (if unused)
67 tc class add dev $DEFAULT_IF parent 1:1 classid 1:11 htb rate ${dataportlimit}kbit ceil ${limit}kbit prio 2 >/dev/null 2>&1
68
69 # filter to assign control traffic to the 1:10 class
70 tc filter add dev $DEFAULT_IF parent 1: protocol ip u32 match ip dport $SESSIOND_CTRL_PORT 0xffff flowid 1:10 >/dev/null 2>&1
71 # filter to assign data traffic to the 1:11 class
72 tc filter add dev $DEFAULT_IF parent 1: protocol ip u32 match ip dport $SESSIOND_DATA_PORT 0xffff flowid 1:11 >/dev/null 2>&1
73 print_ok
74 }
75
76 function reset_bw_limit
77 {
78 echo -n "Resetting bandwidth limits... "
79 tc qdisc del dev $DEFAULT_IF root >/dev/null 2>&1
80 print_ok
81 }
82
83 function create_lttng_session_with_uri
84 {
85 sess_name=$1
86 uri=$2
87 # Create session with custom URI
88 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create -U $uri $sess_name >/dev/null 2>&1
89 }
90
91 function enable_lttng_consumer
92 {
93 uri=$1
94 # Create session with custom URI
95 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-consumer -u $uri >/dev/null 2>&1
96 }
97
98 function run_apps
99 {
100 for i in `seq 1 $NR_APP_ITER`; do
101 # With bandwidth limitation, unfortunately, application easily timeout
102 # due to very slow communication between the consumer and relayd making
103 # the status reply from the consumer quite slow thus delaying the
104 # registration done message.
105 LTTNG_UST_REGISTER_TIMEOUT=-1 ./$CURDIR/$BIN_NAME $NR_ITER & >/dev/null 2>&1
106 done
107 }
108
109 function wait_apps
110 {
111 echo "Waiting for applications to end"
112 while [ -n "$(pidof $BIN_NAME)" ]; do
113 echo -n "."
114 sleep 1
115 done
116 echo ""
117 }
118
119 function test_high_throughput
120 {
121 NETWORK_URI="net://localhost"
122 create_lttng_session_with_uri $SESSION_NAME $NETWORK_URI
123 enable_lttng_consumer $NETWORK_URI
124 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
125 start_lttng_tracing $SESSION_NAME
126 run_apps
127 wait_apps
128
129 stop_lttng_tracing $SESSION_NAME
130 destroy_lttng_session $SESSION_NAME
131 validate_event_count
132 }
133
134 function validate_event_count
135 {
136
137 TEMP_FILE=$(mktemp)
138 TEMP_FILE_2=$(mktemp)
139
140 traced=$(babeltrace $TRACE_PATH 2>/dev/null | wc -l)
141 babeltrace $TRACE_PATH >/dev/null 2>$TEMP_FILE_2
142
143 cat $TEMP_FILE_2 | cut -f4 -d " " >$TEMP_FILE
144
145 dropped=0
146 while read line;
147 do
148 let dropped=$dropped+$line
149 done < $TEMP_FILE
150
151 let total=$dropped+$traced
152 let wanted=$NR_APP_ITER*$NR_ITER
153
154 if [ $wanted -ne $total ]; then
155 echo -n "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... "
156 print_fail
157 return 1
158 else
159 echo -n "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... "
160 print_ok
161
162 # Cleanup only if everything is ok and passes.
163 rm -rf $TRACE_PATH
164 rm $TEMP_FILE $TEMP_FILE_2
165
166 return 0
167 fi
168 }
169
170 function interrupt_cleanup()
171 {
172 echo -en "\n*** Exiting ***\n"
173 stop_lttng_relayd
174 stop_lttng_sessiond
175 reset_bw_limit
176 exit 1
177 }
178
179 # Catch sigint and try to cleanup limits
180 trap interrupt_cleanup SIGINT
181
182 BW_LIMITS=(3200 1600 800 400 200 100 50 25)
183 for BW in ${BW_LIMITS[@]};
184 do
185 echo ""
186 echo -e "=== Testing high-throughput with bandwidth limit set to ${BW}kbits"
187 set_bw_limit $BW
188
189 start_lttng_sessiond
190 start_lttng_relayd "-o $TRACE_PATH"
191 test_high_throughput
192 result=$?
193 stop_lttng_relayd
194 stop_lttng_sessiond
195 reset_bw_limit
196
197 if [ $result -ne 0 ]; then
198 exit 1
199 fi
200 done
This page took 0.034895 seconds and 4 git commands to generate.