fix: relayd: unaligned access in trace_chunk_registry_ht_key_hash
[lttng-tools.git] / tests / regression / tools / streaming / test_high_throughput_limits
1 #!/bin/bash
2 #
3 # Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
4 # Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
5 #
6 # SPDX-License-Identifier: LGPL-2.1-only
7
8 TEST_DESC="Streaming - High throughput with bandwidth limits"
9
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/../../.."
16 NR_APP_ITER=10
17 NR_ITER=5000
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
25 DEFAULT_IF="lo"
26
27 TRACE_PATH=$(mktemp -d -t tmp.test_streaming_high_throughput_limits_trace_path.XXXXXX)
28
29 NUM_TESTS=39
30
31 # shellcheck source-path=SCRIPTDIR/../../../
32 source $TESTDIR/utils/utils.sh
33
34 if [ ! -x "$TESTAPP_BIN" ]; then
35 BAIL_OUT "No UST events binary detected."
36 fi
37
38 function reset_bw_limit
39 {
40 tc qdisc del dev $DEFAULT_IF root >/dev/null 2>&1
41 return $?
42 }
43
44 function set_bw_limit
45 {
46 limit=$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}))
53
54 diag "Set bandwidth limits to ${limit}kbits, ${ctrlportlimit} for control and ${dataportlimit} for data"
55
56 if ! tc qdisc add dev $DEFAULT_IF root handle 1: htb default 15 >/dev/null 2>&1 ; then
57 reset_bw_limit
58 return 1
59 fi
60
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
63 reset_bw_limit
64 return 1
65 fi
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
68 reset_bw_limit
69 return 1
70 fi
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
73 reset_bw_limit
74 return 1
75 fi
76
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
79 reset_bw_limit
80 return 1
81 fi
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
84 reset_bw_limit
85 return 1
86 fi
87
88 return 0
89 }
90
91 function create_lttng_session_with_uri
92 {
93 sess_name=$1
94 uri=$2
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"
98 }
99
100 function run_apps
101 {
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 &
108 done
109 }
110
111 function test_high_throughput
112 {
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
117 run_apps
118 diag "Waiting for applications to end"
119 wait
120 pass "waiting done"
121 stop_lttng_tracing_ok $SESSION_NAME
122 destroy_lttng_session_ok $SESSION_NAME
123 validate_event_count
124 }
125
126 function validate_event_count
127 {
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)
130
131 traced=$("$BABELTRACE_BIN" "$TRACE_PATH" 2>/dev/null | wc -l)
132 "$BABELTRACE_BIN" "$TRACE_PATH" >/dev/null 2>"$TEMP_FILE_2"
133
134 cat "$TEMP_FILE_2" | cut -f4 -d " " >"$TEMP_FILE"
135
136 dropped=0
137 while read -r line; do
138 dropped=$(( dropped + line ))
139 done < "$TEMP_FILE"
140
141 total=$(( dropped + traced ))
142 wanted=$(( NR_APP_ITER * NR_ITER ))
143
144 if [ $dropped -le 0 ]; then
145 diag "No dropped events during test, consider increasing the number of " \
146 "apps or iterations"
147 fi
148 if [ $wanted -ne $total ]; then
149 fail "Validate trace event count"
150 diag "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... "
151 return 1
152 else
153 pass "Validate trace event count"
154 diag "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... "
155
156 rm -rf "$TRACE_PATH"
157 rm "$TEMP_FILE" "$TEMP_FILE_2"
158
159 return 0
160 fi
161 }
162
163 function interrupt_cleanup()
164 {
165 diag "*** Exiting ***"
166 reset_bw_limit
167 # invoke utils cleanup
168 full_cleanup
169 }
170
171 plan_tests $NUM_TESTS
172
173 print_test_banner "$TEST_DESC"
174
175 bail_out_if_no_babeltrace
176
177 check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
178 {
179
180 # Catch sigint and try to cleanup limits
181 trap interrupt_cleanup SIGTERM SIGINT
182
183 BW_LIMITS=(3200 400 100)
184 for BW in "${BW_LIMITS[@]}";
185 do
186 diag "Test high-throughput with bandwidth limit set to ${BW}kbits"
187
188 set_bw_limit "$BW"
189 ok $? "Setting bandwidth limit"
190
191 # shellcheck disable=SC2119
192 start_lttng_sessiond
193 start_lttng_relayd "-o $TRACE_PATH"
194 test_high_throughput
195 result=$?
196 # shellcheck disable=SC2119
197 stop_lttng_relayd
198 # shellcheck disable=SC2119
199 stop_lttng_sessiond
200 reset_bw_limit
201 ok $? "Reset bandwith limits"
202 done
203 }
This page took 0.03577 seconds and 4 git commands to generate.