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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/dynptr.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) 2022 Facebook */
  3 
  4 #include <test_progs.h>
  5 #include <network_helpers.h>
  6 #include "dynptr_fail.skel.h"
  7 #include "dynptr_success.skel.h"
  8 
  9 enum test_setup_type {
 10         SETUP_SYSCALL_SLEEP,
 11         SETUP_SKB_PROG,
 12 };
 13 
 14 static struct {
 15         const char *prog_name;
 16         enum test_setup_type type;
 17 } success_tests[] = {
 18         {"test_read_write", SETUP_SYSCALL_SLEEP},
 19         {"test_dynptr_data", SETUP_SYSCALL_SLEEP},
 20         {"test_ringbuf", SETUP_SYSCALL_SLEEP},
 21         {"test_skb_readonly", SETUP_SKB_PROG},
 22         {"test_dynptr_skb_data", SETUP_SKB_PROG},
 23         {"test_adjust", SETUP_SYSCALL_SLEEP},
 24         {"test_adjust_err", SETUP_SYSCALL_SLEEP},
 25         {"test_zero_size_dynptr", SETUP_SYSCALL_SLEEP},
 26         {"test_dynptr_is_null", SETUP_SYSCALL_SLEEP},
 27         {"test_dynptr_is_rdonly", SETUP_SKB_PROG},
 28         {"test_dynptr_clone", SETUP_SKB_PROG},
 29         {"test_dynptr_skb_no_buff", SETUP_SKB_PROG},
 30         {"test_dynptr_skb_strcmp", SETUP_SKB_PROG},
 31 };
 32 
 33 static void verify_success(const char *prog_name, enum test_setup_type setup_type)
 34 {
 35         struct dynptr_success *skel;
 36         struct bpf_program *prog;
 37         struct bpf_link *link;
 38        int err;
 39 
 40         skel = dynptr_success__open();
 41         if (!ASSERT_OK_PTR(skel, "dynptr_success__open"))
 42                 return;
 43 
 44         skel->bss->pid = getpid();
 45 
 46         prog = bpf_object__find_program_by_name(skel->obj, prog_name);
 47         if (!ASSERT_OK_PTR(prog, "bpf_object__find_program_by_name"))
 48                 goto cleanup;
 49 
 50        bpf_program__set_autoload(prog, true);
 51 
 52         err = dynptr_success__load(skel);
 53         if (!ASSERT_OK(err, "dynptr_success__load"))
 54                 goto cleanup;
 55 
 56         switch (setup_type) {
 57         case SETUP_SYSCALL_SLEEP:
 58                 link = bpf_program__attach(prog);
 59                 if (!ASSERT_OK_PTR(link, "bpf_program__attach"))
 60                         goto cleanup;
 61 
 62                 usleep(1);
 63 
 64                 bpf_link__destroy(link);
 65                 break;
 66         case SETUP_SKB_PROG:
 67         {
 68                 int prog_fd;
 69                 char buf[64];
 70 
 71                 LIBBPF_OPTS(bpf_test_run_opts, topts,
 72                             .data_in = &pkt_v4,
 73                             .data_size_in = sizeof(pkt_v4),
 74                             .data_out = buf,
 75                             .data_size_out = sizeof(buf),
 76                             .repeat = 1,
 77                 );
 78 
 79                 prog_fd = bpf_program__fd(prog);
 80                 if (!ASSERT_GE(prog_fd, 0, "prog_fd"))
 81                         goto cleanup;
 82 
 83                 err = bpf_prog_test_run_opts(prog_fd, &topts);
 84 
 85                 if (!ASSERT_OK(err, "test_run"))
 86                         goto cleanup;
 87 
 88                 break;
 89         }
 90         }
 91 
 92         ASSERT_EQ(skel->bss->err, 0, "err");
 93 
 94 cleanup:
 95         dynptr_success__destroy(skel);
 96 }
 97 
 98 void test_dynptr(void)
 99 {
100         int i;
101 
102         for (i = 0; i < ARRAY_SIZE(success_tests); i++) {
103                 if (!test__start_subtest(success_tests[i].prog_name))
104                         continue;
105 
106                 verify_success(success_tests[i].prog_name, success_tests[i].type);
107         }
108 
109         RUN_TESTS(dynptr_fail);
110 }
111 

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