Test: add disable syscalls when none are enabled
[lttng-tools.git] / tests / regression / kernel / test_syscall
CommitLineData
8cfcd41c
MD
1#!/bin/bash
2#
3# Copyright (C) - 2013 Christian Babeux <christian.babeux@efficios.com>
4# Copyright (C) - 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5#
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.
9#
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
13# more details.
14#
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.
18
19TEST_DESC="Kernel tracer - System calls"
20
21CURDIR=$(dirname $0)/
22TESTDIR=$CURDIR/../..
d96f6315 23NUM_TESTS=132
8cfcd41c
MD
24
25# test command issues at least open and close system calls
26TESTCMD="cat /proc/cpuinfo > /dev/null"
27
28source $TESTDIR/utils/utils.sh
29
30function test_syscall_single()
31{
32 TRACE_PATH=$(mktemp -d)
33 SESSION_NAME="kernel_syscall_single"
34
35 create_lttng_session $SESSION_NAME $TRACE_PATH
36
37 lttng_enable_kernel_syscall_ok $SESSION_NAME "open"
38
39 start_lttng_tracing
40 eval ${TESTCMD}
41 stop_lttng_tracing
42
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
46
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
49
50 destroy_lttng_session $SESSION_NAME
51
52 rm -rf $TRACE_PATH
53}
54
55function test_syscall_two()
56{
57 TRACE_PATH=$(mktemp -d)
58 SESSION_NAME="kernel_syscall_two"
59
60 create_lttng_session $SESSION_NAME $TRACE_PATH
61
62 lttng_enable_kernel_syscall_ok $SESSION_NAME "open"
63 lttng_enable_kernel_syscall_ok $SESSION_NAME "close"
64
65 start_lttng_tracing
66 eval ${TESTCMD}
67 stop_lttng_tracing
68
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
74
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
77
78 destroy_lttng_session $SESSION_NAME
79
80 rm -rf $TRACE_PATH
81}
82
83function test_syscall_all()
84{
85 TRACE_PATH=$(mktemp -d)
86 SESSION_NAME="kernel_syscall_all"
87
88 create_lttng_session $SESSION_NAME $TRACE_PATH
89
90 # enable all syscalls
91 lttng_enable_kernel_syscall_ok $SESSION_NAME
92
93 start_lttng_tracing
94 eval ${TESTCMD}
95 stop_lttng_tracing
96
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.
103
104 destroy_lttng_session $SESSION_NAME
105
106 rm -rf $TRACE_PATH
107}
108
109function test_syscall_all_disable_one()
110{
111 TRACE_PATH=$(mktemp -d)
112 SESSION_NAME="kernel_syscall_all_disable_one"
113
114 create_lttng_session $SESSION_NAME $TRACE_PATH
115
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"
120
121 start_lttng_tracing
122 eval ${TESTCMD}
123 stop_lttng_tracing
124
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
127
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
131
132 destroy_lttng_session $SESSION_NAME
133
134 rm -rf $TRACE_PATH
135}
136
137function test_syscall_all_disable_two()
138{
139 TRACE_PATH=$(mktemp -d)
140 SESSION_NAME="kernel_syscall_all_disable_two"
141
142 create_lttng_session $SESSION_NAME $TRACE_PATH
143
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"
149
150 start_lttng_tracing
151 # generates open, close, execve (at least)
152 eval ${TESTCMD}
153 stop_lttng_tracing
154
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
157
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
161
162 destroy_lttng_session $SESSION_NAME
163
164 rm -rf $TRACE_PATH
165}
166
167function test_syscall_enable_all_disable_all()
168{
169 TRACE_PATH=$(mktemp -d)
170 SESSION_NAME="kernel_syscall_enable_all_disable_all"
171
172 create_lttng_session $SESSION_NAME $TRACE_PATH
173
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
178
179 start_lttng_tracing
180 # generates open, close, execve (at least)
181 eval ${TESTCMD}
182 stop_lttng_tracing
183
184 # ensure nothing has been traced.
185 validate_trace_empty $TRACE_PATH
186
187 destroy_lttng_session $SESSION_NAME
188
189 rm -rf $TRACE_PATH
190}
191
192function test_syscall_enable_all_disable_all_enable_all()
193{
194 TRACE_PATH=$(mktemp -d)
195 SESSION_NAME="kernel_syscall_enable_all_disable_all_enable_all"
196
197 create_lttng_session $SESSION_NAME $TRACE_PATH
198
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
205
206 start_lttng_tracing
207 # generates open, close, execve (at least)
208 eval ${TESTCMD}
209 stop_lttng_tracing
210
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.
217
218 destroy_lttng_session $SESSION_NAME
219
220 rm -rf $TRACE_PATH
221}
222
223function test_syscall_enable_all_disable_all_twice()
224{
225 TRACE_PATH=$(mktemp -d)
226 SESSION_NAME="kernel_syscall_enable_all_disable_all_twice"
227
228 create_lttng_session $SESSION_NAME $TRACE_PATH
229
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
238
239 start_lttng_tracing
240 # generates open, close, execve (at least)
241 eval ${TESTCMD}
242 stop_lttng_tracing
243
244 # ensure nothing has been traced.
245 validate_trace_empty $TRACE_PATH
246
247 destroy_lttng_session $SESSION_NAME
248
249 rm -rf $TRACE_PATH
250}
251
252function test_syscall_enable_one_disable_one()
253{
254 TRACE_PATH=$(mktemp -d)
255 SESSION_NAME="kernel_syscall_enable_one_disable_one"
256
257 create_lttng_session $SESSION_NAME $TRACE_PATH
258
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"
263
264 start_lttng_tracing
265 # generates open, close, execve (at least)
266 eval ${TESTCMD}
267 stop_lttng_tracing
268
269 # ensure nothing has been traced.
270 validate_trace_empty $TRACE_PATH
271
272 destroy_lttng_session $SESSION_NAME
273
274 rm -rf $TRACE_PATH
275}
276
277function test_syscall_enable_two_disable_two()
278{
279 TRACE_PATH=$(mktemp -d)
280 SESSION_NAME="kernel_syscall_enable_two_disable_two"
281
282 create_lttng_session $SESSION_NAME $TRACE_PATH
283
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"
290
291 start_lttng_tracing
292 # generates open, close, execve (at least)
293 eval ${TESTCMD}
294 stop_lttng_tracing
295
296 # ensure nothing has been traced.
297 validate_trace_empty $TRACE_PATH
298
299 destroy_lttng_session $SESSION_NAME
300
301 rm -rf $TRACE_PATH
302}
303
304function test_syscall_enable_two_disable_one()
305{
306 TRACE_PATH=$(mktemp -d)
307 SESSION_NAME="kernel_syscall_enable_two_disable_one"
308
309 create_lttng_session $SESSION_NAME $TRACE_PATH
310
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"
316
317 start_lttng_tracing
318 # generates open, close, execve (at least)
319 eval ${TESTCMD}
320 stop_lttng_tracing
321
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
325
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
328
329 destroy_lttng_session $SESSION_NAME
330
331 rm -rf $TRACE_PATH
332}
333
334function test_syscall_disable_twice()
335{
336 TRACE_PATH=$(mktemp -d)
337 SESSION_NAME="kernel_syscall_disable_twice"
338
339 create_lttng_session $SESSION_NAME $TRACE_PATH
340
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"
346
347 destroy_lttng_session $SESSION_NAME
348
349 rm -rf $TRACE_PATH
350}
351
352function test_syscall_disable_all_twice()
353{
354 TRACE_PATH=$(mktemp -d)
355 SESSION_NAME="kernel_syscall_disable_all_twice"
356
357 create_lttng_session $SESSION_NAME $TRACE_PATH
358
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
364
365 destroy_lttng_session $SESSION_NAME
366
367 rm -rf $TRACE_PATH
368}
369
370
371function test_syscall_enable_unknown()
372{
373 TRACE_PATH=$(mktemp -d)
374 SESSION_NAME="kernel_syscall_enable_unknown"
375
376 create_lttng_session $SESSION_NAME $TRACE_PATH
377
378 lttng_enable_kernel_syscall_fail $SESSION_NAME "thissyscallcannotexist"
379
380 destroy_lttng_session $SESSION_NAME
381
382 rm -rf $TRACE_PATH
383}
384
385function test_syscall_enable_all_enable_one()
386{
387 TRACE_PATH=$(mktemp -d)
388 SESSION_NAME="kernel_syscall_enable_all_enable_one"
389
390 create_lttng_session $SESSION_NAME $TRACE_PATH
391
392 lttng_enable_kernel_syscall_ok $SESSION_NAME
393 # Enabling an event already enabled fails.
394 lttng_enable_kernel_syscall_fail $SESSION_NAME "open"
395
396 destroy_lttng_session $SESSION_NAME
397
398 rm -rf $TRACE_PATH
399}
400
401function test_syscall_disable_all_disable_one()
402{
403 TRACE_PATH=$(mktemp -d)
404 SESSION_NAME="kernel_syscall_enable_all_enable_one"
405
406 create_lttng_session $SESSION_NAME $TRACE_PATH
407
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"
412
413 destroy_lttng_session $SESSION_NAME
414
415 rm -rf $TRACE_PATH
416}
417
d96f6315
MD
418function test_syscall_enable_channel_disable_all()
419{
420 TRACE_PATH=$(mktemp -d)
421 SESSION_NAME="kernel_syscall_enable_channel_disable_all"
422 CHANNEL_NAME="channel"
423
424 create_lttng_session $SESSION_NAME $TRACE_PATH
425
426 lttng_enable_kernel_channel_ok $SESSION_NAME $CHANNEL_NAME
427 lttng_disable_kernel_syscall_fail $SESSION_NAME "-a" $CHANNEL_NAME
428
429 destroy_lttng_session $SESSION_NAME
430
431 rm -rf $TRACE_PATH
432}
433
434function test_syscall_enable_channel_disable_one()
435{
436 TRACE_PATH=$(mktemp -d)
437 SESSION_NAME="kernel_syscall_enable_channel_disable_all"
438 CHANNEL_NAME="channel"
439
440 create_lttng_session $SESSION_NAME $TRACE_PATH
441
442 lttng_enable_kernel_channel_ok $SESSION_NAME $CHANNEL_NAME
443 lttng_disable_kernel_syscall_fail $SESSION_NAME "open" $CHANNEL_NAME
444
445 destroy_lttng_session $SESSION_NAME
446
447 rm -rf $TRACE_PATH
448}
449
8cfcd41c
MD
450# MUST set TESTDIR before calling those functions
451plan_tests $NUM_TESTS
452
453print_test_banner "$TEST_DESC"
454
455if [ "$(id -u)" == "0" ]; then
456 isroot=1
457else
458 isroot=0
459fi
460
461skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
462{
463 start_lttng_sessiond
464
465 test_syscall_single
466 test_syscall_two
467 test_syscall_all
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
d96f6315
MD
481 test_syscall_enable_channel_disable_all
482 test_syscall_enable_channel_disable_one
8cfcd41c
MD
483
484 stop_lttng_sessiond
485}
This page took 0.052397 seconds and 4 git commands to generate.