2019-11-14 10:57:12 -08:00
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2019 Facebook */
# include <test_progs.h>
2021-02-09 19:36:29 -08:00
/* that's kernel internal BPF_MAX_TRAMP_PROGS define */
# define CNT 38
2019-11-14 10:57:12 -08:00
void test_fexit_stress ( void )
{
char test_skb [ 128 ] = { } ;
int fexit_fd [ CNT ] = { } ;
int link_fd [ CNT ] = { } ;
char error [ 4096 ] ;
int err , i , filter_fd ;
const struct bpf_insn trace_program [ ] = {
BPF_MOV64_IMM ( BPF_REG_0 , 0 ) ,
BPF_EXIT_INSN ( ) ,
} ;
2021-11-03 15:08:42 -07:00
LIBBPF_OPTS ( bpf_prog_load_opts , trace_opts ,
2019-11-14 10:57:12 -08:00
. expected_attach_type = BPF_TRACE_FEXIT ,
2021-11-03 15:08:42 -07:00
. log_buf = error ,
. log_size = sizeof ( error ) ,
) ;
2019-11-14 10:57:12 -08:00
const struct bpf_insn skb_program [ ] = {
BPF_MOV64_IMM ( BPF_REG_0 , 0 ) ,
BPF_EXIT_INSN ( ) ,
} ;
2021-11-03 15:08:42 -07:00
LIBBPF_OPTS ( bpf_prog_load_opts , skb_opts ,
. log_buf = error ,
. log_size = sizeof ( error ) ,
) ;
2019-11-14 10:57:12 -08:00
2022-02-02 15:54:20 -08:00
LIBBPF_OPTS ( bpf_test_run_opts , topts ,
. data_in = test_skb ,
. data_size_in = sizeof ( test_skb ) ,
. repeat = 1 ,
) ;
2019-11-14 10:57:12 -08:00
err = libbpf_find_vmlinux_btf_id ( " bpf_fentry_test1 " ,
2021-11-03 15:08:42 -07:00
trace_opts . expected_attach_type ) ;
2022-02-02 15:54:20 -08:00
if ( ! ASSERT_GT ( err , 0 , " find_vmlinux_btf_id " ) )
2019-11-14 10:57:12 -08:00
goto out ;
2021-11-03 15:08:42 -07:00
trace_opts . attach_btf_id = err ;
2019-11-14 10:57:12 -08:00
for ( i = 0 ; i < CNT ; i + + ) {
2021-11-03 15:08:42 -07:00
fexit_fd [ i ] = bpf_prog_load ( BPF_PROG_TYPE_TRACING , NULL , " GPL " ,
trace_program ,
sizeof ( trace_program ) / sizeof ( struct bpf_insn ) ,
& trace_opts ) ;
2022-02-02 15:54:20 -08:00
if ( ! ASSERT_GE ( fexit_fd [ i ] , 0 , " fexit load " ) )
2019-11-14 10:57:12 -08:00
goto out ;
link_fd [ i ] = bpf_raw_tracepoint_open ( NULL , fexit_fd [ i ] ) ;
2022-02-02 15:54:20 -08:00
if ( ! ASSERT_GE ( link_fd [ i ] , 0 , " fexit attach " ) )
2019-11-14 10:57:12 -08:00
goto out ;
}
2021-11-03 15:08:42 -07:00
filter_fd = bpf_prog_load ( BPF_PROG_TYPE_SOCKET_FILTER , NULL , " GPL " ,
skb_program , sizeof ( skb_program ) / sizeof ( struct bpf_insn ) ,
& skb_opts ) ;
2022-02-02 15:54:20 -08:00
if ( ! ASSERT_GE ( filter_fd , 0 , " test_program_loaded " ) )
2019-11-14 10:57:12 -08:00
goto out ;
2022-02-02 15:54:20 -08:00
err = bpf_prog_test_run_opts ( filter_fd , & topts ) ;
2019-11-14 10:57:12 -08:00
close ( filter_fd ) ;
CHECK_FAIL ( err ) ;
out :
for ( i = 0 ; i < CNT ; i + + ) {
if ( link_fd [ i ] )
close ( link_fd [ i ] ) ;
if ( fexit_fd [ i ] )
close ( fexit_fd [ i ] ) ;
}
}