1 // SPDX-License-Identifier: GPL-2.0
4 #include <api/fs/tracing_path.h>
6 #include <linux/string.h>
11 #include "thread_map.h"
15 #include "util/counts.h"
17 static int test__openat_syscall_event(struct test_suite
*test __maybe_unused
,
18 int subtest __maybe_unused
)
20 int err
= TEST_FAIL
, fd
;
22 unsigned int nr_openat_calls
= 111, i
;
23 struct perf_thread_map
*threads
= thread_map__new(-1, getpid(), UINT_MAX
);
24 char sbuf
[STRERR_BUFSIZE
];
27 if (threads
== NULL
) {
28 pr_debug("thread_map__new\n");
32 evsel
= evsel__newtp("syscalls", "sys_enter_openat");
34 tracing_path__strerror_open_tp(errno
, errbuf
, sizeof(errbuf
), "syscalls", "sys_enter_openat");
35 pr_debug("%s\n", errbuf
);
37 goto out_thread_map_delete
;
40 if (evsel__open_per_thread(evsel
, threads
) < 0) {
41 pr_debug("failed to open counter: %s, "
42 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
43 str_error_r(errno
, sbuf
, sizeof(sbuf
)));
45 goto out_evsel_delete
;
48 for (i
= 0; i
< nr_openat_calls
; ++i
) {
49 fd
= openat(0, "/etc/passwd", O_RDONLY
);
53 if (evsel__read_on_cpu(evsel
, 0, 0) < 0) {
54 pr_debug("evsel__read_on_cpu\n");
58 if (perf_counts(evsel
->counts
, 0, 0)->val
!= nr_openat_calls
) {
59 pr_debug("evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64
"\n",
60 nr_openat_calls
, perf_counts(evsel
->counts
, 0, 0)->val
);
66 perf_evsel__close_fd(&evsel
->core
);
69 out_thread_map_delete
:
70 perf_thread_map__put(threads
);
74 static struct test_case tests__openat_syscall_event
[] = {
75 TEST_CASE_REASON("Detect openat syscall event",
81 struct test_suite suite__openat_syscall_event
= {
82 .desc
= "Detect openat syscall event",
83 .test_cases
= tests__openat_syscall_event
,