tests: Move to kernel style SPDX license identifiers
[lttng-tools.git] / tests / regression / tools / streaming / test_high_throughput_limits
CommitLineData
17fe0490
CB
1#!/bin/bash
2#
9d16b343
MJ
3# Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
4# Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
17fe0490 5#
9d16b343 6# SPDX-License-Identifier: LGPL-2.1-only
b2068598
DG
7
8TEST_DESC="Streaming - High throughput with bandwidth limits"
17fe0490
CB
9
10CURDIR=$(dirname $0)/
9ac429ef 11TESTDIR=$CURDIR/../../..
17fe0490
CB
12NR_APP_ITER=10
13NR_ITER=1000000
ea3a3cae
CB
14TESTAPP_PATH="$TESTDIR/utils/testapp"
15TESTAPP_NAME="gen-ust-events"
16TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
17fe0490
CB
17SESSION_NAME="high-throughput"
18EVENT_NAME="tp:tptest"
19SESSIOND_CTRL_PORT=5342
20SESSIOND_DATA_PORT=5343
21DEFAULT_IF="lo"
22
23TRACE_PATH=$(mktemp -d)
24
5dca3876 25NUM_TESTS=104
d346ccad 26
9ac429ef 27source $TESTDIR/utils/utils.sh
17fe0490 28
ea3a3cae
CB
29if [ ! -x "$TESTAPP_BIN" ]; then
30 BAIL_OUT "No UST events binary detected."
17fe0490
CB
31fi
32
24e59479
MD
33function reset_bw_limit
34{
35 tc qdisc del dev $DEFAULT_IF root >/dev/null 2>&1
36 return $?
37}
38
17fe0490
CB
39function set_bw_limit
40{
41 limit=$1
ffaed7f7
JD
42 ctrlportlimit=$(($limit/10))
43 # failsafe to have at least 1kbit/s for control (in the case where $1 < 10)
44 [ $ctrlportlimit = 0 ] && ctrlportlimit=1
45 # if $1 < 10, we might bust the limit set here, but the
46 # parent qdisc (1:) will always limit us to the right max value
47 dataportlimit=$((9*${ctrlportlimit}))
48
24e59479 49 diag "Set bandwidth limits to ${limit}kbits, ${ctrlportlimit} for control and ${dataportlimit} for data"
d346ccad 50
17fe0490 51 tc qdisc add dev $DEFAULT_IF root handle 1: htb default 15 >/dev/null 2>&1
24e59479
MD
52 if [ $? -ne 0 ]; then
53 reset_bw_limit
54 return 1
55 fi
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
24e59479
MD
59 if [ $? -ne 0 ]; then
60 reset_bw_limit
61 return 1
62 fi
ffaed7f7
JD
63 # 1/10 of the bandwidth guaranteed and traffic prioritized for the control port
64 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
65 if [ $? -ne 0 ]; then
66 reset_bw_limit
67 return 1
68 fi
ffaed7f7
JD
69 # 9/10 of the bandwidth guaranteed and can borrow up to the total bandwidth (if unused)
70 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
71 if [ $? -ne 0 ]; then
72 reset_bw_limit
73 return 1
74 fi
17fe0490 75
ffaed7f7
JD
76 # filter to assign control traffic to the 1:10 class
77 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
78 if [ $? -ne 0 ]; then
79 reset_bw_limit
80 return 1
81 fi
ffaed7f7
JD
82 # filter to assign data traffic to the 1:11 class
83 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
84 if [ $? -ne 0 ]; then
85 reset_bw_limit
86 return 1
87 fi
d346ccad 88
24e59479 89 return 0
17fe0490
CB
90}
91
92function create_lttng_session_with_uri
93{
94 sess_name=$1
95 uri=$2
96 # Create session with custom URI
97 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create -U $uri $sess_name >/dev/null 2>&1
d346ccad 98 ok $? "Create session with uri $uri"
17fe0490
CB
99}
100
17fe0490
CB
101function run_apps
102{
103 for i in `seq 1 $NR_APP_ITER`; do
b2068598
DG
104 # With bandwidth limitation, unfortunately, application easily timeout
105 # due to very slow communication between the consumer and relayd making
106 # the status reply from the consumer quite slow thus delaying the
107 # registration done message.
6c4a91d6 108 LTTNG_UST_REGISTER_TIMEOUT=-1 $TESTAPP_BIN -i $NR_ITER & >/dev/null 2>&1
17fe0490
CB
109 done
110}
111
17fe0490
CB
112function test_high_throughput
113{
114 NETWORK_URI="net://localhost"
115 create_lttng_session_with_uri $SESSION_NAME $NETWORK_URI
c4926bb5 116 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
e563bbdb 117 start_lttng_tracing_ok $SESSION_NAME
17fe0490 118 run_apps
5dca3876
MD
119 diag "Waiting for applications to end"
120 wait
121 pass "waiting done"
96340a01 122 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 123 destroy_lttng_session_ok $SESSION_NAME
17fe0490
CB
124 validate_event_count
125}
126
127function validate_event_count
128{
129
130 TEMP_FILE=$(mktemp)
131 TEMP_FILE_2=$(mktemp)
132
133 traced=$(babeltrace $TRACE_PATH 2>/dev/null | wc -l)
134 babeltrace $TRACE_PATH >/dev/null 2>$TEMP_FILE_2
135
136 cat $TEMP_FILE_2 | cut -f4 -d " " >$TEMP_FILE
137
138 dropped=0
139 while read line;
140 do
141 let dropped=$dropped+$line
142 done < $TEMP_FILE
143
144 let total=$dropped+$traced
145 let wanted=$NR_APP_ITER*$NR_ITER
146
17fe0490 147 if [ $wanted -ne $total ]; then
d346ccad
CB
148 fail "Validate trace event count"
149 diag "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... "
17fe0490
CB
150 return 1
151 else
d346ccad
CB
152 pass "Validate trace event count"
153 diag "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... "
b2068598 154
b2068598
DG
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{
d346ccad 164 diag "*** Exiting ***"
17fe0490 165 reset_bw_limit
24e59479
MD
166 # invoke utils cleanup
167 full_cleanup
17fe0490
CB
168}
169
d346ccad 170plan_tests $NUM_TESTS
17fe0490 171
e3bef725
CB
172print_test_banner "$TEST_DESC"
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 183 # Catch sigint and try to cleanup limits
24e59479 184 trap interrupt_cleanup SIGTERM SIGINT
d346ccad
CB
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"
491c49eb 190
d346ccad 191 set_bw_limit $BW
24e59479 192 ok $? "Setting bandwidth limit"
d346ccad
CB
193
194 start_lttng_sessiond
195 start_lttng_relayd "-o $TRACE_PATH"
196 test_high_throughput
197 result=$?
198 stop_lttng_relayd
199 stop_lttng_sessiond
200 reset_bw_limit
24e59479 201 ok $? "Reset bandwith limits"
d346ccad
CB
202 done
203}
This page took 0.070095 seconds and 5 git commands to generate.