Lines Matching +full:test +full:- +full:cpu

1 // SPDX-License-Identifier: GPL-2.0
3 * Test functionality of BPF filters with SO_REUSEPORT. This program creates
4 * an SO_REUSEPORT receiver group containing one socket per CPU core. It then
45 addr4->sin_family = AF_INET; in build_rcv_group()
46 addr4->sin_addr.s_addr = htonl(INADDR_ANY); in build_rcv_group()
47 addr4->sin_port = htons(PORT); in build_rcv_group()
51 addr6->sin6_family = AF_INET6; in build_rcv_group()
52 addr6->sin6_addr = in6addr_any; in build_rcv_group()
53 addr6->sin6_port = htons(PORT); in build_rcv_group()
105 saddr4->sin_family = AF_INET; in send_from_cpu()
106 saddr4->sin_addr.s_addr = htonl(INADDR_ANY); in send_from_cpu()
107 saddr4->sin_port = 0; in send_from_cpu()
110 daddr4->sin_family = AF_INET; in send_from_cpu()
111 daddr4->sin_addr.s_addr = htonl(INADDR_LOOPBACK); in send_from_cpu()
112 daddr4->sin_port = htons(PORT); in send_from_cpu()
116 saddr6->sin6_family = AF_INET6; in send_from_cpu()
117 saddr6->sin6_addr = in6addr_any; in send_from_cpu()
118 saddr6->sin6_port = 0; in send_from_cpu()
121 daddr6->sin6_family = AF_INET6; in send_from_cpu()
122 daddr6->sin6_addr = in6addr_loopback; in send_from_cpu()
123 daddr6->sin6_port = htons(PORT); in send_from_cpu()
132 error(1, errno, "failed to pin to cpu"); in send_from_cpu()
157 i = epoll_wait(epfd, &ev, 1, -1); in receive_on_cpu()
179 fprintf(stderr, "send cpu %d, receive socket %d\n", cpu_id, i); in receive_on_cpu()
181 error(1, 0, "cpu id/receive socket mismatch"); in receive_on_cpu()
184 static void test(int *rcv_fd, int len, int family, int proto) in test() function
187 int epfd, cpu; in test() local
195 for (cpu = 0; cpu < len; ++cpu) { in test()
197 ev.data.fd = rcv_fd[cpu]; in test()
198 if (epoll_ctl(epfd, EPOLL_CTL_ADD, rcv_fd[cpu], &ev)) in test()
203 for (cpu = 0; cpu < len; ++cpu) { in test()
204 send_from_cpu(cpu, family, proto); in test()
205 receive_on_cpu(rcv_fd, len, epfd, cpu, proto); in test()
209 for (cpu = len - 1; cpu >= 0; --cpu) { in test()
210 send_from_cpu(cpu, family, proto); in test()
211 receive_on_cpu(rcv_fd, len, epfd, cpu, proto); in test()
215 for (cpu = 0; cpu < len; cpu += 2) { in test()
216 send_from_cpu(cpu, family, proto); in test()
217 receive_on_cpu(rcv_fd, len, epfd, cpu, proto); in test()
221 for (cpu = 1; cpu < len; cpu += 2) { in test()
222 send_from_cpu(cpu, family, proto); in test()
223 receive_on_cpu(rcv_fd, len, epfd, cpu, proto); in test()
227 for (cpu = 0; cpu < len; ++cpu) in test()
228 close(rcv_fd[cpu]); in test()
243 fprintf(stderr, "---- IPv4 UDP ----\n"); in main()
244 test(rcv_fd, cpus, AF_INET, SOCK_DGRAM); in main()
246 fprintf(stderr, "---- IPv6 UDP ----\n"); in main()
247 test(rcv_fd, cpus, AF_INET6, SOCK_DGRAM); in main()
249 fprintf(stderr, "---- IPv4 TCP ----\n"); in main()
250 test(rcv_fd, cpus, AF_INET, SOCK_STREAM); in main()
252 fprintf(stderr, "---- IPv6 TCP ----\n"); in main()
253 test(rcv_fd, cpus, AF_INET6, SOCK_STREAM); in main()