Merge tag 'fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty...
[linux/fpc-iii.git] / tools / perf / tests / open-syscall-tp-fields.c
blob127dcae0b76033cf457a4a4ff572da6771594e6f
1 #include "perf.h"
2 #include "evlist.h"
3 #include "evsel.h"
4 #include "thread_map.h"
5 #include "tests.h"
6 #include "debug.h"
8 int test__syscall_open_tp_fields(void)
10 struct record_opts opts = {
11 .target = {
12 .uid = UINT_MAX,
13 .uses_mmap = true,
15 .no_buffering = true,
16 .freq = 1,
17 .mmap_pages = 256,
18 .raw_samples = true,
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];
27 if (evlist == NULL) {
28 pr_debug("%s: perf_evlist__new\n", __func__);
29 goto out;
32 evsel = perf_evsel__newtp("syscalls", "sys_enter_open");
33 if (evsel == NULL) {
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);
41 if (err < 0) {
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);
51 if (err < 0) {
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);
58 if (err < 0) {
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);
67 * Generate the event:
69 open(filename, flags);
71 while (1) {
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;
79 int tp_flags;
80 struct perf_sample sample;
82 ++nr_events;
84 if (type != PERF_RECORD_SAMPLE) {
85 perf_evlist__mmap_consume(evlist, i);
86 continue;
89 err = perf_evsel__parse_sample(evsel, event, &sample);
90 if (err) {
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;
103 goto out_ok;
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;
115 out_ok:
116 err = 0;
117 out_delete_evlist:
118 perf_evlist__delete(evlist);
119 out:
120 return err;