151031288SAlexei Starovoitov // SPDX-License-Identifier: GPL-2.0
251031288SAlexei Starovoitov /* Copyright (c) 2019 Facebook */
351031288SAlexei Starovoitov #include <test_progs.h>
44d1b6298SAlexei Starovoitov #include "fentry_test.lskel.h"
54d1b6298SAlexei Starovoitov #include "fexit_test.lskel.h"
6dde53c1bSAndrii Nakryiko
test_fentry_fexit(void)751031288SAlexei Starovoitov void test_fentry_fexit(void)
851031288SAlexei Starovoitov {
9087cba79SKumar Kartikeya Dwivedi struct fentry_test_lskel *fentry_skel = NULL;
10087cba79SKumar Kartikeya Dwivedi struct fexit_test_lskel *fexit_skel = NULL;
11dde53c1bSAndrii Nakryiko __u64 *fentry_res, *fexit_res;
12da00d2f1SKP Singh int err, prog_fd, i;
13*04fcb5f9SDelyan Kratunov LIBBPF_OPTS(bpf_test_run_opts, topts);
1451031288SAlexei Starovoitov
15087cba79SKumar Kartikeya Dwivedi fentry_skel = fentry_test_lskel__open_and_load();
16*04fcb5f9SDelyan Kratunov if (!ASSERT_OK_PTR(fentry_skel, "fentry_skel_load"))
1751031288SAlexei Starovoitov goto close_prog;
18087cba79SKumar Kartikeya Dwivedi fexit_skel = fexit_test_lskel__open_and_load();
19*04fcb5f9SDelyan Kratunov if (!ASSERT_OK_PTR(fexit_skel, "fexit_skel_load"))
2051031288SAlexei Starovoitov goto close_prog;
2151031288SAlexei Starovoitov
22087cba79SKumar Kartikeya Dwivedi err = fentry_test_lskel__attach(fentry_skel);
23*04fcb5f9SDelyan Kratunov if (!ASSERT_OK(err, "fentry_attach"))
2451031288SAlexei Starovoitov goto close_prog;
25087cba79SKumar Kartikeya Dwivedi err = fexit_test_lskel__attach(fexit_skel);
26*04fcb5f9SDelyan Kratunov if (!ASSERT_OK(err, "fexit_attach"))
2751031288SAlexei Starovoitov goto close_prog;
2851031288SAlexei Starovoitov
294d1b6298SAlexei Starovoitov prog_fd = fexit_skel->progs.test1.prog_fd;
30*04fcb5f9SDelyan Kratunov err = bpf_prog_test_run_opts(prog_fd, &topts);
31*04fcb5f9SDelyan Kratunov ASSERT_OK(err, "ipv6 test_run");
32*04fcb5f9SDelyan Kratunov ASSERT_OK(topts.retval, "ipv6 test retval");
3351031288SAlexei Starovoitov
34dde53c1bSAndrii Nakryiko fentry_res = (__u64 *)fentry_skel->bss;
35dde53c1bSAndrii Nakryiko fexit_res = (__u64 *)fexit_skel->bss;
36dde53c1bSAndrii Nakryiko printf("%lld\n", fentry_skel->bss->test1_result);
37d923021cSYonghong Song for (i = 0; i < 8; i++) {
38*04fcb5f9SDelyan Kratunov ASSERT_EQ(fentry_res[i], 1, "fentry result");
39*04fcb5f9SDelyan Kratunov ASSERT_EQ(fexit_res[i], 1, "fexit result");
40dde53c1bSAndrii Nakryiko }
4151031288SAlexei Starovoitov
4251031288SAlexei Starovoitov close_prog:
43087cba79SKumar Kartikeya Dwivedi fentry_test_lskel__destroy(fentry_skel);
44087cba79SKumar Kartikeya Dwivedi fexit_test_lskel__destroy(fexit_skel);
4551031288SAlexei Starovoitov }
46