~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/openat-syscall-tp-fields.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <stdbool.h>
  3 #include <linux/err.h>
  4 #include <linux/string.h>
  5 #include <sys/types.h>
  6 #include <sys/stat.h>
  7 #include <fcntl.h>
  8 #include "evlist.h"
  9 #include "evsel.h"
 10 #include "thread_map.h"
 11 #include "record.h"
 12 #include "tests.h"
 13 #include "debug.h"
 14 #include "util/mmap.h"
 15 #include <errno.h>
 16 #include <perf/mmap.h>
 17 #include "util/sample.h"
 18 
 19 #ifndef O_DIRECTORY
 20 #define O_DIRECTORY    00200000
 21 #endif
 22 #ifndef AT_FDCWD
 23 #define AT_FDCWD       -100
 24 #endif
 25 
 26 static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused,
 27                                           int subtest __maybe_unused)
 28 {
 29         struct record_opts opts = {
 30                 .target = {
 31                         .uid = UINT_MAX,
 32                         .uses_mmap = true,
 33                 },
 34                 .no_buffering = true,
 35                 .freq         = 1,
 36                 .mmap_pages   = 256,
 37                 .raw_samples  = true,
 38         };
 39         const char *filename = "/etc/passwd";
 40         int flags = O_RDONLY | O_DIRECTORY;
 41         struct evlist *evlist = evlist__new();
 42         struct evsel *evsel;
 43         int err = -1, i, nr_events = 0, nr_polls = 0;
 44         char sbuf[STRERR_BUFSIZE];
 45 
 46         if (evlist == NULL) {
 47                 pr_debug("%s: evlist__new\n", __func__);
 48                 goto out;
 49         }
 50 
 51         evsel = evsel__newtp("syscalls", "sys_enter_openat");
 52         if (IS_ERR(evsel)) {
 53                 pr_debug("%s: evsel__newtp\n", __func__);
 54                 goto out_delete_evlist;
 55         }
 56 
 57         evlist__add(evlist, evsel);
 58 
 59         err = evlist__create_maps(evlist, &opts.target);
 60         if (err < 0) {
 61                 pr_debug("%s: evlist__create_maps\n", __func__);
 62                 goto out_delete_evlist;
 63         }
 64 
 65         evsel__config(evsel, &opts, NULL);
 66 
 67         perf_thread_map__set_pid(evlist->core.threads, 0, getpid());
 68 
 69         err = evlist__open(evlist);
 70         if (err < 0) {
 71                 pr_debug("perf_evlist__open: %s\n",
 72                          str_error_r(errno, sbuf, sizeof(sbuf)));
 73                 goto out_delete_evlist;
 74         }
 75 
 76         err = evlist__mmap(evlist, UINT_MAX);
 77         if (err < 0) {
 78                 pr_debug("evlist__mmap: %s\n",
 79                          str_error_r(errno, sbuf, sizeof(sbuf)));
 80                 goto out_delete_evlist;
 81         }
 82 
 83         evlist__enable(evlist);
 84 
 85         /*
 86          * Generate the event:
 87          */
 88         openat(AT_FDCWD, filename, flags);
 89 
 90         while (1) {
 91                 int before = nr_events;
 92 
 93                 for (i = 0; i < evlist->core.nr_mmaps; i++) {
 94                         union perf_event *event;
 95                         struct mmap *md;
 96 
 97                         md = &evlist->mmap[i];
 98                         if (perf_mmap__read_init(&md->core) < 0)
 99                                 continue;
100 
101                         while ((event = perf_mmap__read_event(&md->core)) != NULL) {
102                                 const u32 type = event->header.type;
103                                 int tp_flags;
104                                 struct perf_sample sample;
105 
106                                 ++nr_events;
107 
108                                 if (type != PERF_RECORD_SAMPLE) {
109                                         perf_mmap__consume(&md->core);
110                                         continue;
111                                 }
112 
113                                 err = evsel__parse_sample(evsel, event, &sample);
114                                 if (err) {
115                                         pr_debug("Can't parse sample, err = %d\n", err);
116                                         goto out_delete_evlist;
117                                 }
118 
119                                 tp_flags = evsel__intval(evsel, &sample, "flags");
120 
121                                 if (flags != tp_flags) {
122                                         pr_debug("%s: Expected flags=%#x, got %#x\n",
123                                                  __func__, flags, tp_flags);
124                                         goto out_delete_evlist;
125                                 }
126 
127                                 goto out_ok;
128                         }
129                         perf_mmap__read_done(&md->core);
130                 }
131 
132                 if (nr_events == before)
133                         evlist__poll(evlist, 10);
134 
135                 if (++nr_polls > 5) {
136                         pr_debug("%s: no events!\n", __func__);
137                         goto out_delete_evlist;
138                 }
139         }
140 out_ok:
141         err = 0;
142 out_delete_evlist:
143         evlist__delete(evlist);
144 out:
145         return err;
146 }
147 
148 DEFINE_SUITE("syscalls:sys_enter_openat event fields", syscall_openat_tp_fields);
149 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php