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