Tests: Convert the tools streaming tests output to TAP
[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
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
d346ccad
CB
34NUM_TESTS=112
35
9ac429ef 36source $TESTDIR/utils/utils.sh
17fe0490
CB
37
38print_test_banner "$TEST_DESC"
39
40if [ ! -x "$CURDIR/$BIN_NAME" ]; then
d346ccad 41 BAIL_OUT "No UST nevents binary detected."
17fe0490
CB
42fi
43
44function set_bw_limit
45{
46 limit=$1
ffaed7f7
JD
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
d346ccad 54
17fe0490 55 tc qdisc add dev $DEFAULT_IF root handle 1: htb default 15 >/dev/null 2>&1
17fe0490 56
ffaed7f7
JD
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
17fe0490 63
ffaed7f7
JD
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
d346ccad
CB
68
69 ok $? "Set bandwidth limits to ${limit}kbits, ${ctrlportlimit} for control and ${dataportlimit} for data"
17fe0490
CB
70}
71
72function reset_bw_limit
73{
17fe0490 74 tc qdisc del dev $DEFAULT_IF root >/dev/null 2>&1
d346ccad 75 ok $? "Reset bandwith limits"
17fe0490
CB
76}
77
78function 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
d346ccad 84 ok $? "Create session with uri $uri"
17fe0490
CB
85}
86
87function enable_lttng_consumer
88{
89 uri=$1
90 # Create session with custom URI
91 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-consumer -u $uri >/dev/null 2>&1
d346ccad 92 ok $? "Enable consumer with uri $uri"
17fe0490
CB
93}
94
95function run_apps
96{
97 for i in `seq 1 $NR_APP_ITER`; do
b2068598
DG
98 # With bandwidth limitation, unfortunately, application easily timeout
99 # due to very slow communication between the consumer and relayd making
100 # the status reply from the consumer quite slow thus delaying the
101 # registration done message.
bfdaf0fd 102 LTTNG_UST_REGISTER_TIMEOUT=-1 ./$CURDIR/$BIN_NAME $NR_ITER & >/dev/null 2>&1
17fe0490
CB
103 done
104}
105
106function wait_apps
107{
17fe0490 108 while [ -n "$(pidof $BIN_NAME)" ]; do
17fe0490
CB
109 sleep 1
110 done
d346ccad 111 pass "Wait for applications to end"
17fe0490
CB
112}
113
114function test_high_throughput
115{
116 NETWORK_URI="net://localhost"
117 create_lttng_session_with_uri $SESSION_NAME $NETWORK_URI
118 enable_lttng_consumer $NETWORK_URI
119 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
120 start_lttng_tracing $SESSION_NAME
121 run_apps
122 wait_apps
17fe0490
CB
123 stop_lttng_tracing $SESSION_NAME
124 destroy_lttng_session $SESSION_NAME
125 validate_event_count
126}
127
128function validate_event_count
129{
130
131 TEMP_FILE=$(mktemp)
132 TEMP_FILE_2=$(mktemp)
133
134 traced=$(babeltrace $TRACE_PATH 2>/dev/null | wc -l)
135 babeltrace $TRACE_PATH >/dev/null 2>$TEMP_FILE_2
136
137 cat $TEMP_FILE_2 | cut -f4 -d " " >$TEMP_FILE
138
139 dropped=0
140 while read line;
141 do
142 let dropped=$dropped+$line
143 done < $TEMP_FILE
144
145 let total=$dropped+$traced
146 let wanted=$NR_APP_ITER*$NR_ITER
147
17fe0490 148 if [ $wanted -ne $total ]; then
d346ccad
CB
149 fail "Validate trace event count"
150 diag "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... "
17fe0490
CB
151 return 1
152 else
d346ccad
CB
153 pass "Validate trace event count"
154 diag "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... "
b2068598 155
b2068598
DG
156 rm -rf $TRACE_PATH
157 rm $TEMP_FILE $TEMP_FILE_2
158
17fe0490
CB
159 return 0
160 fi
161}
162
163function interrupt_cleanup()
164{
d346ccad 165 diag "*** Exiting ***"
17fe0490
CB
166 stop_lttng_relayd
167 stop_lttng_sessiond
168 reset_bw_limit
169 exit 1
170}
171
d346ccad 172plan_tests $NUM_TESTS
17fe0490 173
d346ccad
CB
174if [ "$(id -u)" == "0" ]; then
175 isroot=1
176else
177 isroot=0
178fi
17fe0490 179
d346ccad
CB
180skip $isroot "Root access is needed to set bandwith limits. Skipping all tests." $NUM_TESTS ||
181{
17fe0490 182
d346ccad
CB
183 # Catch sigint and try to cleanup limits
184 trap interrupt_cleanup SIGINT
185
186 BW_LIMITS=(3200 1600 800 400 200 100 50 25)
187 for BW in ${BW_LIMITS[@]};
188 do
189 diag "Test high-throughput with bandwidth limit set to ${BW}kbits"
190 set_bw_limit $BW
191
192 start_lttng_sessiond
193 start_lttng_relayd "-o $TRACE_PATH"
194 test_high_throughput
195 result=$?
196 stop_lttng_relayd
197 stop_lttng_sessiond
198 reset_bw_limit
199 done
200}
This page took 0.034404 seconds and 5 git commands to generate.