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 | |
c4926bb5 | 133 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
5e83c405 | 134 | |
e563bbdb | 135 | start_lttng_tracing_ok $SESSION_NAME |
5e83c405 CB |
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 | ||
96340a01 | 152 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 153 | destroy_lttng_session_ok $SESSION_NAME |
5e83c405 CB |
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 | |
c4926bb5 | 161 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
e563bbdb | 162 | start_lttng_tracing_ok $SESSION_NAME |
b5633831 | 163 | lttng_snapshot_add_output_ok $SESSION_NAME $TRACE_PATH |
209b934f DG |
164 | |
165 | # Returns once the application has at least fired ONE tracepoint. | |
166 | start_test_app | |
167 | ||
ebaaaf5e | 168 | lttng_snapshot_record $SESSION_NAME |
96340a01 | 169 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 170 | destroy_lttng_session_ok $SESSION_NAME |
ebaaaf5e JD |
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 | { | |
54959037 | 184 | page_size=`getconf PAGE_SIZE` |
9dfe0fe1 | 185 | num_cpus=$(conf_proc_count) |
5e83c405 | 186 | |
54959037 MJ |
187 | # The minimum subbuf size is the platform PAGE_SIZE |
188 | subbuf_size=$(($page_size*2)) | |
189 | ||
5e83c405 CB |
190 | # The minimum size limit is min(subbuf_size) * nb_streams |
191 | max_size=$(($subbuf_size*$num_cpus)) | |
192 | ||
193 | diag "Test local UST snapshots with max size $max_size" | |
194 | create_lttng_session_no_output $SESSION_NAME | |
195 | ||
196 | enable_mmap_overwrite_subbuf_ust_channel $SESSION_NAME $CHANNEL_NAME $subbuf_size | |
197 | ||
c4926bb5 | 198 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
e563bbdb | 199 | start_lttng_tracing_ok $SESSION_NAME |
5e83c405 CB |
200 | |
201 | snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" "" $max_size | |
202 | ||
209b934f DG |
203 | # Returns once the application has at least fired ONE tracepoint. |
204 | start_test_app | |
5e83c405 CB |
205 | |
206 | lttng_snapshot_record $SESSION_NAME | |
207 | ||
208 | # Check file size | |
209 | sum_size_tracefiles=$(find $TRACE_PATH -name "${CHANNEL_NAME}_*" \ | |
210 | -exec stat -c '%s' {} \; | awk '{s = s + $1}END{print s}') | |
211 | ||
212 | if [ "$sum_size_tracefiles" -gt "$max_size" ]; then | |
213 | fail "Tracefiles size sum validation" | |
214 | diag "Tracefiles size sum: $sum_size_tracefiles Expected max: $max_size" | |
215 | fi | |
216 | ||
217 | pass "Tracefiles size sum validation" | |
218 | ||
96340a01 | 219 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 220 | destroy_lttng_session_ok $SESSION_NAME |
5e83c405 CB |
221 | |
222 | # Validate test | |
223 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
224 | ||
225 | if [ $? -eq 0 ]; then | |
226 | # Only delete if successful | |
227 | rm -rf $TRACE_PATH | |
228 | fi | |
229 | ||
0fc2834c | 230 | stop_test_apps |
5e83c405 CB |
231 | } |
232 | ||
a54047ec JD |
233 | function test_ust_local_snapshot_large_metadata () |
234 | { | |
235 | LM_EVENT="tp:tptest1,tp:tptest2,tp:tptest3,tp:tptest4,tp:tptest5" | |
236 | LM_PATH="$TESTDIR/utils/testapp" | |
237 | LM_NAME="gen-ust-nevents" | |
238 | LM_BIN="$LM_PATH/$LM_NAME/$LM_NAME" | |
239 | ||
240 | diag "Test local UST snapshots with > 4kB metadata" | |
241 | create_lttng_session_no_output $SESSION_NAME | |
242 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
c4926bb5 | 243 | enable_ust_lttng_event_ok $SESSION_NAME $LM_EVENT $CHANNEL_NAME |
e563bbdb | 244 | start_lttng_tracing_ok $SESSION_NAME |
b5633831 | 245 | lttng_snapshot_add_output_ok $SESSION_NAME $TRACE_PATH |
a54047ec JD |
246 | $LM_BIN 1 1 |
247 | ok $? "Start application to trace" | |
248 | lttng_snapshot_record $SESSION_NAME | |
96340a01 | 249 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 250 | destroy_lttng_session_ok $SESSION_NAME |
a54047ec JD |
251 | |
252 | # Validate test | |
253 | validate_trace $LM_EVENT $TRACE_PATH/ | |
254 | if [ $? -eq 0 ]; then | |
255 | # Only delete if successful | |
256 | rm -rf $TRACE_PATH | |
a54047ec JD |
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 | { | |
53a14ff2 | 271 | diag "Test per-uid local UST snapshots" |
5f4c2d80 JD |
272 | create_lttng_session_no_output $SESSION_NAME |
273 | enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME | |
c4926bb5 | 274 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
e563bbdb | 275 | start_lttng_tracing_ok $SESSION_NAME |
b5633831 | 276 | lttng_snapshot_add_output_ok $SESSION_NAME $TRACE_PATH |
209b934f DG |
277 | |
278 | # Returns once the application has at least fired ONE tracepoint. | |
279 | start_test_app | |
280 | ||
5f4c2d80 | 281 | lttng_snapshot_record $SESSION_NAME |
96340a01 | 282 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 283 | destroy_lttng_session_ok $SESSION_NAME |
5f4c2d80 JD |
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 | |
5f4c2d80 | 290 | fi |
209b934f | 291 | |
0fc2834c | 292 | stop_test_apps |
5f4c2d80 JD |
293 | } |
294 | ||
4f03c06d JD |
295 | function test_ust_per_uid_local_snapshot_post_mortem () |
296 | { | |
297 | diag "Test local UST snapshots post-mortem" | |
298 | create_lttng_session_no_output $SESSION_NAME | |
299 | enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME | |
c4926bb5 | 300 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
e563bbdb | 301 | start_lttng_tracing_ok $SESSION_NAME |
b5633831 | 302 | lttng_snapshot_add_output_ok $SESSION_NAME $TRACE_PATH |
209b934f DG |
303 | |
304 | # Returns once the application has at least fired ONE tracepoint. | |
305 | start_test_app | |
0fc2834c | 306 | stop_test_apps |
209b934f | 307 | |
4f03c06d | 308 | lttng_snapshot_record $SESSION_NAME |
96340a01 | 309 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 310 | destroy_lttng_session_ok $SESSION_NAME |
4f03c06d JD |
311 | |
312 | # Validate test | |
313 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
314 | if [ $? -eq 0 ]; then | |
315 | # Only delete if successful | |
316 | rm -rf $TRACE_PATH | |
4f03c06d JD |
317 | fi |
318 | } | |
319 | ||
1d20c959 | 320 | function test_ust_local_snapshots () |
ebaaaf5e | 321 | { |
1d20c959 | 322 | diag "Test $NR_SNAPSHOT local UST snapshots" |
ebaaaf5e JD |
323 | create_lttng_session_no_output $SESSION_NAME |
324 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
c4926bb5 | 325 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
e563bbdb | 326 | start_lttng_tracing_ok $SESSION_NAME |
b5633831 | 327 | lttng_snapshot_add_output_ok $SESSION_NAME $TRACE_PATH |
209b934f DG |
328 | |
329 | # Returns once the application has at least fired ONE tracepoint. | |
330 | start_test_app | |
331 | ||
1d20c959 DG |
332 | for i in $(seq 1 $NR_SNAPSHOT); do |
333 | diag "Snapshot $i/$NR_SNAPSHOT" | |
ebaaaf5e JD |
334 | rm -rf $TRACE_PATH/snapshot/* 2>/dev/null |
335 | lttng_snapshot_record $SESSION_NAME | |
336 | # Validate test | |
337 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
338 | if [ $? -eq 0 ]; then | |
339 | # Only delete if successful | |
340 | rm -rf $TRACE_PATH | |
ebaaaf5e JD |
341 | fi |
342 | done | |
96340a01 | 343 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 344 | destroy_lttng_session_ok $SESSION_NAME |
209b934f | 345 | |
0fc2834c | 346 | stop_test_apps |
ebaaaf5e JD |
347 | } |
348 | ||
349 | plan_tests $NUM_TESTS | |
350 | ||
351 | print_test_banner "$TEST_DESC" | |
352 | ||
ebaaaf5e JD |
353 | start_lttng_sessiond |
354 | ||
5e83c405 CB |
355 | tests=( test_ust_list_output |
356 | test_ust_local_snapshot | |
357 | test_ust_local_snapshot_max_size | |
358 | test_ust_per_uid_local_snapshot | |
359 | test_ust_per_uid_local_snapshot_post_mortem | |
360 | test_ust_local_snapshot_large_metadata | |
1d20c959 | 361 | test_ust_local_snapshots) |
ebaaaf5e JD |
362 | |
363 | for fct_test in ${tests[@]}; | |
364 | do | |
365 | SESSION_NAME=$(randstring 16 0) | |
366 | ${fct_test} | |
ebaaaf5e JD |
367 | done |
368 | ||
369 | stop_lttng_sessiond |