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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/trampoline_count.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-only
  2 #define _GNU_SOURCE
  3 #include <test_progs.h>
  4 
  5 struct inst {
  6         struct bpf_object *obj;
  7         struct bpf_link   *link;
  8 };
  9 
 10 static struct bpf_program *load_prog(char *file, char *name, struct inst *inst)
 11 {
 12         struct bpf_object *obj;
 13         struct bpf_program *prog;
 14         int err;
 15 
 16         obj = bpf_object__open_file(file, NULL);
 17         if (!ASSERT_OK_PTR(obj, "obj_open_file"))
 18                 return NULL;
 19 
 20         inst->obj = obj;
 21 
 22         err = bpf_object__load(obj);
 23         if (!ASSERT_OK(err, "obj_load"))
 24                 return NULL;
 25 
 26         prog = bpf_object__find_program_by_name(obj, name);
 27         if (!ASSERT_OK_PTR(prog, "obj_find_prog"))
 28                 return NULL;
 29 
 30         return prog;
 31 }
 32 
 33 /* TODO: use different target function to run in concurrent mode */
 34 void serial_test_trampoline_count(void)
 35 {
 36         char *file = "test_trampoline_count.bpf.o";
 37         char *const progs[] = { "fentry_test", "fmod_ret_test", "fexit_test" };
 38         int bpf_max_tramp_links, err, i, prog_fd;
 39         struct bpf_program *prog;
 40         struct bpf_link *link;
 41         struct inst *inst;
 42         LIBBPF_OPTS(bpf_test_run_opts, opts);
 43 
 44         bpf_max_tramp_links = get_bpf_max_tramp_links();
 45         if (!ASSERT_GE(bpf_max_tramp_links, 1, "bpf_max_tramp_links"))
 46                 return;
 47         inst = calloc(bpf_max_tramp_links + 1, sizeof(*inst));
 48         if (!ASSERT_OK_PTR(inst, "inst"))
 49                 return;
 50 
 51         /* attach 'allowed' trampoline programs */
 52         for (i = 0; i < bpf_max_tramp_links; i++) {
 53                 prog = load_prog(file, progs[i % ARRAY_SIZE(progs)], &inst[i]);
 54                 if (!prog)
 55                         goto cleanup;
 56 
 57                 link = bpf_program__attach(prog);
 58                 if (!ASSERT_OK_PTR(link, "attach_prog"))
 59                         goto cleanup;
 60 
 61                 inst[i].link = link;
 62         }
 63 
 64         /* and try 1 extra.. */
 65         prog = load_prog(file, "fmod_ret_test", &inst[i]);
 66         if (!prog)
 67                 goto cleanup;
 68 
 69         /* ..that needs to fail */
 70         link = bpf_program__attach(prog);
 71         if (!ASSERT_ERR_PTR(link, "attach_prog")) {
 72                 inst[i].link = link;
 73                 goto cleanup;
 74         }
 75 
 76         /* with E2BIG error */
 77         if (!ASSERT_EQ(libbpf_get_error(link), -E2BIG, "E2BIG"))
 78                 goto cleanup;
 79         if (!ASSERT_EQ(link, NULL, "ptr_is_null"))
 80                 goto cleanup;
 81 
 82         /* and finally execute the probe */
 83         prog_fd = bpf_program__fd(prog);
 84         if (!ASSERT_GE(prog_fd, 0, "bpf_program__fd"))
 85                 goto cleanup;
 86 
 87         err = bpf_prog_test_run_opts(prog_fd, &opts);
 88         if (!ASSERT_OK(err, "bpf_prog_test_run_opts"))
 89                 goto cleanup;
 90 
 91         ASSERT_EQ(opts.retval & 0xffff, 33, "bpf_modify_return_test.result");
 92         ASSERT_EQ(opts.retval >> 16, 2, "bpf_modify_return_test.side_effect");
 93 
 94 cleanup:
 95         for (; i >= 0; i--) {
 96                 bpf_link__destroy(inst[i].link);
 97                 bpf_object__close(inst[i].obj);
 98         }
 99         free(inst);
100 }
101 

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