staging: rtl8192u: remove redundant assignment to pointer crypt
[linux/fpc-iii.git] / tools / testing / selftests / bpf / test_section_names.c
blob29833aeaf0de27013d2af3cb4f40930508c65944
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2018 Facebook
4 #include <err.h>
5 #include <bpf/libbpf.h>
7 #include "bpf_util.h"
9 struct sec_name_test {
10 const char sec_name[32];
11 struct {
12 int rc;
13 enum bpf_prog_type prog_type;
14 enum bpf_attach_type expected_attach_type;
15 } expected_load;
16 struct {
17 int rc;
18 enum bpf_attach_type attach_type;
19 } expected_attach;
22 static struct sec_name_test tests[] = {
23 {"InvAliD", {-EINVAL, 0, 0}, {-EINVAL, 0} },
24 {"cgroup", {-EINVAL, 0, 0}, {-EINVAL, 0} },
25 {"socket", {0, BPF_PROG_TYPE_SOCKET_FILTER, 0}, {-EINVAL, 0} },
26 {"kprobe/", {0, BPF_PROG_TYPE_KPROBE, 0}, {-EINVAL, 0} },
27 {"kretprobe/", {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} },
32 "raw_tracepoint/",
33 {0, BPF_PROG_TYPE_RAW_TRACEPOINT, 0},
34 {-EINVAL, 0},
36 {"xdp", {0, BPF_PROG_TYPE_XDP, 0}, {-EINVAL, 0} },
37 {"perf_event", {0, BPF_PROG_TYPE_PERF_EVENT, 0}, {-EINVAL, 0} },
38 {"lwt_in", {0, BPF_PROG_TYPE_LWT_IN, 0}, {-EINVAL, 0} },
39 {"lwt_out", {0, BPF_PROG_TYPE_LWT_OUT, 0}, {-EINVAL, 0} },
40 {"lwt_xmit", {0, BPF_PROG_TYPE_LWT_XMIT, 0}, {-EINVAL, 0} },
41 {"lwt_seg6local", {0, BPF_PROG_TYPE_LWT_SEG6LOCAL, 0}, {-EINVAL, 0} },
43 "cgroup_skb/ingress",
44 {0, BPF_PROG_TYPE_CGROUP_SKB, 0},
45 {0, BPF_CGROUP_INET_INGRESS},
48 "cgroup_skb/egress",
49 {0, BPF_PROG_TYPE_CGROUP_SKB, 0},
50 {0, BPF_CGROUP_INET_EGRESS},
52 {"cgroup/skb", {0, BPF_PROG_TYPE_CGROUP_SKB, 0}, {-EINVAL, 0} },
54 "cgroup/sock",
55 {0, BPF_PROG_TYPE_CGROUP_SOCK, 0},
56 {0, BPF_CGROUP_INET_SOCK_CREATE},
59 "cgroup/post_bind4",
60 {0, BPF_PROG_TYPE_CGROUP_SOCK, BPF_CGROUP_INET4_POST_BIND},
61 {0, BPF_CGROUP_INET4_POST_BIND},
64 "cgroup/post_bind6",
65 {0, BPF_PROG_TYPE_CGROUP_SOCK, BPF_CGROUP_INET6_POST_BIND},
66 {0, BPF_CGROUP_INET6_POST_BIND},
69 "cgroup/dev",
70 {0, BPF_PROG_TYPE_CGROUP_DEVICE, 0},
71 {0, BPF_CGROUP_DEVICE},
73 {"sockops", {0, BPF_PROG_TYPE_SOCK_OPS, 0}, {0, BPF_CGROUP_SOCK_OPS} },
75 "sk_skb/stream_parser",
76 {0, BPF_PROG_TYPE_SK_SKB, 0},
77 {0, BPF_SK_SKB_STREAM_PARSER},
80 "sk_skb/stream_verdict",
81 {0, BPF_PROG_TYPE_SK_SKB, 0},
82 {0, BPF_SK_SKB_STREAM_VERDICT},
84 {"sk_skb", {0, BPF_PROG_TYPE_SK_SKB, 0}, {-EINVAL, 0} },
85 {"sk_msg", {0, BPF_PROG_TYPE_SK_MSG, 0}, {0, BPF_SK_MSG_VERDICT} },
86 {"lirc_mode2", {0, BPF_PROG_TYPE_LIRC_MODE2, 0}, {0, BPF_LIRC_MODE2} },
88 "flow_dissector",
89 {0, BPF_PROG_TYPE_FLOW_DISSECTOR, 0},
90 {0, BPF_FLOW_DISSECTOR},
93 "cgroup/bind4",
94 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_INET4_BIND},
95 {0, BPF_CGROUP_INET4_BIND},
98 "cgroup/bind6",
99 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_INET6_BIND},
100 {0, BPF_CGROUP_INET6_BIND},
103 "cgroup/connect4",
104 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_INET4_CONNECT},
105 {0, BPF_CGROUP_INET4_CONNECT},
108 "cgroup/connect6",
109 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_INET6_CONNECT},
110 {0, BPF_CGROUP_INET6_CONNECT},
113 "cgroup/sendmsg4",
114 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_UDP4_SENDMSG},
115 {0, BPF_CGROUP_UDP4_SENDMSG},
118 "cgroup/sendmsg6",
119 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_UDP6_SENDMSG},
120 {0, BPF_CGROUP_UDP6_SENDMSG},
123 "cgroup/recvmsg4",
124 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_UDP4_RECVMSG},
125 {0, BPF_CGROUP_UDP4_RECVMSG},
128 "cgroup/recvmsg6",
129 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, BPF_CGROUP_UDP6_RECVMSG},
130 {0, BPF_CGROUP_UDP6_RECVMSG},
133 "cgroup/sysctl",
134 {0, BPF_PROG_TYPE_CGROUP_SYSCTL, BPF_CGROUP_SYSCTL},
135 {0, BPF_CGROUP_SYSCTL},
138 "cgroup/getsockopt",
139 {0, BPF_PROG_TYPE_CGROUP_SOCKOPT, BPF_CGROUP_GETSOCKOPT},
140 {0, BPF_CGROUP_GETSOCKOPT},
143 "cgroup/setsockopt",
144 {0, BPF_PROG_TYPE_CGROUP_SOCKOPT, BPF_CGROUP_SETSOCKOPT},
145 {0, BPF_CGROUP_SETSOCKOPT},
149 static int test_prog_type_by_name(const struct sec_name_test *test)
151 enum bpf_attach_type expected_attach_type;
152 enum bpf_prog_type prog_type;
153 int rc;
155 rc = libbpf_prog_type_by_name(test->sec_name, &prog_type,
156 &expected_attach_type);
158 if (rc != test->expected_load.rc) {
159 warnx("prog: unexpected rc=%d for %s", rc, test->sec_name);
160 return -1;
163 if (rc)
164 return 0;
166 if (prog_type != test->expected_load.prog_type) {
167 warnx("prog: unexpected prog_type=%d for %s", prog_type,
168 test->sec_name);
169 return -1;
172 if (expected_attach_type != test->expected_load.expected_attach_type) {
173 warnx("prog: unexpected expected_attach_type=%d for %s",
174 expected_attach_type, test->sec_name);
175 return -1;
178 return 0;
181 static int test_attach_type_by_name(const struct sec_name_test *test)
183 enum bpf_attach_type attach_type;
184 int rc;
186 rc = libbpf_attach_type_by_name(test->sec_name, &attach_type);
188 if (rc != test->expected_attach.rc) {
189 warnx("attach: unexpected rc=%d for %s", rc, test->sec_name);
190 return -1;
193 if (rc)
194 return 0;
196 if (attach_type != test->expected_attach.attach_type) {
197 warnx("attach: unexpected attach_type=%d for %s", attach_type,
198 test->sec_name);
199 return -1;
202 return 0;
205 static int run_test_case(const struct sec_name_test *test)
207 if (test_prog_type_by_name(test))
208 return -1;
209 if (test_attach_type_by_name(test))
210 return -1;
211 return 0;
214 static int run_tests(void)
216 int passes = 0;
217 int fails = 0;
218 int i;
220 for (i = 0; i < ARRAY_SIZE(tests); ++i) {
221 if (run_test_case(&tests[i]))
222 ++fails;
223 else
224 ++passes;
226 printf("Summary: %d PASSED, %d FAILED\n", passes, fails);
227 return fails ? -1 : 0;
230 int main(int argc, char **argv)
232 return run_tests();