Fix: syscall event rule: emission sites not compared in is_equal
[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 9
0d1c8a68
KS
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.
13
14CURDIR=$(dirname "$0")/
15TESTDIR="$CURDIR/../../.."
17fe0490 16NR_APP_ITER=10
0d1c8a68 17NR_ITER=5000
ea3a3cae
CB
18TESTAPP_PATH="$TESTDIR/utils/testapp"
19TESTAPP_NAME="gen-ust-events"
20TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
17fe0490
CB
21SESSION_NAME="high-throughput"
22EVENT_NAME="tp:tptest"
23SESSIOND_CTRL_PORT=5342
24SESSIOND_DATA_PORT=5343
25DEFAULT_IF="lo"
26
8d5a3312 27TRACE_PATH=$(mktemp -d -t tmp.test_streaming_high_throughput_limits_trace_path.XXXXXX)
17fe0490 28
0d1c8a68 29NUM_TESTS=39
d346ccad 30
0d1c8a68 31# shellcheck source-path=SCRIPTDIR/../../../
9ac429ef 32source $TESTDIR/utils/utils.sh
17fe0490 33
ea3a3cae
CB
34if [ ! -x "$TESTAPP_BIN" ]; then
35 BAIL_OUT "No UST events binary detected."
17fe0490
CB
36fi
37
24e59479
MD
38function reset_bw_limit
39{
40 tc qdisc del dev $DEFAULT_IF root >/dev/null 2>&1
41 return $?
42}
43
17fe0490
CB
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
24e59479 54 diag "Set bandwidth limits to ${limit}kbits, ${ctrlportlimit} for control and ${dataportlimit} for data"
d346ccad 55
0d1c8a68 56 if ! tc qdisc add dev $DEFAULT_IF root handle 1: htb default 15 >/dev/null 2>&1 ; then
24e59479
MD
57 reset_bw_limit
58 return 1
59 fi
17fe0490 60
ffaed7f7 61 # the total bandwidth is the limit set by the user
0d1c8a68 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
24e59479
MD
63 reset_bw_limit
64 return 1
65 fi
ffaed7f7 66 # 1/10 of the bandwidth guaranteed and traffic prioritized for the control port
0d1c8a68 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
24e59479
MD
68 reset_bw_limit
69 return 1
70 fi
ffaed7f7 71 # 9/10 of the bandwidth guaranteed and can borrow up to the total bandwidth (if unused)
0d1c8a68 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
24e59479
MD
73 reset_bw_limit
74 return 1
75 fi
17fe0490 76
ffaed7f7 77 # filter to assign control traffic to the 1:10 class
0d1c8a68 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
24e59479
MD
79 reset_bw_limit
80 return 1
81 fi
ffaed7f7 82 # filter to assign data traffic to the 1:11 class
0d1c8a68 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
24e59479
MD
84 reset_bw_limit
85 return 1
86 fi
d346ccad 87
24e59479 88 return 0
17fe0490
CB
89}
90
91function create_lttng_session_with_uri
92{
93 sess_name=$1
94 uri=$2
95 # Create session with custom URI
0d1c8a68 96 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" create -U "$uri" "$sess_name" >/dev/null 2>&1
d346ccad 97 ok $? "Create session with uri $uri"
17fe0490
CB
98}
99
17fe0490
CB
100function run_apps
101{
0d1c8a68 102 for i in $(seq 1 $NR_APP_ITER); do
b2068598
DG
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.
0d1c8a68 107 LTTNG_UST_REGISTER_TIMEOUT=-1 $TESTAPP_BIN -i "$NR_ITER" >/dev/null 2>&1 &
17fe0490
CB
108 done
109}
110
17fe0490
CB
111function test_high_throughput
112{
113 NETWORK_URI="net://localhost"
114 create_lttng_session_with_uri $SESSION_NAME $NETWORK_URI
c4926bb5 115 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
e563bbdb 116 start_lttng_tracing_ok $SESSION_NAME
17fe0490 117 run_apps
5dca3876
MD
118 diag "Waiting for applications to end"
119 wait
120 pass "waiting done"
96340a01 121 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 122 destroy_lttng_session_ok $SESSION_NAME
17fe0490
CB
123 validate_event_count
124}
125
126function validate_event_count
127{
8d5a3312
MJ
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)
17fe0490 130
0d1c8a68
KS
131 traced=$("$BABELTRACE_BIN" "$TRACE_PATH" 2>/dev/null | wc -l)
132 "$BABELTRACE_BIN" "$TRACE_PATH" >/dev/null 2>"$TEMP_FILE_2"
17fe0490 133
0d1c8a68 134 cat "$TEMP_FILE_2" | cut -f4 -d " " >"$TEMP_FILE"
17fe0490
CB
135
136 dropped=0
0d1c8a68
KS
137 while read -r line; do
138 dropped=$(( dropped + line ))
139 done < "$TEMP_FILE"
17fe0490 140
0d1c8a68
KS
141 total=$(( dropped + traced ))
142 wanted=$(( NR_APP_ITER * NR_ITER ))
17fe0490 143
0d1c8a68
KS
144 if [ $dropped -le 0 ]; then
145 diag "No dropped events during test, consider increasing the number of " \
146 "apps or iterations"
147 fi
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
0d1c8a68
KS
156 rm -rf "$TRACE_PATH"
157 rm "$TEMP_FILE" "$TEMP_FILE_2"
b2068598 158
17fe0490
CB
159 return 0
160 fi
161}
162
163function interrupt_cleanup()
164{
d346ccad 165 diag "*** Exiting ***"
17fe0490 166 reset_bw_limit
24e59479
MD
167 # invoke utils cleanup
168 full_cleanup
17fe0490
CB
169}
170
d346ccad 171plan_tests $NUM_TESTS
17fe0490 172
e3bef725
CB
173print_test_banner "$TEST_DESC"
174
c125de8f
FD
175bail_out_if_no_babeltrace
176
3a174400 177check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
d346ccad 178{
17fe0490 179
d346ccad 180 # Catch sigint and try to cleanup limits
24e59479 181 trap interrupt_cleanup SIGTERM SIGINT
d346ccad 182
0d1c8a68
KS
183 BW_LIMITS=(3200 400 100)
184 for BW in "${BW_LIMITS[@]}";
d346ccad
CB
185 do
186 diag "Test high-throughput with bandwidth limit set to ${BW}kbits"
491c49eb 187
0d1c8a68 188 set_bw_limit "$BW"
24e59479 189 ok $? "Setting bandwidth limit"
d346ccad 190
0d1c8a68 191 # shellcheck disable=SC2119
d346ccad
CB
192 start_lttng_sessiond
193 start_lttng_relayd "-o $TRACE_PATH"
194 test_high_throughput
195 result=$?
0d1c8a68 196 # shellcheck disable=SC2119
d346ccad 197 stop_lttng_relayd
0d1c8a68 198 # shellcheck disable=SC2119
d346ccad
CB
199 stop_lttng_sessiond
200 reset_bw_limit
24e59479 201 ok $? "Reset bandwith limits"
d346ccad
CB
202 done
203}
This page took 0.073632 seconds and 5 git commands to generate.