Tests: Change syscall tests to use `gen-syscall-events` testapp
[lttng-tools.git] / tests / regression / kernel / test_syscall
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
19 TEST_DESC="Kernel tracer - System calls"
20
21 CURDIR=$(dirname $0)/
22 TESTDIR=$CURDIR/../..
23 NUM_TESTS=183
24
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"
28
29 source $TESTDIR/utils/utils.sh
30
31 function trace_testapp()
32 {
33 local start_file_sync
34 start_file_sync=$(mktemp -u)
35
36 # Clear all entries from the resource tracker
37 lttng_untrack_kernel_all_ok
38
39 # Launch the testapp and save its Process ID
40 ./"$TESTCMD" "$start_file_sync" &
41 PID=$!
42
43 # Set LTTng to track this PID and start the tracing
44 lttng_track_pid_ok $PID
45
46 start_lttng_tracing_ok
47
48 # Create start file to launch the execution of the workload by the
49 # test app
50 touch "$start_file_sync"
51
52 wait $PID
53
54 stop_lttng_tracing_ok
55
56 # Clean up the synchronization file
57 rm -f "$start_file_sync"
58 }
59
60 function validate_list()
61 {
62 local session_name=$1
63 local event_name=$2
64 local opt=$3
65
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)"
70 else
71 pass "Validate syscall listing. Found $event_name."
72 fi
73 }
74
75 function test_syscall_event_list()
76 {
77 local EVENT_NAME="getpid"
78
79 diag "Syscall event listing"
80
81 validate_list "" $EVENT_NAME "-k --syscall"
82 }
83
84 function test_syscall_simple_list()
85 {
86 TRACE_PATH=$(mktemp -d)
87 SESSION_NAME="kernel_syscall_simple_list"
88 local EVENT_NAME="close"
89
90 diag "Syscall simple listing"
91
92 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
93
94 lttng_enable_kernel_syscall_ok $SESSION_NAME $EVENT_NAME
95
96 validate_list $SESSION_NAME $EVENT_NAME
97
98 trace_testapp
99
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
103
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
106
107 destroy_lttng_session_ok $SESSION_NAME
108
109 rm -rf $TRACE_PATH
110 }
111
112 function test_syscall_simple_list_two()
113 {
114 TRACE_PATH=$(mktemp -d)
115 SESSION_NAME="kernel_syscall_simple_list_two"
116 local EVENT_NAME="close"
117 local EVENT_NAME2="read"
118
119 diag "Syscall simple listing"
120
121 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
122
123 lttng_enable_kernel_syscall_ok $SESSION_NAME $EVENT_NAME
124 lttng_enable_kernel_syscall_ok $SESSION_NAME $EVENT_NAME2
125
126 validate_list $SESSION_NAME $EVENT_NAME
127 validate_list $SESSION_NAME $EVENT_NAME2
128
129 trace_testapp
130
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
134
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
137
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
140
141 destroy_lttng_session_ok $SESSION_NAME
142
143 rm -rf $TRACE_PATH
144 }
145
146 function test_syscall_single()
147 {
148 TRACE_PATH=$(mktemp -d)
149 SESSION_NAME="kernel_syscall_single"
150
151 diag "Syscall trace single"
152
153 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
154
155 lttng_enable_kernel_syscall_ok $SESSION_NAME "open"
156
157 trace_testapp
158
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
162
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
165
166 destroy_lttng_session_ok $SESSION_NAME
167
168 rm -rf $TRACE_PATH
169 }
170
171 function test_syscall_two()
172 {
173 TRACE_PATH=$(mktemp -d)
174 SESSION_NAME="kernel_syscall_two"
175
176 diag "Syscall trace two events"
177
178 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
179
180 lttng_enable_kernel_syscall_ok $SESSION_NAME "open"
181 lttng_enable_kernel_syscall_ok $SESSION_NAME "close"
182
183 trace_testapp
184
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
190
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
193
194 destroy_lttng_session_ok $SESSION_NAME
195
196 rm -rf $TRACE_PATH
197 }
198
199 function test_syscall_all()
200 {
201 TRACE_PATH=$(mktemp -d)
202 SESSION_NAME="kernel_syscall_all"
203
204 diag "Syscall trace all events"
205
206 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
207
208 # enable all syscalls
209 lttng_enable_kernel_syscall_ok $SESSION_NAME
210
211 trace_testapp
212
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.
219
220 destroy_lttng_session_ok $SESSION_NAME
221
222 rm -rf $TRACE_PATH
223 }
224
225 function test_syscall_all_disable_one()
226 {
227 TRACE_PATH=$(mktemp -d)
228 SESSION_NAME="kernel_syscall_all_disable_one"
229
230 diag "Syscall trace all events and disable one"
231
232 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
233
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"
239
240 trace_testapp
241
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
244
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
248
249 destroy_lttng_session_ok $SESSION_NAME
250
251 rm -rf $TRACE_PATH
252 }
253
254 function test_syscall_all_disable_two()
255 {
256 TRACE_PATH=$(mktemp -d)
257 SESSION_NAME="kernel_syscall_all_disable_two"
258
259 diag "Syscall trace all events and disable two"
260
261 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
262
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"
269
270 trace_testapp
271
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
274
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
278
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
282
283 destroy_lttng_session_ok $SESSION_NAME
284
285 rm -rf $TRACE_PATH
286 }
287
288 function test_syscall_enable_all_disable_all()
289 {
290 TRACE_PATH=$(mktemp -d)
291 SESSION_NAME="kernel_syscall_enable_all_disable_all"
292
293 diag "Syscall trace all events and disable all"
294
295 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
296
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
301
302 trace_testapp
303
304 # ensure nothing has been traced.
305 validate_trace_empty $TRACE_PATH
306
307 destroy_lttng_session_ok $SESSION_NAME
308
309 rm -rf $TRACE_PATH
310 }
311
312 function test_syscall_enable_all_disable_all_enable_all()
313 {
314 TRACE_PATH=$(mktemp -d)
315 SESSION_NAME="kernel_syscall_enable_all_disable_all_enable_all"
316
317 diag "Syscall trace all events and enable/disable all"
318
319 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
320
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
327
328 trace_testapp
329
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.
336
337 destroy_lttng_session_ok $SESSION_NAME
338
339 rm -rf $TRACE_PATH
340 }
341
342 function test_syscall_enable_all_disable_all_twice()
343 {
344 TRACE_PATH=$(mktemp -d)
345 SESSION_NAME="kernel_syscall_enable_all_disable_all_twice"
346
347 diag "Syscall trace all events and enable/disable all twice"
348
349 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
350
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
359
360 trace_testapp
361
362 # ensure nothing has been traced.
363 validate_trace_empty $TRACE_PATH
364
365 destroy_lttng_session_ok $SESSION_NAME
366
367 rm -rf $TRACE_PATH
368 }
369
370 function test_syscall_enable_one_disable_one()
371 {
372 TRACE_PATH=$(mktemp -d)
373 SESSION_NAME="kernel_syscall_enable_one_disable_one"
374
375 diag "Syscall trace one event and disable one"
376
377 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
378
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"
383
384 trace_testapp
385
386 # ensure nothing has been traced.
387 validate_trace_empty $TRACE_PATH
388
389 destroy_lttng_session_ok $SESSION_NAME
390
391 rm -rf $TRACE_PATH
392 }
393
394 function test_syscall_enable_two_disable_two()
395 {
396 TRACE_PATH=$(mktemp -d)
397 SESSION_NAME="kernel_syscall_enable_two_disable_two"
398
399 diag "Syscall trace two events and disable two"
400
401 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
402
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"
409
410 trace_testapp
411
412 # ensure nothing has been traced.
413 validate_trace_empty $TRACE_PATH
414
415 destroy_lttng_session_ok $SESSION_NAME
416
417 rm -rf $TRACE_PATH
418 }
419
420 function test_syscall_enable_two_disable_one()
421 {
422 TRACE_PATH=$(mktemp -d)
423 SESSION_NAME="kernel_syscall_enable_two_disable_one"
424
425 diag "Syscall trace two events and disable one"
426
427 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
428
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"
434
435 trace_testapp
436
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
440
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
443
444 destroy_lttng_session_ok $SESSION_NAME
445
446 rm -rf $TRACE_PATH
447 }
448
449 function test_syscall_disable_twice()
450 {
451 TRACE_PATH=$(mktemp -d)
452 SESSION_NAME="kernel_syscall_disable_twice"
453
454 diag "Syscall trace one event and disable twice"
455
456 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
457
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"
463
464 destroy_lttng_session_ok $SESSION_NAME
465
466 rm -rf $TRACE_PATH
467 }
468
469 function test_syscall_disable_all_twice()
470 {
471 TRACE_PATH=$(mktemp -d)
472 SESSION_NAME="kernel_syscall_disable_all_twice"
473
474 diag "Syscall trace all events and disable all twice"
475
476 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
477
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
483
484 destroy_lttng_session_ok $SESSION_NAME
485
486 rm -rf $TRACE_PATH
487 }
488
489
490 function test_syscall_enable_unknown()
491 {
492 TRACE_PATH=$(mktemp -d)
493 SESSION_NAME="kernel_syscall_enable_unknown"
494
495 diag "Syscall enable an unknown event"
496
497 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
498
499 # Enabling a syscall that does not exist succeeds, due to enabler
500 # semantic.
501 lttng_enable_kernel_syscall_ok $SESSION_NAME "thissyscallcannotexist"
502
503 destroy_lttng_session_ok $SESSION_NAME
504
505 rm -rf $TRACE_PATH
506 }
507
508 function test_syscall_enable_all_enable_one()
509 {
510 TRACE_PATH=$(mktemp -d)
511 SESSION_NAME="kernel_syscall_enable_all_enable_one"
512
513 diag "Syscall enable all and enable one"
514
515 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
516
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"
520
521 destroy_lttng_session_ok $SESSION_NAME
522
523 rm -rf $TRACE_PATH
524 }
525
526 function test_syscall_disable_all_disable_one()
527 {
528 TRACE_PATH=$(mktemp -d)
529 SESSION_NAME="kernel_syscall_enable_all_enable_one"
530
531 diag "Syscall disable all and disable one"
532
533 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
534
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"
539
540 destroy_lttng_session_ok $SESSION_NAME
541
542 rm -rf $TRACE_PATH
543 }
544
545 function test_syscall_enable_channel_disable_all()
546 {
547 TRACE_PATH=$(mktemp -d)
548 SESSION_NAME="kernel_syscall_enable_channel_disable_all"
549 CHANNEL_NAME="channel"
550
551 diag "Syscall enable channel and disable all"
552
553 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
554
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
559
560 destroy_lttng_session_ok $SESSION_NAME
561
562 rm -rf $TRACE_PATH
563 }
564
565 function test_syscall_enable_channel_disable_one()
566 {
567 TRACE_PATH=$(mktemp -d)
568 SESSION_NAME="kernel_syscall_enable_channel_disable_all"
569 CHANNEL_NAME="channel"
570
571 diag "Syscall enable channel and disable one"
572
573 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
574
575 lttng_enable_kernel_channel_ok $SESSION_NAME $CHANNEL_NAME
576 lttng_disable_kernel_syscall_fail $SESSION_NAME "open" $CHANNEL_NAME
577
578 destroy_lttng_session_ok $SESSION_NAME
579
580 rm -rf $TRACE_PATH
581 }
582
583 # MUST set TESTDIR before calling those functions
584 plan_tests $NUM_TESTS
585
586 print_test_banner "$TEST_DESC"
587
588 if [ "$(id -u)" == "0" ]; then
589 isroot=1
590 else
591 isroot=0
592 fi
593
594 skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
595 {
596 start_lttng_sessiond
597
598 test_syscall_event_list
599 test_syscall_simple_list
600 test_syscall_simple_list_two
601 test_syscall_single
602 test_syscall_two
603 test_syscall_all
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
619
620 stop_lttng_sessiond
621 }
This page took 0.044652 seconds and 6 git commands to generate.