tools/testing/selftests/bpf/test_cpp.cpp
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/test_cpp.cpp
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/test_cpp.cpp- Extension
.cpp- Size
- 2804 bytes
- Lines
- 140
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- Status
- atlas-only
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
iostreamunistd.hlinux/bpf.hlinux/btf.hbpf/libbpf.hbpf/bpf.hbpf/btf.htest_core_extern.skel.hstruct_ops_module.skel.h
Detected Declarations
function openfunction loadfunction attachfunction detachfunction dump_printffunction main
Annotated Snippet
if (err) {
skel = nullptr;
return err;
}
return 0;
}
int load() { return T::load(skel); }
int attach() { return T::attach(skel); }
void detach() { return T::detach(skel); }
const T* operator->() const { return skel; }
T* operator->() { return skel; }
const T *get() const { return skel; }
};
static void dump_printf(void *ctx, const char *fmt, va_list args)
{
}
static void try_skeleton_template()
{
Skeleton<test_core_extern> skel;
std::string prog_name;
int err;
LIBBPF_OPTS(bpf_object_open_opts, opts);
err = skel.open(&opts);
if (err) {
fprintf(stderr, "Skeleton open failed: %d\n", err);
return;
}
skel->data->kern_ver = 123;
skel->data->int_val = skel->data->ushort_val;
err = skel.load();
if (err) {
fprintf(stderr, "Skeleton load failed: %d\n", err);
return;
}
if (!skel->kconfig->CONFIG_BPF_SYSCALL)
fprintf(stderr, "Seems like CONFIG_BPF_SYSCALL isn't set?!\n");
err = skel.attach();
if (err) {
fprintf(stderr, "Skeleton attach failed: %d\n", err);
return;
}
prog_name = bpf_program__name(skel->progs.handle_sys_enter);
if (prog_name != "handle_sys_enter")
fprintf(stderr, "Unexpected program name: %s\n", prog_name.c_str());
bpf_link__destroy(skel->links.handle_sys_enter);
skel->links.handle_sys_enter = bpf_program__attach(skel->progs.handle_sys_enter);
skel.detach();
/* destructor will destroy underlying skeleton */
}
int main(int argc, char *argv[])
{
Annotation
- Immediate include surface: `iostream`, `unistd.h`, `linux/bpf.h`, `linux/btf.h`, `bpf/libbpf.h`, `bpf/bpf.h`, `bpf/btf.h`, `test_core_extern.skel.h`.
- Detected declarations: `function open`, `function load`, `function attach`, `function detach`, `function dump_printf`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
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.