4 #include "thread_map.h"
8 int test__syscall_open_tp_fields(void)
10 struct record_opts opts
= {
20 const char *filename
= "/etc/passwd";
21 int flags
= O_RDONLY
| O_DIRECTORY
;
22 struct perf_evlist
*evlist
= perf_evlist__new();
23 struct perf_evsel
*evsel
;
24 int err
= -1, i
, nr_events
= 0, nr_polls
= 0;
25 char sbuf
[STRERR_BUFSIZE
];
28 pr_debug("%s: perf_evlist__new\n", __func__
);
32 evsel
= perf_evsel__newtp("syscalls", "sys_enter_open");
34 pr_debug("%s: perf_evsel__newtp\n", __func__
);
35 goto out_delete_evlist
;
38 perf_evlist__add(evlist
, evsel
);
40 err
= perf_evlist__create_maps(evlist
, &opts
.target
);
42 pr_debug("%s: perf_evlist__create_maps\n", __func__
);
43 goto out_delete_evlist
;
46 perf_evsel__config(evsel
, &opts
);
48 evlist
->threads
->map
[0] = getpid();
50 err
= perf_evlist__open(evlist
);
52 pr_debug("perf_evlist__open: %s\n",
53 strerror_r(errno
, sbuf
, sizeof(sbuf
)));
54 goto out_delete_evlist
;
57 err
= perf_evlist__mmap(evlist
, UINT_MAX
, false);
59 pr_debug("perf_evlist__mmap: %s\n",
60 strerror_r(errno
, sbuf
, sizeof(sbuf
)));
61 goto out_delete_evlist
;
64 perf_evlist__enable(evlist
);
69 open(filename
, flags
);
72 int before
= nr_events
;
74 for (i
= 0; i
< evlist
->nr_mmaps
; i
++) {
75 union perf_event
*event
;
77 while ((event
= perf_evlist__mmap_read(evlist
, i
)) != NULL
) {
78 const u32 type
= event
->header
.type
;
80 struct perf_sample sample
;
84 if (type
!= PERF_RECORD_SAMPLE
) {
85 perf_evlist__mmap_consume(evlist
, i
);
89 err
= perf_evsel__parse_sample(evsel
, event
, &sample
);
91 pr_err("Can't parse sample, err = %d\n", err
);
92 goto out_delete_evlist
;
95 tp_flags
= perf_evsel__intval(evsel
, &sample
, "flags");
97 if (flags
!= tp_flags
) {
98 pr_debug("%s: Expected flags=%#x, got %#x\n",
99 __func__
, flags
, tp_flags
);
100 goto out_delete_evlist
;
107 if (nr_events
== before
)
108 perf_evlist__poll(evlist
, 10);
110 if (++nr_polls
> 5) {
111 pr_debug("%s: no events!\n", __func__
);
112 goto out_delete_evlist
;
118 perf_evlist__delete(evlist
);