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