Commit | Line | Data |
---|---|---|
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 | |
8 | TEST_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 | ||
14 | CURDIR=$(dirname "$0")/ | |
15 | TESTDIR="$CURDIR/../../.." | |
17fe0490 | 16 | NR_APP_ITER=10 |
0d1c8a68 | 17 | NR_ITER=5000 |
ea3a3cae CB |
18 | TESTAPP_PATH="$TESTDIR/utils/testapp" |
19 | TESTAPP_NAME="gen-ust-events" | |
20 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
17fe0490 CB |
21 | SESSION_NAME="high-throughput" |
22 | EVENT_NAME="tp:tptest" | |
23 | SESSIOND_CTRL_PORT=5342 | |
24 | SESSIOND_DATA_PORT=5343 | |
25 | DEFAULT_IF="lo" | |
26 | ||
8d5a3312 | 27 | TRACE_PATH=$(mktemp -d -t tmp.test_streaming_high_throughput_limits_trace_path.XXXXXX) |
17fe0490 | 28 | |
0d1c8a68 | 29 | NUM_TESTS=39 |
d346ccad | 30 | |
0d1c8a68 | 31 | # shellcheck source-path=SCRIPTDIR/../../../ |
9ac429ef | 32 | source $TESTDIR/utils/utils.sh |
17fe0490 | 33 | |
ea3a3cae CB |
34 | if [ ! -x "$TESTAPP_BIN" ]; then |
35 | BAIL_OUT "No UST events binary detected." | |
17fe0490 CB |
36 | fi |
37 | ||
24e59479 MD |
38 | function reset_bw_limit |
39 | { | |
40 | tc qdisc del dev $DEFAULT_IF root >/dev/null 2>&1 | |
41 | return $? | |
42 | } | |
43 | ||
17fe0490 CB |
44 | function 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 | ||
91 | function 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 |
100 | function 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 |
111 | function 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 | ||
126 | function 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 | ||
163 | function 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 | 171 | plan_tests $NUM_TESTS |
17fe0490 | 172 | |
e3bef725 CB |
173 | print_test_banner "$TEST_DESC" |
174 | ||
c125de8f FD |
175 | bail_out_if_no_babeltrace |
176 | ||
d346ccad CB |
177 | if [ "$(id -u)" == "0" ]; then |
178 | isroot=1 | |
179 | else | |
180 | isroot=0 | |
181 | fi | |
17fe0490 | 182 | |
d346ccad CB |
183 | skip $isroot "Root access is needed to set bandwith limits. Skipping all tests." $NUM_TESTS || |
184 | { | |
17fe0490 | 185 | |
d346ccad | 186 | # Catch sigint and try to cleanup limits |
24e59479 | 187 | trap interrupt_cleanup SIGTERM SIGINT |
d346ccad | 188 | |
0d1c8a68 KS |
189 | BW_LIMITS=(3200 400 100) |
190 | for BW in "${BW_LIMITS[@]}"; | |
d346ccad CB |
191 | do |
192 | diag "Test high-throughput with bandwidth limit set to ${BW}kbits" | |
491c49eb | 193 | |
0d1c8a68 | 194 | set_bw_limit "$BW" |
24e59479 | 195 | ok $? "Setting bandwidth limit" |
d346ccad | 196 | |
0d1c8a68 | 197 | # shellcheck disable=SC2119 |
d346ccad CB |
198 | start_lttng_sessiond |
199 | start_lttng_relayd "-o $TRACE_PATH" | |
200 | test_high_throughput | |
201 | result=$? | |
0d1c8a68 | 202 | # shellcheck disable=SC2119 |
d346ccad | 203 | stop_lttng_relayd |
0d1c8a68 | 204 | # shellcheck disable=SC2119 |
d346ccad CB |
205 | stop_lttng_sessiond |
206 | reset_bw_limit | |
24e59479 | 207 | ok $? "Reset bandwith limits" |
d346ccad CB |
208 | done |
209 | } |