1 // SPDX-License-Identifier: GPL-2.0
4 #include <api/fs/tracing_path.h>
6 #include <linux/string.h>
10 #include "thread_map.h"
14 #include "util/counts.h"
16 int test__openat_syscall_event(struct test
*test __maybe_unused
, int subtest __maybe_unused
)
20 unsigned int nr_openat_calls
= 111, i
;
21 struct perf_thread_map
*threads
= thread_map__new(-1, getpid(), UINT_MAX
);
22 char sbuf
[STRERR_BUFSIZE
];
25 if (threads
== NULL
) {
26 pr_debug("thread_map__new\n");
30 evsel
= evsel__newtp("syscalls", "sys_enter_openat");
32 tracing_path__strerror_open_tp(errno
, errbuf
, sizeof(errbuf
), "syscalls", "sys_enter_openat");
33 pr_debug("%s\n", errbuf
);
34 goto out_thread_map_delete
;
37 if (evsel__open_per_thread(evsel
, threads
) < 0) {
38 pr_debug("failed to open counter: %s, "
39 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
40 str_error_r(errno
, sbuf
, sizeof(sbuf
)));
41 goto out_evsel_delete
;
44 for (i
= 0; i
< nr_openat_calls
; ++i
) {
45 fd
= openat(0, "/etc/passwd", O_RDONLY
);
49 if (evsel__read_on_cpu(evsel
, 0, 0) < 0) {
50 pr_debug("evsel__read_on_cpu\n");
54 if (perf_counts(evsel
->counts
, 0, 0)->val
!= nr_openat_calls
) {
55 pr_debug("evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64
"\n",
56 nr_openat_calls
, perf_counts(evsel
->counts
, 0, 0)->val
);
62 perf_evsel__close_fd(&evsel
->core
);
65 out_thread_map_delete
:
66 perf_thread_map__put(threads
);