1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2021 Facebook */ 3 4 #include <test_progs.h> 5 #include <network_helpers.h> 6 #include "test_ksyms_module.lskel.h" 7 #include "test_ksyms_module.skel.h" 8 9 void test_ksyms_module_lskel(void) 10 { 11 struct test_ksyms_module_lskel *skel; 12 int retval; 13 int err; 14 15 if (!env.has_testmod) { 16 test__skip(); 17 return; 18 } 19 20 skel = test_ksyms_module_lskel__open_and_load(); 21 if (!ASSERT_OK_PTR(skel, "test_ksyms_module_lskel__open_and_load")) 22 return; 23 err = bpf_prog_test_run(skel->progs.load.prog_fd, 1, &pkt_v4, sizeof(pkt_v4), 24 NULL, NULL, (__u32 *)&retval, NULL); 25 if (!ASSERT_OK(err, "bpf_prog_test_run")) 26 goto cleanup; 27 ASSERT_EQ(retval, 0, "retval"); 28 ASSERT_EQ(skel->bss->out_bpf_testmod_ksym, 42, "bpf_testmod_ksym"); 29 cleanup: 30 test_ksyms_module_lskel__destroy(skel); 31 } 32 33 void test_ksyms_module_libbpf(void) 34 { 35 struct test_ksyms_module *skel; 36 int retval, err; 37 38 if (!env.has_testmod) { 39 test__skip(); 40 return; 41 } 42 43 skel = test_ksyms_module__open_and_load(); 44 if (!ASSERT_OK_PTR(skel, "test_ksyms_module__open")) 45 return; 46 err = bpf_prog_test_run(bpf_program__fd(skel->progs.load), 1, &pkt_v4, 47 sizeof(pkt_v4), NULL, NULL, (__u32 *)&retval, NULL); 48 if (!ASSERT_OK(err, "bpf_prog_test_run")) 49 goto cleanup; 50 ASSERT_EQ(retval, 0, "retval"); 51 ASSERT_EQ(skel->bss->out_bpf_testmod_ksym, 42, "bpf_testmod_ksym"); 52 cleanup: 53 test_ksyms_module__destroy(skel); 54 } 55 56 void test_ksyms_module(void) 57 { 58 if (test__start_subtest("lskel")) 59 test_ksyms_module_lskel(); 60 if (test__start_subtest("libbpf")) 61 test_ksyms_module_libbpf(); 62 } 63