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