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

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

Version: ~ [ linux-6.1-rc5 ] ~ [ linux-6.0.8 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.78 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.154 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.224 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.265 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.299 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.333 ] ~ [ 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 <errno.h>
  3 #include <inttypes.h>
  4 #include <api/fs/tracing_path.h>
  5 #include <linux/err.h>
  6 #include <linux/string.h>
  7 #include <sys/types.h>
  8 #include <sys/stat.h>
  9 #include <fcntl.h>
 10 #include "thread_map.h"
 11 #include "evsel.h"
 12 #include "debug.h"
 13 #include "tests.h"
 14 #include "util/counts.h"
 15 
 16 static int test__openat_syscall_event(struct test_suite *test __maybe_unused,
 17                                       int subtest __maybe_unused)
 18 {
 19         int err = -1, fd;
 20         struct evsel *evsel;
 21         unsigned int nr_openat_calls = 111, i;
 22         struct perf_thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX);
 23         char sbuf[STRERR_BUFSIZE];
 24         char errbuf[BUFSIZ];
 25 
 26         if (threads == NULL) {
 27                 pr_debug("thread_map__new\n");
 28                 return -1;
 29         }
 30 
 31         evsel = evsel__newtp("syscalls", "sys_enter_openat");
 32         if (IS_ERR(evsel)) {
 33                 tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat");
 34                 pr_debug("%s\n", errbuf);
 35                 goto out_thread_map_delete;
 36         }
 37 
 38         if (evsel__open_per_thread(evsel, threads) < 0) {
 39                 pr_debug("failed to open counter: %s, "
 40                          "tweak /proc/sys/kernel/perf_event_paranoid?\n",
 41                          str_error_r(errno, sbuf, sizeof(sbuf)));
 42                 goto out_evsel_delete;
 43         }
 44 
 45         for (i = 0; i < nr_openat_calls; ++i) {
 46                 fd = openat(0, "/etc/passwd", O_RDONLY);
 47                 close(fd);
 48         }
 49 
 50         if (evsel__read_on_cpu(evsel, 0, 0) < 0) {
 51                 pr_debug("evsel__read_on_cpu\n");
 52                 goto out_close_fd;
 53         }
 54 
 55         if (perf_counts(evsel->counts, 0, 0)->val != nr_openat_calls) {
 56                 pr_debug("evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64 "\n",
 57                          nr_openat_calls, perf_counts(evsel->counts, 0, 0)->val);
 58                 goto out_close_fd;
 59         }
 60 
 61         err = 0;
 62 out_close_fd:
 63         perf_evsel__close_fd(&evsel->core);
 64 out_evsel_delete:
 65         evsel__delete(evsel);
 66 out_thread_map_delete:
 67         perf_thread_map__put(threads);
 68         return err;
 69 }
 70 
 71 DEFINE_SUITE("Detect openat syscall event", openat_syscall_event);
 72 

~ [ 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