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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/local_kptr_stash.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 /* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
  3 
  4 #include <test_progs.h>
  5 #include <network_helpers.h>
  6 
  7 #include "local_kptr_stash.skel.h"
  8 #include "local_kptr_stash_fail.skel.h"
  9 static void test_local_kptr_stash_simple(void)
 10 {
 11         LIBBPF_OPTS(bpf_test_run_opts, opts,
 12                     .data_in = &pkt_v4,
 13                     .data_size_in = sizeof(pkt_v4),
 14                     .repeat = 1,
 15         );
 16         struct local_kptr_stash *skel;
 17         int ret;
 18 
 19         skel = local_kptr_stash__open_and_load();
 20         if (!ASSERT_OK_PTR(skel, "local_kptr_stash__open_and_load"))
 21                 return;
 22 
 23         ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.stash_rb_nodes), &opts);
 24         ASSERT_OK(ret, "local_kptr_stash_add_nodes run");
 25         ASSERT_OK(opts.retval, "local_kptr_stash_add_nodes retval");
 26 
 27         local_kptr_stash__destroy(skel);
 28 }
 29 
 30 static void test_local_kptr_stash_plain(void)
 31 {
 32         LIBBPF_OPTS(bpf_test_run_opts, opts,
 33                     .data_in = &pkt_v4,
 34                     .data_size_in = sizeof(pkt_v4),
 35                     .repeat = 1,
 36         );
 37         struct local_kptr_stash *skel;
 38         int ret;
 39 
 40         skel = local_kptr_stash__open_and_load();
 41         if (!ASSERT_OK_PTR(skel, "local_kptr_stash__open_and_load"))
 42                 return;
 43 
 44         ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.stash_plain), &opts);
 45         ASSERT_OK(ret, "local_kptr_stash_add_plain run");
 46         ASSERT_OK(opts.retval, "local_kptr_stash_add_plain retval");
 47 
 48         local_kptr_stash__destroy(skel);
 49 }
 50 
 51 static void test_local_kptr_stash_local_with_root(void)
 52 {
 53         LIBBPF_OPTS(bpf_test_run_opts, opts,
 54                     .data_in = &pkt_v4,
 55                     .data_size_in = sizeof(pkt_v4),
 56                     .repeat = 1,
 57         );
 58         struct local_kptr_stash *skel;
 59         int ret;
 60 
 61         skel = local_kptr_stash__open_and_load();
 62         if (!ASSERT_OK_PTR(skel, "local_kptr_stash__open_and_load"))
 63                 return;
 64 
 65         ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.stash_local_with_root), &opts);
 66         ASSERT_OK(ret, "local_kptr_stash_add_local_with_root run");
 67         ASSERT_OK(opts.retval, "local_kptr_stash_add_local_with_root retval");
 68 
 69         local_kptr_stash__destroy(skel);
 70 }
 71 
 72 static void test_local_kptr_stash_unstash(void)
 73 {
 74         LIBBPF_OPTS(bpf_test_run_opts, opts,
 75                     .data_in = &pkt_v4,
 76                     .data_size_in = sizeof(pkt_v4),
 77                     .repeat = 1,
 78         );
 79         struct local_kptr_stash *skel;
 80         int ret;
 81 
 82         skel = local_kptr_stash__open_and_load();
 83         if (!ASSERT_OK_PTR(skel, "local_kptr_stash__open_and_load"))
 84                 return;
 85 
 86         ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.stash_rb_nodes), &opts);
 87         ASSERT_OK(ret, "local_kptr_stash_add_nodes run");
 88         ASSERT_OK(opts.retval, "local_kptr_stash_add_nodes retval");
 89 
 90         ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.unstash_rb_node), &opts);
 91         ASSERT_OK(ret, "local_kptr_stash_add_nodes run");
 92         ASSERT_EQ(opts.retval, 42, "local_kptr_stash_add_nodes retval");
 93 
 94         local_kptr_stash__destroy(skel);
 95 }
 96 
 97 static void test_refcount_acquire_without_unstash(void)
 98 {
 99         LIBBPF_OPTS(bpf_test_run_opts, opts,
100                     .data_in = &pkt_v4,
101                     .data_size_in = sizeof(pkt_v4),
102                     .repeat = 1,
103         );
104         struct local_kptr_stash *skel;
105         int ret;
106 
107         skel = local_kptr_stash__open_and_load();
108         if (!ASSERT_OK_PTR(skel, "local_kptr_stash__open_and_load"))
109                 return;
110 
111         ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.refcount_acquire_without_unstash),
112                                      &opts);
113         ASSERT_OK(ret, "refcount_acquire_without_unstash run");
114         ASSERT_EQ(opts.retval, 2, "refcount_acquire_without_unstash retval");
115 
116         ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.stash_refcounted_node), &opts);
117         ASSERT_OK(ret, "stash_refcounted_node run");
118         ASSERT_OK(opts.retval, "stash_refcounted_node retval");
119 
120         ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.refcount_acquire_without_unstash),
121                                      &opts);
122         ASSERT_OK(ret, "refcount_acquire_without_unstash (2) run");
123         ASSERT_EQ(opts.retval, 42, "refcount_acquire_without_unstash (2) retval");
124 
125         local_kptr_stash__destroy(skel);
126 }
127 
128 static void test_local_kptr_stash_fail(void)
129 {
130         RUN_TESTS(local_kptr_stash_fail);
131 }
132 
133 void test_local_kptr_stash(void)
134 {
135         if (test__start_subtest("local_kptr_stash_simple"))
136                 test_local_kptr_stash_simple();
137         if (test__start_subtest("local_kptr_stash_plain"))
138                 test_local_kptr_stash_plain();
139         if (test__start_subtest("local_kptr_stash_local_with_root"))
140                 test_local_kptr_stash_local_with_root();
141         if (test__start_subtest("local_kptr_stash_unstash"))
142                 test_local_kptr_stash_unstash();
143         if (test__start_subtest("refcount_acquire_without_unstash"))
144                 test_refcount_acquire_without_unstash();
145         if (test__start_subtest("local_kptr_stash_fail"))
146                 test_local_kptr_stash_fail();
147 }
148 

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