Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Copyright (c) 2021 Hengqi Chen */
0003 
0004 #include <test_progs.h>
0005 #include <bpf/btf.h>
0006 
0007 static const char *module_name = "bpf_testmod";
0008 static const char *symbol_name = "bpf_testmod_test_read";
0009 
0010 void test_btf_module()
0011 {
0012     struct btf *vmlinux_btf, *module_btf;
0013     __s32 type_id;
0014 
0015     if (!env.has_testmod) {
0016         test__skip();
0017         return;
0018     }
0019 
0020     vmlinux_btf = btf__load_vmlinux_btf();
0021     if (!ASSERT_OK_PTR(vmlinux_btf, "could not load vmlinux BTF"))
0022         return;
0023 
0024     module_btf = btf__load_module_btf(module_name, vmlinux_btf);
0025     if (!ASSERT_OK_PTR(module_btf, "could not load module BTF"))
0026         goto cleanup;
0027 
0028     type_id = btf__find_by_name(module_btf, symbol_name);
0029     ASSERT_GT(type_id, 0, "func not found");
0030 
0031 cleanup:
0032     btf__free(module_btf);
0033     btf__free(vmlinux_btf);
0034 }