2019-11-14 10:57:10 -08:00
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2019 Facebook */
# include <test_progs.h>
2020-03-04 20:18:52 +01:00
# include "fexit_test.skel.h"
2019-11-14 10:57:10 -08:00
void test_fexit_test ( void )
{
2020-03-04 20:18:52 +01:00
struct fexit_test * fexit_skel = NULL ;
int err , prog_fd , i ;
selftests/bpf: Initialize duration variable before using
The 'duration' variable is referenced in the CHECK() macro, and there are
some uses of the macro before 'duration' is set. The clang compiler
(validly) complains about this.
Sample error:
.../selftests/bpf/prog_tests/fexit_test.c:23:6: warning: variable 'duration' is uninitialized when used here [-Wuninitialized]
if (CHECK(err, "prog_load sched cls", "err %d errno %d\n", err, errno))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../selftests/bpf/test_progs.h:134:25: note: expanded from macro 'CHECK'
if (CHECK(err, "prog_load sched cls", "err %d errno %d\n", err, errno))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_CHECK(condition, tag, duration, format)
^~~~~~~~
Signed-off-by: John Sperbeck <jsperbeck@google.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20200123235144.93610-1-sdf@google.com
2020-01-23 15:51:44 -08:00
__u32 duration = 0 , retval ;
2020-03-04 20:18:52 +01:00
__u64 * result ;
2019-11-14 10:57:10 -08:00
2020-03-04 20:18:52 +01:00
fexit_skel = fexit_test__open_and_load ( ) ;
if ( CHECK ( ! fexit_skel , " fexit_skel_load " , " fexit skeleton failed \n " ) )
goto cleanup ;
2019-11-14 10:57:10 -08:00
2020-03-04 20:18:52 +01:00
err = fexit_test__attach ( fexit_skel ) ;
if ( CHECK ( err , " fexit_attach " , " fexit attach failed: %d \n " , err ) )
goto cleanup ;
2019-11-14 10:57:10 -08:00
2020-03-04 20:18:52 +01:00
prog_fd = bpf_program__fd ( fexit_skel - > progs . test1 ) ;
err = bpf_prog_test_run ( prog_fd , 1 , NULL , 0 ,
2019-11-14 10:57:10 -08:00
NULL , NULL , & retval , & duration ) ;
2020-03-04 20:18:52 +01:00
CHECK ( err | | retval , " test_run " ,
2019-11-14 10:57:10 -08:00
" err %d errno %d retval %d duration %d \n " ,
err , errno , retval , duration ) ;
2020-03-04 20:18:52 +01:00
result = ( __u64 * ) fexit_skel - > bss ;
for ( i = 0 ; i < 6 ; i + + ) {
if ( CHECK ( result [ i ] ! = 1 , " result " ,
" fexit_test%d failed err %lld \n " , i + 1 , result [ i ] ) )
goto cleanup ;
}
2019-11-14 10:57:10 -08:00
2020-03-04 20:18:52 +01:00
cleanup :
fexit_test__destroy ( fexit_skel ) ;
2019-11-14 10:57:10 -08:00
}