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 | ||
19cb8605 | 66 | function stop_test_app() |
209b934f DG |
67 | { |
68 | diag "Killing $TESTAPP_NAME" | |
69 | PID_APP=`pidof $TESTAPP_NAME` | |
70 | kill $PID_APP >/dev/null 2>&1 | |
19cb8605 MD |
71 | diag "Waiting on $TESTAPP_NAME" |
72 | wait | |
209b934f DG |
73 | } |
74 | ||
5e83c405 CB |
75 | function snapshot_add_output () |
76 | { | |
77 | local sess_name=$1 | |
78 | local trace_path=$2 | |
79 | local name=$3 | |
80 | local max_size=$4 | |
81 | local extra_opt="" | |
82 | ||
83 | if [ ! -z $name ]; then | |
84 | extra_opt+=" -n $name " | |
85 | fi | |
86 | ||
87 | if [ ! -z $max_size ]; then | |
88 | extra_opt+=" -m $max_size " | |
89 | fi | |
90 | ||
91 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output \ | |
92 | -s $sess_name $extra_opt $trace_path > /dev/null 2>&1 | |
93 | ||
94 | ok $? "Added snapshot output $trace_path ($extra_opt)" | |
95 | } | |
96 | ||
97 | function snapshot_del_output () | |
98 | { | |
99 | local sess_name=$1 | |
100 | local name=$2 | |
101 | ||
102 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output \ | |
103 | -s $sess_name $name > /dev/null 2>&1 | |
104 | ||
105 | ok $? "Deleted snapshot output named $name" | |
106 | } | |
107 | ||
108 | function enable_mmap_overwrite_subbuf_ust_channel () | |
109 | { | |
110 | local sess_name=$1 | |
111 | local chan_name=$2 | |
112 | local subbuf_size=$3 | |
113 | ||
114 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name \ | |
115 | $chan_name -u --output mmap --overwrite \ | |
116 | --subbuf-size $subbuf_size > /dev/null 2>&1 | |
117 | ||
118 | ok $? "Enable channel $channel_name for session $sess_name with subbuf size $subbuf_size" | |
119 | } | |
120 | ||
121 | ||
122 | function test_ust_list_output () | |
123 | { | |
124 | output_names=("randomname" "somesnapshot") | |
125 | ||
126 | diag "Test UST snapshot output listing" | |
127 | create_lttng_session_no_output $SESSION_NAME | |
128 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
129 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
130 | ||
131 | start_lttng_tracing $SESSION_NAME | |
132 | ||
133 | snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" ${output_names[0]} | |
134 | ||
135 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output \ | |
136 | -s $SESSION_NAME 2>&1 | grep ${output_names[0]} > /dev/null | |
137 | ok $? "Snapshot named ${output_names[0]} present in list-output listing" | |
138 | ||
139 | snapshot_del_output $SESSION_NAME ${output_names[0]} | |
140 | ||
141 | snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" ${output_names[1]} | |
142 | ||
143 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output \ | |
144 | -s $SESSION_NAME 2>&1 | grep ${output_names[1]} > /dev/null | |
145 | ||
146 | ok $? "Snapshot named ${output_names[1]} present in list-output listing" | |
147 | ||
148 | stop_lttng_tracing $SESSION_NAME | |
149 | destroy_lttng_session $SESSION_NAME | |
150 | } | |
151 | ||
ebaaaf5e JD |
152 | function test_ust_local_snapshot () |
153 | { | |
154 | diag "Test local UST snapshots" | |
155 | create_lttng_session_no_output $SESSION_NAME | |
156 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
157 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
158 | start_lttng_tracing $SESSION_NAME | |
159 | lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH | |
209b934f DG |
160 | |
161 | # Returns once the application has at least fired ONE tracepoint. | |
162 | start_test_app | |
163 | ||
ebaaaf5e JD |
164 | lttng_snapshot_record $SESSION_NAME |
165 | stop_lttng_tracing $SESSION_NAME | |
166 | destroy_lttng_session $SESSION_NAME | |
167 | ||
168 | # Validate test | |
169 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
170 | if [ $? -eq 0 ]; then | |
171 | # Only delete if successful | |
172 | rm -rf $TRACE_PATH | |
ebaaaf5e | 173 | fi |
209b934f | 174 | |
19cb8605 | 175 | stop_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 | ||
19cb8605 | 223 | stop_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 | |
a54047ec JD |
250 | fi |
251 | } | |
252 | ||
5f4c2d80 JD |
253 | function enable_channel_per_uid_mmap_overwrite() |
254 | { | |
255 | sess_name=$1 | |
256 | channel_name=$2 | |
257 | ||
258 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name --output mmap --overwrite >/dev/null 2>&1 | |
259 | ok $? "Enable channel $channel_name per UID for session $sess_name" | |
260 | } | |
261 | ||
262 | function test_ust_per_uid_local_snapshot () | |
263 | { | |
264 | diag "Test local UST snapshots" | |
265 | create_lttng_session_no_output $SESSION_NAME | |
266 | enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME | |
267 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
268 | start_lttng_tracing $SESSION_NAME | |
269 | lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH | |
209b934f DG |
270 | |
271 | # Returns once the application has at least fired ONE tracepoint. | |
272 | start_test_app | |
273 | ||
5f4c2d80 JD |
274 | lttng_snapshot_record $SESSION_NAME |
275 | stop_lttng_tracing $SESSION_NAME | |
276 | destroy_lttng_session $SESSION_NAME | |
277 | ||
278 | # Validate test | |
279 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
280 | if [ $? -eq 0 ]; then | |
281 | # Only delete if successful | |
282 | rm -rf $TRACE_PATH | |
5f4c2d80 | 283 | fi |
209b934f | 284 | |
19cb8605 | 285 | stop_test_app |
5f4c2d80 JD |
286 | } |
287 | ||
4f03c06d JD |
288 | function test_ust_per_uid_local_snapshot_post_mortem () |
289 | { | |
290 | diag "Test local UST snapshots post-mortem" | |
291 | create_lttng_session_no_output $SESSION_NAME | |
292 | enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME | |
293 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
294 | start_lttng_tracing $SESSION_NAME | |
295 | lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH | |
209b934f DG |
296 | |
297 | # Returns once the application has at least fired ONE tracepoint. | |
298 | start_test_app | |
19cb8605 | 299 | stop_test_app |
209b934f | 300 | |
4f03c06d JD |
301 | lttng_snapshot_record $SESSION_NAME |
302 | stop_lttng_tracing $SESSION_NAME | |
303 | destroy_lttng_session $SESSION_NAME | |
304 | ||
305 | # Validate test | |
306 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
307 | if [ $? -eq 0 ]; then | |
308 | # Only delete if successful | |
309 | rm -rf $TRACE_PATH | |
4f03c06d JD |
310 | fi |
311 | } | |
312 | ||
1d20c959 | 313 | function test_ust_local_snapshots () |
ebaaaf5e | 314 | { |
1d20c959 | 315 | diag "Test $NR_SNAPSHOT local UST snapshots" |
ebaaaf5e JD |
316 | create_lttng_session_no_output $SESSION_NAME |
317 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
318 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
319 | start_lttng_tracing $SESSION_NAME | |
320 | lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH | |
209b934f DG |
321 | |
322 | # Returns once the application has at least fired ONE tracepoint. | |
323 | start_test_app | |
324 | ||
1d20c959 DG |
325 | for i in $(seq 1 $NR_SNAPSHOT); do |
326 | diag "Snapshot $i/$NR_SNAPSHOT" | |
ebaaaf5e JD |
327 | rm -rf $TRACE_PATH/snapshot/* 2>/dev/null |
328 | lttng_snapshot_record $SESSION_NAME | |
329 | # Validate test | |
330 | validate_trace $EVENT_NAME $TRACE_PATH/ | |
331 | if [ $? -eq 0 ]; then | |
332 | # Only delete if successful | |
333 | rm -rf $TRACE_PATH | |
ebaaaf5e JD |
334 | fi |
335 | done | |
336 | stop_lttng_tracing $SESSION_NAME | |
337 | destroy_lttng_session $SESSION_NAME | |
209b934f | 338 | |
19cb8605 | 339 | stop_test_app |
ebaaaf5e JD |
340 | } |
341 | ||
342 | plan_tests $NUM_TESTS | |
343 | ||
344 | print_test_banner "$TEST_DESC" | |
345 | ||
ebaaaf5e JD |
346 | start_lttng_sessiond |
347 | ||
5e83c405 CB |
348 | tests=( test_ust_list_output |
349 | test_ust_local_snapshot | |
350 | test_ust_local_snapshot_max_size | |
351 | test_ust_per_uid_local_snapshot | |
352 | test_ust_per_uid_local_snapshot_post_mortem | |
353 | test_ust_local_snapshot_large_metadata | |
1d20c959 | 354 | test_ust_local_snapshots) |
ebaaaf5e JD |
355 | |
356 | for fct_test in ${tests[@]}; | |
357 | do | |
358 | SESSION_NAME=$(randstring 16 0) | |
359 | ${fct_test} | |
ebaaaf5e JD |
360 | done |
361 | ||
362 | stop_lttng_sessiond |