]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
a43783ae | 2 | #include <errno.h> |
fd20e811 | 3 | #include <inttypes.h> |
fbf99625 | 4 | #include <api/fs/tracing_path.h> |
8dd2a131 | 5 | #include <linux/err.h> |
9a3993d4 ACM |
6 | #include <sys/types.h> |
7 | #include <sys/stat.h> | |
8 | #include <fcntl.h> | |
d3b59a38 JO |
9 | #include "thread_map.h" |
10 | #include "evsel.h" | |
11 | #include "debug.h" | |
12 | #include "tests.h" | |
13 | ||
81f17c90 | 14 | int test__openat_syscall_event(struct test *test __maybe_unused, int subtest __maybe_unused) |
d3b59a38 JO |
15 | { |
16 | int err = -1, fd; | |
d3b59a38 | 17 | struct perf_evsel *evsel; |
43f322b4 | 18 | unsigned int nr_openat_calls = 111, i; |
a60d7953 | 19 | struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX); |
ba3dfff8 | 20 | char sbuf[STRERR_BUFSIZE]; |
fbf99625 | 21 | char errbuf[BUFSIZ]; |
d3b59a38 | 22 | |
d3b59a38 JO |
23 | if (threads == NULL) { |
24 | pr_debug("thread_map__new\n"); | |
25 | return -1; | |
26 | } | |
27 | ||
43f322b4 | 28 | evsel = perf_evsel__newtp("syscalls", "sys_enter_openat"); |
8dd2a131 | 29 | if (IS_ERR(evsel)) { |
fbf99625 | 30 | tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat"); |
87191383 | 31 | pr_debug("%s\n", errbuf); |
d3b59a38 JO |
32 | goto out_thread_map_delete; |
33 | } | |
34 | ||
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", | |
c8b5f2c9 | 38 | str_error_r(errno, sbuf, sizeof(sbuf))); |
d3b59a38 JO |
39 | goto out_evsel_delete; |
40 | } | |
41 | ||
43f322b4 RV |
42 | for (i = 0; i < nr_openat_calls; ++i) { |
43 | fd = openat(0, "/etc/passwd", O_RDONLY); | |
d3b59a38 JO |
44 | close(fd); |
45 | } | |
46 | ||
47 | if (perf_evsel__read_on_cpu(evsel, 0, 0) < 0) { | |
48 | pr_debug("perf_evsel__read_on_cpu\n"); | |
49 | goto out_close_fd; | |
50 | } | |
51 | ||
a6fa0038 | 52 | if (perf_counts(evsel->counts, 0, 0)->val != nr_openat_calls) { |
d3b59a38 | 53 | pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64 "\n", |
a6fa0038 | 54 | nr_openat_calls, perf_counts(evsel->counts, 0, 0)->val); |
d3b59a38 JO |
55 | goto out_close_fd; |
56 | } | |
57 | ||
58 | err = 0; | |
59 | out_close_fd: | |
475fb533 | 60 | perf_evsel__close_fd(evsel); |
d3b59a38 JO |
61 | out_evsel_delete: |
62 | perf_evsel__delete(evsel); | |
63 | out_thread_map_delete: | |
186fbb74 | 64 | thread_map__put(threads); |
d3b59a38 JO |
65 | return err; |
66 | } |