1 // SPDX-License-Identifier: GPL-2.0
4 #include <api/fs/tracing_path.h>
6 #include <linux/string.h>
10 #include "thread_map.h"
14 #include "util/counts.h"
16 static int test__openat_syscall_event(struct test_suite *test __maybe_unused,
17 int subtest __maybe_unused)
19 int err = TEST_FAIL, fd;
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];
26 if (threads == NULL) {
27 pr_debug("thread_map__new\n");
31 evsel = evsel__newtp("syscalls", "sys_enter_openat");
33 tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat");
34 pr_debug("%s\n", errbuf);
36 goto out_thread_map_delete;
39 if (evsel__open_per_thread(evsel, threads) < 0) {
40 pr_debug("failed to open counter: %s, "
41 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
42 str_error_r(errno, sbuf, sizeof(sbuf)));
44 goto out_evsel_delete;
47 for (i = 0; i < nr_openat_calls; ++i) {
48 fd = openat(0, "/etc/passwd", O_RDONLY);
52 if (evsel__read_on_cpu(evsel, 0, 0) < 0) {
53 pr_debug("evsel__read_on_cpu\n");
57 if (perf_counts(evsel->counts, 0, 0)->val != nr_openat_calls) {
58 pr_debug("evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64 "\n",
59 nr_openat_calls, perf_counts(evsel->counts, 0, 0)->val);
65 perf_evsel__close_fd(&evsel->core);
68 out_thread_map_delete:
69 perf_thread_map__put(threads);
73 static struct test_case tests__openat_syscall_event[] = {
74 TEST_CASE_REASON("Detect openat syscall event",
80 struct test_suite suite__openat_syscall_event = {
81 .desc = "Detect openat syscall event",
82 .test_cases = tests__openat_syscall_event,