1 // SPDX-License-Identifier: GPL-2.0
4 #include <api/fs/tracing_path.h>
9 #include "thread_map.h"
14 int test__openat_syscall_event(struct test *test __maybe_unused, int subtest __maybe_unused)
17 struct perf_evsel *evsel;
18 unsigned int nr_openat_calls = 111, i;
19 struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX);
20 char sbuf[STRERR_BUFSIZE];
23 if (threads == NULL) {
24 pr_debug("thread_map__new\n");
28 evsel = perf_evsel__newtp("syscalls", "sys_enter_openat");
30 tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat");
31 pr_debug("%s\n", errbuf);
32 goto out_thread_map_delete;
35 if (perf_evsel__open_per_thread(evsel, threads) < 0) {
36 pr_debug("failed to open counter: %s, "
37 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
38 str_error_r(errno, sbuf, sizeof(sbuf)));
39 goto out_evsel_delete;
42 for (i = 0; i < nr_openat_calls; ++i) {
43 fd = openat(0, "/etc/passwd", O_RDONLY);
47 if (perf_evsel__read_on_cpu(evsel, 0, 0) < 0) {
48 pr_debug("perf_evsel__read_on_cpu\n");
52 if (perf_counts(evsel->counts, 0, 0)->val != nr_openat_calls) {
53 pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64 "\n",
54 nr_openat_calls, perf_counts(evsel->counts, 0, 0)->val);
60 perf_evsel__close_fd(evsel);
62 perf_evsel__delete(evsel);
63 out_thread_map_delete:
64 thread_map__put(threads);