1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2019 Facebook */ 3 #include <test_progs.h> 4 #include "test_pkt_access.skel.h" 5 #include "fentry_test.skel.h" 6 #include "fexit_test.skel.h" 7 8 void test_fentry_fexit(void) 9 { 10 struct test_pkt_access *pkt_skel = NULL; 11 struct fentry_test *fentry_skel = NULL; 12 struct fexit_test *fexit_skel = NULL; 13 __u64 *fentry_res, *fexit_res; 14 __u32 duration = 0, retval; 15 int err, pkt_fd, i; 16 17 pkt_skel = test_pkt_access__open_and_load(); 18 if (CHECK(!pkt_skel, "pkt_skel_load", "pkt_access skeleton failed\n")) 19 return; 20 fentry_skel = fentry_test__open_and_load(); 21 if (CHECK(!fentry_skel, "fentry_skel_load", "fentry skeleton failed\n")) 22 goto close_prog; 23 fexit_skel = fexit_test__open_and_load(); 24 if (CHECK(!fexit_skel, "fexit_skel_load", "fexit skeleton failed\n")) 25 goto close_prog; 26 27 err = fentry_test__attach(fentry_skel); 28 if (CHECK(err, "fentry_attach", "fentry attach failed: %d\n", err)) 29 goto close_prog; 30 err = fexit_test__attach(fexit_skel); 31 if (CHECK(err, "fexit_attach", "fexit attach failed: %d\n", err)) 32 goto close_prog; 33 34 pkt_fd = bpf_program__fd(pkt_skel->progs.test_pkt_access); 35 err = bpf_prog_test_run(pkt_fd, 1, &pkt_v6, sizeof(pkt_v6), 36 NULL, NULL, &retval, &duration); 37 CHECK(err || retval, "ipv6", 38 "err %d errno %d retval %d duration %d\n", 39 err, errno, retval, duration); 40 41 fentry_res = (__u64 *)fentry_skel->bss; 42 fexit_res = (__u64 *)fexit_skel->bss; 43 printf("%lld\n", fentry_skel->bss->test1_result); 44 for (i = 0; i < 6; i++) { 45 CHECK(fentry_res[i] != 1, "result", 46 "fentry_test%d failed err %lld\n", i + 1, fentry_res[i]); 47 CHECK(fexit_res[i] != 1, "result", 48 "fexit_test%d failed err %lld\n", i + 1, fexit_res[i]); 49 } 50 51 close_prog: 52 test_pkt_access__destroy(pkt_skel); 53 fentry_test__destroy(fentry_skel); 54 fexit_test__destroy(fexit_skel); 55 } 56