Commit | Line | Data |
---|---|---|
d8b7ee90 JR |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) - 2019 Jonathan Rajotte-Julien <jonathan.rajotte-julien@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 | ||
18 | # This is a common test for kernel and ust. DOMAIN must be set. | |
19 | ||
20 | ||
21 | TEST_DESC="Clear - ${DOMAIN} tracing" | |
22 | ||
23 | CURDIR=$(dirname "$0")/ | |
24 | TESTDIR=$CURDIR/../../.. | |
25 | SESSION_NAME="" | |
26 | TESTAPP_PATH="$TESTDIR/utils/testapp" | |
27 | TESTAPP_NAME="gen-ust-events" | |
28 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
29 | TESTPOINT=$(readlink -f "${CURDIR}/.libs/librelayd_state.so") | |
30 | ||
31 | NUM_CPUS=$(nproc) | |
32 | PAGE_SIZE=$(getconf PAGE_SIZE) | |
33 | ||
34 | ||
35 | source "$TESTDIR/utils/utils.sh" | |
36 | ||
37 | if [ "x$DOMAIN" == "x" ]; then | |
38 | BAIL_OUT "This script must be called with DOMAIN set." | |
39 | fi | |
40 | ||
41 | function clean_path () | |
42 | { | |
43 | local trace_path=$1 | |
44 | rm -rf "${trace_path:?}"/* | |
45 | } | |
46 | ||
47 | function generate_events () | |
48 | { | |
49 | local cpu=$1 | |
50 | local nb=$2 | |
51 | if [ "$DOMAIN" == "kernel" ]; then | |
52 | taskset -c "$cpu" echo -n "$nb" > /proc/lttng-test-filter-event | |
53 | else | |
54 | taskset -c "$cpu" "$TESTAPP_BIN" -i "$nb" | |
55 | fi | |
56 | } | |
57 | ||
58 | function is_viewer_alive () | |
59 | { | |
60 | local viewer_pid=$1 | |
61 | jobs -p | grep "$viewer_pid" > /dev/null | |
62 | return $? | |
63 | } | |
64 | ||
65 | function sync_attach_viewer () | |
66 | { | |
67 | local viewer_pid=$1 | |
68 | local state_path=$2 | |
69 | local sync_msg="Viewer attached" | |
70 | ||
71 | while ! grep -q "$sync_msg" "$state_path"; do | |
72 | if ! is_viewer_alive "$viewer_pid"; then | |
73 | break | |
74 | fi | |
75 | diag "Waiting for viewer to attach" | |
76 | sleep 0.5 | |
77 | done | |
78 | } | |
79 | ||
80 | function saturate_tracefile_rotation () | |
81 | { | |
82 | local session_name="$1" | |
83 | local channel_name="$2" | |
84 | local tracefile_count="$3" | |
85 | ||
86 | local path="$TRACE_PATH" | |
87 | local num_cpus="$NUM_CPUS" | |
88 | local events_per_call=1000 | |
89 | local saturation_count=$((( tracefile_count * num_cpus ))) | |
90 | local file_pattern="${channel_name}_*" | |
91 | ||
92 | # The number of event generation necessary to fill a single tracefile. | |
93 | # We will use this to ensure that the tracefile rotation wrapped around. | |
94 | local minimum_iteration_rotate=-1 | |
95 | ||
96 | local current_tracefile_count=0 | |
97 | counter=0 | |
98 | while [ "$current_tracefile_count" -lt "$saturation_count" ]; do | |
99 | for i in $(seq 0 $(((num_cpus - 1)))); do | |
100 | generate_events "$i" "$events_per_call" | |
101 | done | |
102 | # We need to stop & start to ensure that all data touch disk. | |
103 | # This is useful in streaming mode where we do not have | |
104 | # confirmation that data is present on disk otherwise. | |
105 | stop_lttng_tracing_notap "$session_name" | |
106 | start_lttng_tracing_notap "$session_name" | |
107 | current_tracefile_count=$(find "$path" -name "$file_pattern" -type f \( ! -iname "*.idx" \) | wc -l) | |
108 | if [ "$minimum_iteration_rotate" -eq "-1" ] && \ | |
109 | [ "$current_tracefile_count" -ge $(((2 * num_cpus))) ]; then | |
110 | minimum_iteration_rotate="$counter" | |
111 | fi | |
112 | (( counter= counter + 1 )) | |
113 | diag "Saturating tracefile rotation: $counter" | |
114 | done | |
115 | ||
116 | # Ensure that we wrap around. | |
117 | for j in $(seq 0 "$minimum_iteration_rotate"); do | |
118 | for i in $(seq 0 $(((num_cpus - 1)))); do | |
119 | generate_events "$i" "$events_per_call" | |
120 | done | |
121 | diag "Saturating tracefile rotation wrap around: $j" | |
122 | done | |
123 | stop_lttng_tracing_notap "$session_name" | |
124 | start_lttng_tracing_notap "$session_name" | |
125 | ||
126 | } | |
127 | ||
128 | # The session must be configured and started before calling this session. | |
129 | # The clear command will be issued before the stop command. | |
130 | function do_uid () | |
131 | { | |
132 | local session_name=$1 | |
133 | local trace_path=$2 | |
134 | local event_name=$3 | |
135 | local nb_iters=$4 | |
136 | local nb_events_per_iter=$5 | |
137 | ||
138 | # Generate nb_events_per_iter events that will be flushed to disk on | |
139 | # stop, we want to validate that tracing works. They will also validate | |
140 | # that cleaning of file on disks works. | |
141 | generate_events 0 "$nb_events_per_iter" | |
142 | stop_lttng_tracing_ok "$session_name" | |
143 | validate_trace_count "$event_name" "$trace_path" "$nb_events_per_iter" | |
144 | ||
145 | local i=0 | |
146 | while [[ "$i" -lt "$nb_iters" ]]; do | |
147 | start_lttng_tracing_ok "$session_name" | |
148 | # Generate $nb_events_per_iter events that will sit in the | |
149 | # buffer. In live mode we cannot control the flushing still we | |
150 | # expect the trace to be empty on the relayd. In case of live we | |
151 | # expect all event to be present on the viewer side. | |
152 | generate_events 0 "$nb_events_per_iter" | |
153 | ||
154 | # Clear the session while active, this take care of both the | |
155 | # buffers and data on disks. Expect an empty trace. | |
156 | lttng_clear_session_ok "$session_name" | |
157 | stop_lttng_tracing_ok "$session_name" | |
158 | validate_trace_empty "$trace_path" | |
159 | ((i = i + 1)) | |
160 | done | |
161 | ||
162 | # Validate that tracing still works. | |
163 | start_lttng_tracing_ok "$session_name" | |
164 | generate_events 0 "$nb_events_per_iter" | |
165 | stop_lttng_tracing_ok "$session_name" | |
166 | validate_trace_count "$event_name" "$trace_path" "$nb_events_per_iter" | |
167 | ||
168 | # Validate that clear while stopped works. | |
169 | lttng_clear_session_ok "$session_name" | |
170 | validate_trace_empty "$trace_path" | |
171 | } | |
172 | ||
173 | function test_streaming () | |
174 | { | |
175 | diag "Test ${DOMAIN} streaming clear" | |
176 | create_lttng_session_uri "$SESSION_NAME" net://localhost | |
177 | enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" | |
178 | start_lttng_tracing_ok "$SESSION_NAME" | |
179 | do_uid "$SESSION_NAME" "$TRACE_PATH" "$EVENT_NAME" 100 10 | |
180 | destroy_lttng_session_ok "$SESSION_NAME" | |
181 | } | |
182 | ||
183 | # We cannot user babeltrace to validate live reception or buffer clearing when | |
184 | # the session is active due to the timing of the live timer that could influence | |
185 | # the number of event the viewer sees or not. | |
186 | function test_streaming_live_with_viewer () | |
187 | { | |
188 | local babeltrace_stdout | |
189 | local babeltrace_stderr | |
190 | local nb_iter=100 | |
191 | local nb_event_per_iter=1000 | |
192 | local events_expected=$(((2 + nb_iter) * nb_event_per_iter)) | |
193 | local url="net://127.0.0.1/host/${HOSTNAME}/${SESSION_NAME}" | |
194 | local ret | |
195 | local events_seen | |
196 | ||
197 | babeltrace_stdout=$(mktemp) | |
198 | babeltrace_stderr=$(mktemp) | |
199 | ||
200 | diag "Test ${DOMAIN} streaming live clear hook viewer before clear" | |
201 | create_lttng_session_uri "$SESSION_NAME" net://localhost "--live" | |
202 | enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" | |
203 | start_lttng_tracing_ok "$SESSION_NAME" | |
204 | # We use a testpoint inside lttng-relayd as a sync point to validate | |
205 | # that the viewer is attached. We are looking for a string inside | |
206 | # RELAYD_STATE_PATH. We need to bailout if the string is not found and | |
207 | # babeltrace exited. Trash the stdout of babeltrace since we cannot | |
208 | # infer anything from it. | |
209 | $BABELTRACE_BIN -i lttng-live "$url" 1> /dev/null 2> "$babeltrace_stderr" & | |
210 | babeltrace_pid=$! | |
211 | ||
212 | sync_attach_viewer "$babeltrace_pid" "$RELAYD_STATE_PATH" | |
213 | ||
214 | do_uid "$SESSION_NAME" "$TRACE_PATH" \ | |
215 | "$EVENT_NAME" \ | |
216 | "$nb_iter" \ | |
217 | "$nb_event_per_iter" | |
218 | ||
219 | # Validate that the viewer is still alive | |
220 | is_viewer_alive "$babeltrace_pid" | |
221 | ok $? "Viewer is still alive" | |
222 | ||
223 | # The viewer should detach itself on session destroy | |
224 | destroy_lttng_session_ok "$SESSION_NAME" | |
225 | ||
226 | wait "$babeltrace_pid" | |
227 | ret=$? | |
228 | ok $ret "Babeltrace exited with no error" | |
229 | if [ "$ret" -ne "0" ]; then | |
230 | diag "$(cat "$babeltrace_stderr")" | |
231 | fi | |
232 | ||
233 | rm -f "$babeltrace_stderr" | |
234 | } | |
235 | ||
236 | function test_streaming_live_attach_viewer_after_clear () | |
237 | { | |
238 | local babeltrace_stdout | |
239 | local babeltrace_stderr | |
240 | local ret | |
241 | local events_seen | |
242 | local nb_iter=10 | |
243 | local nb_event_per_iter=100 | |
244 | local events_expected=$nb_event_per_iter | |
245 | local url="net://127.0.0.1/host/${HOSTNAME}/${SESSION_NAME}" | |
246 | ||
247 | babeltrace_stdout=$(mktemp) | |
248 | babeltrace_stderr=$(mktemp) | |
249 | ||
250 | diag "Test ${DOMAIN} streaming live hook viewer after clear" | |
251 | create_lttng_session_uri "$SESSION_NAME" net://localhost "--live" | |
252 | enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" | |
253 | start_lttng_tracing_ok "$SESSION_NAME" | |
254 | do_uid "$SESSION_NAME" "$TRACE_PATH" \ | |
255 | "$EVENT_NAME" \ | |
256 | "$nb_iter" \ | |
257 | "$nb_event_per_iter" | |
258 | ||
259 | "$BABELTRACE_BIN" -i lttng-live "$url" 1> "$babeltrace_stdout" 2> "$babeltrace_stderr" & | |
260 | babeltrace_pid=$! | |
261 | sync_attach_viewer "$babeltrace_pid" "$RELAYD_STATE_PATH" | |
262 | ||
263 | start_lttng_tracing_ok "$SESSION_NAME" | |
264 | ||
265 | # We only expect these last events. | |
266 | generate_events 0 "$nb_event_per_iter" | |
267 | ||
268 | stop_lttng_tracing_ok "$session_name" | |
269 | destroy_lttng_session_ok "$SESSION_NAME" | |
270 | ||
271 | wait "$babeltrace_pid" | |
272 | ret=$? | |
273 | ok $ret "Babeltrace exited with no error" | |
274 | if [ "$ret" -ne "0" ]; then | |
275 | diag "$(cat "$babeltrace_stderr")" | |
276 | fi | |
277 | ||
278 | # TODO: sometime the viewer does not see 100 events... not sure why yet. | |
279 | # Does not seems related to clear. | |
280 | #events_seen=$(cat "$babeltrace_stdout" | wc -l) | |
281 | #test $events_seen -eq $events_expected | |
282 | #ok $? "Viewer saw the expected number of event: ${events_seen}/${events_expected}" | |
283 | ||
284 | rm -f "$babeltrace_stdout" | |
285 | rm -f "$babeltrace_stderr" | |
286 | } | |
287 | ||
288 | function test_local () | |
289 | { | |
290 | diag "Test ${DOMAIN} local" | |
291 | create_lttng_session_ok "$SESSION_NAME" "$TRACE_PATH" | |
292 | enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" | |
293 | start_lttng_tracing_ok "$SESSION_NAME" | |
294 | do_uid "$SESSION_NAME" "$TRACE_PATH" "$EVENT_NAME" 100 10 | |
295 | destroy_lttng_session_ok "$SESSION_NAME" | |
296 | } | |
297 | ||
298 | function do_snapshot () | |
299 | { | |
300 | local session_name=$1 | |
301 | local trace_path=$2 | |
302 | ||
303 | enable_"$DOMAIN"_lttng_event_ok "$session_name" "$EVENT_NAME" | |
304 | start_lttng_tracing_ok "$session_name" | |
305 | ||
306 | # Generate 10 events that will sit in the buffers. | |
307 | generate_events 0 10 | |
308 | ||
309 | # Take a first snapshot and validate that the events are present. | |
310 | lttng_snapshot_record "$session_name" | |
311 | stop_lttng_tracing_ok "$session_name" | |
312 | validate_trace_count "$EVENT_NAME" "$trace_path" 10 | |
313 | ||
314 | # Clean the output path | |
315 | clean_path "$trace_path" | |
316 | start_lttng_tracing_ok "$session_name" | |
317 | ||
318 | lttng_clear_session_ok "$session_name" | |
319 | ||
320 | # Make sure the subsequent snapshot is empty and valid. | |
321 | lttng_snapshot_record "$session_name" | |
322 | stop_lttng_tracing_ok "$session_name" | |
323 | validate_trace_empty "$trace_path" | |
324 | ||
325 | # Clean the output path | |
326 | clean_path "$trace_path" | |
327 | start_lttng_tracing_ok "$session_name" | |
328 | ||
329 | # Make sure that everything still works, generate events and take a | |
330 | # snapshot. | |
331 | generate_events 0 10 | |
332 | lttng_snapshot_record "$session_name" | |
333 | stop_lttng_tracing_ok "$session_name" | |
334 | validate_trace_count "$EVENT_NAME" "$trace_path" 10 | |
335 | } | |
336 | ||
337 | function test_streaming_snapshot () | |
338 | { | |
339 | diag "Test $DOMAIN streaming snapshot clear" | |
340 | ||
341 | create_lttng_session_uri "$SESSION_NAME" net://localhost "--snapshot" | |
342 | do_snapshot "$SESSION_NAME" "$TRACE_PATH" | |
343 | destroy_lttng_session_ok "$SESSION_NAME" | |
344 | } | |
345 | ||
346 | function test_local_snapshot () | |
347 | { | |
348 | diag "Test $DOMAIN local snapshot clear" | |
349 | ||
350 | create_lttng_session_ok "$SESSION_NAME" "$TRACE_PATH" "--snapshot" | |
351 | do_snapshot "$SESSION_NAME" "$TRACE_PATH" | |
352 | destroy_lttng_session_ok "$SESSION_NAME" | |
353 | } | |
354 | ||
355 | function test_ust_local_snapshot_per_pid () | |
356 | { | |
357 | local file_sync_before_last | |
358 | local file_sync_before_last_touch | |
359 | local file_sync_before_exit | |
360 | local file_sync_before_exit_touch | |
361 | local channel_name="channel0" | |
362 | ||
363 | file_sync_before_last=$(mktemp -u) | |
364 | file_sync_before_last_touch=$(mktemp -u) | |
365 | file_sync_before_exit=$(mktemp -u) | |
366 | file_sync_before_exit_touch=$(mktemp -u) | |
367 | ||
368 | diag "Test ust local snapshot clear per pid " | |
369 | ||
370 | create_lttng_session_ok "$SESSION_NAME" "$TRACE_PATH" "--snapshot" | |
371 | enable_ust_lttng_channel_ok "$SESSION_NAME" "$channel_name" "--buffers-pid" | |
372 | enable_ust_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" "$channel_name" | |
373 | start_lttng_tracing_ok "$SESSION_NAME" | |
374 | ||
375 | # Generate 10 events that will sit in the buffers. | |
376 | "$TESTAPP_BIN" -i 10 -w 0 \ | |
377 | --sync-before-last-event "$file_sync_before_last" \ | |
378 | --sync-before-last-event-touch "$file_sync_before_last_touch" \ | |
379 | --sync-before-exit "$file_sync_before_exit" \ | |
380 | --sync-before-exit-touch "$file_sync_before_exit_touch" >/dev/null 2>&1 & | |
381 | ||
382 | # Continue only when there is only the last event remaining. | |
383 | while [ ! -f "$file_sync_before_last_touch" ]; do | |
384 | sleep 0.5 | |
385 | done | |
386 | ||
387 | # Take a first snapshot and validate that the events are present. | |
388 | lttng_snapshot_record "$SESSION_NAME" | |
389 | stop_lttng_tracing_ok "$SESSION_NAME" | |
390 | validate_trace_count "$EVENT_NAME" "$TRACE_PATH" 9 | |
391 | ||
392 | # Clean the output path | |
393 | clean_path "$TRACE_PATH" | |
394 | start_lttng_tracing_ok "$SESSION_NAME" | |
395 | ||
396 | lttng_clear_session_ok "$SESSION_NAME" | |
397 | ||
398 | # Make sure the subsequent snapshot is empty and valid. | |
399 | lttng_snapshot_record "$SESSION_NAME" | |
400 | stop_lttng_tracing_ok "$SESSION_NAME" | |
401 | validate_trace_empty "$TRACE_PATH" | |
402 | ||
403 | # Validate that tracing still works and subsequent snapshots are valid. | |
404 | # Clean the output path. | |
405 | clean_path "$TRACE_PATH" | |
406 | start_lttng_tracing_ok "$SESSION_NAME" | |
407 | ||
408 | # Continue over the last event. | |
409 | touch "$file_sync_before_last" | |
410 | ||
411 | # Wait for the before exit sync point. This ensure that we went over the | |
412 | # last tracepoint. | |
413 | while [ ! -f "$file_sync_before_exit_touch" ]; do | |
414 | sleep 0.5 | |
415 | done | |
416 | ||
417 | # Make sure the snapshot contains the last event. | |
418 | lttng_snapshot_record "$SESSION_NAME" | |
419 | stop_lttng_tracing_ok "$SESSION_NAME" | |
420 | validate_trace_count "$EVENT_NAME" "$TRACE_PATH" 1 | |
421 | ||
422 | # Release the application. | |
423 | touch "$file_sync_before_exit" | |
424 | wait | |
425 | destroy_lttng_session_ok "$SESSION_NAME" | |
426 | ||
427 | rm -f "$file_sync_before_last" | |
428 | rm -f "$file_sync_before_last_touch" | |
429 | rm -f "$file_sync_before_exit" | |
430 | rm -f "$file_sync_before_exit_touch" | |
431 | } | |
432 | ||
433 | function test_relayd_dissalow_clear () | |
434 | { | |
435 | diag "Test lttng-relayd disallow clear" | |
436 | start_lttng_relayd "-o $TRACE_PATH --disallow-clear" | |
437 | start_lttng_sessiond | |
438 | ||
439 | create_lttng_session_uri "$SESSION_NAME" net://localhost "--live" | |
440 | enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" | |
441 | start_lttng_tracing_ok "$SESSION_NAME" | |
442 | ||
443 | generate_events 0 1 | |
444 | ||
445 | lttng_clear_session_fail "$SESSION_NAME" | |
446 | ||
447 | destroy_lttng_session_ok "$SESSION_NAME" | |
448 | ||
449 | stop_lttng_sessiond | |
450 | stop_lttng_relayd | |
451 | } | |
452 | ||
453 | function test_per_pid () | |
454 | { | |
455 | local channel_name=chan | |
456 | diag "Test clear on per-pid session" | |
457 | create_lttng_session_ok "$SESSION_NAME" "$TRACE_PATH" | |
458 | enable_"$DOMAIN"_lttng_channel_ok "$SESSION_NAME" $channel_name --buffers-pid | |
459 | enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" $channel_name | |
460 | start_lttng_tracing_ok "$SESSION_NAME" | |
461 | ||
462 | # Per pid is not supported in this version. Clear must fail. | |
463 | lttng_clear_session_fail "$SESSION_NAME" | |
464 | ||
465 | destroy_lttng_session_ok "$SESSION_NAME" | |
466 | } | |
467 | ||
468 | function test_local_tracefile_rotation () | |
469 | { | |
470 | local channel_name="over9000" | |
471 | local tracefile_count=6 | |
472 | local tracefile_size=$(((3 * PAGE_SIZE))) | |
473 | local iteration=5 | |
474 | ||
475 | diag "Test ${DOMAIN} local with tracefile rotation" | |
476 | create_lttng_session_ok "$SESSION_NAME" "$TRACE_PATH" | |
477 | enable_"$DOMAIN"_lttng_channel_ok "$SESSION_NAME" $channel_name \ | |
478 | "--tracefile-count $tracefile_count --tracefile-size $tracefile_size --overwrite" | |
479 | enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" $channel_name | |
480 | start_lttng_tracing_ok "$SESSION_NAME" | |
481 | ||
482 | # Saturate the tracefile. | |
483 | for i in $(seq 0 $iteration); do | |
484 | saturate_tracefile_rotation "$SESSION_NAME" "$channel_name" "$tracefile_count" | |
485 | lttng_clear_session_ok "$session_name" | |
486 | stop_lttng_tracing_ok "$session_name" | |
487 | validate_trace_empty "$TRACE_PATH" | |
488 | lttng_clear_session_ok "$session_name" | |
489 | start_lttng_tracing_ok "$session_name" | |
490 | done | |
491 | ||
492 | destroy_lttng_session_ok "$SESSION_NAME" | |
493 | } | |
494 | ||
495 | function test_streaming_tracefile_rotation () | |
496 | { | |
497 | local channel_name="over9000" | |
498 | local tracefile_count=6 | |
499 | local tracefile_size=$(((3 * PAGE_SIZE))) | |
500 | local iteration=5 | |
501 | ||
502 | diag "Test ${DOMAIN} streamin with tracefile rotation" | |
503 | create_lttng_session_uri "$SESSION_NAME" net://localhost | |
504 | enable_"$DOMAIN"_lttng_channel_ok "$SESSION_NAME" "$channel_name" \ | |
505 | "--tracefile-count $tracefile_count --tracefile-size $tracefile_size --overwrite" | |
506 | enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" "$channel_name" | |
507 | start_lttng_tracing_ok "$SESSION_NAME" | |
508 | ||
509 | # Saturate the tracefile. | |
510 | for i in $(seq 0 $iteration); do | |
511 | saturate_tracefile_rotation "$SESSION_NAME" "$channel_name" "$tracefile_count" | |
512 | lttng_clear_session_ok "$session_name" | |
513 | stop_lttng_tracing_ok "$session_name" | |
514 | validate_trace_empty "$TRACE_PATH" | |
515 | lttng_clear_session_ok "$session_name" | |
516 | start_lttng_tracing_ok "$session_name" | |
517 | done | |
518 | ||
519 | destroy_lttng_session_ok "$SESSION_NAME" | |
520 | } | |
521 | ||
522 | function test_streaming_live_tracefile_rotation_with_viewer () | |
523 | { | |
524 | local babeltrace_stderr | |
525 | local channel_name="over9000" | |
526 | local tracefile_count=6 | |
527 | local tracefile_size=$(((3 * PAGE_SIZE))) | |
528 | local iteration=2 | |
529 | local babeltrace_pid | |
530 | local url="net://127.0.0.1/host/${HOSTNAME}/${SESSION_NAME}" | |
531 | ||
532 | babeltrace_stderr=$(mktemp) | |
533 | ||
534 | ||
535 | diag "Test ${DOMAIN} streaming live with tracefile rotation viewer attached" | |
536 | create_lttng_session_uri "$SESSION_NAME" net://localhost "--live" | |
537 | enable_"$DOMAIN"_lttng_channel_ok "$SESSION_NAME" "$channel_name" \ | |
538 | "--tracefile-count $tracefile_count --tracefile-size $tracefile_size --overwrite" | |
539 | enable_"$DOMAIN"_lttng_event_ok "$SESSION_NAME" "$EVENT_NAME" "$channel_name" | |
540 | start_lttng_tracing_ok "$SESSION_NAME" | |
541 | ||
542 | $BABELTRACE_BIN -i lttng-live "$url" 1> /dev/null 2> "$babeltrace_stderr" & | |
543 | babeltrace_pid=$! | |
544 | ||
545 | sync_attach_viewer "$babeltrace_pid" "$RELAYD_STATE_PATH" | |
546 | ||
547 | # Saturate the tracefile. | |
548 | for i in $(seq 0 $iteration); do | |
549 | saturate_tracefile_rotation "$SESSION_NAME" "$channel_name" "$tracefile_count" | |
550 | lttng_clear_session_ok "$session_name" | |
551 | stop_lttng_tracing_ok "$session_name" | |
552 | validate_trace_empty "$TRACE_PATH" | |
553 | lttng_clear_session_ok "$session_name" | |
554 | start_lttng_tracing_ok "$session_name" | |
555 | done | |
556 | ||
557 | # Validate that the viewer is still alive. | |
558 | is_viewer_alive "$babeltrace_pid" | |
559 | ok $? "Viewer is still alive" | |
560 | ||
561 | # The viewer should detach on destroy. | |
562 | destroy_lttng_session_ok "$SESSION_NAME" | |
563 | ||
564 | wait "$babeltrace_pid" | |
565 | ret=$? | |
566 | ok "$ret" "Babeltrace exited with no error" | |
567 | if [ "$ret" -ne "0" ]; then | |
568 | diag "$(cat "$babeltrace_stderr")" | |
569 | fi | |
570 | ||
571 | rm -f "$babeltrace_stderr" | |
572 | } | |
573 | ||
574 | if [ "$DOMAIN" == "ust" ]; then | |
575 | NUM_TESTS=1438 | |
576 | elif [ "$DOMAIN" == "kernel" ]; then | |
577 | NUM_TESTS=1429 | |
578 | else | |
579 | BAIL_OUT "Invalid domain: $DOMAIN" | |
580 | fi | |
581 | ||
582 | plan_tests $NUM_TESTS | |
583 | ||
584 | print_test_banner "$TEST_DESC" | |
585 | ||
586 | tests=( | |
587 | test_local | |
588 | test_local_snapshot | |
589 | test_local_tracefile_rotation | |
590 | test_streaming | |
591 | test_streaming_snapshot | |
592 | test_streaming_tracefile_rotation | |
593 | test_streaming_live_with_viewer | |
594 | test_streaming_live_attach_viewer_after_clear | |
595 | test_streaming_live_tracefile_rotation_with_viewer | |
596 | ) | |
597 | ||
598 | if [ "$DOMAIN" == "ust" ]; then | |
599 | if [ ! -x "$TESTAPP_BIN" ]; then | |
600 | BAIL_OUT "No UST events binary detected." | |
601 | fi | |
602 | test+=( | |
603 | test_ust_local_snapshot_per_pid | |
604 | test_per_pid | |
605 | ) | |
606 | EVENT_NAME="tp:tptest" | |
607 | else | |
608 | # Kernel domain | |
609 | if [ "$(id -u)" -ne "0" ]; then | |
610 | skip 0 "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS && exit 0 | |
611 | fi | |
612 | validate_lttng_modules_present | |
613 | EVENT_NAME="lttng_test_filter_event" | |
614 | fi | |
615 | ||
616 | ||
617 | TRACE_PATH=$(mktemp -d) | |
618 | RELAYD_STATE_PATH=$(mktemp) | |
619 | TESTPOINT_ARGS="RELAYD_STATE_PATH=${RELAYD_STATE_PATH} LTTNG_TESTPOINT_ENABLE=1" | |
620 | LTTNG_RELAYD_ENV_VARS="$TESTPOINT_ARGS LD_PRELOAD=$TESTPOINT" | |
621 | ||
622 | start_lttng_relayd "-o $TRACE_PATH" | |
623 | start_lttng_sessiond | |
624 | ||
625 | if [ "$DOMAIN" == "kernel" ]; then | |
626 | modprobe lttng-test | |
627 | fi | |
628 | ||
629 | ||
630 | for fct_test in "${tests[@]}"; | |
631 | do | |
632 | SESSION_NAME=$(randstring 16 0) | |
633 | ${fct_test} | |
634 | clean_path "$TRACE_PATH" | |
635 | # Truncate the RELAYD_STATE_PATH file | |
636 | : > "$RELAYD_STATE_PATH" | |
637 | done | |
638 | ||
639 | if [ "$DOMAIN" == "kernel" ]; then | |
640 | rmmod lttng-test | |
641 | fi | |
642 | ||
643 | stop_lttng_sessiond | |
644 | stop_lttng_relayd | |
645 | ||
646 | if [ "$DOMAIN" == "ust" ]; then | |
647 | # This test control how lttng-relayd is started. Do it after everything else. | |
648 | test_relayd_dissalow_clear | |
649 | fi | |
650 | ||
651 | rm -f "$RELAYD_STATE_PATH" |