5 #include "thread_map.h"
9 int test__syscall_openat_tp_fields(void)
11 struct record_opts opts = {
21 const char *filename = "/etc/passwd";
22 int flags = O_RDONLY | O_DIRECTORY;
23 struct perf_evlist *evlist = perf_evlist__new();
24 struct perf_evsel *evsel;
25 int err = -1, i, nr_events = 0, nr_polls = 0;
26 char sbuf[STRERR_BUFSIZE];
29 pr_debug("%s: perf_evlist__new\n", __func__);
33 evsel = perf_evsel__newtp("syscalls", "sys_enter_openat");
35 pr_debug("%s: perf_evsel__newtp\n", __func__);
36 goto out_delete_evlist;
39 perf_evlist__add(evlist, evsel);
41 err = perf_evlist__create_maps(evlist, &opts.target);
43 pr_debug("%s: perf_evlist__create_maps\n", __func__);
44 goto out_delete_evlist;
47 perf_evsel__config(evsel, &opts);
49 thread_map__set_pid(evlist->threads, 0, getpid());
51 err = perf_evlist__open(evlist);
53 pr_debug("perf_evlist__open: %s\n",
54 strerror_r(errno, sbuf, sizeof(sbuf)));
55 goto out_delete_evlist;
58 err = perf_evlist__mmap(evlist, UINT_MAX, false);
60 pr_debug("perf_evlist__mmap: %s\n",
61 strerror_r(errno, sbuf, sizeof(sbuf)));
62 goto out_delete_evlist;
65 perf_evlist__enable(evlist);
70 openat(AT_FDCWD, filename, flags);
73 int before = nr_events;
75 for (i = 0; i < evlist->nr_mmaps; i++) {
76 union perf_event *event;
78 while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) {
79 const u32 type = event->header.type;
81 struct perf_sample sample;
85 if (type != PERF_RECORD_SAMPLE) {
86 perf_evlist__mmap_consume(evlist, i);
90 err = perf_evsel__parse_sample(evsel, event, &sample);
92 pr_err("Can't parse sample, err = %d\n", err);
93 goto out_delete_evlist;
96 tp_flags = perf_evsel__intval(evsel, &sample, "flags");
98 if (flags != tp_flags) {
99 pr_debug("%s: Expected flags=%#x, got %#x\n",
100 __func__, flags, tp_flags);
101 goto out_delete_evlist;
108 if (nr_events == before)
109 perf_evlist__poll(evlist, 10);
111 if (++nr_polls > 5) {
112 pr_debug("%s: no events!\n", __func__);
113 goto out_delete_evlist;
119 perf_evlist__delete(evlist);