Commit | Line | Data |
---|---|---|
fbf99625 | 1 | #include <api/fs/tracing_path.h> |
8dd2a131 | 2 | #include <linux/err.h> |
d3b59a38 JO |
3 | #include "thread_map.h" |
4 | #include "evsel.h" | |
5 | #include "debug.h" | |
6 | #include "tests.h" | |
7 | ||
721a1f53 | 8 | int test__openat_syscall_event(int subtest __maybe_unused) |
d3b59a38 JO |
9 | { |
10 | int err = -1, fd; | |
d3b59a38 | 11 | struct perf_evsel *evsel; |
43f322b4 | 12 | unsigned int nr_openat_calls = 111, i; |
a60d7953 | 13 | struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX); |
ba3dfff8 | 14 | char sbuf[STRERR_BUFSIZE]; |
fbf99625 | 15 | char errbuf[BUFSIZ]; |
d3b59a38 | 16 | |
d3b59a38 JO |
17 | if (threads == NULL) { |
18 | pr_debug("thread_map__new\n"); | |
19 | return -1; | |
20 | } | |
21 | ||
43f322b4 | 22 | evsel = perf_evsel__newtp("syscalls", "sys_enter_openat"); |
8dd2a131 | 23 | if (IS_ERR(evsel)) { |
fbf99625 | 24 | tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat"); |
87191383 | 25 | pr_debug("%s\n", errbuf); |
d3b59a38 JO |
26 | goto out_thread_map_delete; |
27 | } | |
28 | ||
29 | if (perf_evsel__open_per_thread(evsel, threads) < 0) { | |
30 | pr_debug("failed to open counter: %s, " | |
31 | "tweak /proc/sys/kernel/perf_event_paranoid?\n", | |
c8b5f2c9 | 32 | str_error_r(errno, sbuf, sizeof(sbuf))); |
d3b59a38 JO |
33 | goto out_evsel_delete; |
34 | } | |
35 | ||
43f322b4 RV |
36 | for (i = 0; i < nr_openat_calls; ++i) { |
37 | fd = openat(0, "/etc/passwd", O_RDONLY); | |
d3b59a38 JO |
38 | close(fd); |
39 | } | |
40 | ||
41 | if (perf_evsel__read_on_cpu(evsel, 0, 0) < 0) { | |
42 | pr_debug("perf_evsel__read_on_cpu\n"); | |
43 | goto out_close_fd; | |
44 | } | |
45 | ||
a6fa0038 | 46 | if (perf_counts(evsel->counts, 0, 0)->val != nr_openat_calls) { |
d3b59a38 | 47 | pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64 "\n", |
a6fa0038 | 48 | nr_openat_calls, perf_counts(evsel->counts, 0, 0)->val); |
d3b59a38 JO |
49 | goto out_close_fd; |
50 | } | |
51 | ||
52 | err = 0; | |
53 | out_close_fd: | |
54 | perf_evsel__close_fd(evsel, 1, threads->nr); | |
55 | out_evsel_delete: | |
56 | perf_evsel__delete(evsel); | |
57 | out_thread_map_delete: | |
186fbb74 | 58 | thread_map__put(threads); |
d3b59a38 JO |
59 | return err; |
60 | } |