@@ -410,6 +410,57 @@ static void pe_subtest(struct test_bpf_cookie *skel)
410410 bpf_link__destroy (link );
411411}
412412
413+ static void tracing_subtest (struct test_bpf_cookie * skel )
414+ {
415+ __u64 cookie ;
416+ int prog_fd ;
417+ int fentry_fd = -1 , fexit_fd = -1 , fmod_ret_fd = -1 ;
418+ LIBBPF_OPTS (bpf_test_run_opts , opts );
419+ LIBBPF_OPTS (bpf_link_create_opts , link_opts );
420+
421+ skel -> bss -> fentry_res = 0 ;
422+ skel -> bss -> fexit_res = 0 ;
423+
424+ cookie = 0x10000000000000L ;
425+ prog_fd = bpf_program__fd (skel -> progs .fentry_test1 );
426+ link_opts .tracing .cookie = cookie ;
427+ fentry_fd = bpf_link_create (prog_fd , 0 , BPF_TRACE_FENTRY , & link_opts );
428+ if (!ASSERT_GE (fentry_fd , 0 , "fentry.link_create" ))
429+ goto cleanup ;
430+
431+ cookie = 0x20000000000000L ;
432+ prog_fd = bpf_program__fd (skel -> progs .fexit_test1 );
433+ link_opts .tracing .cookie = cookie ;
434+ fexit_fd = bpf_link_create (prog_fd , 0 , BPF_TRACE_FEXIT , & link_opts );
435+ if (!ASSERT_GE (fexit_fd , 0 , "fexit.link_create" ))
436+ goto cleanup ;
437+
438+ cookie = 0x30000000000000L ;
439+ prog_fd = bpf_program__fd (skel -> progs .fmod_ret_test );
440+ link_opts .tracing .cookie = cookie ;
441+ fmod_ret_fd = bpf_link_create (prog_fd , 0 , BPF_MODIFY_RETURN , & link_opts );
442+ if (!ASSERT_GE (fmod_ret_fd , 0 , "fmod_ret.link_create" ))
443+ goto cleanup ;
444+
445+ prog_fd = bpf_program__fd (skel -> progs .fentry_test1 );
446+ bpf_prog_test_run_opts (prog_fd , & opts );
447+
448+ prog_fd = bpf_program__fd (skel -> progs .fmod_ret_test );
449+ bpf_prog_test_run_opts (prog_fd , & opts );
450+
451+ ASSERT_EQ (skel -> bss -> fentry_res , 0x10000000000000L , "fentry_res" );
452+ ASSERT_EQ (skel -> bss -> fexit_res , 0x20000000000000L , "fexit_res" );
453+ ASSERT_EQ (skel -> bss -> fmod_ret_res , 0x30000000000000L , "fmod_ret_res" );
454+
455+ cleanup :
456+ if (fentry_fd >= 0 )
457+ close (fentry_fd );
458+ if (fexit_fd >= 0 )
459+ close (fexit_fd );
460+ if (fmod_ret_fd >= 0 )
461+ close (fmod_ret_fd );
462+ }
463+
413464void test_bpf_cookie (void )
414465{
415466 struct test_bpf_cookie * skel ;
@@ -432,6 +483,8 @@ void test_bpf_cookie(void)
432483 tp_subtest (skel );
433484 if (test__start_subtest ("perf_event" ))
434485 pe_subtest (skel );
486+ if (test__start_subtest ("trampoline" ))
487+ tracing_subtest (skel );
435488
436489 test_bpf_cookie__destroy (skel );
437490}
0 commit comments