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 # test command issues at least open and close system calls
26 TESTCMD
="cat /proc/cpuinfo > /dev/null"
28 source $TESTDIR/utils
/utils.sh
30 function test_syscall_single
()
32 TRACE_PATH
=$
(mktemp
-d)
33 SESSION_NAME
="kernel_syscall_single"
35 create_lttng_session
$SESSION_NAME $TRACE_PATH
37 lttng_enable_kernel_syscall_ok
$SESSION_NAME "open"
43 # ensure each is there.
44 validate_trace_exp
"-e syscall_entry_open -e compat_syscall_entry_open" $TRACE_PATH
45 validate_trace_exp
"-e syscall_exit_open -e compat_syscall_exit_open" $TRACE_PATH
47 # ensure trace only contains those.
48 validate_trace_only_exp
"-e syscall_entry_open -e compat_syscall_entry_open -e syscall_exit_open -e compat_syscall_exit_open" $TRACE_PATH
50 destroy_lttng_session
$SESSION_NAME
55 function test_syscall_two
()
57 TRACE_PATH
=$
(mktemp
-d)
58 SESSION_NAME
="kernel_syscall_two"
60 create_lttng_session
$SESSION_NAME $TRACE_PATH
62 lttng_enable_kernel_syscall_ok
$SESSION_NAME "open"
63 lttng_enable_kernel_syscall_ok
$SESSION_NAME "close"
69 # ensure each is there.
70 validate_trace_exp
"-e syscall_entry_open -e compat_syscall_entry_open" $TRACE_PATH
71 validate_trace_exp
"-e syscall_exit_open -e compat_syscall_exit_open" $TRACE_PATH
72 validate_trace_exp
"-e syscall_entry_close -e compat_syscall_entry_close" $TRACE_PATH
73 validate_trace_exp
"-e syscall_exit_close -e compat_syscall_exit_close" $TRACE_PATH
75 # ensure trace only contains those.
76 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
78 destroy_lttng_session
$SESSION_NAME
83 function test_syscall_all
()
85 TRACE_PATH
=$
(mktemp
-d)
86 SESSION_NAME
="kernel_syscall_all"
88 create_lttng_session
$SESSION_NAME $TRACE_PATH
91 lttng_enable_kernel_syscall_ok
$SESSION_NAME
97 # ensure at least open and close are there.
98 validate_trace_exp
"-e syscall_entry_open -e compat_syscall_entry_open" $TRACE_PATH
99 validate_trace_exp
"-e syscall_exit_open -e compat_syscall_exit_open" $TRACE_PATH
100 validate_trace_exp
"-e syscall_entry_close -e compat_syscall_entry_close" $TRACE_PATH
101 validate_trace_exp
"-e syscall_exit_close -e compat_syscall_exit_close" $TRACE_PATH
102 # trace may contain other syscalls.
104 destroy_lttng_session
$SESSION_NAME
109 function test_syscall_all_disable_one
()
111 TRACE_PATH
=$
(mktemp
-d)
112 SESSION_NAME
="kernel_syscall_all_disable_one"
114 create_lttng_session
$SESSION_NAME $TRACE_PATH
116 # enable all syscalls
117 lttng_enable_kernel_syscall_ok
$SESSION_NAME
118 # disable open system call
119 lttng_disable_kernel_syscall_ok
$SESSION_NAME "open"
125 # ensure "open" syscall is not there.
126 validate_trace_only_exp
"-v -e syscall_entry_open -e compat_syscall_entry_open -e syscall_exit_open -e compat_syscall_exit_open" $TRACE_PATH
128 # ensure "close" syscall is there.
129 validate_trace_exp
"-e syscall_entry_close -e compat_syscall_entry_close" $TRACE_PATH
130 validate_trace_exp
"-e syscall_exit_close -e compat_syscall_exit_close" $TRACE_PATH
132 destroy_lttng_session
$SESSION_NAME
137 function test_syscall_all_disable_two
()
139 TRACE_PATH
=$
(mktemp
-d)
140 SESSION_NAME
="kernel_syscall_all_disable_two"
142 create_lttng_session
$SESSION_NAME $TRACE_PATH
144 # enable all syscalls
145 lttng_enable_kernel_syscall_ok
$SESSION_NAME
146 # disable open system call
147 lttng_disable_kernel_syscall_ok
$SESSION_NAME "open"
148 lttng_disable_kernel_syscall_ok
$SESSION_NAME "close"
151 # generates open, close, execve (at least)
155 # ensure "open" and "close" syscalls are not there.
156 validate_trace_only_exp
"-v -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
158 # ensure "execve" syscall is there.
159 validate_trace_exp
"-e syscall_entry_execve -e compat_syscall_entry_execve" $TRACE_PATH
160 validate_trace_exp
"-e syscall_exit_execve -e compat_syscall_exit_execve" $TRACE_PATH
162 destroy_lttng_session
$SESSION_NAME
167 function test_syscall_enable_all_disable_all
()
169 TRACE_PATH
=$
(mktemp
-d)
170 SESSION_NAME
="kernel_syscall_enable_all_disable_all"
172 create_lttng_session
$SESSION_NAME $TRACE_PATH
174 # enable all system calls
175 lttng_enable_kernel_syscall_ok
$SESSION_NAME
176 # disable all system calls
177 lttng_disable_kernel_syscall_ok
$SESSION_NAME
180 # generates open, close, execve (at least)
184 # ensure nothing has been traced.
185 validate_trace_empty
$TRACE_PATH
187 destroy_lttng_session
$SESSION_NAME
192 function test_syscall_enable_all_disable_all_enable_all
()
194 TRACE_PATH
=$
(mktemp
-d)
195 SESSION_NAME
="kernel_syscall_enable_all_disable_all_enable_all"
197 create_lttng_session
$SESSION_NAME $TRACE_PATH
199 # enable all system calls
200 lttng_enable_kernel_syscall_ok
$SESSION_NAME
201 # disable all system calls
202 lttng_disable_kernel_syscall_ok
$SESSION_NAME
203 # enable all system calls
204 lttng_enable_kernel_syscall_ok
$SESSION_NAME
207 # generates open, close, execve (at least)
211 # ensure at least open and close are there.
212 validate_trace_exp
"-e syscall_entry_open -e compat_syscall_entry_open" $TRACE_PATH
213 validate_trace_exp
"-e syscall_exit_open -e compat_syscall_exit_open" $TRACE_PATH
214 validate_trace_exp
"-e syscall_entry_close -e compat_syscall_entry_close" $TRACE_PATH
215 validate_trace_exp
"-e syscall_exit_close -e compat_syscall_exit_close" $TRACE_PATH
216 # trace may contain other syscalls.
218 destroy_lttng_session
$SESSION_NAME
223 function test_syscall_enable_all_disable_all_twice
()
225 TRACE_PATH
=$
(mktemp
-d)
226 SESSION_NAME
="kernel_syscall_enable_all_disable_all_twice"
228 create_lttng_session
$SESSION_NAME $TRACE_PATH
230 # enable all system calls
231 lttng_enable_kernel_syscall_ok
$SESSION_NAME
232 # disable all system calls
233 lttng_disable_kernel_syscall_ok
$SESSION_NAME
234 # enable all system calls
235 lttng_enable_kernel_syscall_ok
$SESSION_NAME
236 # disable all system calls
237 lttng_disable_kernel_syscall_ok
$SESSION_NAME
240 # generates open, close, execve (at least)
244 # ensure nothing has been traced.
245 validate_trace_empty
$TRACE_PATH
247 destroy_lttng_session
$SESSION_NAME
252 function test_syscall_enable_one_disable_one
()
254 TRACE_PATH
=$
(mktemp
-d)
255 SESSION_NAME
="kernel_syscall_enable_one_disable_one"
257 create_lttng_session
$SESSION_NAME $TRACE_PATH
259 # enable open system call
260 lttng_enable_kernel_syscall_ok
$SESSION_NAME "open"
261 # disable open system call
262 lttng_disable_kernel_syscall_ok
$SESSION_NAME "open"
265 # generates open, close, execve (at least)
269 # ensure nothing has been traced.
270 validate_trace_empty
$TRACE_PATH
272 destroy_lttng_session
$SESSION_NAME
277 function test_syscall_enable_two_disable_two
()
279 TRACE_PATH
=$
(mktemp
-d)
280 SESSION_NAME
="kernel_syscall_enable_two_disable_two"
282 create_lttng_session
$SESSION_NAME $TRACE_PATH
284 # enable open and close system calls
285 lttng_enable_kernel_syscall_ok
$SESSION_NAME "open"
286 lttng_enable_kernel_syscall_ok
$SESSION_NAME "close"
287 # disable open and close system calls
288 lttng_disable_kernel_syscall_ok
$SESSION_NAME "open"
289 lttng_disable_kernel_syscall_ok
$SESSION_NAME "close"
292 # generates open, close, execve (at least)
296 # ensure nothing has been traced.
297 validate_trace_empty
$TRACE_PATH
299 destroy_lttng_session
$SESSION_NAME
304 function test_syscall_enable_two_disable_one
()
306 TRACE_PATH
=$
(mktemp
-d)
307 SESSION_NAME
="kernel_syscall_enable_two_disable_one"
309 create_lttng_session
$SESSION_NAME $TRACE_PATH
311 # enable open and close system calls
312 lttng_enable_kernel_syscall_ok
$SESSION_NAME "open"
313 lttng_enable_kernel_syscall_ok
$SESSION_NAME "close"
314 # disable close system call
315 lttng_disable_kernel_syscall_ok
$SESSION_NAME "close"
318 # generates open, close, execve (at least)
322 # ensure open is there.
323 validate_trace_exp
"-e syscall_entry_open -e compat_syscall_entry_open" $TRACE_PATH
324 validate_trace_exp
"-e syscall_exit_open -e compat_syscall_exit_open" $TRACE_PATH
326 # ensure trace only contains those.
327 validate_trace_only_exp
"-e syscall_entry_open -e compat_syscall_entry_open -e syscall_exit_open -e compat_syscall_exit_open" $TRACE_PATH
329 destroy_lttng_session
$SESSION_NAME
334 function test_syscall_disable_twice
()
336 TRACE_PATH
=$
(mktemp
-d)
337 SESSION_NAME
="kernel_syscall_disable_twice"
339 create_lttng_session
$SESSION_NAME $TRACE_PATH
341 lttng_enable_kernel_syscall_ok
$SESSION_NAME "open"
342 # First disable will succeed
343 lttng_disable_kernel_syscall_ok
$SESSION_NAME "open"
344 # Second disable will fail
345 lttng_disable_kernel_syscall_fail
$SESSION_NAME "open"
347 destroy_lttng_session
$SESSION_NAME
352 function test_syscall_disable_all_twice
()
354 TRACE_PATH
=$
(mktemp
-d)
355 SESSION_NAME
="kernel_syscall_disable_all_twice"
357 create_lttng_session
$SESSION_NAME $TRACE_PATH
359 lttng_enable_kernel_syscall_ok
$SESSION_NAME
360 # First disable will succeed
361 lttng_disable_kernel_syscall_ok
$SESSION_NAME
362 # Second disable will fail
363 lttng_disable_kernel_syscall_fail
$SESSION_NAME
365 destroy_lttng_session
$SESSION_NAME
371 function test_syscall_enable_unknown
()
373 TRACE_PATH
=$
(mktemp
-d)
374 SESSION_NAME
="kernel_syscall_enable_unknown"
376 create_lttng_session
$SESSION_NAME $TRACE_PATH
378 lttng_enable_kernel_syscall_fail
$SESSION_NAME "thissyscallcannotexist"
380 destroy_lttng_session
$SESSION_NAME
385 function test_syscall_enable_all_enable_one
()
387 TRACE_PATH
=$
(mktemp
-d)
388 SESSION_NAME
="kernel_syscall_enable_all_enable_one"
390 create_lttng_session
$SESSION_NAME $TRACE_PATH
392 lttng_enable_kernel_syscall_ok
$SESSION_NAME
393 # Enabling an event already enabled fails.
394 lttng_enable_kernel_syscall_fail
$SESSION_NAME "open"
396 destroy_lttng_session
$SESSION_NAME
401 function test_syscall_disable_all_disable_one
()
403 TRACE_PATH
=$
(mktemp
-d)
404 SESSION_NAME
="kernel_syscall_enable_all_enable_one"
406 create_lttng_session
$SESSION_NAME $TRACE_PATH
408 lttng_enable_kernel_syscall_ok
$SESSION_NAME
409 lttng_disable_kernel_syscall_ok
$SESSION_NAME
410 # Disabling an event already disabled fails.
411 lttng_disable_kernel_syscall_fail
$SESSION_NAME "open"
413 destroy_lttng_session
$SESSION_NAME
418 function test_syscall_enable_channel_disable_all
()
420 TRACE_PATH
=$
(mktemp
-d)
421 SESSION_NAME
="kernel_syscall_enable_channel_disable_all"
422 CHANNEL_NAME
="channel"
424 create_lttng_session
$SESSION_NAME $TRACE_PATH
426 lttng_enable_kernel_channel_ok
$SESSION_NAME $CHANNEL_NAME
427 lttng_disable_kernel_syscall_fail
$SESSION_NAME "-a" $CHANNEL_NAME
429 destroy_lttng_session
$SESSION_NAME
434 function test_syscall_enable_channel_disable_one
()
436 TRACE_PATH
=$
(mktemp
-d)
437 SESSION_NAME
="kernel_syscall_enable_channel_disable_all"
438 CHANNEL_NAME
="channel"
440 create_lttng_session
$SESSION_NAME $TRACE_PATH
442 lttng_enable_kernel_channel_ok
$SESSION_NAME $CHANNEL_NAME
443 lttng_disable_kernel_syscall_fail
$SESSION_NAME "open" $CHANNEL_NAME
445 destroy_lttng_session
$SESSION_NAME
450 # MUST set TESTDIR before calling those functions
451 plan_tests
$NUM_TESTS
453 print_test_banner
"$TEST_DESC"
455 if [ "$(id -u)" == "0" ]; then
461 skip
$isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
468 test_syscall_all_disable_one
469 test_syscall_all_disable_two
470 test_syscall_enable_all_disable_all
471 test_syscall_enable_all_disable_all_enable_all
472 test_syscall_enable_all_disable_all_twice
473 test_syscall_enable_one_disable_one
474 test_syscall_enable_two_disable_two
475 test_syscall_enable_two_disable_one
476 test_syscall_disable_twice
477 test_syscall_disable_all_twice
478 test_syscall_enable_unknown
479 test_syscall_enable_all_enable_one
480 test_syscall_disable_all_disable_one
481 test_syscall_enable_channel_disable_all
482 test_syscall_enable_channel_disable_one