WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / prog_tests / section_names.c
blob8b571890c57e2a904479c8c96460d9c48a6dfcec
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2018 Facebook
3 #include <test_progs.h>
5 static int duration = 0;
7 struct sec_name_test {
8 const char sec_name[32];
9 struct {
10 int rc;
11 enum bpf_prog_type prog_type;
12 enum bpf_attach_type expected_attach_type;
13 } expected_load;
14 struct {
15 int rc;
16 enum bpf_attach_type attach_type;
17 } expected_attach;
20 static struct sec_name_test tests[] = {
21 {"InvAliD", {-ESRCH, 0, 0}, {-EINVAL, 0} },
22 {"cgroup", {-ESRCH, 0, 0}, {-EINVAL, 0} },
23 {"socket", {0, BPF_PROG_TYPE_SOCKET_FILTER, 0}, {-EINVAL, 0} },
24 {"kprobe/", {0, BPF_PROG_TYPE_KPROBE, 0}, {-EINVAL, 0} },
25 {"uprobe/", {0, BPF_PROG_TYPE_KPROBE, 0}, {-EINVAL, 0} },
26 {"kretprobe/", {0, BPF_PROG_TYPE_KPROBE, 0}, {-EINVAL, 0} },
27 {"uretprobe/", {0, BPF_PROG_TYPE_KPROBE, 0}, {-EINVAL, 0} },
28 {"classifier", {0, BPF_PROG_TYPE_SCHED_CLS, 0}, {-EINVAL, 0} },
29 {"action", {0, BPF_PROG_TYPE_SCHED_ACT, 0}, {-EINVAL, 0} },
30 {"tracepoint/", {0, BPF_PROG_TYPE_TRACEPOINT, 0}, {-EINVAL, 0} },
31 {"tp/", {0, BPF_PROG_TYPE_TRACEPOINT, 0}, {-EINVAL, 0} },
33 "raw_tracepoint/",
34 {0, BPF_PROG_TYPE_RAW_TRACEPOINT, 0},
35 {-EINVAL, 0},
37 {"raw_tp/", {0, BPF_PROG_TYPE_RAW_TRACEPOINT, 0}, {-EINVAL, 0} },
38 {"xdp", {0, BPF_PROG_TYPE_XDP, BPF_XDP}, {0, BPF_XDP} },
39 {"perf_event", {0, BPF_PROG_TYPE_PERF_EVENT, 0}, {-EINVAL, 0} },
40 {"lwt_in", {0, BPF_PROG_TYPE_LWT_IN, 0}, {-EINVAL, 0} },
41 {"lwt_out", {0, BPF_PROG_TYPE_LWT_OUT, 0}, {-EINVAL, 0} },
42 {"lwt_xmit", {0, BPF_PROG_TYPE_LWT_XMIT, 0}, {-EINVAL, 0} },
43 {"lwt_seg6local", {0, BPF_PROG_TYPE_LWT_SEG6LOCAL, 0}, {-EINVAL, 0} },
45 "cgroup_skb/ingress",
46 {0, BPF_PROG_TYPE_CGROUP_SKB, BPF_CGROUP_INET_INGRESS},
47 {0, BPF_CGROUP_INET_INGRESS},
50 "cgroup_skb/egress",
51 {0, BPF_PROG_TYPE_CGROUP_SKB, BPF_CGROUP_INET_EGRESS},
52 {0, BPF_CGROUP_INET_EGRESS},
54 {"cgroup/skb", {0, BPF_PROG_TYPE_CGROUP_SKB, 0}, {-EINVAL, 0} },
56 "cgroup/sock",
57 {0, BPF_PROG_TYPE_CGROUP_SOCK, BPF_CGROUP_INET_SOCK_CREATE},
58 {0, BPF_CGROUP_INET_SOCK_CREATE},
61 "cgroup/post_bind4",
62 {0, BPF_PROG_TYPE_CGROUP_SOCK, BPF_CGROUP_INET4_POST_BIND},
63 {0, BPF_CGROUP_INET4_POST_BIND},
66 "cgroup/post_bind6",
67 {0, BPF_PROG_TYPE_CGROUP_SOCK, BPF_CGROUP_INET6_POST_BIND},
68 {0, BPF_CGROUP_INET6_POST_BIND},
71 "cgroup/dev",
72 {0, BPF_PROG_TYPE_CGROUP_DEVICE, BPF_CGROUP_DEVICE},
73 {0, BPF_CGROUP_DEVICE},
76 "sockops",
77 {0, BPF_PROG_TYPE_SOCK_OPS, BPF_CGROUP_SOCK_OPS},
78 {0, BPF_CGROUP_SOCK_OPS},
81 "sk_skb/stream_parser",
82 {0, BPF_PROG_TYPE_SK_SKB, BPF_SK_SKB_STREAM_PARSER},
83 {0, BPF_SK_SKB_STREAM_PARSER},
86 "sk_skb/stream_verdict",
87 {0, BPF_PROG_TYPE_SK_SKB, BPF_SK_SKB_STREAM_VERDICT},
88 {0, BPF_SK_SKB_STREAM_VERDICT},
90 {"sk_skb", {0, BPF_PROG_TYPE_SK_SKB, 0}, {-EINVAL, 0} },
92 "sk_msg",
93 {0, BPF_PROG_TYPE_SK_MSG, BPF_SK_MSG_VERDICT},
94 {0, BPF_SK_MSG_VERDICT},
97 "lirc_mode2",
98 {0, BPF_PROG_TYPE_LIRC_MODE2, BPF_LIRC_MODE2},
99 {0, BPF_LIRC_MODE2},
102 "flow_dissector",
103 {0, BPF_PROG_TYPE_FLOW_DISSECTOR, BPF_FLOW_DISSECTOR},
104 {0, BPF_FLOW_DISSECTOR},
107 "cgroup/bind4",
108 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_INET4_BIND},
109 {0, BPF_CGROUP_INET4_BIND},
112 "cgroup/bind6",
113 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_INET6_BIND},
114 {0, BPF_CGROUP_INET6_BIND},
117 "cgroup/connect4",
118 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_INET4_CONNECT},
119 {0, BPF_CGROUP_INET4_CONNECT},
122 "cgroup/connect6",
123 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_INET6_CONNECT},
124 {0, BPF_CGROUP_INET6_CONNECT},
127 "cgroup/sendmsg4",
128 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_UDP4_SENDMSG},
129 {0, BPF_CGROUP_UDP4_SENDMSG},
132 "cgroup/sendmsg6",
133 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_UDP6_SENDMSG},
134 {0, BPF_CGROUP_UDP6_SENDMSG},
137 "cgroup/recvmsg4",
138 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_UDP4_RECVMSG},
139 {0, BPF_CGROUP_UDP4_RECVMSG},
142 "cgroup/recvmsg6",
143 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_UDP6_RECVMSG},
144 {0, BPF_CGROUP_UDP6_RECVMSG},
147 "cgroup/sysctl",
148 {0, BPF_PROG_TYPE_CGROUP_SYSCTL, BPF_CGROUP_SYSCTL},
149 {0, BPF_CGROUP_SYSCTL},
152 "cgroup/getsockopt",
153 {0, BPF_PROG_TYPE_CGROUP_SOCKOPT, BPF_CGROUP_GETSOCKOPT},
154 {0, BPF_CGROUP_GETSOCKOPT},
157 "cgroup/setsockopt",
158 {0, BPF_PROG_TYPE_CGROUP_SOCKOPT, BPF_CGROUP_SETSOCKOPT},
159 {0, BPF_CGROUP_SETSOCKOPT},
163 static void test_prog_type_by_name(const struct sec_name_test *test)
165 enum bpf_attach_type expected_attach_type;
166 enum bpf_prog_type prog_type;
167 int rc;
169 rc = libbpf_prog_type_by_name(test->sec_name, &prog_type,
170 &expected_attach_type);
172 CHECK(rc != test->expected_load.rc, "check_code",
173 "prog: unexpected rc=%d for %s\n", rc, test->sec_name);
175 if (rc)
176 return;
178 CHECK(prog_type != test->expected_load.prog_type, "check_prog_type",
179 "prog: unexpected prog_type=%d for %s\n",
180 prog_type, test->sec_name);
182 CHECK(expected_attach_type != test->expected_load.expected_attach_type,
183 "check_attach_type", "prog: unexpected expected_attach_type=%d for %s\n",
184 expected_attach_type, test->sec_name);
187 static void test_attach_type_by_name(const struct sec_name_test *test)
189 enum bpf_attach_type attach_type;
190 int rc;
192 rc = libbpf_attach_type_by_name(test->sec_name, &attach_type);
194 CHECK(rc != test->expected_attach.rc, "check_ret",
195 "attach: unexpected rc=%d for %s\n", rc, test->sec_name);
197 if (rc)
198 return;
200 CHECK(attach_type != test->expected_attach.attach_type,
201 "check_attach_type", "attach: unexpected attach_type=%d for %s\n",
202 attach_type, test->sec_name);
205 void test_section_names(void)
207 int i;
209 for (i = 0; i < ARRAY_SIZE(tests); ++i) {
210 struct sec_name_test *test = &tests[i];
212 test_prog_type_by_name(test);
213 test_attach_type_by_name(test);