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

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

Version: ~ [ linux-6.1-rc7 ] ~ [ linux-6.0.10 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.80 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.156 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.225 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.267 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.300 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.334 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ 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 
 18 #ifndef O_DIRECTORY
 19 #define O_DIRECTORY    00200000
 20 #endif
 21 #ifndef AT_FDCWD
 22 #define AT_FDCWD       -100
 23 #endif
 24 
 25 static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused,
 26                                           int subtest __maybe_unused)
 27 {
 28         struct record_opts opts = {
 29                 .target = {
 30                         .uid = UINT_MAX,
 31                         .uses_mmap = true,
 32                 },
 33                 .no_buffering = true,
 34                 .freq         = 1,
 35                 .mmap_pages   = 256,
 36                 .raw_samples  = true,
 37         };
 38         const char *filename = "/etc/passwd";
 39         int flags = O_RDONLY | O_DIRECTORY;
 40         struct evlist *evlist = evlist__new();
 41         struct evsel *evsel;
 42         int err = -1, i, nr_events = 0, nr_polls = 0;
 43         char sbuf[STRERR_BUFSIZE];
 44 
 45         if (evlist == NULL) {
 46                 pr_debug("%s: evlist__new\n", __func__);
 47                 goto out;
 48         }
 49 
 50         evsel = evsel__newtp("syscalls", "sys_enter_openat");
 51         if (IS_ERR(evsel)) {
 52                 pr_debug("%s: evsel__newtp\n", __func__);
 53                 goto out_delete_evlist;
 54         }
 55 
 56         evlist__add(evlist, evsel);
 57 
 58         err = evlist__create_maps(evlist, &opts.target);
 59         if (err < 0) {
 60                 pr_debug("%s: evlist__create_maps\n", __func__);
 61                 goto out_delete_evlist;
 62         }
 63 
 64         evsel__config(evsel, &opts, NULL);
 65 
 66         perf_thread_map__set_pid(evlist->core.threads, 0, getpid());
 67 
 68         err = evlist__open(evlist);
 69         if (err < 0) {
 70                 pr_debug("perf_evlist__open: %s\n",
 71                          str_error_r(errno, sbuf, sizeof(sbuf)));
 72                 goto out_delete_evlist;
 73         }
 74 
 75         err = evlist__mmap(evlist, UINT_MAX);
 76         if (err < 0) {
 77                 pr_debug("evlist__mmap: %s\n",
 78                          str_error_r(errno, sbuf, sizeof(sbuf)));
 79                 goto out_delete_evlist;
 80         }
 81 
 82         evlist__enable(evlist);
 83 
 84         /*
 85          * Generate the event:
 86          */
 87         openat(AT_FDCWD, filename, flags);
 88 
 89         while (1) {
 90                 int before = nr_events;
 91 
 92                 for (i = 0; i < evlist->core.nr_mmaps; i++) {
 93                         union perf_event *event;
 94                         struct mmap *md;
 95 
 96                         md = &evlist->mmap[i];
 97                         if (perf_mmap__read_init(&md->core) < 0)
 98                                 continue;
 99 
100                         while ((event = perf_mmap__read_event(&md->core)) != NULL) {
101                                 const u32 type = event->header.type;
102                                 int tp_flags;
103                                 struct perf_sample sample;
104 
105                                 ++nr_events;
106 
107                                 if (type != PERF_RECORD_SAMPLE) {
108                                         perf_mmap__consume(&md->core);
109                                         continue;
110                                 }
111 
112                                 err = evsel__parse_sample(evsel, event, &sample);
113                                 if (err) {
114                                         pr_debug("Can't parse sample, err = %d\n", err);
115                                         goto out_delete_evlist;
116                                 }
117 
118                                 tp_flags = evsel__intval(evsel, &sample, "flags");
119 
120                                 if (flags != tp_flags) {
121                                         pr_debug("%s: Expected flags=%#x, got %#x\n",
122                                                  __func__, flags, tp_flags);
123                                         goto out_delete_evlist;
124                                 }
125 
126                                 goto out_ok;
127                         }
128                         perf_mmap__read_done(&md->core);
129                 }
130 
131                 if (nr_events == before)
132                         evlist__poll(evlist, 10);
133 
134                 if (++nr_polls > 5) {
135                         pr_debug("%s: no events!\n", __func__);
136                         goto out_delete_evlist;
137                 }
138         }
139 out_ok:
140         err = 0;
141 out_delete_evlist:
142         evlist__delete(evlist);
143 out:
144         return err;
145 }
146 
147 DEFINE_SUITE("syscalls:sys_enter_openat event fields", syscall_openat_tp_fields);
148 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp