tools/testing/selftests/bpf/prog_tests/btf_tag.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/btf_tag.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/btf_tag.c- Extension
.c- Size
- 6489 bytes
- Lines
- 250
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
test_progs.hbpf/btf.htest_btf_decl_tag.skel.hbtf_type_tag.skel.hbtf_type_tag_user.skel.hbtf_type_tag_percpu.skel.h
Detected Declarations
struct btf_type_tag_testfunction test_btf_decl_tagfunction test_btf_type_tagfunction load_btfsfunction test_btf_type_tag_mod_userfunction test_btf_type_tag_vmlinux_userfunction test_btf_type_tag_mod_percpufunction test_btf_type_tag_vmlinux_percpufunction test_btf_tag
Annotated Snippet
struct btf_type_tag_test {
int **p;
};
#include "btf_type_tag.skel.h"
#include "btf_type_tag_user.skel.h"
#include "btf_type_tag_percpu.skel.h"
static void test_btf_decl_tag(void)
{
struct test_btf_decl_tag *skel;
skel = test_btf_decl_tag__open_and_load();
if (!ASSERT_OK_PTR(skel, "btf_decl_tag"))
return;
if (skel->rodata->skip_tests) {
printf("%s:SKIP: btf_decl_tag attribute not supported", __func__);
test__skip();
}
test_btf_decl_tag__destroy(skel);
}
static void test_btf_type_tag(void)
{
struct btf_type_tag *skel;
skel = btf_type_tag__open_and_load();
if (!ASSERT_OK_PTR(skel, "btf_type_tag"))
return;
if (skel->rodata->skip_tests) {
printf("%s:SKIP: btf_type_tag attribute not supported", __func__);
test__skip();
}
btf_type_tag__destroy(skel);
}
/* loads vmlinux_btf as well as module_btf. If the caller passes NULL as
* module_btf, it will not load module btf.
*
* Returns 0 on success.
* Return -1 On error. In case of error, the loaded btf will be freed and the
* input parameters will be set to pointing to NULL.
*/
static int load_btfs(struct btf **vmlinux_btf, struct btf **module_btf,
bool needs_vmlinux_tag)
{
const char *module_name = "bpf_testmod";
__s32 type_id;
if (!env.has_testmod) {
test__skip();
return -1;
}
*vmlinux_btf = btf__load_vmlinux_btf();
if (!ASSERT_OK_PTR(*vmlinux_btf, "could not load vmlinux BTF"))
return -1;
if (!needs_vmlinux_tag)
goto load_module_btf;
/* skip the test if the vmlinux does not have __user tags */
type_id = btf__find_by_name_kind(*vmlinux_btf, "user", BTF_KIND_TYPE_TAG);
if (type_id <= 0) {
printf("%s:SKIP: btf_type_tag attribute not in vmlinux btf", __func__);
test__skip();
goto free_vmlinux_btf;
}
load_module_btf:
/* skip loading module_btf, if not requested by caller */
if (!module_btf)
return 0;
*module_btf = btf__load_module_btf(module_name, *vmlinux_btf);
if (!ASSERT_OK_PTR(*module_btf, "could not load module BTF"))
goto free_vmlinux_btf;
/* skip the test if the module does not have __user tags */
type_id = btf__find_by_name_kind(*module_btf, "user", BTF_KIND_TYPE_TAG);
if (type_id <= 0) {
printf("%s:SKIP: btf_type_tag attribute not in %s", __func__, module_name);
test__skip();
goto free_module_btf;
}
return 0;
Annotation
- Immediate include surface: `test_progs.h`, `bpf/btf.h`, `test_btf_decl_tag.skel.h`, `btf_type_tag.skel.h`, `btf_type_tag_user.skel.h`, `btf_type_tag_percpu.skel.h`.
- Detected declarations: `struct btf_type_tag_test`, `function test_btf_decl_tag`, `function test_btf_type_tag`, `function load_btfs`, `function test_btf_type_tag_mod_user`, `function test_btf_type_tag_vmlinux_user`, `function test_btf_type_tag_mod_percpu`, `function test_btf_type_tag_vmlinux_percpu`, `function test_btf_tag`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.