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