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