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 | |
ebaaaf5e | 177 | fi |
209b934f | 178 | |
0fc2834c | 179 | stop_test_apps |
ebaaaf5e JD |
180 | } |
181 | ||
5e83c405 CB |
182 | function test_ust_local_snapshot_max_size () |
183 | { | |
184 | subbuf_size=8192 | |
185 | num_cpus=`nproc` | |
186 | ||
187 | # The minimum size limit is min(subbuf_size) * nb_streams | |
188 | max_size=$(($subbuf_size*$num_cpus)) | |
189 | ||
190 | diag "Test local UST snapshots with max size $max_size" | |
191 | create_lttng_session_no_output $SESSION_NAME | |
192 | ||
193 | enable_mmap_overwrite_subbuf_ust_channel $SESSION_NAME $CHANNEL_NAME $subbuf_size | |
194 | ||
195 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
196 | start_lttng_tracing $SESSION_NAME | |
197 | ||
198 | snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" "" $max_size | |
199 | ||
209b934f DG |
200 | # Returns once the application has at least fired ONE tracepoint. |
201 | start_test_app | |
5e83c405 CB |
202 | |
203 | lttng_snapshot_record $SESSION_NAME | |
204 | ||
205 | # Check file size | |
206 | sum_size_tracefiles=$(find $TRACE_PATH -name "${CHANNEL_NAME}_*" \ | |
207 | -exec stat -c '%s' {} \; | awk '{s = s + $1}END{print s}') | |
208 | ||
209 | if [ "$sum_size_tracefiles" -gt "$max_size" ]; then | |
210 | fail "Tracefiles size sum validation" | |
211 | diag "Tracefiles size sum: $sum_size_tracefiles Expected max: $max_size" | |
212 | fi | |
213 | ||
214 | pass "Tracefiles size sum validation" | |
215 | ||
216 | stop_lttng_tracing $SESSION_NAME | |
217 | destroy_lttng_session $SESSION_NAME | |
218 | ||
219 | # Validate test | |
220 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
221 | ||
222 | if [ $? -eq 0 ]; then | |
223 | # Only delete if successful | |
224 | rm -rf $TRACE_PATH | |
225 | fi | |
226 | ||
0fc2834c | 227 | stop_test_apps |
5e83c405 CB |
228 | } |
229 | ||
a54047ec JD |
230 | function test_ust_local_snapshot_large_metadata () |
231 | { | |
232 | LM_EVENT="tp:tptest1,tp:tptest2,tp:tptest3,tp:tptest4,tp:tptest5" | |
233 | LM_PATH="$TESTDIR/utils/testapp" | |
234 | LM_NAME="gen-ust-nevents" | |
235 | LM_BIN="$LM_PATH/$LM_NAME/$LM_NAME" | |
236 | ||
237 | diag "Test local UST snapshots with > 4kB metadata" | |
238 | create_lttng_session_no_output $SESSION_NAME | |
239 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
240 | enable_ust_lttng_event $SESSION_NAME $LM_EVENT $CHANNEL_NAME | |
241 | start_lttng_tracing $SESSION_NAME | |
242 | lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH | |
243 | $LM_BIN 1 1 | |
244 | ok $? "Start application to trace" | |
245 | lttng_snapshot_record $SESSION_NAME | |
246 | stop_lttng_tracing $SESSION_NAME | |
247 | destroy_lttng_session $SESSION_NAME | |
248 | ||
249 | # Validate test | |
250 | validate_trace $LM_EVENT $TRACE_PATH/ | |
251 | if [ $? -eq 0 ]; then | |
252 | # Only delete if successful | |
253 | rm -rf $TRACE_PATH | |
a54047ec JD |
254 | fi |
255 | } | |
256 | ||
5f4c2d80 JD |
257 | function enable_channel_per_uid_mmap_overwrite() |
258 | { | |
259 | sess_name=$1 | |
260 | channel_name=$2 | |
261 | ||
262 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name --output mmap --overwrite >/dev/null 2>&1 | |
263 | ok $? "Enable channel $channel_name per UID for session $sess_name" | |
264 | } | |
265 | ||
266 | function test_ust_per_uid_local_snapshot () | |
267 | { | |
268 | diag "Test local UST snapshots" | |
269 | create_lttng_session_no_output $SESSION_NAME | |
270 | enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME | |
271 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
272 | start_lttng_tracing $SESSION_NAME | |
273 | lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH | |
209b934f DG |
274 | |
275 | # Returns once the application has at least fired ONE tracepoint. | |
276 | start_test_app | |
277 | ||
5f4c2d80 JD |
278 | lttng_snapshot_record $SESSION_NAME |
279 | stop_lttng_tracing $SESSION_NAME | |
280 | destroy_lttng_session $SESSION_NAME | |
281 | ||
282 | # Validate test | |
283 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
284 | if [ $? -eq 0 ]; then | |
285 | # Only delete if successful | |
286 | rm -rf $TRACE_PATH | |
5f4c2d80 | 287 | fi |
209b934f | 288 | |
0fc2834c | 289 | stop_test_apps |
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 | |
0fc2834c | 303 | stop_test_apps |
209b934f | 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 | |
4f03c06d JD |
314 | fi |
315 | } | |
316 | ||
1d20c959 | 317 | function test_ust_local_snapshots () |
ebaaaf5e | 318 | { |
1d20c959 | 319 | diag "Test $NR_SNAPSHOT local UST snapshots" |
ebaaaf5e JD |
320 | create_lttng_session_no_output $SESSION_NAME |
321 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
322 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
323 | start_lttng_tracing $SESSION_NAME | |
324 | lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH | |
209b934f DG |
325 | |
326 | # Returns once the application has at least fired ONE tracepoint. | |
327 | start_test_app | |
328 | ||
1d20c959 DG |
329 | for i in $(seq 1 $NR_SNAPSHOT); do |
330 | diag "Snapshot $i/$NR_SNAPSHOT" | |
ebaaaf5e JD |
331 | rm -rf $TRACE_PATH/snapshot/* 2>/dev/null |
332 | lttng_snapshot_record $SESSION_NAME | |
333 | # Validate test | |
334 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
335 | if [ $? -eq 0 ]; then | |
336 | # Only delete if successful | |
337 | rm -rf $TRACE_PATH | |
ebaaaf5e JD |
338 | fi |
339 | done | |
340 | stop_lttng_tracing $SESSION_NAME | |
341 | destroy_lttng_session $SESSION_NAME | |
209b934f | 342 | |
0fc2834c | 343 | stop_test_apps |
ebaaaf5e JD |
344 | } |
345 | ||
346 | plan_tests $NUM_TESTS | |
347 | ||
348 | print_test_banner "$TEST_DESC" | |
349 | ||
ebaaaf5e JD |
350 | start_lttng_sessiond |
351 | ||
5e83c405 CB |
352 | tests=( test_ust_list_output |
353 | test_ust_local_snapshot | |
354 | test_ust_local_snapshot_max_size | |
355 | test_ust_per_uid_local_snapshot | |
356 | test_ust_per_uid_local_snapshot_post_mortem | |
357 | test_ust_local_snapshot_large_metadata | |
1d20c959 | 358 | test_ust_local_snapshots) |
ebaaaf5e JD |
359 | |
360 | for fct_test in ${tests[@]}; | |
361 | do | |
362 | SESSION_NAME=$(randstring 16 0) | |
363 | ${fct_test} | |
ebaaaf5e JD |
364 | done |
365 | ||
366 | stop_lttng_sessiond |