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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/trace_ext.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 
  3 #define _GNU_SOURCE
  4 #include <test_progs.h>
  5 #include <network_helpers.h>
  6 #include <sys/stat.h>
  7 #include <linux/sched.h>
  8 #include <sys/syscall.h>
  9 
 10 #include "test_pkt_md_access.skel.h"
 11 #include "test_trace_ext.skel.h"
 12 #include "test_trace_ext_tracing.skel.h"
 13 
 14 static __u32 duration;
 15 
 16 void test_trace_ext(void)
 17 {
 18         struct test_pkt_md_access *skel_pkt = NULL;
 19         struct test_trace_ext_tracing *skel_trace = NULL;
 20         struct test_trace_ext_tracing__bss *bss_trace;
 21         struct test_trace_ext *skel_ext = NULL;
 22         struct test_trace_ext__bss *bss_ext;
 23         int err, pkt_fd, ext_fd;
 24         struct bpf_program *prog;
 25         char buf[100];
 26         __u64 len;
 27         LIBBPF_OPTS(bpf_test_run_opts, topts,
 28                 .data_in = &pkt_v4,
 29                 .data_size_in = sizeof(pkt_v4),
 30                 .repeat = 1,
 31         );
 32 
 33         /* open/load/attach test_pkt_md_access */
 34         skel_pkt = test_pkt_md_access__open_and_load();
 35         if (CHECK(!skel_pkt, "setup", "classifier/test_pkt_md_access open failed\n"))
 36                 goto cleanup;
 37 
 38         err = test_pkt_md_access__attach(skel_pkt);
 39         if (CHECK(err, "setup", "classifier/test_pkt_md_access attach failed: %d\n", err))
 40                 goto cleanup;
 41 
 42         prog = skel_pkt->progs.test_pkt_md_access;
 43         pkt_fd = bpf_program__fd(prog);
 44 
 45         /* open extension */
 46         skel_ext = test_trace_ext__open();
 47         if (CHECK(!skel_ext, "setup", "freplace/test_pkt_md_access open failed\n"))
 48                 goto cleanup;
 49 
 50         /* set extension's attach target - test_pkt_md_access  */
 51         prog = skel_ext->progs.test_pkt_md_access_new;
 52         bpf_program__set_attach_target(prog, pkt_fd, "test_pkt_md_access");
 53 
 54         /* load/attach extension */
 55         err = test_trace_ext__load(skel_ext);
 56         if (CHECK(err, "setup", "freplace/test_pkt_md_access load failed\n")) {
 57                 libbpf_strerror(err, buf, sizeof(buf));
 58                 fprintf(stderr, "%s\n", buf);
 59                 goto cleanup;
 60         }
 61 
 62         err = test_trace_ext__attach(skel_ext);
 63         if (CHECK(err, "setup", "freplace/test_pkt_md_access attach failed: %d\n", err))
 64                 goto cleanup;
 65 
 66         prog = skel_ext->progs.test_pkt_md_access_new;
 67         ext_fd = bpf_program__fd(prog);
 68 
 69         /* open tracing  */
 70         skel_trace = test_trace_ext_tracing__open();
 71         if (CHECK(!skel_trace, "setup", "tracing/test_pkt_md_access_new open failed\n"))
 72                 goto cleanup;
 73 
 74         /* set tracing's attach target - fentry */
 75         prog = skel_trace->progs.fentry;
 76         bpf_program__set_attach_target(prog, ext_fd, "test_pkt_md_access_new");
 77 
 78         /* set tracing's attach target - fexit */
 79         prog = skel_trace->progs.fexit;
 80         bpf_program__set_attach_target(prog, ext_fd, "test_pkt_md_access_new");
 81 
 82         /* load/attach tracing */
 83         err = test_trace_ext_tracing__load(skel_trace);
 84         if (!ASSERT_OK(err, "tracing/test_pkt_md_access_new load")) {
 85                 libbpf_strerror(err, buf, sizeof(buf));
 86                 fprintf(stderr, "%s\n", buf);
 87                 goto cleanup;
 88         }
 89 
 90         err = test_trace_ext_tracing__attach(skel_trace);
 91         if (!ASSERT_OK(err, "tracing/test_pkt_md_access_new attach"))
 92                 goto cleanup;
 93 
 94         /* trigger the test */
 95         err = bpf_prog_test_run_opts(pkt_fd, &topts);
 96         ASSERT_OK(err, "test_run_opts err");
 97         ASSERT_OK(topts.retval, "test_run_opts retval");
 98 
 99         bss_ext = skel_ext->bss;
100         bss_trace = skel_trace->bss;
101 
102         len = bss_ext->ext_called;
103 
104         ASSERT_NEQ(bss_ext->ext_called, 0,
105                   "failed to trigger freplace/test_pkt_md_access");
106         ASSERT_EQ(bss_trace->fentry_called, len,
107                   "failed to trigger fentry/test_pkt_md_access_new");
108         ASSERT_EQ(bss_trace->fexit_called, len,
109                    "failed to trigger fexit/test_pkt_md_access_new");
110 
111 cleanup:
112         test_trace_ext_tracing__destroy(skel_trace);
113         test_trace_ext__destroy(skel_ext);
114         test_pkt_md_access__destroy(skel_pkt);
115 }
116 

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