tools/testing/selftests/bpf/prog_tests/btf.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/btf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/btf.c- Extension
.c- Size
- 233009 bytes
- Lines
- 8358
- 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
linux/bpf.hlinux/btf.hlinux/err.hlinux/kernel.hlinux/filter.hlinux/unistd.hbpf/bpf.hlibelf.hgelf.hstring.hstdlib.hstdio.hstdarg.hunistd.hfcntl.herrno.hassert.hbpf/libbpf.hbpf/btf.hbpf_util.h../test_btf.htest_progs.h
Detected Declarations
struct btf_raw_teststruct btf_get_info_teststruct btf_file_teststruct pprint_mapvstruct pprint_mapv_int128struct btf_raw_datastruct btf_dedup_testenum pprint_mapv_kind_tfunction get_raw_sec_sizefunction load_raw_btffunction do_test_rawfunction CHECKfunction test_big_btf_infofunction test_btf_idfunction do_test_get_infofunction do_test_filefunction get_pprint_mapv_sizefunction set_pprint_mapvfunction get_pprint_expected_linefunction check_linefunction do_test_pprintfunction test_pprintfunction probe_prog_lengthfunction test_get_finfofunction test_get_linfofunction do_test_info_rawfunction CHECKfunction btf_type_sizefunction dump_btf_stringsfunction do_test_dedupfunction test_btf
Annotated Snippet
struct btf_raw_test {
const char *descr;
const char *str_sec;
const char *map_name;
const char *err_str;
__u32 raw_types[MAX_NR_RAW_U32];
__u32 str_sec_size;
enum bpf_map_type map_type;
__u32 key_size;
__u32 value_size;
__u32 key_type_id;
__u32 value_type_id;
__u32 max_entries;
bool btf_load_err;
bool map_create_err;
bool ordered_map;
bool lossless_map;
bool percpu_map;
int hdr_len_delta;
int type_off_delta;
int str_off_delta;
int str_len_delta;
enum pprint_mapv_kind_t mapv_kind;
};
#define BTF_STR_SEC(str) \
.str_sec = str, .str_sec_size = sizeof(str)
static struct btf_raw_test raw_tests[] = {
/* enum E {
* E0,
* E1,
* };
*
* struct A {
* unsigned long long m;
* int n;
* char o;
* [3 bytes hole]
* int p[8];
* int q[4][8];
* enum E r;
* };
*/
{
.descr = "struct test #1",
.raw_types = {
/* int */
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
/* unsigned long long */
BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
/* char */
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1), /* [3] */
/* int[8] */
BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
/* struct A { */ /* [5] */
BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 6), 180),
BTF_MEMBER_ENC(NAME_TBD, 2, 0), /* unsigned long long m;*/
BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n; */
BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o; */
BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8] */
BTF_MEMBER_ENC(NAME_TBD, 6, 384),/* int q[4][8] */
BTF_MEMBER_ENC(NAME_TBD, 7, 1408), /* enum E r */
/* } */
/* int[4][8] */
BTF_TYPE_ARRAY_ENC(4, 1, 4), /* [6] */
/* enum E */ /* [7] */
BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 2), sizeof(int)),
BTF_ENUM_ENC(NAME_TBD, 0),
BTF_ENUM_ENC(NAME_TBD, 1),
BTF_END_RAW,
},
.str_sec = "\0A\0m\0n\0o\0p\0q\0r\0E\0E0\0E1",
.str_sec_size = sizeof("\0A\0m\0n\0o\0p\0q\0r\0E\0E0\0E1"),
.map_type = BPF_MAP_TYPE_ARRAY,
.map_name = "struct_test1_map",
.key_size = sizeof(int),
.value_size = 180,
.key_type_id = 1,
.value_type_id = 5,
.max_entries = 4,
},
/* typedef struct b Struct_B;
*
* struct A {
* int m;
* struct b n[4];
* const Struct_B o[4];
* };
Annotation
- Immediate include surface: `linux/bpf.h`, `linux/btf.h`, `linux/err.h`, `linux/kernel.h`, `linux/filter.h`, `linux/unistd.h`, `bpf/bpf.h`, `libelf.h`.
- Detected declarations: `struct btf_raw_test`, `struct btf_get_info_test`, `struct btf_file_test`, `struct pprint_mapv`, `struct pprint_mapv_int128`, `struct btf_raw_data`, `struct btf_dedup_test`, `enum pprint_mapv_kind_t`, `function get_raw_sec_size`, `function load_raw_btf`.
- 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.