1 // SPDX-License-Identifier: GPL-2.0
2 #include <test_progs.h>
3 
test_spinlock(void)4 void test_spinlock(void)
5 {
6 	const char *file = "./test_spin_lock.o";
7 	pthread_t thread_id[4];
8 	struct bpf_object *obj = NULL;
9 	int prog_fd;
10 	int err = 0, i;
11 	void *ret;
12 
13 	err = bpf_prog_load(file, BPF_PROG_TYPE_CGROUP_SKB, &obj, &prog_fd);
14 	if (CHECK_FAIL(err)) {
15 		printf("test_spin_lock:bpf_prog_load errno %d\n", errno);
16 		goto close_prog;
17 	}
18 	for (i = 0; i < 4; i++)
19 		if (CHECK_FAIL(pthread_create(&thread_id[i], NULL,
20 					      &spin_lock_thread, &prog_fd)))
21 			goto close_prog;
22 
23 	for (i = 0; i < 4; i++)
24 		if (CHECK_FAIL(pthread_join(thread_id[i], &ret) ||
25 			       ret != (void *)&prog_fd))
26 			goto close_prog;
27 close_prog:
28 	bpf_object__close(obj);
29 }
30