SoW-2020-0002: Trace Hit Counters: trigger error reporting integration
[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 # SPDX-License-Identifier: GPL-2.0-only
7 #
8
9 TEST_DESC="Kernel tracer - System calls"
10
11 CURDIR=$(dirname $0)/
12 TESTDIR=$CURDIR/../..
13 NUM_TESTS=183
14
15 # `gen-syscall-event` starts and waits for the creation a file passed by
16 # arguments to start executing 3 syscalls (open,read,close) and returning.
17 TESTCMD="$TESTDIR/utils/testapp/gen-syscall-events/gen-syscall-events"
18
19 source $TESTDIR/utils/utils.sh
20
21 function trace_testapp()
22 {
23 local start_file_sync
24 start_file_sync=$(mktemp -u)
25
26 # Clear all entries from the resource tracker
27 lttng_untrack_kernel_all_ok
28
29 # Launch the testapp and save its Process ID
30 ./"$TESTCMD" "$start_file_sync" "/proc/cpuinfo" "/proc/cmdline" &
31 PID=$!
32
33 # Set LTTng to track this PID and start the tracing
34 lttng_track_pid_ok $PID
35
36 start_lttng_tracing_ok
37
38 # Create start file to launch the execution of the workload by the
39 # test app
40 touch "$start_file_sync"
41
42 wait $PID
43
44 stop_lttng_tracing_ok
45
46 # Clean up the synchronization file
47 rm -f "$start_file_sync"
48 }
49
50 function validate_list()
51 {
52 local session_name=$1
53 local event_name=$2
54 local opt=$3
55
56 out=$($TESTDIR/../src/bin/lttng/$LTTNG_BIN list $session_name $opt | grep $event_name)
57 if [ -z "$out" ]; then
58 fail "Validate syscall listing"
59 diag "$event_name not found when listing $session_name (opt $opt)"
60 else
61 pass "Validate syscall listing. Found $event_name."
62 fi
63 }
64
65 function test_syscall_event_list()
66 {
67 local EVENT_NAME="getpid"
68
69 diag "Syscall event listing"
70
71 validate_list "" $EVENT_NAME "-k --syscall"
72 }
73
74 function test_syscall_simple_list()
75 {
76 TRACE_PATH=$(mktemp -d)
77 SESSION_NAME="kernel_syscall_simple_list"
78 local EVENT_NAME="close"
79
80 diag "Syscall simple listing"
81
82 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
83
84 lttng_enable_kernel_syscall_ok $SESSION_NAME $EVENT_NAME
85
86 validate_list $SESSION_NAME $EVENT_NAME
87
88 trace_testapp
89
90 # ensure all events are in the trace.
91 validate_trace_exp "-e syscall_entry_$EVENT_NAME: -e compat_syscall_entry_$EVENT_NAME:" $TRACE_PATH
92 validate_trace_exp "-e syscall_exit_$EVENT_NAME: -e compat_syscall_exit_$EVENT_NAME:" $TRACE_PATH
93
94 # ensure trace only contains those.
95 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
96
97 destroy_lttng_session_ok $SESSION_NAME
98
99 rm -rf $TRACE_PATH
100 }
101
102 function test_syscall_simple_list_two()
103 {
104 TRACE_PATH=$(mktemp -d)
105 SESSION_NAME="kernel_syscall_simple_list_two"
106 local EVENT_NAME="close"
107 local EVENT_NAME2="read"
108
109 diag "Syscall simple listing"
110
111 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
112
113 lttng_enable_kernel_syscall_ok $SESSION_NAME $EVENT_NAME
114 lttng_enable_kernel_syscall_ok $SESSION_NAME $EVENT_NAME2
115
116 validate_list $SESSION_NAME $EVENT_NAME
117 validate_list $SESSION_NAME $EVENT_NAME2
118
119 trace_testapp
120
121 # ensure all events are in the trace.
122 validate_trace_exp "-e syscall_entry_$EVENT_NAME: -e compat_syscall_entry_$EVENT_NAME:" $TRACE_PATH
123 validate_trace_exp "-e syscall_exit_$EVENT_NAME: -e compat_syscall_exit_$EVENT_NAME:" $TRACE_PATH
124
125 validate_trace_exp "-e syscall_entry_$EVENT_NAME2: -e compat_syscall_entry_$EVENT_NAME2:" $TRACE_PATH
126 validate_trace_exp "-e syscall_exit_$EVENT_NAME2: -e compat_syscall_exit_$EVENT_NAME2:" $TRACE_PATH
127
128 # ensure trace only contains those.
129 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
130
131 destroy_lttng_session_ok $SESSION_NAME
132
133 rm -rf $TRACE_PATH
134 }
135
136 function test_syscall_single()
137 {
138 TRACE_PATH=$(mktemp -d)
139 SESSION_NAME="kernel_syscall_single"
140
141 diag "Syscall trace single"
142
143 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
144
145 lttng_enable_kernel_syscall_ok $SESSION_NAME "openat"
146
147 trace_testapp
148
149 # ensure all events are in the trace.
150 validate_trace_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat:" $TRACE_PATH
151 validate_trace_exp "-e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH
152
153 # ensure trace only contains those.
154 validate_trace_only_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat: -e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH
155
156 destroy_lttng_session_ok $SESSION_NAME
157
158 rm -rf $TRACE_PATH
159 }
160
161 function test_syscall_two()
162 {
163 TRACE_PATH=$(mktemp -d)
164 SESSION_NAME="kernel_syscall_two"
165
166 diag "Syscall trace two events"
167
168 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
169
170 lttng_enable_kernel_syscall_ok $SESSION_NAME "openat"
171 lttng_enable_kernel_syscall_ok $SESSION_NAME "close"
172
173 trace_testapp
174
175 # ensure all events are in the trace.
176 validate_trace_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat:" $TRACE_PATH
177 validate_trace_exp "-e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH
178 validate_trace_exp "-e syscall_entry_close: -e compat_syscall_entry_close:" $TRACE_PATH
179 validate_trace_exp "-e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH
180
181 # ensure trace only contains those.
182 validate_trace_only_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat: -e syscall_exit_openat: -e compat_syscall_exit_openat: -e syscall_entry_close: -e compat_syscall_entry_close: -e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH
183
184 destroy_lttng_session_ok $SESSION_NAME
185
186 rm -rf $TRACE_PATH
187 }
188
189 function test_syscall_all()
190 {
191 TRACE_PATH=$(mktemp -d)
192 SESSION_NAME="kernel_syscall_all"
193
194 diag "Syscall trace all events"
195
196 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
197
198 # enable all syscalls
199 lttng_enable_kernel_syscall_ok $SESSION_NAME
200
201 trace_testapp
202
203 # ensure at least open and close are there.
204 validate_trace_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat:" $TRACE_PATH
205 validate_trace_exp "-e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH
206 validate_trace_exp "-e syscall_entry_close: -e compat_syscall_entry_close:" $TRACE_PATH
207 validate_trace_exp "-e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH
208 # trace may contain other syscalls.
209
210 destroy_lttng_session_ok $SESSION_NAME
211
212 rm -rf $TRACE_PATH
213 }
214
215 function test_syscall_all_disable_one()
216 {
217 TRACE_PATH=$(mktemp -d)
218 SESSION_NAME="kernel_syscall_all_disable_one"
219
220 diag "Syscall trace all events and disable one"
221
222 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
223
224 # enable all syscalls
225 lttng_enable_kernel_syscall_ok $SESSION_NAME
226 # try to disable open system call: fails because enabler semantic of
227 # "all syscalls" is not "the open" system call.
228 lttng_disable_kernel_syscall_fail $SESSION_NAME "openat"
229
230 trace_testapp
231
232 # ensure "openat" syscall is there.
233 validate_trace_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat: -e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH
234
235 # ensure "close" syscall is there.
236 validate_trace_exp "-e syscall_entry_close: -e compat_syscall_entry_close:" $TRACE_PATH
237 validate_trace_exp "-e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH
238
239 destroy_lttng_session_ok $SESSION_NAME
240
241 rm -rf $TRACE_PATH
242 }
243
244 function test_syscall_all_disable_two()
245 {
246 TRACE_PATH=$(mktemp -d)
247 SESSION_NAME="kernel_syscall_all_disable_two"
248
249 diag "Syscall trace all events and disable two"
250
251 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
252
253 # enable all syscalls
254 lttng_enable_kernel_syscall_ok $SESSION_NAME
255 # try to disable open and close system calls: fails because enabler
256 # semantic of "all syscalls" is not "the open" system call.
257 lttng_disable_kernel_syscall_fail $SESSION_NAME "openat"
258 lttng_disable_kernel_syscall_fail $SESSION_NAME "close"
259
260 trace_testapp
261
262 # ensure "openat" syscall is there.
263 validate_trace_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat: -e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH
264
265 # ensure "close" syscall is there.
266 validate_trace_exp "-e syscall_entry_close: -e compat_syscall_entry_close:" $TRACE_PATH
267 validate_trace_exp "-e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH
268
269 # ensure "read" syscall is there.
270 validate_trace_exp "-e syscall_entry_read: -e compat_syscall_entry_read:" $TRACE_PATH
271 validate_trace_exp "-e syscall_exit_read: -e compat_syscall_exit_read:" $TRACE_PATH
272
273 destroy_lttng_session_ok $SESSION_NAME
274
275 rm -rf $TRACE_PATH
276 }
277
278 function test_syscall_enable_all_disable_all()
279 {
280 TRACE_PATH=$(mktemp -d)
281 SESSION_NAME="kernel_syscall_enable_all_disable_all"
282
283 diag "Syscall trace all events and disable all"
284
285 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
286
287 # enable all system calls
288 lttng_enable_kernel_syscall_ok $SESSION_NAME
289 # disable all system calls
290 lttng_disable_kernel_syscall_ok $SESSION_NAME
291
292 trace_testapp
293
294 # ensure nothing has been traced.
295 validate_trace_empty $TRACE_PATH
296
297 destroy_lttng_session_ok $SESSION_NAME
298
299 rm -rf $TRACE_PATH
300 }
301
302 function test_syscall_enable_all_disable_all_enable_all()
303 {
304 TRACE_PATH=$(mktemp -d)
305 SESSION_NAME="kernel_syscall_enable_all_disable_all_enable_all"
306
307 diag "Syscall trace all events and enable/disable all"
308
309 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
310
311 # enable all system calls
312 lttng_enable_kernel_syscall_ok $SESSION_NAME
313 # disable all system calls
314 lttng_disable_kernel_syscall_ok $SESSION_NAME
315 # enable all system calls
316 lttng_enable_kernel_syscall_ok $SESSION_NAME
317
318 trace_testapp
319
320 # ensure at least open and close are there.
321 validate_trace_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat:" $TRACE_PATH
322 validate_trace_exp "-e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH
323 validate_trace_exp "-e syscall_entry_close: -e compat_syscall_entry_close:" $TRACE_PATH
324 validate_trace_exp "-e syscall_exit_close: -e compat_syscall_exit_close:" $TRACE_PATH
325 # trace may contain other syscalls.
326
327 destroy_lttng_session_ok $SESSION_NAME
328
329 rm -rf $TRACE_PATH
330 }
331
332 function test_syscall_enable_all_disable_all_twice()
333 {
334 TRACE_PATH=$(mktemp -d)
335 SESSION_NAME="kernel_syscall_enable_all_disable_all_twice"
336
337 diag "Syscall trace all events and enable/disable all twice"
338
339 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
340
341 # enable all system calls
342 lttng_enable_kernel_syscall_ok $SESSION_NAME
343 # disable all system calls
344 lttng_disable_kernel_syscall_ok $SESSION_NAME
345 # enable all system calls
346 lttng_enable_kernel_syscall_ok $SESSION_NAME
347 # disable all system calls
348 lttng_disable_kernel_syscall_ok $SESSION_NAME
349
350 trace_testapp
351
352 # ensure nothing has been traced.
353 validate_trace_empty $TRACE_PATH
354
355 destroy_lttng_session_ok $SESSION_NAME
356
357 rm -rf $TRACE_PATH
358 }
359
360 function test_syscall_enable_one_disable_one()
361 {
362 TRACE_PATH=$(mktemp -d)
363 SESSION_NAME="kernel_syscall_enable_one_disable_one"
364
365 diag "Syscall trace one event and disable one"
366
367 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
368
369 # enable open system call
370 lttng_enable_kernel_syscall_ok $SESSION_NAME "openat"
371 # disable open system call
372 lttng_disable_kernel_syscall_ok $SESSION_NAME "openat"
373
374 trace_testapp
375
376 # ensure nothing has been traced.
377 validate_trace_empty $TRACE_PATH
378
379 destroy_lttng_session_ok $SESSION_NAME
380
381 rm -rf $TRACE_PATH
382 }
383
384 function test_syscall_enable_two_disable_two()
385 {
386 TRACE_PATH=$(mktemp -d)
387 SESSION_NAME="kernel_syscall_enable_two_disable_two"
388
389 diag "Syscall trace two events and disable two"
390
391 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
392
393 # enable open and close system calls
394 lttng_enable_kernel_syscall_ok $SESSION_NAME "openat"
395 lttng_enable_kernel_syscall_ok $SESSION_NAME "close"
396 # disable open and close system calls
397 lttng_disable_kernel_syscall_ok $SESSION_NAME "openat"
398 lttng_disable_kernel_syscall_ok $SESSION_NAME "close"
399
400 trace_testapp
401
402 # ensure nothing has been traced.
403 validate_trace_empty $TRACE_PATH
404
405 destroy_lttng_session_ok $SESSION_NAME
406
407 rm -rf $TRACE_PATH
408 }
409
410 function test_syscall_enable_two_disable_one()
411 {
412 TRACE_PATH=$(mktemp -d)
413 SESSION_NAME="kernel_syscall_enable_two_disable_one"
414
415 diag "Syscall trace two events and disable one"
416
417 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
418
419 # enable open and close system calls
420 lttng_enable_kernel_syscall_ok $SESSION_NAME "openat"
421 lttng_enable_kernel_syscall_ok $SESSION_NAME "close"
422 # disable close system call
423 lttng_disable_kernel_syscall_ok $SESSION_NAME "close"
424
425 trace_testapp
426
427 # ensure open is there.
428 validate_trace_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat:" $TRACE_PATH
429 validate_trace_exp "-e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH
430
431 # ensure trace only contains those.
432 validate_trace_only_exp "-e syscall_entry_openat: -e compat_syscall_entry_openat: -e syscall_exit_openat: -e compat_syscall_exit_openat:" $TRACE_PATH
433
434 destroy_lttng_session_ok $SESSION_NAME
435
436 rm -rf $TRACE_PATH
437 }
438
439 function test_syscall_disable_twice()
440 {
441 TRACE_PATH=$(mktemp -d)
442 SESSION_NAME="kernel_syscall_disable_twice"
443
444 diag "Syscall trace one event and disable twice"
445
446 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
447
448 lttng_enable_kernel_syscall_ok $SESSION_NAME "openat"
449 # First disable will succeed
450 lttng_disable_kernel_syscall_ok $SESSION_NAME "openat"
451 # Second disable succeeds too, due to enabler semantic.
452 lttng_disable_kernel_syscall_ok $SESSION_NAME "openat"
453
454 destroy_lttng_session_ok $SESSION_NAME
455
456 rm -rf $TRACE_PATH
457 }
458
459 function test_syscall_disable_all_twice()
460 {
461 TRACE_PATH=$(mktemp -d)
462 SESSION_NAME="kernel_syscall_disable_all_twice"
463
464 diag "Syscall trace all events and disable all twice"
465
466 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
467
468 lttng_enable_kernel_syscall_ok $SESSION_NAME
469 # First disable will succeed
470 lttng_disable_kernel_syscall_ok $SESSION_NAME
471 # Second disable succeeds too, due to enabler semantic.
472 lttng_disable_kernel_syscall_ok $SESSION_NAME
473
474 destroy_lttng_session_ok $SESSION_NAME
475
476 rm -rf $TRACE_PATH
477 }
478
479
480 function test_syscall_enable_unknown()
481 {
482 TRACE_PATH=$(mktemp -d)
483 SESSION_NAME="kernel_syscall_enable_unknown"
484
485 diag "Syscall enable an unknown event"
486
487 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
488
489 # Enabling a syscall that does not exist succeeds, due to enabler
490 # semantic.
491 lttng_enable_kernel_syscall_ok $SESSION_NAME "thissyscallcannotexist"
492
493 destroy_lttng_session_ok $SESSION_NAME
494
495 rm -rf $TRACE_PATH
496 }
497
498 function test_syscall_enable_all_enable_one()
499 {
500 TRACE_PATH=$(mktemp -d)
501 SESSION_NAME="kernel_syscall_enable_all_enable_one"
502
503 diag "Syscall enable all and enable one"
504
505 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
506
507 lttng_enable_kernel_syscall_ok $SESSION_NAME
508 # Enabling an event already enabled succeeds, due to enabler semantic.
509 lttng_enable_kernel_syscall_ok $SESSION_NAME "openat"
510
511 destroy_lttng_session_ok $SESSION_NAME
512
513 rm -rf $TRACE_PATH
514 }
515
516 function test_syscall_disable_all_disable_one()
517 {
518 TRACE_PATH=$(mktemp -d)
519 SESSION_NAME="kernel_syscall_enable_all_enable_one"
520
521 diag "Syscall disable all and disable one"
522
523 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
524
525 lttng_enable_kernel_syscall_ok $SESSION_NAME
526 lttng_disable_kernel_syscall_ok $SESSION_NAME
527 # Disabling an event already disabled fails.
528 lttng_disable_kernel_syscall_fail $SESSION_NAME "openat"
529
530 destroy_lttng_session_ok $SESSION_NAME
531
532 rm -rf $TRACE_PATH
533 }
534
535 function test_syscall_enable_channel_disable_all()
536 {
537 TRACE_PATH=$(mktemp -d)
538 SESSION_NAME="kernel_syscall_enable_channel_disable_all"
539 CHANNEL_NAME="channel"
540
541 diag "Syscall enable channel and disable all"
542
543 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
544
545 lttng_enable_kernel_channel_ok $SESSION_NAME $CHANNEL_NAME
546 # sessiond semantic for "disable all" is to try to match all enalers
547 # it knowns about. Disable all succeeds if it finds no match.
548 lttng_disable_kernel_syscall_ok $SESSION_NAME "-a" $CHANNEL_NAME
549
550 destroy_lttng_session_ok $SESSION_NAME
551
552 rm -rf $TRACE_PATH
553 }
554
555 function test_syscall_enable_channel_disable_one()
556 {
557 TRACE_PATH=$(mktemp -d)
558 SESSION_NAME="kernel_syscall_enable_channel_disable_all"
559 CHANNEL_NAME="channel"
560
561 diag "Syscall enable channel and disable one"
562
563 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
564
565 lttng_enable_kernel_channel_ok $SESSION_NAME $CHANNEL_NAME
566 lttng_disable_kernel_syscall_fail $SESSION_NAME "openat" $CHANNEL_NAME
567
568 destroy_lttng_session_ok $SESSION_NAME
569
570 rm -rf $TRACE_PATH
571 }
572
573 # MUST set TESTDIR before calling those functions
574 plan_tests $NUM_TESTS
575
576 print_test_banner "$TEST_DESC"
577
578 if [ "$(id -u)" == "0" ]; then
579 isroot=1
580 else
581 isroot=0
582 fi
583
584 skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
585 {
586 start_lttng_sessiond
587
588 test_syscall_event_list
589 test_syscall_simple_list
590 test_syscall_simple_list_two
591 test_syscall_single
592 test_syscall_two
593 test_syscall_all
594 test_syscall_all_disable_one
595 test_syscall_all_disable_two
596 test_syscall_enable_all_disable_all
597 test_syscall_enable_all_disable_all_enable_all
598 test_syscall_enable_all_disable_all_twice
599 test_syscall_enable_one_disable_one
600 test_syscall_enable_two_disable_two
601 test_syscall_enable_two_disable_one
602 test_syscall_disable_twice
603 test_syscall_disable_all_twice
604 test_syscall_enable_unknown
605 test_syscall_enable_all_enable_one
606 test_syscall_disable_all_disable_one
607 test_syscall_enable_channel_disable_all
608 test_syscall_enable_channel_disable_one
609
610 stop_lttng_sessiond
611 }
This page took 0.06806 seconds and 5 git commands to generate.