3 # Copyright (C) 2013 Christian Babeux <christian.babeux@efficios.com>
4 # Copyright (C) 2015-2018 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 # SPDX-License-Identifier: GPL-2.0-only
8 TEST_DESC
="LTTng - Event tracker test"
10 CURDIR
=$
(dirname "$0")/
11 TESTDIR
="$CURDIR/../../.."
12 TESTAPP_PATH
="$TESTDIR/utils/testapp"
13 TESTAPP_NAME
="gen-ust-events"
14 TESTAPP_KERNEL_NAME
="gen-kernel-test-events"
15 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
16 TESTAPP_KERNEL_BIN
="$TESTAPP_PATH/$TESTAPP_KERNEL_NAME/$TESTAPP_KERNEL_NAME"
17 SESSION_NAME
="tracker"
22 NUM_TESTS
=$
((NUM_UST_TESTS
+NUM_KERNEL_TESTS
+NUM_GLOBAL_TESTS
))
24 NR_USEC_WAIT
=0 #for UST gen events
28 SCRIPT_USERNAME
="$(id -un)"
29 SCRIPT_GROUPNAME
="$(id -gn)"
33 TOUCH_BEFORE_LAST_PATH
=
34 SYNC_BEFORE_LAST_PATH
=
36 source $TESTDIR/utils
/utils.sh
38 # Launch the testapp and execute it up until right before the last event. It is
39 # useful to do it in two seperate steps in order to test tracking and
40 # untracking on an active app.
41 function prepare_ust_app
43 TOUCH_BEFORE_LAST_PATH
=$
(mktemp
--tmpdir -u tmp.
${FUNCNAME[0]}_touch_before_last.XXXXXX
)
44 SYNC_BEFORE_LAST_PATH
=$
(mktemp
--tmpdir -u tmp.
${FUNCNAME[0]}_sync_before_last.XXXXXX
)
46 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
47 --sync-before-last-event-touch "$TOUCH_BEFORE_LAST_PATH" \
48 --sync-before-last-event "$SYNC_BEFORE_LAST_PATH" &
52 # Wait for the app to execute all the way to right before the last
54 while [ ! -f "${TOUCH_BEFORE_LAST_PATH}" ]; do
59 # Generate the last event.
60 function trace_ust_app
62 # Ask the test app to generate the last event.
63 touch "$SYNC_BEFORE_LAST_PATH"
65 ok $?
"Traced application stopped."
66 rm "$SYNC_BEFORE_LAST_PATH"
67 rm "$TOUCH_BEFORE_LAST_PATH"
70 function prepare_kernel_app
72 WAIT_PATH
=$
(mktemp
--tmpdir -u "tmp.${FUNCNAME[0]}_wait_path.XXXXXX")
74 "$TESTAPP_KERNEL_BIN" "$WAIT_PATH" $NR_ITER &
78 function trace_kernel_app
82 ok $?
"Traced application stopped."
86 function test_event_tracker
()
90 local expect_event
="$2"
95 diag
"${FUNCNAME[0]} $*"
97 trace_path
=$
(mktemp
--tmpdir -d tmp.
${FUNCNAME[0]}_trace_path.XXXXXX
)
99 create_lttng_session_ok
$SESSION_NAME "$trace_path"
101 if [ "$domain" = kernel
]; then
103 lttng_enable_kernel_channel
1 0 $SESSION_NAME $channel "--subbuf-size=8M --num-subbuf=4"
106 enable_
"$domain"_lttng_event_ok
$SESSION_NAME "$wildcard" "$channel"
108 start_lttng_tracing_ok
110 lttng_track_
"$domain"_ok
"${tracker}"
112 prepare_
"$domain"_app
116 stop_lttng_tracing_ok
117 destroy_lttng_session_ok
$SESSION_NAME
119 if [ "$expect_event" -eq 1 ]; then
120 trace_matches
"$EVENT_NAME" $NR_ITER "$trace_path"
122 validate_trace_session_
"$domain"_empty
"$trace_path"
128 function test_event_vpid_tracker
()
132 local expect_event
="$2"
136 diag
"${FUNCNAME[0]} $*"
138 trace_path
=$
(mktemp
--tmpdir -d tmp.
${FUNCNAME[0]}_trace_path.XXXXXX
)
140 create_lttng_session_ok
$SESSION_NAME "$trace_path"
142 if [ "$domain" = kernel
]; then
144 lttng_enable_kernel_channel
1 0 $SESSION_NAME $channel "--subbuf-size=8M --num-subbuf=4"
147 enable_
"$domain"_lttng_event_ok
$SESSION_NAME "$wildcard" "$channel"
149 prepare_
"$domain"_app
151 start_lttng_tracing_ok
153 if [ "$expect_event" -eq 1 ]; then
154 lttng_track_
"$domain"_ok
"--vpid ${CHILD_PID}"
156 lttng_track_
"$domain"_ok
"--vpid $((CHILD_PID+1))"
161 stop_lttng_tracing_ok
162 destroy_lttng_session_ok
$SESSION_NAME
164 if [ "$expect_event" -eq 1 ]; then
165 validate_trace
"$EVENT_NAME" "$trace_path"
167 validate_trace_empty
"$trace_path"
173 function test_event_pid_tracker
()
177 local expect_event
="$2"
181 diag
"${FUNCNAME[0]} $*"
183 trace_path
=$
(mktemp
--tmpdir -d tmp.
${FUNCNAME[0]}_trace_path.XXXXXX
)
185 create_lttng_session_ok
$SESSION_NAME "$trace_path"
187 if [ "$domain" = kernel
]; then
189 lttng_enable_kernel_channel
1 0 $SESSION_NAME $channel "--subbuf-size=8M --num-subbuf=4"
192 enable_
"$domain"_lttng_event_ok
$SESSION_NAME "$wildcard" "$channel"
194 prepare_
"$domain"_app
196 start_lttng_tracing_ok
198 if [ "$expect_event" -eq 1 ]; then
199 lttng_track_
"$domain"_ok
"--pid ${CHILD_PID}"
201 lttng_track_
"$domain"_ok
"--pid $((CHILD_PID+1))"
206 stop_lttng_tracing_ok
207 destroy_lttng_session_ok
$SESSION_NAME
209 if [ "$expect_event" -eq 1 ]; then
210 validate_trace
"$EVENT_NAME" "$trace_path"
212 validate_trace_empty
"$trace_path"
219 function test_event_tracker_fail
()
226 diag
"${FUNCNAME[0]} $*"
228 trace_path
=$
(mktemp
--tmpdir -d tmp.
${FUNCNAME[0]}_trace_path.XXXXXX
)
230 create_lttng_session_ok
$SESSION_NAME "$trace_path"
231 enable_
"$domain"_lttng_event_ok
$SESSION_NAME "$wildcard"
232 lttng_track_
"$domain"_fail
"${tracker}"
233 destroy_lttng_session_ok
$SESSION_NAME
238 function test_event_track_untrack
()
242 local expect_event
="$2"
247 diag
"${FUNCNAME[0]} $*"
249 trace_path
=$
(mktemp
--tmpdir -d tmp.
${FUNCNAME[0]}_trace_path.XXXXXX
)
251 create_lttng_session_ok
$SESSION_NAME "$trace_path"
253 if [ "$domain" = kernel
]; then
255 lttng_enable_kernel_channel
1 0 $SESSION_NAME $channel "--subbuf-size=8M --num-subbuf=4"
258 enable_
"$domain"_lttng_event_ok
$SESSION_NAME "$wildcard" "$channel"
260 start_lttng_tracing_ok
262 lttng_track_
"$domain"_ok
"${tracker}"
263 lttng_untrack_
"$domain"_ok
"${tracker}"
265 prepare_
"$domain"_app
269 stop_lttng_tracing_ok
270 destroy_lttng_session_ok
$SESSION_NAME
272 if [ "$expect_event" -eq 1 ]; then
273 trace_matches
"$EVENT_NAME" $NR_ITER "$trace_path"
275 validate_trace_session_
"$domain"_empty
"$trace_path"
281 function test_event_vpid_track_untrack
()
285 local expect_event
="$2"
289 diag
"${FUNCNAME[0]} $*"
291 trace_path
=$
(mktemp
--tmpdir -d tmp.
${FUNCNAME[0]}_trace_path.XXXXXX
)
293 create_lttng_session_ok
$SESSION_NAME "$trace_path"
295 if [ "$domain" = kernel
]; then
297 lttng_enable_kernel_channel
1 0 $SESSION_NAME $channel "--subbuf-size=8M --num-subbuf=4"
300 enable_
"$domain"_lttng_event_ok
$SESSION_NAME "$wildcard" "$channel"
302 prepare_
"$domain"_app
304 start_lttng_tracing_ok
306 lttng_track_
"$domain"_ok
"--vpid ${CHILD_PID}"
307 lttng_untrack_
"$domain"_ok
"--vpid ${CHILD_PID}"
311 stop_lttng_tracing_ok
312 destroy_lttng_session_ok
$SESSION_NAME
314 if [ "$expect_event" -eq 1 ]; then
315 validate_trace
"$EVENT_NAME" "$trace_path"
317 validate_trace_empty
"$trace_path"
323 function test_event_pid_track_untrack
()
327 local expect_event
="$2"
331 diag
"${FUNCNAME[0]} $*"
333 trace_path
=$
(mktemp
--tmpdir -d tmp.
${FUNCNAME[0]}_trace_path.XXXXXX
)
335 create_lttng_session_ok
$SESSION_NAME "$trace_path"
337 if [ "$domain" = kernel
]; then
339 lttng_enable_kernel_channel
1 0 $SESSION_NAME $channel "--subbuf-size=8M --num-subbuf=4"
342 enable_
"$domain"_lttng_event_ok
$SESSION_NAME "$wildcard" "$channel"
344 prepare_
"$domain"_app
346 start_lttng_tracing_ok
348 lttng_track_
"$domain"_ok
"--pid ${CHILD_PID}"
349 lttng_untrack_
"$domain"_ok
"--pid ${CHILD_PID}"
353 stop_lttng_tracing_ok
354 destroy_lttng_session_ok
$SESSION_NAME
356 if [ "$expect_event" -eq 1 ]; then
357 validate_trace
"$EVENT_NAME" "$trace_path"
359 validate_trace_empty
"$trace_path"
365 function test_event_ust_vpid_untrack_snapshot
()
367 diag
"${FUNCNAME[0]} $*"
369 local trace_path
=$
(mktemp
--tmpdir -d tmp.
${FUNCNAME[0]}_trace_path.XXXXXX
)
371 create_lttng_session_ok
$SESSION_NAME "$trace_path" "--snapshot"
373 enable_ust_lttng_event_ok
$SESSION_NAME "$EVENT_NAME"
377 lttng_untrack_ust_ok
"--vpid --all"
379 start_lttng_tracing_ok
382 lttng_snapshot_record
$SESSION_NAME
384 stop_lttng_tracing_ok
385 destroy_lttng_session_ok
$SESSION_NAME
387 snapshot_count
=$
(find "$trace_path" -name metadata |
wc -l)
388 is
"$snapshot_count" 0 "Number of snapshot is zero"
393 # MUST set TESTDIR before calling those functions
394 plan_tests
$NUM_TESTS
396 print_test_banner
"$TEST_DESC"
400 diag
"Test UST tracker"
402 if [ ! -x "$TESTAPP_BIN" ]; then
403 BAIL_OUT
"No UST nevents binary detected."
406 EVENT_NAME
="tp:tptest"
408 # Both ordering of tracker type and `--all` are valid.
409 test_event_track_untrack ust
0 "${EVENT_NAME}" "--vgid --all"
410 test_event_track_untrack ust
0 "${EVENT_NAME}" "--all --vgid"
415 test_event_tracker ust
0 "${EVENT_NAME}" "--vuid $((SCRIPT_UID+1))"
416 test_event_tracker ust
0 "${EVENT_NAME}" "--vgid $((SCRIPT_GID+1))"
417 test_event_tracker ust
0 "${EVENT_NAME}" "--vuid $((SCRIPT_UID+1)) --vgid $((SCRIPT_GID+1))"
418 test_event_tracker ust
0 "${EVENT_NAME}" "--vuid $((SCRIPT_UID+1)) --vgid ${SCRIPT_GID}"
419 test_event_tracker ust
0 "${EVENT_NAME}" "--vuid ${SCRIPT_UID} --vgid $((SCRIPT_GID+1))"
420 test_event_track_untrack ust
0 "${EVENT_NAME}" "--vuid ${SCRIPT_UID}"
421 test_event_track_untrack ust
0 "${EVENT_NAME}" "--vgid ${SCRIPT_GID}"
422 test_event_track_untrack ust
0 "${EVENT_NAME}" "--vuid --all"
423 test_event_track_untrack ust
0 "${EVENT_NAME}" "--vgid --all"
426 test_event_tracker ust
1 "${EVENT_NAME}" "--vuid ${SCRIPT_UID}"
427 test_event_tracker ust
1 "${EVENT_NAME}" "--vgid ${SCRIPT_GID}"
428 test_event_tracker ust
1 "${EVENT_NAME}" "--vuid ${SCRIPT_UID} --vgid ${SCRIPT_GID}"
429 test_event_tracker ust
1 "${EVENT_NAME}" "--vuid ${SCRIPT_USERNAME}"
430 test_event_tracker ust
1 "${EVENT_NAME}" "--vgid ${SCRIPT_GROUPNAME}"
431 test_event_tracker ust
1 "${EVENT_NAME}" "--vuid ${SCRIPT_UID},$((SCRIPT_UID+1))"
432 test_event_tracker ust
1 "${EVENT_NAME}" "--vgid ${SCRIPT_GID},$((SCRIPT_GID+1))"
433 test_event_tracker ust
1 "${EVENT_NAME}" "--vuid ${SCRIPT_USERNAME},$((SCRIPT_UID+1))"
434 test_event_tracker ust
1 "${EVENT_NAME}" "--vgid ${SCRIPT_GROUPNAME},$((SCRIPT_GID+1))"
435 test_event_tracker ust
1 "${EVENT_NAME}" "--vuid --all"
436 test_event_tracker ust
1 "${EVENT_NAME}" "--vgid --all"
439 test_event_tracker_fail ust
"${EVENT_NAME}" "--vuid lttng_unexisting_user"
440 test_event_tracker_fail ust
"${EVENT_NAME}" "--vgid lttng_unexisting_group"
446 test_event_track_untrack ust
0 "${EVENT_NAME}" "--vpid --all"
447 test_event_vpid_tracker ust
0 "${EVENT_NAME}"
448 test_event_vpid_track_untrack ust
0 "${EVENT_NAME}"
451 test_event_tracker ust
1 "${EVENT_NAME}" "--vpid --all"
452 test_event_vpid_tracker ust
1 "${EVENT_NAME}"
454 #snapshot untrack vpid
456 test_event_ust_vpid_untrack_snapshot
458 #pid (backward compat)
461 test_event_pid_tracker ust
0 "${EVENT_NAME}"
462 test_event_pid_track_untrack ust
0 "${EVENT_NAME}"
463 test_event_track_untrack ust
0 "${EVENT_NAME}" "--pid --all" # backward compat
466 test_event_tracker ust
1 "${EVENT_NAME}" "--pid --all" # backward compat
467 test_event_pid_tracker ust
1 "${EVENT_NAME}"
469 if [ "$(id -u)" == "0" ]; then
475 skip
$isroot "Root access is needed. Skipping all kernel tracker tests." $NUM_KERNEL_TESTS ||
477 diag
"Test kernel tracker"
480 ok $?
"Loading lttng-test module"
482 EVENT_NAME
="lttng_test_filter_event"
487 test_event_tracker kernel
0 "${EVENT_NAME}" "--vuid $((SCRIPT_UID+1))"
488 test_event_tracker kernel
0 "${EVENT_NAME}" "--vgid $((SCRIPT_GID+1))"
489 test_event_tracker kernel
0 "${EVENT_NAME}" "--vuid $((SCRIPT_UID+1)) --vgid $((SCRIPT_GID+1))"
490 test_event_tracker kernel
0 "${EVENT_NAME}" "--vuid $((SCRIPT_UID+1)) --vgid ${SCRIPT_GID}"
491 test_event_tracker kernel
0 "${EVENT_NAME}" "--vuid ${SCRIPT_UID} --vgid $((SCRIPT_GID+1))"
492 test_event_track_untrack kernel
0 "${EVENT_NAME}" "--vuid ${SCRIPT_UID}"
493 test_event_track_untrack kernel
0 "${EVENT_NAME}" "--vgid ${SCRIPT_GID}"
494 test_event_track_untrack kernel
0 "${EVENT_NAME}" "--vuid --all"
495 test_event_track_untrack kernel
0 "${EVENT_NAME}" "--vgid --all"
498 test_event_tracker kernel
1 "${EVENT_NAME}" "--vuid ${SCRIPT_UID}"
499 test_event_tracker kernel
1 "${EVENT_NAME}" "--vgid ${SCRIPT_GID}"
500 test_event_tracker kernel
1 "${EVENT_NAME}" "--vuid ${SCRIPT_UID} --vgid ${SCRIPT_GID}"
501 test_event_tracker kernel
1 "${EVENT_NAME}" "--vuid ${SCRIPT_USERNAME}"
502 test_event_tracker kernel
1 "${EVENT_NAME}" "--vgid ${SCRIPT_GROUPNAME}"
503 test_event_tracker kernel
1 "${EVENT_NAME}" "--vuid ${SCRIPT_UID},$((SCRIPT_UID+1))"
504 test_event_tracker kernel
1 "${EVENT_NAME}" "--vgid ${SCRIPT_GID},$((SCRIPT_GID+1))"
505 test_event_tracker kernel
1 "${EVENT_NAME}" "--vuid ${SCRIPT_USERNAME},$((SCRIPT_UID+1))"
506 test_event_tracker kernel
1 "${EVENT_NAME}" "--vgid ${SCRIPT_GROUPNAME},$((SCRIPT_GID+1))"
507 test_event_tracker kernel
1 "${EVENT_NAME}" "--vuid --all"
508 test_event_tracker kernel
1 "${EVENT_NAME}" "--vgid --all"
511 test_event_tracker_fail kernel
"${EVENT_NAME}" "--vuid lttng_unexisting_user"
512 test_event_tracker_fail kernel
"${EVENT_NAME}" "--vgid lttng_unexisting_group"
518 test_event_tracker kernel
0 "${EVENT_NAME}" "--uid $((SCRIPT_UID+1))"
519 test_event_tracker kernel
0 "${EVENT_NAME}" "--gid $((SCRIPT_GID+1))"
520 test_event_tracker kernel
0 "${EVENT_NAME}" "--uid $((SCRIPT_UID+1)) --gid $((SCRIPT_GID+1))"
521 test_event_tracker kernel
0 "${EVENT_NAME}" "--uid $((SCRIPT_UID+1)) --gid ${SCRIPT_GID}"
522 test_event_tracker kernel
0 "${EVENT_NAME}" "--uid ${SCRIPT_UID} --gid $((SCRIPT_GID+1))"
523 test_event_track_untrack kernel
0 "${EVENT_NAME}" "--uid ${SCRIPT_UID}"
524 test_event_track_untrack kernel
0 "${EVENT_NAME}" "--gid ${SCRIPT_GID}"
525 test_event_track_untrack kernel
0 "${EVENT_NAME}" "--uid --all"
526 test_event_track_untrack kernel
0 "${EVENT_NAME}" "--gid --all"
529 test_event_tracker kernel
1 "${EVENT_NAME}" "--uid ${SCRIPT_UID}"
530 test_event_tracker kernel
1 "${EVENT_NAME}" "--gid ${SCRIPT_GID}"
531 test_event_tracker kernel
1 "${EVENT_NAME}" "--uid ${SCRIPT_UID} --gid ${SCRIPT_GID}"
532 test_event_tracker kernel
1 "${EVENT_NAME}" "--uid ${SCRIPT_USERNAME}"
533 test_event_tracker kernel
1 "${EVENT_NAME}" "--gid ${SCRIPT_GROUPNAME}"
534 test_event_tracker kernel
1 "${EVENT_NAME}" "--uid ${SCRIPT_UID},$((SCRIPT_UID+1))"
535 test_event_tracker kernel
1 "${EVENT_NAME}" "--gid ${SCRIPT_GID},$((SCRIPT_GID+1))"
536 test_event_tracker kernel
1 "${EVENT_NAME}" "--uid ${SCRIPT_USERNAME},$((SCRIPT_UID+1))"
537 test_event_tracker kernel
1 "${EVENT_NAME}" "--gid ${SCRIPT_GROUPNAME},$((SCRIPT_GID+1))"
540 test_event_tracker_fail kernel
"${EVENT_NAME}" "--uid lttng_unexisting_user"
541 test_event_tracker_fail kernel
"${EVENT_NAME}" "--gid lttng_unexisting_group"
547 test_event_track_untrack kernel
0 "${EVENT_NAME}" "--vpid --all"
548 test_event_vpid_tracker kernel
0 "${EVENT_NAME}"
549 test_event_vpid_track_untrack kernel
0 "${EVENT_NAME}"
552 test_event_tracker kernel
1 "${EVENT_NAME}" "--vpid --all"
553 test_event_vpid_tracker kernel
1 "${EVENT_NAME}"
558 test_event_pid_tracker kernel
0 "${EVENT_NAME}"
559 test_event_pid_track_untrack kernel
0 "${EVENT_NAME}"
560 test_event_track_untrack kernel
0 "${EVENT_NAME}" "--pid --all"
563 test_event_tracker kernel
1 "${EVENT_NAME}" "--pid --all"
564 test_event_pid_tracker kernel
1 "${EVENT_NAME}"
566 modprobe
--remove lttng-test
567 ok $?
"Unloading lttng-test module"