1 // SPDX-License-Identifier: GPL-2.0
2 #include <test_progs.h>
4 void test_obj_name(void)
12 { "_123456789ABCDE", 1, 0 },
13 { "_123456789ABCDEF", 0, EINVAL
},
14 { "_123456789ABCD\n", 0, EINVAL
},
16 struct bpf_insn prog
[] = {
17 BPF_ALU64_IMM(BPF_MOV
, BPF_REG_0
, 0),
23 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++) {
24 size_t name_len
= strlen(tests
[i
].name
) + 1;
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
;
35 attr
.insns
= ptr_to_u64(prog
);
36 attr
.license
= ptr_to_u64("");
37 memcpy(attr
.prog_name
, tests
[i
].name
, ncopy
);
39 fd
= syscall(__NR_bpf
, BPF_PROG_LOAD
, &attr
, sizeof(attr
));
40 CHECK((tests
[i
].success
&& fd
< 0) ||
41 (!tests
[i
].success
&& fd
!= -1) ||
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
);
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
;
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
!= -1) ||
63 (!tests
[i
].success
&& errno
!= tests
[i
].expected_errno
),
65 "fd %d(%d) errno %d(%d)\n",
66 fd
, tests
[i
].success
, errno
, tests
[i
].expected_errno
);