2019-03-01 19:42:18 -08:00
// SPDX-License-Identifier: GPL-2.0
# include <test_progs.h>
2020-05-08 10:46:09 -07:00
# include <network_helpers.h>
static void * spin_lock_thread ( void * arg )
{
int err , prog_fd = * ( u32 * ) arg ;
2022-02-02 15:54:20 -08:00
LIBBPF_OPTS ( bpf_test_run_opts , topts ,
. data_in = & pkt_v4 ,
. data_size_in = sizeof ( pkt_v4 ) ,
. repeat = 10000 ,
) ;
2020-05-08 10:46:09 -07:00
2022-02-02 15:54:20 -08:00
err = bpf_prog_test_run_opts ( prog_fd , & topts ) ;
ASSERT_OK ( err , " test_run " ) ;
ASSERT_OK ( topts . retval , " test_run retval " ) ;
2020-05-08 10:46:09 -07:00
pthread_exit ( arg ) ;
}
2019-03-01 19:42:18 -08:00
void test_spinlock ( void )
{
2022-09-01 22:22:53 +00:00
const char * file = " ./test_spin_lock.bpf.o " ;
2019-03-01 19:42:18 -08:00
pthread_t thread_id [ 4 ] ;
2019-03-11 22:21:09 -07:00
struct bpf_object * obj = NULL ;
2019-03-01 19:42:18 -08:00
int prog_fd ;
int err = 0 , i ;
void * ret ;
2021-11-03 15:08:44 -07:00
err = bpf_prog_test_load ( file , BPF_PROG_TYPE_CGROUP_SKB , & obj , & prog_fd ) ;
2019-08-21 16:44:25 -07:00
if ( CHECK_FAIL ( err ) ) {
2021-11-03 15:08:44 -07:00
printf ( " test_spin_lock:bpf_prog_test_load errno %d \n " , errno ) ;
2019-03-01 19:42:18 -08:00
goto close_prog ;
}
for ( i = 0 ; i < 4 ; i + + )
2019-08-21 16:44:26 -07:00
if ( CHECK_FAIL ( pthread_create ( & thread_id [ i ] , NULL ,
& spin_lock_thread , & prog_fd ) ) )
goto close_prog ;
2019-08-21 16:44:25 -07:00
2019-08-21 16:44:26 -07:00
for ( i = 0 ; i < 4 ; i + + )
if ( CHECK_FAIL ( pthread_join ( thread_id [ i ] , & ret ) | |
ret ! = ( void * ) & prog_fd ) )
goto close_prog ;
2019-03-01 19:42:18 -08:00
close_prog :
bpf_object__close ( obj ) ;
}