tools/testing/selftests/bpf/prog_tests/core_autosize.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/core_autosize.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/core_autosize.c- Extension
.c- Size
- 7407 bytes
- Lines
- 224
- 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_core_autosize.skel.h
Detected Declarations
struct test_struct___realfunction test_core_autosize
Annotated Snippet
struct test_struct___real {
unsigned int ptr; /* can't use `void *`, it is always 8 byte in BPF target */
unsigned int val2;
unsigned long long val1;
unsigned short val3;
unsigned char val4;
unsigned char _pad;
};
#include "test_core_autosize.skel.h"
static int duration = 0;
static struct {
unsigned long long ptr_samesized;
unsigned long long val1_samesized;
unsigned long long val2_samesized;
unsigned long long val3_samesized;
unsigned long long val4_samesized;
struct test_struct___real output_samesized;
unsigned long long ptr_downsized;
unsigned long long val1_downsized;
unsigned long long val2_downsized;
unsigned long long val3_downsized;
unsigned long long val4_downsized;
struct test_struct___real output_downsized;
unsigned long long ptr_probed;
unsigned long long val1_probed;
unsigned long long val2_probed;
unsigned long long val3_probed;
unsigned long long val4_probed;
unsigned long long ptr_signed;
unsigned long long val1_signed;
unsigned long long val2_signed;
unsigned long long val3_signed;
unsigned long long val4_signed;
struct test_struct___real output_signed;
} out;
void test_core_autosize(void)
{
char btf_file[] = "/tmp/core_autosize.btf.XXXXXX";
int err, fd = -1, zero = 0;
int char_id, short_id, int_id, long_long_id, void_ptr_id, id;
DECLARE_LIBBPF_OPTS(bpf_object_open_opts, open_opts);
struct test_core_autosize* skel = NULL;
struct bpf_program *prog;
struct bpf_map *bss_map;
struct btf *btf = NULL;
size_t written;
const void *raw_data;
__u32 raw_sz;
FILE *f = NULL;
btf = btf__new_empty();
if (!ASSERT_OK_PTR(btf, "empty_btf"))
return;
/* Emit the following struct with 32-bit pointer size:
*
* struct test_struct {
* void *ptr;
* unsigned long val2;
* unsigned long long val1;
* unsigned short val3;
* unsigned char val4;
* char: 8;
* };
*
* This struct is going to be used as the "kernel BTF" for this test.
* It's equivalent memory-layout-wise to test_struct__real above.
*/
/* force 32-bit pointer size */
btf__set_pointer_size(btf, 4);
char_id = btf__add_int(btf, "unsigned char", 1, 0);
ASSERT_EQ(char_id, 1, "char_id");
short_id = btf__add_int(btf, "unsigned short", 2, 0);
ASSERT_EQ(short_id, 2, "short_id");
/* "long unsigned int" of 4 byte size tells BTF that sizeof(void *) == 4 */
int_id = btf__add_int(btf, "long unsigned int", 4, 0);
ASSERT_EQ(int_id, 3, "int_id");
long_long_id = btf__add_int(btf, "unsigned long long", 8, 0);
ASSERT_EQ(long_long_id, 4, "long_long_id");
void_ptr_id = btf__add_ptr(btf, 0);
ASSERT_EQ(void_ptr_id, 5, "void_ptr_id");
Annotation
- Immediate include surface: `test_progs.h`, `bpf/btf.h`, `test_core_autosize.skel.h`.
- Detected declarations: `struct test_struct___real`, `function test_core_autosize`.
- 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.