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 #include "kfunc_call_test_subprog.lskel.h" 8 9 static void test_main(void) 10 { 11 struct kfunc_call_test_lskel *skel; 12 int prog_fd, retval, err; 13 14 skel = kfunc_call_test_lskel__open_and_load(); 15 if (!ASSERT_OK_PTR(skel, "skel")) 16 return; 17 18 prog_fd = skel->progs.kfunc_call_test1.prog_fd; 19 err = bpf_prog_test_run(prog_fd, 1, &pkt_v4, sizeof(pkt_v4), 20 NULL, NULL, (__u32 *)&retval, NULL); 21 ASSERT_OK(err, "bpf_prog_test_run(test1)"); 22 ASSERT_EQ(retval, 12, "test1-retval"); 23 24 prog_fd = skel->progs.kfunc_call_test2.prog_fd; 25 err = bpf_prog_test_run(prog_fd, 1, &pkt_v4, sizeof(pkt_v4), 26 NULL, NULL, (__u32 *)&retval, NULL); 27 ASSERT_OK(err, "bpf_prog_test_run(test2)"); 28 ASSERT_EQ(retval, 3, "test2-retval"); 29 30 kfunc_call_test_lskel__destroy(skel); 31 } 32 33 static void test_subprog(void) 34 { 35 struct kfunc_call_test_subprog *skel; 36 int prog_fd, retval, err; 37 38 skel = kfunc_call_test_subprog__open_and_load(); 39 if (!ASSERT_OK_PTR(skel, "skel")) 40 return; 41 42 prog_fd = bpf_program__fd(skel->progs.kfunc_call_test1); 43 err = bpf_prog_test_run(prog_fd, 1, &pkt_v4, sizeof(pkt_v4), 44 NULL, NULL, (__u32 *)&retval, NULL); 45 ASSERT_OK(err, "bpf_prog_test_run(test1)"); 46 ASSERT_EQ(retval, 10, "test1-retval"); 47 ASSERT_NEQ(skel->data->active_res, -1, "active_res"); 48 ASSERT_EQ(skel->data->sk_state_res, BPF_TCP_CLOSE, "sk_state_res"); 49 50 kfunc_call_test_subprog__destroy(skel); 51 } 52 53 static void test_subprog_lskel(void) 54 { 55 struct kfunc_call_test_subprog_lskel *skel; 56 int prog_fd, retval, err; 57 58 skel = kfunc_call_test_subprog_lskel__open_and_load(); 59 if (!ASSERT_OK_PTR(skel, "skel")) 60 return; 61 62 prog_fd = skel->progs.kfunc_call_test1.prog_fd; 63 err = bpf_prog_test_run(prog_fd, 1, &pkt_v4, sizeof(pkt_v4), 64 NULL, NULL, (__u32 *)&retval, NULL); 65 ASSERT_OK(err, "bpf_prog_test_run(test1)"); 66 ASSERT_EQ(retval, 10, "test1-retval"); 67 ASSERT_NEQ(skel->data->active_res, -1, "active_res"); 68 ASSERT_EQ(skel->data->sk_state_res, BPF_TCP_CLOSE, "sk_state_res"); 69 70 kfunc_call_test_subprog_lskel__destroy(skel); 71 } 72 73 void test_kfunc_call(void) 74 { 75 if (test__start_subtest("main")) 76 test_main(); 77 78 if (test__start_subtest("subprog")) 79 test_subprog(); 80 81 if (test__start_subtest("subprog_lskel")) 82 test_subprog_lskel(); 83 } 84