2019-11-14 10:57:09 -08:00
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2019 Facebook */
# include <test_progs.h>
2021-05-13 17:36:20 -07:00
# include "fentry_test.lskel.h"
2019-12-13 17:43:39 -08:00
2021-10-28 12:04:59 +05:30
static int fentry_test ( struct fentry_test_lskel * fentry_skel )
2019-11-14 10:57:09 -08:00
{
2020-03-04 20:18:52 +01:00
int err , prog_fd , i ;
2021-05-13 17:36:20 -07:00
int link_fd ;
2019-12-13 17:43:39 -08:00
__u64 * result ;
2022-02-02 15:54:20 -08:00
LIBBPF_OPTS ( bpf_test_run_opts , topts ) ;
2019-11-14 10:57:09 -08:00
2021-10-28 12:04:59 +05:30
err = fentry_test_lskel__attach ( fentry_skel ) ;
2021-04-14 21:51:43 +02:00
if ( ! ASSERT_OK ( err , " fentry_attach " ) )
return err ;
/* Check that already linked program can't be attached again. */
2021-10-28 12:04:59 +05:30
link_fd = fentry_test_lskel__test1__attach ( fentry_skel ) ;
2021-05-13 17:36:20 -07:00
if ( ! ASSERT_LT ( link_fd , 0 , " fentry_attach_link " ) )
2021-04-14 21:51:43 +02:00
return - 1 ;
2019-11-14 10:57:09 -08:00
2021-05-13 17:36:20 -07:00
prog_fd = fentry_skel - > progs . test1 . prog_fd ;
2022-02-02 15:54:20 -08:00
err = bpf_prog_test_run_opts ( prog_fd , & topts ) ;
2021-04-14 21:51:43 +02:00
ASSERT_OK ( err , " test_run " ) ;
2022-02-02 15:54:20 -08:00
ASSERT_EQ ( topts . retval , 0 , " test_run " ) ;
2019-11-14 10:57:09 -08:00
2019-12-13 17:43:39 -08:00
result = ( __u64 * ) fentry_skel - > bss ;
2021-04-14 21:51:43 +02:00
for ( i = 0 ; i < sizeof ( * fentry_skel - > bss ) / sizeof ( __u64 ) ; i + + ) {
if ( ! ASSERT_EQ ( result [ i ] , 1 , " fentry_result " ) )
return - 1 ;
2019-12-13 17:43:39 -08:00
}
2019-11-14 10:57:09 -08:00
2021-10-28 12:04:59 +05:30
fentry_test_lskel__detach ( fentry_skel ) ;
2021-04-14 21:51:43 +02:00
/* zero results for re-attach test */
memset ( fentry_skel - > bss , 0 , sizeof ( * fentry_skel - > bss ) ) ;
return 0 ;
}
void test_fentry_test ( void )
{
2021-10-28 12:04:59 +05:30
struct fentry_test_lskel * fentry_skel = NULL ;
2021-04-14 21:51:43 +02:00
int err ;
2021-10-28 12:04:59 +05:30
fentry_skel = fentry_test_lskel__open_and_load ( ) ;
2021-04-14 21:51:43 +02:00
if ( ! ASSERT_OK_PTR ( fentry_skel , " fentry_skel_load " ) )
goto cleanup ;
err = fentry_test ( fentry_skel ) ;
if ( ! ASSERT_OK ( err , " fentry_first_attach " ) )
goto cleanup ;
err = fentry_test ( fentry_skel ) ;
ASSERT_OK ( err , " fentry_second_attach " ) ;
2019-12-13 17:43:39 -08:00
cleanup :
2021-10-28 12:04:59 +05:30
fentry_test_lskel__destroy ( fentry_skel ) ;
2019-11-14 10:57:09 -08:00
}