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