1 // SPDX-License-Identifier: GPL-2.0
4 #include <linux/string.h>
10 #include "thread_map.h"
14 #include "util/mmap.h"
16 #include <perf/mmap.h>
19 #define O_DIRECTORY 00200000
25 int test__syscall_openat_tp_fields(struct test
*test __maybe_unused
, int subtest __maybe_unused
)
27 struct record_opts opts
= {
37 const char *filename
= "/etc/passwd";
38 int flags
= O_RDONLY
| O_DIRECTORY
;
39 struct evlist
*evlist
= evlist__new();
41 int err
= -1, i
, nr_events
= 0, nr_polls
= 0;
42 char sbuf
[STRERR_BUFSIZE
];
45 pr_debug("%s: evlist__new\n", __func__
);
49 evsel
= evsel__newtp("syscalls", "sys_enter_openat");
51 pr_debug("%s: evsel__newtp\n", __func__
);
52 goto out_delete_evlist
;
55 evlist__add(evlist
, evsel
);
57 err
= evlist__create_maps(evlist
, &opts
.target
);
59 pr_debug("%s: evlist__create_maps\n", __func__
);
60 goto out_delete_evlist
;
63 evsel__config(evsel
, &opts
, NULL
);
65 perf_thread_map__set_pid(evlist
->core
.threads
, 0, getpid());
67 err
= evlist__open(evlist
);
69 pr_debug("perf_evlist__open: %s\n",
70 str_error_r(errno
, sbuf
, sizeof(sbuf
)));
71 goto out_delete_evlist
;
74 err
= evlist__mmap(evlist
, UINT_MAX
);
76 pr_debug("evlist__mmap: %s\n",
77 str_error_r(errno
, sbuf
, sizeof(sbuf
)));
78 goto out_delete_evlist
;
81 evlist__enable(evlist
);
86 openat(AT_FDCWD
, filename
, flags
);
89 int before
= nr_events
;
91 for (i
= 0; i
< evlist
->core
.nr_mmaps
; i
++) {
92 union perf_event
*event
;
95 md
= &evlist
->mmap
[i
];
96 if (perf_mmap__read_init(&md
->core
) < 0)
99 while ((event
= perf_mmap__read_event(&md
->core
)) != NULL
) {
100 const u32 type
= event
->header
.type
;
102 struct perf_sample sample
;
106 if (type
!= PERF_RECORD_SAMPLE
) {
107 perf_mmap__consume(&md
->core
);
111 err
= evsel__parse_sample(evsel
, event
, &sample
);
113 pr_debug("Can't parse sample, err = %d\n", err
);
114 goto out_delete_evlist
;
117 tp_flags
= evsel__intval(evsel
, &sample
, "flags");
119 if (flags
!= tp_flags
) {
120 pr_debug("%s: Expected flags=%#x, got %#x\n",
121 __func__
, flags
, tp_flags
);
122 goto out_delete_evlist
;
127 perf_mmap__read_done(&md
->core
);
130 if (nr_events
== before
)
131 evlist__poll(evlist
, 10);
133 if (++nr_polls
> 5) {
134 pr_debug("%s: no events!\n", __func__
);
135 goto out_delete_evlist
;
141 evlist__delete(evlist
);