Fix: mark generated python bindings files as nodist
[lttng-tools.git] / tests / tools / streaming / high_throughput_limits
CommitLineData
17fe0490
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
b2068598
DG
18
19TEST_DESC="Streaming - High throughput with bandwidth limits"
17fe0490
CB
20
21CURDIR=$(dirname $0)/
22TESTDIR=$CURDIR/../..
23NR_APP_ITER=10
24NR_ITER=1000000
25BIN_NAME="gen-ust-events"
26SESSION_NAME="high-throughput"
27EVENT_NAME="tp:tptest"
28SESSIOND_CTRL_PORT=5342
29SESSIOND_DATA_PORT=5343
30DEFAULT_IF="lo"
31
32TRACE_PATH=$(mktemp -d)
33
34source $TESTDIR/utils.sh
35
36print_test_banner "$TEST_DESC"
37
38if [ ! -x "$CURDIR/$BIN_NAME" ]; then
39 echo -e "No UST nevents binary detected. Passing."
40 exit 0
41fi
42
43if [ "$(id -u)" != "0" ]; then
b2068598 44 echo "This test must be running as root to set bandwidth limits. Aborting"
17fe0490
CB
45 # Exit status 0 so the tests can continue
46 exit 0
47fi
48
49function set_bw_limit
50{
51 limit=$1
ffaed7f7
JD
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)... "
17fe0490 60 tc qdisc add dev $DEFAULT_IF root handle 1: htb default 15 >/dev/null 2>&1
17fe0490 61
ffaed7f7
JD
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
17fe0490 68
ffaed7f7
JD
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
17fe0490
CB
73 print_ok
74}
75
76function reset_bw_limit
77{
b2068598 78 echo -n "Resetting bandwidth limits... "
17fe0490
CB
79 tc qdisc del dev $DEFAULT_IF root >/dev/null 2>&1
80 print_ok
81}
82
83function 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
17fe0490
CB
91function run_apps
92{
93 for i in `seq 1 $NR_APP_ITER`; do
b2068598
DG
94 # With bandwidth limitation, unfortunately, application easily timeout
95 # due to very slow communication between the consumer and relayd making
96 # the status reply from the consumer quite slow thus delaying the
97 # registration done message.
bfdaf0fd 98 LTTNG_UST_REGISTER_TIMEOUT=-1 ./$CURDIR/$BIN_NAME $NR_ITER & >/dev/null 2>&1
17fe0490
CB
99 done
100}
101
102function wait_apps
103{
104 echo "Waiting for applications to end"
105 while [ -n "$(pidof $BIN_NAME)" ]; do
106 echo -n "."
107 sleep 1
108 done
109 echo ""
110}
111
112function test_high_throughput
113{
114 NETWORK_URI="net://localhost"
115 create_lttng_session_with_uri $SESSION_NAME $NETWORK_URI
17fe0490
CB
116 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
117 start_lttng_tracing $SESSION_NAME
118 run_apps
119 wait_apps
120
17fe0490
CB
121 stop_lttng_tracing $SESSION_NAME
122 destroy_lttng_session $SESSION_NAME
123 validate_event_count
124}
125
126function validate_event_count
127{
128
129 TEMP_FILE=$(mktemp)
130 TEMP_FILE_2=$(mktemp)
131
132 traced=$(babeltrace $TRACE_PATH 2>/dev/null | wc -l)
133 babeltrace $TRACE_PATH >/dev/null 2>$TEMP_FILE_2
134
135 cat $TEMP_FILE_2 | cut -f4 -d " " >$TEMP_FILE
136
137 dropped=0
138 while read line;
139 do
140 let dropped=$dropped+$line
141 done < $TEMP_FILE
142
143 let total=$dropped+$traced
144 let wanted=$NR_APP_ITER*$NR_ITER
145
17fe0490
CB
146 if [ $wanted -ne $total ]; then
147 echo -n "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... "
148 print_fail
149 return 1
150 else
151 echo -n "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... "
152 print_ok
b2068598
DG
153
154 # Cleanup only if everything is ok and passes.
155 rm -rf $TRACE_PATH
156 rm $TEMP_FILE $TEMP_FILE_2
157
17fe0490
CB
158 return 0
159 fi
160}
161
162function interrupt_cleanup()
163{
164 echo -en "\n*** Exiting ***\n"
165 stop_lttng_relayd
166 stop_lttng_sessiond
167 reset_bw_limit
168 exit 1
169}
170
171# Catch sigint and try to cleanup limits
172trap interrupt_cleanup SIGINT
173
174BW_LIMITS=(3200 1600 800 400 200 100 50 25)
175for BW in ${BW_LIMITS[@]};
176do
177 echo ""
b2068598 178 echo -e "=== Testing high-throughput with bandwidth limit set to ${BW}kbits"
17fe0490
CB
179 set_bw_limit $BW
180
181 start_lttng_sessiond
182 start_lttng_relayd "-o $TRACE_PATH"
183 test_high_throughput
184 result=$?
185 stop_lttng_relayd
186 stop_lttng_sessiond
187 reset_bw_limit
188
189 if [ $result -ne 0 ]; then
190 exit 1
191 fi
192done
This page took 0.029907 seconds and 4 git commands to generate.