1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun #include <test_progs.h>
3*4882a593Smuzhiyun #include <network_helpers.h>
4*4882a593Smuzhiyun
spin_lock_thread(void * arg)5*4882a593Smuzhiyun static void *spin_lock_thread(void *arg)
6*4882a593Smuzhiyun {
7*4882a593Smuzhiyun __u32 duration, retval;
8*4882a593Smuzhiyun int err, prog_fd = *(u32 *) arg;
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun err = bpf_prog_test_run(prog_fd, 10000, &pkt_v4, sizeof(pkt_v4),
11*4882a593Smuzhiyun NULL, NULL, &retval, &duration);
12*4882a593Smuzhiyun CHECK(err || retval, "",
13*4882a593Smuzhiyun "err %d errno %d retval %d duration %d\n",
14*4882a593Smuzhiyun err, errno, retval, duration);
15*4882a593Smuzhiyun pthread_exit(arg);
16*4882a593Smuzhiyun }
17*4882a593Smuzhiyun
test_spinlock(void)18*4882a593Smuzhiyun void test_spinlock(void)
19*4882a593Smuzhiyun {
20*4882a593Smuzhiyun const char *file = "./test_spin_lock.o";
21*4882a593Smuzhiyun pthread_t thread_id[4];
22*4882a593Smuzhiyun struct bpf_object *obj = NULL;
23*4882a593Smuzhiyun int prog_fd;
24*4882a593Smuzhiyun int err = 0, i;
25*4882a593Smuzhiyun void *ret;
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun err = bpf_prog_load(file, BPF_PROG_TYPE_CGROUP_SKB, &obj, &prog_fd);
28*4882a593Smuzhiyun if (CHECK_FAIL(err)) {
29*4882a593Smuzhiyun printf("test_spin_lock:bpf_prog_load errno %d\n", errno);
30*4882a593Smuzhiyun goto close_prog;
31*4882a593Smuzhiyun }
32*4882a593Smuzhiyun for (i = 0; i < 4; i++)
33*4882a593Smuzhiyun if (CHECK_FAIL(pthread_create(&thread_id[i], NULL,
34*4882a593Smuzhiyun &spin_lock_thread, &prog_fd)))
35*4882a593Smuzhiyun goto close_prog;
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun for (i = 0; i < 4; i++)
38*4882a593Smuzhiyun if (CHECK_FAIL(pthread_join(thread_id[i], &ret) ||
39*4882a593Smuzhiyun ret != (void *)&prog_fd))
40*4882a593Smuzhiyun goto close_prog;
41*4882a593Smuzhiyun close_prog:
42*4882a593Smuzhiyun bpf_object__close(obj);
43*4882a593Smuzhiyun }
44