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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/task_fd_query_rawtp.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ 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 <test_progs.h>
  3 
  4 void test_task_fd_query_rawtp(void)
  5 {
  6         const char *file = "./test_get_stack_rawtp.bpf.o";
  7         __u64 probe_offset, probe_addr;
  8         __u32 len, prog_id, fd_type;
  9         struct bpf_object *obj;
 10         int efd, err, prog_fd;
 11         __u32 duration = 0;
 12         char buf[256];
 13 
 14         err = bpf_prog_test_load(file, BPF_PROG_TYPE_RAW_TRACEPOINT, &obj, &prog_fd);
 15         if (CHECK(err, "prog_load raw tp", "err %d errno %d\n", err, errno))
 16                 return;
 17 
 18         efd = bpf_raw_tracepoint_open("sys_enter", prog_fd);
 19         if (CHECK(efd < 0, "raw_tp_open", "err %d errno %d\n", efd, errno))
 20                 goto close_prog;
 21 
 22         /* query (getpid(), efd) */
 23         len = sizeof(buf);
 24         err = bpf_task_fd_query(getpid(), efd, 0, buf, &len, &prog_id,
 25                                 &fd_type, &probe_offset, &probe_addr);
 26         if (CHECK(err < 0, "bpf_task_fd_query", "err %d errno %d\n", err,
 27                   errno))
 28                 goto close_prog;
 29 
 30         err = fd_type == BPF_FD_TYPE_RAW_TRACEPOINT &&
 31               strcmp(buf, "sys_enter") == 0;
 32         if (CHECK(!err, "check_results", "fd_type %d tp_name %s\n",
 33                   fd_type, buf))
 34                 goto close_prog;
 35 
 36         /* test zero len */
 37         len = 0;
 38         err = bpf_task_fd_query(getpid(), efd, 0, buf, &len, &prog_id,
 39                                 &fd_type, &probe_offset, &probe_addr);
 40         if (CHECK(err < 0, "bpf_task_fd_query (len = 0)", "err %d errno %d\n",
 41                   err, errno))
 42                 goto close_prog;
 43         err = fd_type == BPF_FD_TYPE_RAW_TRACEPOINT &&
 44               len == strlen("sys_enter");
 45         if (CHECK(!err, "check_results", "fd_type %d len %u\n", fd_type, len))
 46                 goto close_prog;
 47 
 48         /* test empty buffer */
 49         len = sizeof(buf);
 50         err = bpf_task_fd_query(getpid(), efd, 0, 0, &len, &prog_id,
 51                                 &fd_type, &probe_offset, &probe_addr);
 52         if (CHECK(err < 0, "bpf_task_fd_query (buf = 0)", "err %d errno %d\n",
 53                   err, errno))
 54                 goto close_prog;
 55         err = fd_type == BPF_FD_TYPE_RAW_TRACEPOINT &&
 56               len == strlen("sys_enter");
 57         if (CHECK(!err, "check_results", "fd_type %d len %u\n", fd_type, len))
 58                 goto close_prog;
 59 
 60         /* test smaller buffer */
 61         len = 3;
 62         err = bpf_task_fd_query(getpid(), efd, 0, buf, &len, &prog_id,
 63                                 &fd_type, &probe_offset, &probe_addr);
 64         if (CHECK(err >= 0 || errno != ENOSPC, "bpf_task_fd_query (len = 3)",
 65                   "err %d errno %d\n", err, errno))
 66                 goto close_prog;
 67         err = fd_type == BPF_FD_TYPE_RAW_TRACEPOINT &&
 68               len == strlen("sys_enter") &&
 69               strcmp(buf, "sy") == 0;
 70         if (CHECK(!err, "check_results", "fd_type %d len %u\n", fd_type, len))
 71                 goto close_prog;
 72 
 73 close_prog:
 74         bpf_object__close(obj);
 75 }
 76 

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