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>
17 #include "util/sample.h"
20 #define O_DIRECTORY 00200000
26 static int test__syscall_openat_tp_fields(struct test_suite
*test __maybe_unused
,
27 int subtest __maybe_unused
)
29 struct record_opts opts
= {
39 const char *filename
= "/etc/passwd";
40 int flags
= O_RDONLY
| O_DIRECTORY
;
41 struct evlist
*evlist
= evlist__new();
43 int ret
= TEST_FAIL
, err
, i
, nr_events
= 0, nr_polls
= 0;
44 char sbuf
[STRERR_BUFSIZE
];
47 pr_debug("%s: evlist__new\n", __func__
);
51 evsel
= evsel__newtp("syscalls", "sys_enter_openat");
53 pr_debug("%s: evsel__newtp\n", __func__
);
54 ret
= PTR_ERR(evsel
) == -EACCES
? TEST_SKIP
: TEST_FAIL
;
55 goto out_delete_evlist
;
58 evlist__add(evlist
, evsel
);
60 err
= evlist__create_maps(evlist
, &opts
.target
);
62 pr_debug("%s: evlist__create_maps\n", __func__
);
63 goto out_delete_evlist
;
66 evsel__config(evsel
, &opts
, NULL
);
68 perf_thread_map__set_pid(evlist
->core
.threads
, 0, getpid());
70 err
= evlist__open(evlist
);
72 pr_debug("perf_evlist__open: %s\n",
73 str_error_r(errno
, sbuf
, sizeof(sbuf
)));
74 goto out_delete_evlist
;
77 err
= evlist__mmap(evlist
, UINT_MAX
);
79 pr_debug("evlist__mmap: %s\n",
80 str_error_r(errno
, sbuf
, sizeof(sbuf
)));
81 goto out_delete_evlist
;
84 evlist__enable(evlist
);
89 openat(AT_FDCWD
, filename
, flags
);
92 int before
= nr_events
;
94 for (i
= 0; i
< evlist
->core
.nr_mmaps
; i
++) {
95 union perf_event
*event
;
98 md
= &evlist
->mmap
[i
];
99 if (perf_mmap__read_init(&md
->core
) < 0)
102 while ((event
= perf_mmap__read_event(&md
->core
)) != NULL
) {
103 const u32 type
= event
->header
.type
;
105 struct perf_sample sample
;
109 if (type
!= PERF_RECORD_SAMPLE
) {
110 perf_mmap__consume(&md
->core
);
114 err
= evsel__parse_sample(evsel
, event
, &sample
);
116 pr_debug("Can't parse sample, err = %d\n", err
);
117 goto out_delete_evlist
;
120 tp_flags
= evsel__intval(evsel
, &sample
, "flags");
122 if (flags
!= tp_flags
) {
123 pr_debug("%s: Expected flags=%#x, got %#x\n",
124 __func__
, flags
, tp_flags
);
125 goto out_delete_evlist
;
130 perf_mmap__read_done(&md
->core
);
133 if (nr_events
== before
)
134 evlist__poll(evlist
, 10);
136 if (++nr_polls
> 5) {
137 pr_debug("%s: no events!\n", __func__
);
138 goto out_delete_evlist
;
144 evlist__delete(evlist
);
149 static struct test_case tests__syscall_openat_tp_fields
[] = {
150 TEST_CASE_REASON("syscalls:sys_enter_openat event fields",
151 syscall_openat_tp_fields
,
156 struct test_suite suite__syscall_openat_tp_fields
= {
157 .desc
= "syscalls:sys_enter_openat event fields",
158 .test_cases
= tests__syscall_openat_tp_fields
,