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