3 # Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
4 # Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
6 # SPDX-License-Identifier: LGPL-2.1-only
8 TEST_DESC
="Streaming - High throughput with bandwidth limits"
10 # The goal of this test is to try and catch races during tests in conditions
11 # where bandwidth is quite limited. It is useful to have enough iterations and
12 # apps so that there are dropped events.
14 CURDIR
=$
(dirname "$0")/
15 TESTDIR
="$CURDIR/../../.."
18 TESTAPP_PATH
="$TESTDIR/utils/testapp"
19 TESTAPP_NAME
="gen-ust-events"
20 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
21 SESSION_NAME
="high-throughput"
22 EVENT_NAME
="tp:tptest"
23 SESSIOND_CTRL_PORT
=5342
24 SESSIOND_DATA_PORT
=5343
27 TRACE_PATH
=$
(mktemp
-d -t tmp.test_streaming_high_throughput_limits_trace_path.XXXXXX
)
31 # shellcheck source-path=SCRIPTDIR/../../../
32 source $TESTDIR/utils
/utils.sh
34 if [ ! -x "$TESTAPP_BIN" ]; then
35 BAIL_OUT
"No UST events binary detected."
38 function reset_bw_limit
40 tc qdisc del dev
$DEFAULT_IF root
>/dev
/null
2>&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}))
54 diag
"Set bandwidth limits to ${limit}kbits, ${ctrlportlimit} for control and ${dataportlimit} for data"
56 if ! tc qdisc add dev
$DEFAULT_IF root handle
1: htb default
15 >/dev
/null
2>&1 ; then
61 # the total bandwidth is the limit set by the user
62 if ! tc class add dev
$DEFAULT_IF parent
1: classid
1:1 htb rate
${limit}kbit ceil
${limit}kbit
>/dev
/null
2>&1 ; then
66 # 1/10 of the bandwidth guaranteed and traffic prioritized for the control port
67 if ! 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 ; then
71 # 9/10 of the bandwidth guaranteed and can borrow up to the total bandwidth (if unused)
72 if ! 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 ; then
77 # filter to assign control traffic to the 1:10 class
78 if ! 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 ; then
82 # filter to assign data traffic to the 1:11 class
83 if ! 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 ; then
91 function create_lttng_session_with_uri
95 # Create session with custom URI
96 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" create
-U "$uri" "$sess_name" >/dev
/null
2>&1
97 ok $?
"Create session with uri $uri"
102 for i
in $
(seq 1 $NR_APP_ITER); do
103 # With bandwidth limitation, unfortunately, application easily timeout
104 # due to very slow communication between the consumer and relayd making
105 # the status reply from the consumer quite slow thus delaying the
106 # registration done message.
107 LTTNG_UST_REGISTER_TIMEOUT
=-1 $TESTAPP_BIN -i "$NR_ITER" >/dev
/null
2>&1 &
111 function test_high_throughput
113 NETWORK_URI
="net://localhost"
114 create_lttng_session_with_uri
$SESSION_NAME $NETWORK_URI
115 enable_ust_lttng_event_ok
$SESSION_NAME $EVENT_NAME
116 start_lttng_tracing_ok
$SESSION_NAME
118 diag
"Waiting for applications to end"
121 stop_lttng_tracing_ok
$SESSION_NAME
122 destroy_lttng_session_ok
$SESSION_NAME
126 function validate_event_count
128 TEMP_FILE
=$
(mktemp
-t tmp.streaming_high_throughput_limit_file1.XXXXXX
)
129 TEMP_FILE_2
=$
(mktemp
-t tmp.streaming_high_throughput_limit_file2.XXXXXX
)
131 traced
=$
("$BABELTRACE_BIN" "$TRACE_PATH" 2>"${TEMP_FILE_2}" |
wc -l)
132 cat "$TEMP_FILE_2" | cut
-f4 -d " " >"$TEMP_FILE"
135 while read -r line
; do
136 dropped
=$
(( dropped
+ line
))
139 total
=$
(( dropped
+ traced
))
140 wanted
=$
(( NR_APP_ITER
* NR_ITER
))
142 if [ $dropped -le 0 ]; then
143 diag
"No dropped events during test, consider increasing the number of " \
146 if [ $wanted -ne $total ]; then
147 fail
"Validate trace event count"
148 diag
"Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... "
151 pass
"Validate trace event count"
152 diag
"Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... "
155 rm "$TEMP_FILE" "$TEMP_FILE_2"
161 function interrupt_cleanup
()
163 diag
"*** Exiting ***"
165 # invoke utils cleanup
169 plan_tests
$NUM_TESTS
171 print_test_banner
"$TEST_DESC"
173 bail_out_if_no_babeltrace
175 check_skip_kernel_test
"$NUM_TESTS" "Skipping all tests." ||
178 # Catch sigint and try to cleanup limits
179 trap interrupt_cleanup SIGTERM SIGINT
181 BW_LIMITS
=(3200 400 100)
182 for BW
in "${BW_LIMITS[@]}";
184 diag
"Test high-throughput with bandwidth limit set to ${BW}kbits"
187 ok $?
"Setting bandwidth limit"
189 # shellcheck disable=SC2119
191 start_lttng_relayd
"-o $TRACE_PATH"
194 # shellcheck disable=SC2119
196 # shellcheck disable=SC2119
199 ok $?
"Reset bandwith limits"