1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2021 Facebook */
3 #include <test_progs.h>
4 #include <network_helpers.h>
5 #include "kfunc_call_test.lskel.h"
6 #include "kfunc_call_test_subprog.skel.h"
7
test_main(void)8 static void test_main(void)
9 {
10 struct kfunc_call_test_lskel *skel;
11 int prog_fd, retval, err;
12
13 skel = kfunc_call_test_lskel__open_and_load();
14 if (!ASSERT_OK_PTR(skel, "skel"))
15 return;
16
17 prog_fd = skel->progs.kfunc_call_test1.prog_fd;
18 err = bpf_prog_test_run(prog_fd, 1, &pkt_v4, sizeof(pkt_v4),
19 NULL, NULL, (__u32 *)&retval, NULL);
20 ASSERT_OK(err, "bpf_prog_test_run(test1)");
21 ASSERT_EQ(retval, 12, "test1-retval");
22
23 prog_fd = skel->progs.kfunc_call_test2.prog_fd;
24 err = bpf_prog_test_run(prog_fd, 1, &pkt_v4, sizeof(pkt_v4),
25 NULL, NULL, (__u32 *)&retval, NULL);
26 ASSERT_OK(err, "bpf_prog_test_run(test2)");
27 ASSERT_EQ(retval, 3, "test2-retval");
28
29 kfunc_call_test_lskel__destroy(skel);
30 }
31
test_subprog(void)32 static void test_subprog(void)
33 {
34 struct kfunc_call_test_subprog *skel;
35 int prog_fd, retval, err;
36
37 skel = kfunc_call_test_subprog__open_and_load();
38 if (!ASSERT_OK_PTR(skel, "skel"))
39 return;
40
41 prog_fd = bpf_program__fd(skel->progs.kfunc_call_test1);
42 err = bpf_prog_test_run(prog_fd, 1, &pkt_v4, sizeof(pkt_v4),
43 NULL, NULL, (__u32 *)&retval, NULL);
44 ASSERT_OK(err, "bpf_prog_test_run(test1)");
45 ASSERT_EQ(retval, 10, "test1-retval");
46 ASSERT_NEQ(skel->data->active_res, -1, "active_res");
47 ASSERT_EQ(skel->data->sk_state_res, BPF_TCP_CLOSE, "sk_state_res");
48
49 kfunc_call_test_subprog__destroy(skel);
50 }
51
test_kfunc_call(void)52 void test_kfunc_call(void)
53 {
54 if (test__start_subtest("main"))
55 test_main();
56
57 if (test__start_subtest("subprog"))
58 test_subprog();
59 }
60