xref: /linux/tools/testing/selftests/bpf/prog_tests/fentry_fexit.c (revision 14e77332e74603efab8347c89d3cda447c3b97c9)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2019 Facebook */
3 #include <test_progs.h>
4 #include "fentry_test.lskel.h"
5 #include "fexit_test.lskel.h"
6 
7 void test_fentry_fexit(void)
8 {
9 	struct fentry_test_lskel *fentry_skel = NULL;
10 	struct fexit_test_lskel *fexit_skel = NULL;
11 	__u64 *fentry_res, *fexit_res;
12 	int err, prog_fd, i;
13 	LIBBPF_OPTS(bpf_test_run_opts, topts);
14 
15 	fentry_skel = fentry_test_lskel__open_and_load();
16 	if (!ASSERT_OK_PTR(fentry_skel, "fentry_skel_load"))
17 		goto close_prog;
18 	fexit_skel = fexit_test_lskel__open_and_load();
19 	if (!ASSERT_OK_PTR(fexit_skel, "fexit_skel_load"))
20 		goto close_prog;
21 
22 	err = fentry_test_lskel__attach(fentry_skel);
23 	if (!ASSERT_OK(err, "fentry_attach"))
24 		goto close_prog;
25 	err = fexit_test_lskel__attach(fexit_skel);
26 	if (!ASSERT_OK(err, "fexit_attach"))
27 		goto close_prog;
28 
29 	prog_fd = fexit_skel->progs.test1.prog_fd;
30 	err = bpf_prog_test_run_opts(prog_fd, &topts);
31 	ASSERT_OK(err, "ipv6 test_run");
32 	ASSERT_OK(topts.retval, "ipv6 test retval");
33 
34 	fentry_res = (__u64 *)fentry_skel->bss;
35 	fexit_res = (__u64 *)fexit_skel->bss;
36 	printf("%lld\n", fentry_skel->bss->test1_result);
37 	for (i = 0; i < 8; i++) {
38 		ASSERT_EQ(fentry_res[i], 1, "fentry result");
39 		ASSERT_EQ(fexit_res[i], 1, "fexit result");
40 	}
41 
42 close_prog:
43 	fentry_test_lskel__destroy(fentry_skel);
44 	fexit_test_lskel__destroy(fexit_skel);
45 }
46