Commit | Line | Data |
---|---|---|
ebaaaf5e JD |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) - 2013 Julien Desfossez <jdesfossez@efficios.com> | |
4 | # | |
5 | # This library is free software; you can redistribute it and/or modify it under | |
6 | # the terms of the GNU Lesser General Public License as published by the Free | |
7 | # Software Foundation; version 2.1 of the License. | |
8 | # | |
9 | # This library is distributed in the hope that it will be useful, but WITHOUT | |
10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
11 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
12 | # details. | |
13 | # | |
14 | # You should have received a copy of the GNU Lesser General Public License | |
15 | # along with this library; if not, write to the Free Software Foundation, Inc., | |
16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | TEST_DESC="Snapshots - UST tracing" | |
18 | ||
19 | CURDIR=$(dirname $0)/ | |
20 | TESTDIR=$CURDIR/../../.. | |
21 | EVENT_NAME="tp:tptest" | |
ebaaaf5e JD |
22 | PID_RELAYD=0 |
23 | SESSION_NAME="" | |
24 | CHANNEL_NAME="snapchan" | |
25 | TESTAPP_PATH="$TESTDIR/utils/testapp" | |
26 | TESTAPP_NAME="gen-ust-events" | |
27 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
28 | NR_ITER=2000000 | |
29 | NR_USEC_WAIT=100 | |
30 | ||
31 | TRACE_PATH=$(mktemp -d) | |
32 | ||
5e83c405 | 33 | NUM_TESTS=2075 |
ebaaaf5e JD |
34 | |
35 | source $TESTDIR/utils/utils.sh | |
36 | ||
37 | if [ ! -x "$TESTAPP_BIN" ]; then | |
38 | BAIL_OUT "No UST events binary detected." | |
39 | fi | |
40 | ||
5e83c405 CB |
41 | function snapshot_add_output () |
42 | { | |
43 | local sess_name=$1 | |
44 | local trace_path=$2 | |
45 | local name=$3 | |
46 | local max_size=$4 | |
47 | local extra_opt="" | |
48 | ||
49 | if [ ! -z $name ]; then | |
50 | extra_opt+=" -n $name " | |
51 | fi | |
52 | ||
53 | if [ ! -z $max_size ]; then | |
54 | extra_opt+=" -m $max_size " | |
55 | fi | |
56 | ||
57 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output \ | |
58 | -s $sess_name $extra_opt $trace_path > /dev/null 2>&1 | |
59 | ||
60 | ok $? "Added snapshot output $trace_path ($extra_opt)" | |
61 | } | |
62 | ||
63 | function snapshot_del_output () | |
64 | { | |
65 | local sess_name=$1 | |
66 | local name=$2 | |
67 | ||
68 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output \ | |
69 | -s $sess_name $name > /dev/null 2>&1 | |
70 | ||
71 | ok $? "Deleted snapshot output named $name" | |
72 | } | |
73 | ||
74 | function enable_mmap_overwrite_subbuf_ust_channel () | |
75 | { | |
76 | local sess_name=$1 | |
77 | local chan_name=$2 | |
78 | local subbuf_size=$3 | |
79 | ||
80 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name \ | |
81 | $chan_name -u --output mmap --overwrite \ | |
82 | --subbuf-size $subbuf_size > /dev/null 2>&1 | |
83 | ||
84 | ok $? "Enable channel $channel_name for session $sess_name with subbuf size $subbuf_size" | |
85 | } | |
86 | ||
87 | ||
88 | function test_ust_list_output () | |
89 | { | |
90 | output_names=("randomname" "somesnapshot") | |
91 | ||
92 | diag "Test UST snapshot output listing" | |
93 | create_lttng_session_no_output $SESSION_NAME | |
94 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
95 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
96 | ||
97 | start_lttng_tracing $SESSION_NAME | |
98 | ||
99 | snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" ${output_names[0]} | |
100 | ||
101 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output \ | |
102 | -s $SESSION_NAME 2>&1 | grep ${output_names[0]} > /dev/null | |
103 | ok $? "Snapshot named ${output_names[0]} present in list-output listing" | |
104 | ||
105 | snapshot_del_output $SESSION_NAME ${output_names[0]} | |
106 | ||
107 | snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" ${output_names[1]} | |
108 | ||
109 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output \ | |
110 | -s $SESSION_NAME 2>&1 | grep ${output_names[1]} > /dev/null | |
111 | ||
112 | ok $? "Snapshot named ${output_names[1]} present in list-output listing" | |
113 | ||
114 | stop_lttng_tracing $SESSION_NAME | |
115 | destroy_lttng_session $SESSION_NAME | |
116 | } | |
117 | ||
ebaaaf5e JD |
118 | function test_ust_local_snapshot () |
119 | { | |
120 | diag "Test local UST snapshots" | |
121 | create_lttng_session_no_output $SESSION_NAME | |
122 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
123 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
124 | start_lttng_tracing $SESSION_NAME | |
125 | lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH | |
126 | $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT & | |
127 | ok $? "Start application to trace" | |
128 | lttng_snapshot_record $SESSION_NAME | |
129 | stop_lttng_tracing $SESSION_NAME | |
130 | destroy_lttng_session $SESSION_NAME | |
131 | ||
132 | # Validate test | |
133 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
134 | if [ $? -eq 0 ]; then | |
135 | # Only delete if successful | |
136 | rm -rf $TRACE_PATH | |
137 | else | |
138 | break | |
139 | fi | |
140 | diag "Killing $TESTAPP_NAME" | |
141 | PID_APP=`pidof $TESTAPP_NAME` | |
142 | kill $PID_APP >/dev/null 2>&1 | |
143 | } | |
144 | ||
5e83c405 CB |
145 | function test_ust_local_snapshot_max_size () |
146 | { | |
147 | subbuf_size=8192 | |
148 | num_cpus=`nproc` | |
149 | ||
150 | # The minimum size limit is min(subbuf_size) * nb_streams | |
151 | max_size=$(($subbuf_size*$num_cpus)) | |
152 | ||
153 | diag "Test local UST snapshots with max size $max_size" | |
154 | create_lttng_session_no_output $SESSION_NAME | |
155 | ||
156 | enable_mmap_overwrite_subbuf_ust_channel $SESSION_NAME $CHANNEL_NAME $subbuf_size | |
157 | ||
158 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
159 | start_lttng_tracing $SESSION_NAME | |
160 | ||
161 | snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" "" $max_size | |
162 | ||
163 | $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT & | |
164 | ok $? "Start application to trace" | |
165 | ||
166 | lttng_snapshot_record $SESSION_NAME | |
167 | ||
168 | # Check file size | |
169 | sum_size_tracefiles=$(find $TRACE_PATH -name "${CHANNEL_NAME}_*" \ | |
170 | -exec stat -c '%s' {} \; | awk '{s = s + $1}END{print s}') | |
171 | ||
172 | if [ "$sum_size_tracefiles" -gt "$max_size" ]; then | |
173 | fail "Tracefiles size sum validation" | |
174 | diag "Tracefiles size sum: $sum_size_tracefiles Expected max: $max_size" | |
175 | fi | |
176 | ||
177 | pass "Tracefiles size sum validation" | |
178 | ||
179 | stop_lttng_tracing $SESSION_NAME | |
180 | destroy_lttng_session $SESSION_NAME | |
181 | ||
182 | # Validate test | |
183 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
184 | ||
185 | if [ $? -eq 0 ]; then | |
186 | # Only delete if successful | |
187 | rm -rf $TRACE_PATH | |
188 | fi | |
189 | ||
190 | diag "Killing $TESTAPP_NAME" | |
191 | PID_APP=`pidof $TESTAPP_NAME` | |
192 | kill $PID_APP >/dev/null 2>&1 | |
193 | } | |
194 | ||
a54047ec JD |
195 | function test_ust_local_snapshot_large_metadata () |
196 | { | |
197 | LM_EVENT="tp:tptest1,tp:tptest2,tp:tptest3,tp:tptest4,tp:tptest5" | |
198 | LM_PATH="$TESTDIR/utils/testapp" | |
199 | LM_NAME="gen-ust-nevents" | |
200 | LM_BIN="$LM_PATH/$LM_NAME/$LM_NAME" | |
201 | ||
202 | diag "Test local UST snapshots with > 4kB metadata" | |
203 | create_lttng_session_no_output $SESSION_NAME | |
204 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
205 | enable_ust_lttng_event $SESSION_NAME $LM_EVENT $CHANNEL_NAME | |
206 | start_lttng_tracing $SESSION_NAME | |
207 | lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH | |
208 | $LM_BIN 1 1 | |
209 | ok $? "Start application to trace" | |
210 | lttng_snapshot_record $SESSION_NAME | |
211 | stop_lttng_tracing $SESSION_NAME | |
212 | destroy_lttng_session $SESSION_NAME | |
213 | ||
214 | # Validate test | |
215 | validate_trace $LM_EVENT $TRACE_PATH/ | |
216 | if [ $? -eq 0 ]; then | |
217 | # Only delete if successful | |
218 | rm -rf $TRACE_PATH | |
219 | else | |
220 | break | |
221 | fi | |
222 | } | |
223 | ||
5f4c2d80 JD |
224 | function enable_channel_per_uid_mmap_overwrite() |
225 | { | |
226 | sess_name=$1 | |
227 | channel_name=$2 | |
228 | ||
229 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name --output mmap --overwrite >/dev/null 2>&1 | |
230 | ok $? "Enable channel $channel_name per UID for session $sess_name" | |
231 | } | |
232 | ||
233 | function test_ust_per_uid_local_snapshot () | |
234 | { | |
235 | diag "Test local UST snapshots" | |
236 | create_lttng_session_no_output $SESSION_NAME | |
237 | enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME | |
238 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
239 | start_lttng_tracing $SESSION_NAME | |
240 | lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH | |
241 | $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT & | |
242 | ok $? "Start application to trace" | |
243 | lttng_snapshot_record $SESSION_NAME | |
244 | stop_lttng_tracing $SESSION_NAME | |
245 | destroy_lttng_session $SESSION_NAME | |
246 | ||
247 | # Validate test | |
248 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
249 | if [ $? -eq 0 ]; then | |
250 | # Only delete if successful | |
251 | rm -rf $TRACE_PATH | |
252 | else | |
253 | break | |
254 | fi | |
255 | diag "Killing $TESTAPP_NAME" | |
256 | PID_APP=`pidof $TESTAPP_NAME` | |
257 | kill $PID_APP >/dev/null 2>&1 | |
258 | } | |
259 | ||
4f03c06d JD |
260 | function test_ust_per_uid_local_snapshot_post_mortem () |
261 | { | |
262 | diag "Test local UST snapshots post-mortem" | |
263 | create_lttng_session_no_output $SESSION_NAME | |
264 | enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME | |
265 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
266 | start_lttng_tracing $SESSION_NAME | |
267 | lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH | |
268 | $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT & | |
269 | ok $? "Start application to trace" | |
270 | diag "Killing $TESTAPP_NAME" | |
271 | PID_APP=`pidof $TESTAPP_NAME` | |
272 | kill $PID_APP >/dev/null 2>&1 | |
273 | lttng_snapshot_record $SESSION_NAME | |
274 | stop_lttng_tracing $SESSION_NAME | |
275 | destroy_lttng_session $SESSION_NAME | |
276 | ||
277 | # Validate test | |
278 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
279 | if [ $? -eq 0 ]; then | |
280 | # Only delete if successful | |
281 | rm -rf $TRACE_PATH | |
282 | else | |
283 | break | |
284 | fi | |
285 | } | |
286 | ||
ebaaaf5e JD |
287 | function test_ust_1000_local_snapshots () |
288 | { | |
289 | NB_SNAP=1000 | |
290 | ||
291 | diag "Test $NB_SNAP local UST snapshots" | |
292 | create_lttng_session_no_output $SESSION_NAME | |
293 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
294 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
295 | start_lttng_tracing $SESSION_NAME | |
296 | lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH | |
297 | $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT & | |
298 | for i in $(seq 1 $NB_SNAP); do | |
299 | diag "Snapshot $i/$NB_SNAP" | |
300 | rm -rf $TRACE_PATH/snapshot/* 2>/dev/null | |
301 | lttng_snapshot_record $SESSION_NAME | |
302 | # Validate test | |
303 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
304 | if [ $? -eq 0 ]; then | |
305 | # Only delete if successful | |
306 | rm -rf $TRACE_PATH | |
307 | else | |
308 | break | |
309 | fi | |
310 | done | |
311 | stop_lttng_tracing $SESSION_NAME | |
312 | destroy_lttng_session $SESSION_NAME | |
313 | diag "Killing $TESTAPP_NAME" | |
314 | PID_APP=`pidof $TESTAPP_NAME` | |
7f12ef5d | 315 | kill $PID_APP >/dev/null 2>&1 |
ebaaaf5e JD |
316 | } |
317 | ||
318 | plan_tests $NUM_TESTS | |
319 | ||
320 | print_test_banner "$TEST_DESC" | |
321 | ||
322 | if [ "$(id -u)" == "0" ]; then | |
323 | isroot=1 | |
324 | else | |
325 | isroot=0 | |
326 | fi | |
327 | ||
328 | start_lttng_sessiond | |
329 | ||
5e83c405 CB |
330 | tests=( test_ust_list_output |
331 | test_ust_local_snapshot | |
332 | test_ust_local_snapshot_max_size | |
333 | test_ust_per_uid_local_snapshot | |
334 | test_ust_per_uid_local_snapshot_post_mortem | |
335 | test_ust_local_snapshot_large_metadata | |
4f03c06d | 336 | test_ust_1000_local_snapshots ) |
ebaaaf5e JD |
337 | |
338 | for fct_test in ${tests[@]}; | |
339 | do | |
340 | SESSION_NAME=$(randstring 16 0) | |
341 | ${fct_test} | |
ebaaaf5e JD |
342 | done |
343 | ||
344 | stop_lttng_sessiond |