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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/obj_name.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 #include <test_progs.h>
  3 
  4 void test_obj_name(void)
  5 {
  6         struct {
  7                 const char *name;
  8                 int success;
  9                 int expected_errno;
 10         } tests[] = {
 11                 { "", 1, 0 },
 12                 { "_123456789ABCDE", 1, 0 },
 13                 { "_123456789ABCDEF", 0, EINVAL },
 14                 { "_123456789ABCD\n", 0, EINVAL },
 15         };
 16         struct bpf_insn prog[] = {
 17                 BPF_ALU64_IMM(BPF_MOV, BPF_REG_0, 0),
 18                 BPF_EXIT_INSN(),
 19         };
 20         __u32 duration = 0;
 21         int i;
 22 
 23         for (i = 0; i < ARRAY_SIZE(tests); i++) {
 24                 size_t name_len = strlen(tests[i].name) + 1;
 25                 union bpf_attr attr;
 26                 size_t ncopy;
 27                 int fd;
 28 
 29                 /* test different attr.prog_name during BPF_PROG_LOAD */
 30                 ncopy = name_len < sizeof(attr.prog_name) ?
 31                         name_len : sizeof(attr.prog_name);
 32                 bzero(&attr, sizeof(attr));
 33                 attr.prog_type = BPF_PROG_TYPE_SCHED_CLS;
 34                 attr.insn_cnt = 2;
 35                 attr.insns = ptr_to_u64(prog);
 36                 attr.license = ptr_to_u64("");
 37                 memcpy(attr.prog_name, tests[i].name, ncopy);
 38 
 39                 fd = syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr));
 40                 CHECK((tests[i].success && fd < 0) ||
 41                       (!tests[i].success && fd >= 0) ||
 42                       (!tests[i].success && errno != tests[i].expected_errno),
 43                       "check-bpf-prog-name",
 44                       "fd %d(%d) errno %d(%d)\n",
 45                        fd, tests[i].success, errno, tests[i].expected_errno);
 46 
 47                 if (fd >= 0)
 48                         close(fd);
 49 
 50                 /* test different attr.map_name during BPF_MAP_CREATE */
 51                 ncopy = name_len < sizeof(attr.map_name) ?
 52                         name_len : sizeof(attr.map_name);
 53                 bzero(&attr, sizeof(attr));
 54                 attr.map_type = BPF_MAP_TYPE_ARRAY;
 55                 attr.key_size = 4;
 56                 attr.value_size = 4;
 57                 attr.max_entries = 1;
 58                 attr.map_flags = 0;
 59                 memcpy(attr.map_name, tests[i].name, ncopy);
 60                 fd = syscall(__NR_bpf, BPF_MAP_CREATE, &attr, sizeof(attr));
 61                 CHECK((tests[i].success && fd < 0) ||
 62                       (!tests[i].success && fd >= 0) ||
 63                       (!tests[i].success && errno != tests[i].expected_errno),
 64                       "check-bpf-map-name",
 65                       "fd %d(%d) errno %d(%d)\n",
 66                       fd, tests[i].success, errno, tests[i].expected_errno);
 67 
 68                 if (fd >= 0)
 69                         close(fd);
 70         }
 71 }
 72 

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