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 | |
0fc2834c | 30 | APPS_PID= |
ebaaaf5e | 31 | |
1d20c959 | 32 | NUM_TESTS=76 |
ebaaaf5e | 33 | |
1d20c959 | 34 | TRACE_PATH=$(mktemp -d) |
ebaaaf5e JD |
35 | |
36 | source $TESTDIR/utils/utils.sh | |
37 | ||
38 | if [ ! -x "$TESTAPP_BIN" ]; then | |
39 | BAIL_OUT "No UST events binary detected." | |
40 | fi | |
41 | ||
1d20c959 DG |
42 | # Need the number of snapshot to do. |
43 | if [ -z $1 ]; then | |
44 | BAIL_OUT "A number of snapshot is needed." | |
45 | fi | |
46 | NR_SNAPSHOT=$1 | |
47 | ||
48 | NUM_TESTS=$(($NUM_TESTS + ($NR_SNAPSHOT * 2))) | |
49 | ||
209b934f DG |
50 | function start_test_app() |
51 | { | |
5fcaccbc | 52 | local tmp_file=$(mktemp -u) |
209b934f DG |
53 | |
54 | # Start application with a temporary file. | |
55 | $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file & | |
0fc2834c MD |
56 | ret=$? |
57 | APPS_PID="${APPS_PID} ${!}" | |
58 | ok $ret "Start application to trace" | |
209b934f DG |
59 | |
60 | # Wait for the application file to appear indicating that at least one | |
61 | # tracepoint has been fired. | |
62 | while [ ! -f "$tmp_file" ]; do | |
63 | sleep 0.5 | |
64 | done | |
65 | diag "Removing test app temporary file $tmp_file" | |
66 | rm -f $tmp_file | |
67 | } | |
68 | ||
0fc2834c | 69 | function stop_test_apps() |
209b934f | 70 | { |
0fc2834c MD |
71 | diag "Stopping $TESTAPP_NAME" |
72 | for p in ${APPS_PID}; do | |
73 | kill ${p} | |
5402fe87 | 74 | wait ${p} 2>/dev/null |
0fc2834c | 75 | done |
c7613334 | 76 | APPS_PID= |
209b934f DG |
77 | } |
78 | ||
5e83c405 CB |
79 | function snapshot_add_output () |
80 | { | |
81 | local sess_name=$1 | |
82 | local trace_path=$2 | |
83 | local name=$3 | |
84 | local max_size=$4 | |
85 | local extra_opt="" | |
86 | ||
87 | if [ ! -z $name ]; then | |
88 | extra_opt+=" -n $name " | |
89 | fi | |
90 | ||
91 | if [ ! -z $max_size ]; then | |
92 | extra_opt+=" -m $max_size " | |
93 | fi | |
94 | ||
95 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output \ | |
96 | -s $sess_name $extra_opt $trace_path > /dev/null 2>&1 | |
97 | ||
98 | ok $? "Added snapshot output $trace_path ($extra_opt)" | |
99 | } | |
100 | ||
101 | function snapshot_del_output () | |
102 | { | |
103 | local sess_name=$1 | |
104 | local name=$2 | |
105 | ||
106 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output \ | |
107 | -s $sess_name $name > /dev/null 2>&1 | |
108 | ||
109 | ok $? "Deleted snapshot output named $name" | |
110 | } | |
111 | ||
112 | function enable_mmap_overwrite_subbuf_ust_channel () | |
113 | { | |
114 | local sess_name=$1 | |
115 | local chan_name=$2 | |
116 | local subbuf_size=$3 | |
117 | ||
118 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name \ | |
119 | $chan_name -u --output mmap --overwrite \ | |
120 | --subbuf-size $subbuf_size > /dev/null 2>&1 | |
121 | ||
122 | ok $? "Enable channel $channel_name for session $sess_name with subbuf size $subbuf_size" | |
123 | } | |
124 | ||
125 | ||
126 | function test_ust_list_output () | |
127 | { | |
128 | output_names=("randomname" "somesnapshot") | |
129 | ||
130 | diag "Test UST snapshot output listing" | |
131 | create_lttng_session_no_output $SESSION_NAME | |
132 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
133 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
134 | ||
135 | start_lttng_tracing $SESSION_NAME | |
136 | ||
137 | snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" ${output_names[0]} | |
138 | ||
139 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output \ | |
140 | -s $SESSION_NAME 2>&1 | grep ${output_names[0]} > /dev/null | |
141 | ok $? "Snapshot named ${output_names[0]} present in list-output listing" | |
142 | ||
143 | snapshot_del_output $SESSION_NAME ${output_names[0]} | |
144 | ||
145 | snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" ${output_names[1]} | |
146 | ||
147 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output \ | |
148 | -s $SESSION_NAME 2>&1 | grep ${output_names[1]} > /dev/null | |
149 | ||
150 | ok $? "Snapshot named ${output_names[1]} present in list-output listing" | |
151 | ||
152 | stop_lttng_tracing $SESSION_NAME | |
153 | destroy_lttng_session $SESSION_NAME | |
154 | } | |
155 | ||
ebaaaf5e JD |
156 | function test_ust_local_snapshot () |
157 | { | |
158 | diag "Test local UST snapshots" | |
159 | create_lttng_session_no_output $SESSION_NAME | |
160 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
161 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
162 | start_lttng_tracing $SESSION_NAME | |
163 | lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH | |
209b934f DG |
164 | |
165 | # Returns once the application has at least fired ONE tracepoint. | |
166 | start_test_app | |
167 | ||
ebaaaf5e JD |
168 | lttng_snapshot_record $SESSION_NAME |
169 | stop_lttng_tracing $SESSION_NAME | |
170 | destroy_lttng_session $SESSION_NAME | |
171 | ||
172 | # Validate test | |
173 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
174 | if [ $? -eq 0 ]; then | |
175 | # Only delete if successful | |
176 | rm -rf $TRACE_PATH | |
177 | else | |
178 | break | |
179 | fi | |
209b934f | 180 | |
0fc2834c | 181 | stop_test_apps |
ebaaaf5e JD |
182 | } |
183 | ||
5e83c405 CB |
184 | function test_ust_local_snapshot_max_size () |
185 | { | |
186 | subbuf_size=8192 | |
187 | num_cpus=`nproc` | |
188 | ||
189 | # The minimum size limit is min(subbuf_size) * nb_streams | |
190 | max_size=$(($subbuf_size*$num_cpus)) | |
191 | ||
192 | diag "Test local UST snapshots with max size $max_size" | |
193 | create_lttng_session_no_output $SESSION_NAME | |
194 | ||
195 | enable_mmap_overwrite_subbuf_ust_channel $SESSION_NAME $CHANNEL_NAME $subbuf_size | |
196 | ||
197 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
198 | start_lttng_tracing $SESSION_NAME | |
199 | ||
200 | snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" "" $max_size | |
201 | ||
209b934f DG |
202 | # Returns once the application has at least fired ONE tracepoint. |
203 | start_test_app | |
5e83c405 CB |
204 | |
205 | lttng_snapshot_record $SESSION_NAME | |
206 | ||
207 | # Check file size | |
208 | sum_size_tracefiles=$(find $TRACE_PATH -name "${CHANNEL_NAME}_*" \ | |
209 | -exec stat -c '%s' {} \; | awk '{s = s + $1}END{print s}') | |
210 | ||
211 | if [ "$sum_size_tracefiles" -gt "$max_size" ]; then | |
212 | fail "Tracefiles size sum validation" | |
213 | diag "Tracefiles size sum: $sum_size_tracefiles Expected max: $max_size" | |
214 | fi | |
215 | ||
216 | pass "Tracefiles size sum validation" | |
217 | ||
218 | stop_lttng_tracing $SESSION_NAME | |
219 | destroy_lttng_session $SESSION_NAME | |
220 | ||
221 | # Validate test | |
222 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
223 | ||
224 | if [ $? -eq 0 ]; then | |
225 | # Only delete if successful | |
226 | rm -rf $TRACE_PATH | |
227 | fi | |
228 | ||
0fc2834c | 229 | stop_test_apps |
5e83c405 CB |
230 | } |
231 | ||
a54047ec JD |
232 | function test_ust_local_snapshot_large_metadata () |
233 | { | |
234 | LM_EVENT="tp:tptest1,tp:tptest2,tp:tptest3,tp:tptest4,tp:tptest5" | |
235 | LM_PATH="$TESTDIR/utils/testapp" | |
236 | LM_NAME="gen-ust-nevents" | |
237 | LM_BIN="$LM_PATH/$LM_NAME/$LM_NAME" | |
238 | ||
239 | diag "Test local UST snapshots with > 4kB metadata" | |
240 | create_lttng_session_no_output $SESSION_NAME | |
241 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
242 | enable_ust_lttng_event $SESSION_NAME $LM_EVENT $CHANNEL_NAME | |
243 | start_lttng_tracing $SESSION_NAME | |
244 | lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH | |
245 | $LM_BIN 1 1 | |
246 | ok $? "Start application to trace" | |
247 | lttng_snapshot_record $SESSION_NAME | |
248 | stop_lttng_tracing $SESSION_NAME | |
249 | destroy_lttng_session $SESSION_NAME | |
250 | ||
251 | # Validate test | |
252 | validate_trace $LM_EVENT $TRACE_PATH/ | |
253 | if [ $? -eq 0 ]; then | |
254 | # Only delete if successful | |
255 | rm -rf $TRACE_PATH | |
256 | else | |
257 | break | |
258 | fi | |
259 | } | |
260 | ||
5f4c2d80 JD |
261 | function enable_channel_per_uid_mmap_overwrite() |
262 | { | |
263 | sess_name=$1 | |
264 | channel_name=$2 | |
265 | ||
266 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name --output mmap --overwrite >/dev/null 2>&1 | |
267 | ok $? "Enable channel $channel_name per UID for session $sess_name" | |
268 | } | |
269 | ||
270 | function test_ust_per_uid_local_snapshot () | |
271 | { | |
272 | diag "Test local UST snapshots" | |
273 | create_lttng_session_no_output $SESSION_NAME | |
274 | enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME | |
275 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
276 | start_lttng_tracing $SESSION_NAME | |
277 | lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH | |
209b934f DG |
278 | |
279 | # Returns once the application has at least fired ONE tracepoint. | |
280 | start_test_app | |
281 | ||
5f4c2d80 JD |
282 | lttng_snapshot_record $SESSION_NAME |
283 | stop_lttng_tracing $SESSION_NAME | |
284 | destroy_lttng_session $SESSION_NAME | |
285 | ||
286 | # Validate test | |
287 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
288 | if [ $? -eq 0 ]; then | |
289 | # Only delete if successful | |
290 | rm -rf $TRACE_PATH | |
291 | else | |
292 | break | |
293 | fi | |
209b934f | 294 | |
0fc2834c | 295 | stop_test_apps |
5f4c2d80 JD |
296 | } |
297 | ||
4f03c06d JD |
298 | function test_ust_per_uid_local_snapshot_post_mortem () |
299 | { | |
300 | diag "Test local UST snapshots post-mortem" | |
301 | create_lttng_session_no_output $SESSION_NAME | |
302 | enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME | |
303 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
304 | start_lttng_tracing $SESSION_NAME | |
305 | lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH | |
209b934f DG |
306 | |
307 | # Returns once the application has at least fired ONE tracepoint. | |
308 | start_test_app | |
0fc2834c | 309 | stop_test_apps |
209b934f | 310 | |
4f03c06d JD |
311 | lttng_snapshot_record $SESSION_NAME |
312 | stop_lttng_tracing $SESSION_NAME | |
313 | destroy_lttng_session $SESSION_NAME | |
314 | ||
315 | # Validate test | |
316 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
317 | if [ $? -eq 0 ]; then | |
318 | # Only delete if successful | |
319 | rm -rf $TRACE_PATH | |
320 | else | |
321 | break | |
322 | fi | |
323 | } | |
324 | ||
1d20c959 | 325 | function test_ust_local_snapshots () |
ebaaaf5e | 326 | { |
1d20c959 | 327 | diag "Test $NR_SNAPSHOT local UST snapshots" |
ebaaaf5e JD |
328 | create_lttng_session_no_output $SESSION_NAME |
329 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
330 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
331 | start_lttng_tracing $SESSION_NAME | |
332 | lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH | |
209b934f DG |
333 | |
334 | # Returns once the application has at least fired ONE tracepoint. | |
335 | start_test_app | |
336 | ||
1d20c959 DG |
337 | for i in $(seq 1 $NR_SNAPSHOT); do |
338 | diag "Snapshot $i/$NR_SNAPSHOT" | |
ebaaaf5e JD |
339 | rm -rf $TRACE_PATH/snapshot/* 2>/dev/null |
340 | lttng_snapshot_record $SESSION_NAME | |
341 | # Validate test | |
342 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
343 | if [ $? -eq 0 ]; then | |
344 | # Only delete if successful | |
345 | rm -rf $TRACE_PATH | |
346 | else | |
347 | break | |
348 | fi | |
349 | done | |
350 | stop_lttng_tracing $SESSION_NAME | |
351 | destroy_lttng_session $SESSION_NAME | |
209b934f | 352 | |
0fc2834c | 353 | stop_test_apps |
ebaaaf5e JD |
354 | } |
355 | ||
356 | plan_tests $NUM_TESTS | |
357 | ||
358 | print_test_banner "$TEST_DESC" | |
359 | ||
ebaaaf5e JD |
360 | start_lttng_sessiond |
361 | ||
5e83c405 CB |
362 | tests=( test_ust_list_output |
363 | test_ust_local_snapshot | |
364 | test_ust_local_snapshot_max_size | |
365 | test_ust_per_uid_local_snapshot | |
366 | test_ust_per_uid_local_snapshot_post_mortem | |
367 | test_ust_local_snapshot_large_metadata | |
1d20c959 | 368 | test_ust_local_snapshots) |
ebaaaf5e JD |
369 | |
370 | for fct_test in ${tests[@]}; | |
371 | do | |
372 | SESSION_NAME=$(randstring 16 0) | |
373 | ${fct_test} | |
ebaaaf5e JD |
374 | done |
375 | ||
376 | stop_lttng_sessiond |