tools/testing/selftests/bpf/prog_tests/btf_split.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/btf_split.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/btf_split.c- Extension
.c- Size
- 6315 bytes
- Lines
- 227
- 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.h
Detected Declarations
function btf_dump_printffunction btf_raw_writefunction __test_btf_splitfunction test_btf_split
Annotated Snippet
if (!ASSERT_GE(ret, 0, "write succeeded")) {
close(fd);
return -errno;
}
written += ret;
}
close(fd);
return written;
}
static void __test_btf_split(bool multi)
{
char multisplit_btf_file[] = "/tmp/test_btf_multisplit.XXXXXX";
char split_btf_file[] = "/tmp/test_btf_split.XXXXXX";
char base_btf_file[] = "/tmp/test_btf_base.XXXXXX";
ssize_t multisplit_btf_sz = 0, split_btf_sz = 0, base_btf_sz = 0;
struct btf_dump *d = NULL;
const struct btf_type *t, *ot;
struct btf *btf1 = NULL, *btf2 = NULL, *btf3 = NULL;
struct btf *btf4 = NULL, *btf5 = NULL, *btf6 = NULL;
int str_off, i, err;
btf1 = btf__new_empty();
if (!ASSERT_OK_PTR(btf1, "empty_main_btf"))
return;
btf__set_pointer_size(btf1, 8); /* enforce 64-bit arch */
btf__add_int(btf1, "int", 4, BTF_INT_SIGNED); /* [1] int */
btf__add_ptr(btf1, 1); /* [2] ptr to int */
btf__add_struct(btf1, "s1", 4); /* [3] struct s1 { */
btf__add_field(btf1, "f1", 1, 0, 0); /* int f1; */
/* } */
btf2 = btf__new_empty_split(btf1);
if (!ASSERT_OK_PTR(btf2, "empty_split_btf"))
goto cleanup;
/* pointer size should be "inherited" from main BTF */
ASSERT_EQ(btf__pointer_size(btf2), 8, "inherit_ptr_sz");
str_off = btf__find_str(btf2, "int");
ASSERT_NEQ(str_off, -ENOENT, "str_int_missing");
t = btf__type_by_id(btf2, 1);
if (!ASSERT_OK_PTR(t, "int_type"))
goto cleanup;
ASSERT_EQ(btf_is_int(t), true, "int_kind");
ASSERT_STREQ(btf__str_by_offset(btf2, t->name_off), "int", "int_name");
btf__add_struct(btf2, "s2", 16); /* [4] struct s2 { */
btf__add_field(btf2, "f1", 3, 0, 0); /* struct s1 f1; */
btf__add_field(btf2, "f2", 1, 32, 0); /* int f2; */
btf__add_field(btf2, "f3", 2, 64, 0); /* int *f3; */
/* } */
t = btf__type_by_id(btf1, 4);
ASSERT_NULL(t, "split_type_in_main");
t = btf__type_by_id(btf2, 4);
if (!ASSERT_OK_PTR(t, "split_struct_type"))
goto cleanup;
ASSERT_EQ(btf_is_struct(t), true, "split_struct_kind");
ASSERT_EQ(btf_vlen(t), 3, "split_struct_vlen");
ASSERT_STREQ(btf__str_by_offset(btf2, t->name_off), "s2", "split_struct_name");
if (multi) {
btf3 = btf__new_empty_split(btf2);
if (!ASSERT_OK_PTR(btf3, "multi_split_btf"))
goto cleanup;
} else {
btf3 = btf2;
}
btf__add_union(btf3, "u1", 16); /* [5] union u1 { */
btf__add_field(btf3, "f1", 4, 0, 0); /* struct s2 f1; */
btf__add_field(btf3, "uf2", 1, 0, 0); /* int f2; */
/* } */
if (multi) {
t = btf__type_by_id(btf2, 5);
ASSERT_NULL(t, "multisplit_type_in_first_split");
}
t = btf__type_by_id(btf3, 5);
if (!ASSERT_OK_PTR(t, "split_union_type"))
goto cleanup;
ASSERT_EQ(btf_is_union(t), true, "split_union_kind");
ASSERT_EQ(btf_vlen(t), 2, "split_union_vlen");
Annotation
- Immediate include surface: `test_progs.h`, `bpf/btf.h`.
- Detected declarations: `function btf_dump_printf`, `function btf_raw_write`, `function __test_btf_split`, `function test_btf_split`.
- 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.