Commit | Line | Data |
---|---|---|
17fe0490 CB |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) - 2012 Christian Babeux <christian.babeux@efficios.com> | |
4 | # David Goulet <dgoulet@efficios.com> | |
5 | # | |
6 | # This library is free software; you can redistribute it and/or modify it under | |
7 | # the terms of the GNU Lesser General Public License as published by the Free | |
8 | # Software Foundation; version 2.1 of the License. | |
9 | # | |
10 | # This library is distributed in the hope that it will be useful, but WITHOUT | |
11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
12 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
13 | # details. | |
14 | # | |
15 | # You should have received a copy of the GNU Lesser General Public License | |
16 | # along with this library; if not, write to the Free Software Foundation, Inc., | |
17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | TEST_DESC="Streaming - High throughput with bandwith limits" | |
19 | ||
20 | CURDIR=$(dirname $0)/ | |
21 | TESTDIR=$CURDIR/../.. | |
22 | NR_APP_ITER=10 | |
23 | NR_ITER=1000000 | |
24 | BIN_NAME="gen-ust-events" | |
25 | SESSION_NAME="high-throughput" | |
26 | EVENT_NAME="tp:tptest" | |
27 | SESSIOND_CTRL_PORT=5342 | |
28 | SESSIOND_DATA_PORT=5343 | |
29 | DEFAULT_IF="lo" | |
30 | ||
31 | TRACE_PATH=$(mktemp -d) | |
32 | ||
33 | source $TESTDIR/utils.sh | |
34 | ||
35 | print_test_banner "$TEST_DESC" | |
36 | ||
37 | if [ ! -x "$CURDIR/$BIN_NAME" ]; then | |
38 | echo -e "No UST nevents binary detected. Passing." | |
39 | exit 0 | |
40 | fi | |
41 | ||
42 | if [ "$(id -u)" != "0" ]; then | |
43 | echo "This test must be running as root to set bandwith limits. Aborting" | |
44 | # Exit status 0 so the tests can continue | |
45 | exit 0 | |
46 | fi | |
47 | ||
48 | function set_bw_limit | |
49 | { | |
50 | limit=$1 | |
51 | echo -n "Setting bandwith limits to ${limit}kbits... " | |
52 | tc qdisc add dev $DEFAULT_IF root handle 1: htb default 15 >/dev/null 2>&1 | |
53 | tc class add dev $DEFAULT_IF parent 1: classid 1:1 htb rate ${limit}kbit ceil ${limit}kbit >/dev/null 2>&1 | |
54 | ||
55 | # FIXME: Timeout when setting limits on ctrl port. | |
56 | #tc filter add dev $DEFAULT_IF parent 1: protocol ip u32 match ip dport $SESSIOND_CTRL_PORT 0xffff flowid 1:1 >/dev/null 2>&1 | |
57 | ||
58 | tc filter add dev $DEFAULT_IF parent 1: protocol ip u32 match ip dport $SESSIOND_DATA_PORT 0xffff flowid 1:1 >/dev/null 2>&1 | |
59 | print_ok | |
60 | } | |
61 | ||
62 | function reset_bw_limit | |
63 | { | |
64 | echo -n "Resetting bandwith limits... " | |
65 | tc qdisc del dev $DEFAULT_IF root >/dev/null 2>&1 | |
66 | print_ok | |
67 | } | |
68 | ||
69 | function create_lttng_session_with_uri | |
70 | { | |
71 | sess_name=$1 | |
72 | uri=$2 | |
73 | # Create session with custom URI | |
74 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create -U $uri $sess_name >/dev/null 2>&1 | |
75 | } | |
76 | ||
77 | function enable_lttng_consumer | |
78 | { | |
79 | uri=$1 | |
80 | # Create session with custom URI | |
81 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-consumer -u $uri >/dev/null 2>&1 | |
82 | } | |
83 | ||
84 | function run_apps | |
85 | { | |
86 | for i in `seq 1 $NR_APP_ITER`; do | |
87 | ./$CURDIR/$BIN_NAME $NR_ITER & >/dev/null 2>&1 | |
88 | done | |
89 | } | |
90 | ||
91 | function wait_apps | |
92 | { | |
93 | echo "Waiting for applications to end" | |
94 | while [ -n "$(pidof $BIN_NAME)" ]; do | |
95 | echo -n "." | |
96 | sleep 1 | |
97 | done | |
98 | echo "" | |
99 | } | |
100 | ||
101 | function test_high_throughput | |
102 | { | |
103 | NETWORK_URI="net://localhost" | |
104 | create_lttng_session_with_uri $SESSION_NAME $NETWORK_URI | |
105 | enable_lttng_consumer $NETWORK_URI | |
106 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME | |
107 | start_lttng_tracing $SESSION_NAME | |
108 | run_apps | |
109 | wait_apps | |
110 | ||
111 | # FIXME: Should not be necessary... | |
112 | #echo "Sleeping..." | |
113 | #sleep 180 | |
114 | ||
115 | stop_lttng_tracing $SESSION_NAME | |
116 | destroy_lttng_session $SESSION_NAME | |
117 | validate_event_count | |
118 | } | |
119 | ||
120 | function validate_event_count | |
121 | { | |
122 | ||
123 | TEMP_FILE=$(mktemp) | |
124 | TEMP_FILE_2=$(mktemp) | |
125 | ||
126 | traced=$(babeltrace $TRACE_PATH 2>/dev/null | wc -l) | |
127 | babeltrace $TRACE_PATH >/dev/null 2>$TEMP_FILE_2 | |
128 | ||
129 | cat $TEMP_FILE_2 | cut -f4 -d " " >$TEMP_FILE | |
130 | ||
131 | dropped=0 | |
132 | while read line; | |
133 | do | |
134 | let dropped=$dropped+$line | |
135 | done < $TEMP_FILE | |
136 | ||
137 | let total=$dropped+$traced | |
138 | let wanted=$NR_APP_ITER*$NR_ITER | |
139 | ||
140 | rm -rf $TRACE_PATH | |
141 | rm $TEMP_FILE $TEMP_FILE_2 | |
142 | ||
143 | if [ $wanted -ne $total ]; then | |
144 | echo -n "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... " | |
145 | print_fail | |
146 | return 1 | |
147 | else | |
148 | echo -n "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... " | |
149 | print_ok | |
150 | return 0 | |
151 | fi | |
152 | } | |
153 | ||
154 | function interrupt_cleanup() | |
155 | { | |
156 | echo -en "\n*** Exiting ***\n" | |
157 | stop_lttng_relayd | |
158 | stop_lttng_sessiond | |
159 | reset_bw_limit | |
160 | exit 1 | |
161 | } | |
162 | ||
163 | # Catch sigint and try to cleanup limits | |
164 | trap interrupt_cleanup SIGINT | |
165 | ||
166 | BW_LIMITS=(3200 1600 800 400 200 100 50 25) | |
167 | for BW in ${BW_LIMITS[@]}; | |
168 | do | |
169 | echo "" | |
170 | echo -e "=== Testing high-throughput with bandwith limit set to ${BW}kbits" | |
171 | set_bw_limit $BW | |
172 | ||
173 | start_lttng_sessiond | |
174 | start_lttng_relayd "-o $TRACE_PATH" | |
175 | test_high_throughput | |
176 | result=$? | |
177 | stop_lttng_relayd | |
178 | stop_lttng_sessiond | |
179 | reset_bw_limit | |
180 | ||
181 | if [ $result -ne 0 ]; then | |
182 | exit 1 | |
183 | fi | |
184 | done |