3 # Copyright (C) - 2013 Christian Babeux <christian.babeux@efficios.com>
4 # Copyright (C) - 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License, version 2 only, as
8 # published by the Free Software Foundation.
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 # You should have received a copy of the GNU General Public License along with
16 # this program; if not, write to the Free Software Foundation, Inc., 51
17 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 TEST_DESC
="Kernel tracer - System calls"
25 # `gen-syscall-event` starts and waits for the creation a file passed by
26 # arguments to start executing 3 syscalls (open,read,close) and returning.
27 TESTCMD
="$TESTDIR/utils/testapp/gen-syscall-events/gen-syscall-events"
29 source $TESTDIR/utils
/utils.sh
31 function trace_testapp
()
34 start_file_sync
=$
(mktemp
-u)
36 # Clear all entries from the resource tracker
37 lttng_untrack_kernel_all_ok
39 # Launch the testapp and save its Process ID
40 .
/"$TESTCMD" "$start_file_sync" &
43 # Set LTTng to track this PID and start the tracing
44 lttng_track_pid_ok
$PID
46 start_lttng_tracing_ok
48 # Create start file to launch the execution of the workload by the
50 touch "$start_file_sync"
56 # Clean up the synchronization file
57 rm -f "$start_file_sync"
60 function validate_list
()
66 out
=$
($TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN list
$session_name $opt |
grep $event_name)
67 if [ -z "$out" ]; then
68 fail
"Validate syscall listing"
69 diag
"$event_name not found when listing $session_name (opt $opt)"
71 pass
"Validate syscall listing. Found $event_name."
75 function test_syscall_event_list
()
77 local EVENT_NAME
="getpid"
79 diag
"Syscall event listing"
81 validate_list
"" $EVENT_NAME "-k --syscall"
84 function test_syscall_simple_list
()
86 TRACE_PATH
=$
(mktemp
-d)
87 SESSION_NAME
="kernel_syscall_simple_list"
88 local EVENT_NAME
="close"
90 diag
"Syscall simple listing"
92 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
94 lttng_enable_kernel_syscall_ok
$SESSION_NAME $EVENT_NAME
96 validate_list
$SESSION_NAME $EVENT_NAME
100 # ensure all events are in the trace.
101 validate_trace_exp
"-e syscall_entry_$EVENT_NAME: -e compat_syscall_entry_$EVENT_NAME:" $TRACE_PATH
102 validate_trace_exp
"-e syscall_exit_$EVENT_NAME: -e compat_syscall_exit_$EVENT_NAME:" $TRACE_PATH
104 # ensure trace only contains those.
105 validate_trace_only_exp
"-e syscall_entry_$EVENT_NAME: -e compat_syscall_entry_$EVENT_NAME: -e syscall_exit_$EVENT_NAME: -e compat_syscall_exit_$EVENT_NAME:" $TRACE_PATH
107 destroy_lttng_session_ok
$SESSION_NAME
112 function test_syscall_simple_list_two
()
114 TRACE_PATH
=$
(mktemp
-d)
115 SESSION_NAME
="kernel_syscall_simple_list_two"
116 local EVENT_NAME
="close"
117 local EVENT_NAME2
="read"
119 diag
"Syscall simple listing"
121 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
123 lttng_enable_kernel_syscall_ok
$SESSION_NAME $EVENT_NAME
124 lttng_enable_kernel_syscall_ok
$SESSION_NAME $EVENT_NAME2
126 validate_list
$SESSION_NAME $EVENT_NAME
127 validate_list
$SESSION_NAME $EVENT_NAME2
131 # ensure all events are in the trace.
132 validate_trace_exp
"-e syscall_entry_$EVENT_NAME: -e compat_syscall_entry_$EVENT_NAME:" $TRACE_PATH
133 validate_trace_exp
"-e syscall_exit_$EVENT_NAME: -e compat_syscall_exit_$EVENT_NAME:" $TRACE_PATH
135 validate_trace_exp
"-e syscall_entry_$EVENT_NAME2: -e compat_syscall_entry_$EVENT_NAME2:" $TRACE_PATH
136 validate_trace_exp
"-e syscall_exit_$EVENT_NAME2: -e compat_syscall_exit_$EVENT_NAME2:" $TRACE_PATH
138 # ensure trace only contains those.
139 validate_trace_only_exp
"-e syscall_entry_$EVENT_NAME: -e compat_syscall_entry_$EVENT_NAME: -e syscall_exit_$EVENT_NAME: -e compat_syscall_exit_$EVENT_NAME: -e syscall_entry_$EVENT_NAME2: -e compat_syscall_entry_$EVENT_NAME2: -e syscall_exit_$EVENT_NAME2: -e compat_syscall_exit_$EVENT_NAME2:" $TRACE_PATH
141 destroy_lttng_session_ok
$SESSION_NAME
146 function test_syscall_single
()
148 TRACE_PATH
=$
(mktemp
-d)
149 SESSION_NAME
="kernel_syscall_single"
151 diag
"Syscall trace single"
153 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
155 lttng_enable_kernel_syscall_ok
$SESSION_NAME "open"
159 # ensure all events are in the trace.
160 validate_trace_exp
"-e syscall_entry_open: -e compat_syscall_entry_open:" $TRACE_PATH
161 validate_trace_exp
"-e syscall_exit_open: -e compat_syscall_exit_open:" $TRACE_PATH
163 # ensure trace only contains those.
164 validate_trace_only_exp
"-e syscall_entry_open: -e compat_syscall_entry_open: -e syscall_exit_open: -e compat_syscall_exit_open:" $TRACE_PATH
166 destroy_lttng_session_ok
$SESSION_NAME
171 function test_syscall_two
()
173 TRACE_PATH
=$
(mktemp
-d)
174 SESSION_NAME
="kernel_syscall_two"
176 diag
"Syscall trace two events"
178 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
180 lttng_enable_kernel_syscall_ok
$SESSION_NAME "open"
181 lttng_enable_kernel_syscall_ok
$SESSION_NAME "close"
185 # ensure all events are in the trace.
186 validate_trace_exp
"-e syscall_entry_open: -e compat_syscall_entry_open:" $TRACE_PATH
187 validate_trace_exp
"-e syscall_exit_open: -e compat_syscall_exit_open:" $TRACE_PATH
188 validate_trace_exp
"-e syscall_entry_close: -e compat_syscall_entry_close:" $TRACE_PATH
189 validate_trace_exp
"-e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH
191 # ensure trace only contains those.
192 validate_trace_only_exp
"-e syscall_entry_open: -e compat_syscall_entry_open: -e syscall_exit_open: -e compat_syscall_exit_open: -e syscall_entry_close: -e compat_syscall_entry_close: -e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH
194 destroy_lttng_session_ok
$SESSION_NAME
199 function test_syscall_all
()
201 TRACE_PATH
=$
(mktemp
-d)
202 SESSION_NAME
="kernel_syscall_all"
204 diag
"Syscall trace all events"
206 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
208 # enable all syscalls
209 lttng_enable_kernel_syscall_ok
$SESSION_NAME
213 # ensure at least open and close are there.
214 validate_trace_exp
"-e syscall_entry_open: -e compat_syscall_entry_open:" $TRACE_PATH
215 validate_trace_exp
"-e syscall_exit_open: -e compat_syscall_exit_open:" $TRACE_PATH
216 validate_trace_exp
"-e syscall_entry_close: -e compat_syscall_entry_close:" $TRACE_PATH
217 validate_trace_exp
"-e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH
218 # trace may contain other syscalls.
220 destroy_lttng_session_ok
$SESSION_NAME
225 function test_syscall_all_disable_one
()
227 TRACE_PATH
=$
(mktemp
-d)
228 SESSION_NAME
="kernel_syscall_all_disable_one"
230 diag
"Syscall trace all events and disable one"
232 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
234 # enable all syscalls
235 lttng_enable_kernel_syscall_ok
$SESSION_NAME
236 # try to disable open system call: fails because enabler semantic of
237 # "all syscalls" is not "the open" system call.
238 lttng_disable_kernel_syscall_fail
$SESSION_NAME "open"
242 # ensure "open" syscall is there.
243 validate_trace_exp
"-e syscall_entry_open: -e compat_syscall_entry_open: -e syscall_exit_open: -e compat_syscall_exit_open:" $TRACE_PATH
245 # ensure "close" syscall is there.
246 validate_trace_exp
"-e syscall_entry_close: -e compat_syscall_entry_close:" $TRACE_PATH
247 validate_trace_exp
"-e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH
249 destroy_lttng_session_ok
$SESSION_NAME
254 function test_syscall_all_disable_two
()
256 TRACE_PATH
=$
(mktemp
-d)
257 SESSION_NAME
="kernel_syscall_all_disable_two"
259 diag
"Syscall trace all events and disable two"
261 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
263 # enable all syscalls
264 lttng_enable_kernel_syscall_ok
$SESSION_NAME
265 # try to disable open and close system calls: fails because enabler
266 # semantic of "all syscalls" is not "the open" system call.
267 lttng_disable_kernel_syscall_fail
$SESSION_NAME "open"
268 lttng_disable_kernel_syscall_fail
$SESSION_NAME "close"
272 # ensure "open" syscall is there.
273 validate_trace_exp
"-e syscall_entry_open: -e compat_syscall_entry_open: -e syscall_exit_open: -e compat_syscall_exit_open:" $TRACE_PATH
275 # ensure "close" syscall is there.
276 validate_trace_exp
"-e syscall_entry_close: -e compat_syscall_entry_close:" $TRACE_PATH
277 validate_trace_exp
"-e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH
279 # ensure "read" syscall is there.
280 validate_trace_exp
"-e syscall_entry_read: -e compat_syscall_entry_read:" $TRACE_PATH
281 validate_trace_exp
"-e syscall_exit_read: -e compat_syscall_exit_read:" $TRACE_PATH
283 destroy_lttng_session_ok
$SESSION_NAME
288 function test_syscall_enable_all_disable_all
()
290 TRACE_PATH
=$
(mktemp
-d)
291 SESSION_NAME
="kernel_syscall_enable_all_disable_all"
293 diag
"Syscall trace all events and disable all"
295 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
297 # enable all system calls
298 lttng_enable_kernel_syscall_ok
$SESSION_NAME
299 # disable all system calls
300 lttng_disable_kernel_syscall_ok
$SESSION_NAME
304 # ensure nothing has been traced.
305 validate_trace_empty
$TRACE_PATH
307 destroy_lttng_session_ok
$SESSION_NAME
312 function test_syscall_enable_all_disable_all_enable_all
()
314 TRACE_PATH
=$
(mktemp
-d)
315 SESSION_NAME
="kernel_syscall_enable_all_disable_all_enable_all"
317 diag
"Syscall trace all events and enable/disable all"
319 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
321 # enable all system calls
322 lttng_enable_kernel_syscall_ok
$SESSION_NAME
323 # disable all system calls
324 lttng_disable_kernel_syscall_ok
$SESSION_NAME
325 # enable all system calls
326 lttng_enable_kernel_syscall_ok
$SESSION_NAME
330 # ensure at least open and close are there.
331 validate_trace_exp
"-e syscall_entry_open: -e compat_syscall_entry_open:" $TRACE_PATH
332 validate_trace_exp
"-e syscall_exit_open: -e compat_syscall_exit_open:" $TRACE_PATH
333 validate_trace_exp
"-e syscall_entry_close: -e compat_syscall_entry_close:" $TRACE_PATH
334 validate_trace_exp
"-e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH
335 # trace may contain other syscalls.
337 destroy_lttng_session_ok
$SESSION_NAME
342 function test_syscall_enable_all_disable_all_twice
()
344 TRACE_PATH
=$
(mktemp
-d)
345 SESSION_NAME
="kernel_syscall_enable_all_disable_all_twice"
347 diag
"Syscall trace all events and enable/disable all twice"
349 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
351 # enable all system calls
352 lttng_enable_kernel_syscall_ok
$SESSION_NAME
353 # disable all system calls
354 lttng_disable_kernel_syscall_ok
$SESSION_NAME
355 # enable all system calls
356 lttng_enable_kernel_syscall_ok
$SESSION_NAME
357 # disable all system calls
358 lttng_disable_kernel_syscall_ok
$SESSION_NAME
362 # ensure nothing has been traced.
363 validate_trace_empty
$TRACE_PATH
365 destroy_lttng_session_ok
$SESSION_NAME
370 function test_syscall_enable_one_disable_one
()
372 TRACE_PATH
=$
(mktemp
-d)
373 SESSION_NAME
="kernel_syscall_enable_one_disable_one"
375 diag
"Syscall trace one event and disable one"
377 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
379 # enable open system call
380 lttng_enable_kernel_syscall_ok
$SESSION_NAME "open"
381 # disable open system call
382 lttng_disable_kernel_syscall_ok
$SESSION_NAME "open"
386 # ensure nothing has been traced.
387 validate_trace_empty
$TRACE_PATH
389 destroy_lttng_session_ok
$SESSION_NAME
394 function test_syscall_enable_two_disable_two
()
396 TRACE_PATH
=$
(mktemp
-d)
397 SESSION_NAME
="kernel_syscall_enable_two_disable_two"
399 diag
"Syscall trace two events and disable two"
401 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
403 # enable open and close system calls
404 lttng_enable_kernel_syscall_ok
$SESSION_NAME "open"
405 lttng_enable_kernel_syscall_ok
$SESSION_NAME "close"
406 # disable open and close system calls
407 lttng_disable_kernel_syscall_ok
$SESSION_NAME "open"
408 lttng_disable_kernel_syscall_ok
$SESSION_NAME "close"
412 # ensure nothing has been traced.
413 validate_trace_empty
$TRACE_PATH
415 destroy_lttng_session_ok
$SESSION_NAME
420 function test_syscall_enable_two_disable_one
()
422 TRACE_PATH
=$
(mktemp
-d)
423 SESSION_NAME
="kernel_syscall_enable_two_disable_one"
425 diag
"Syscall trace two events and disable one"
427 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
429 # enable open and close system calls
430 lttng_enable_kernel_syscall_ok
$SESSION_NAME "open"
431 lttng_enable_kernel_syscall_ok
$SESSION_NAME "close"
432 # disable close system call
433 lttng_disable_kernel_syscall_ok
$SESSION_NAME "close"
437 # ensure open is there.
438 validate_trace_exp
"-e syscall_entry_open: -e compat_syscall_entry_open:" $TRACE_PATH
439 validate_trace_exp
"-e syscall_exit_open: -e compat_syscall_exit_open:" $TRACE_PATH
441 # ensure trace only contains those.
442 validate_trace_only_exp
"-e syscall_entry_open: -e compat_syscall_entry_open: -e syscall_exit_open: -e compat_syscall_exit_open:" $TRACE_PATH
444 destroy_lttng_session_ok
$SESSION_NAME
449 function test_syscall_disable_twice
()
451 TRACE_PATH
=$
(mktemp
-d)
452 SESSION_NAME
="kernel_syscall_disable_twice"
454 diag
"Syscall trace one event and disable twice"
456 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
458 lttng_enable_kernel_syscall_ok
$SESSION_NAME "open"
459 # First disable will succeed
460 lttng_disable_kernel_syscall_ok
$SESSION_NAME "open"
461 # Second disable succeeds too, due to enabler semantic.
462 lttng_disable_kernel_syscall_ok
$SESSION_NAME "open"
464 destroy_lttng_session_ok
$SESSION_NAME
469 function test_syscall_disable_all_twice
()
471 TRACE_PATH
=$
(mktemp
-d)
472 SESSION_NAME
="kernel_syscall_disable_all_twice"
474 diag
"Syscall trace all events and disable all twice"
476 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
478 lttng_enable_kernel_syscall_ok
$SESSION_NAME
479 # First disable will succeed
480 lttng_disable_kernel_syscall_ok
$SESSION_NAME
481 # Second disable succeeds too, due to enabler semantic.
482 lttng_disable_kernel_syscall_ok
$SESSION_NAME
484 destroy_lttng_session_ok
$SESSION_NAME
490 function test_syscall_enable_unknown
()
492 TRACE_PATH
=$
(mktemp
-d)
493 SESSION_NAME
="kernel_syscall_enable_unknown"
495 diag
"Syscall enable an unknown event"
497 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
499 # Enabling a syscall that does not exist succeeds, due to enabler
501 lttng_enable_kernel_syscall_ok
$SESSION_NAME "thissyscallcannotexist"
503 destroy_lttng_session_ok
$SESSION_NAME
508 function test_syscall_enable_all_enable_one
()
510 TRACE_PATH
=$
(mktemp
-d)
511 SESSION_NAME
="kernel_syscall_enable_all_enable_one"
513 diag
"Syscall enable all and enable one"
515 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
517 lttng_enable_kernel_syscall_ok
$SESSION_NAME
518 # Enabling an event already enabled succeeds, due to enabler semantic.
519 lttng_enable_kernel_syscall_ok
$SESSION_NAME "open"
521 destroy_lttng_session_ok
$SESSION_NAME
526 function test_syscall_disable_all_disable_one
()
528 TRACE_PATH
=$
(mktemp
-d)
529 SESSION_NAME
="kernel_syscall_enable_all_enable_one"
531 diag
"Syscall disable all and disable one"
533 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
535 lttng_enable_kernel_syscall_ok
$SESSION_NAME
536 lttng_disable_kernel_syscall_ok
$SESSION_NAME
537 # Disabling an event already disabled fails.
538 lttng_disable_kernel_syscall_fail
$SESSION_NAME "open"
540 destroy_lttng_session_ok
$SESSION_NAME
545 function test_syscall_enable_channel_disable_all
()
547 TRACE_PATH
=$
(mktemp
-d)
548 SESSION_NAME
="kernel_syscall_enable_channel_disable_all"
549 CHANNEL_NAME
="channel"
551 diag
"Syscall enable channel and disable all"
553 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
555 lttng_enable_kernel_channel_ok
$SESSION_NAME $CHANNEL_NAME
556 # sessiond semantic for "disable all" is to try to match all enalers
557 # it knowns about. Disable all succeeds if it finds no match.
558 lttng_disable_kernel_syscall_ok
$SESSION_NAME "-a" $CHANNEL_NAME
560 destroy_lttng_session_ok
$SESSION_NAME
565 function test_syscall_enable_channel_disable_one
()
567 TRACE_PATH
=$
(mktemp
-d)
568 SESSION_NAME
="kernel_syscall_enable_channel_disable_all"
569 CHANNEL_NAME
="channel"
571 diag
"Syscall enable channel and disable one"
573 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
575 lttng_enable_kernel_channel_ok
$SESSION_NAME $CHANNEL_NAME
576 lttng_disable_kernel_syscall_fail
$SESSION_NAME "open" $CHANNEL_NAME
578 destroy_lttng_session_ok
$SESSION_NAME
583 # MUST set TESTDIR before calling those functions
584 plan_tests
$NUM_TESTS
586 print_test_banner
"$TEST_DESC"
588 if [ "$(id -u)" == "0" ]; then
594 skip
$isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
598 test_syscall_event_list
599 test_syscall_simple_list
600 test_syscall_simple_list_two
604 test_syscall_all_disable_one
605 test_syscall_all_disable_two
606 test_syscall_enable_all_disable_all
607 test_syscall_enable_all_disable_all_enable_all
608 test_syscall_enable_all_disable_all_twice
609 test_syscall_enable_one_disable_one
610 test_syscall_enable_two_disable_two
611 test_syscall_enable_two_disable_one
612 test_syscall_disable_twice
613 test_syscall_disable_all_twice
614 test_syscall_enable_unknown
615 test_syscall_enable_all_enable_one
616 test_syscall_disable_all_disable_one
617 test_syscall_enable_channel_disable_all
618 test_syscall_enable_channel_disable_one