tools/testing/selftests/bpf/prog_tests/vmlinux.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/vmlinux.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/vmlinux.c- Extension
.c- Size
- 2017 bytes
- Lines
- 85
- 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.htime.htest_vmlinux.skel.h
Detected Declarations
function nsleepfunction setup_hrtimer_progsfunction test_vmlinux
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2020 Facebook */
#include <test_progs.h>
#include <time.h>
#include "test_vmlinux.skel.h"
#define MY_TV_NSEC 1337
static void nsleep()
{
struct timespec ts = { .tv_nsec = MY_TV_NSEC };
(void)syscall(__NR_nanosleep, &ts, NULL);
}
static const char *hrtimer_func = "hrtimer_start_range_ns";
static int setup_hrtimer_progs(struct test_vmlinux *skel)
{
int err;
if (libbpf_find_vmlinux_btf_id("hrtimer_start_range_ns_user", BPF_TRACE_FENTRY) > 0)
hrtimer_func = "hrtimer_start_range_ns_user";
err = bpf_program__set_attach_target(skel->progs.handle__fentry, 0, hrtimer_func);
if (err)
return err;
/*
* Bare SEC("kprobe") has no target function, so attach it manually
* later after selecting the hrtimer function to probe.
*/
bpf_program__set_autoattach(skel->progs.handle__kprobe, false);
return 0;
}
void test_vmlinux(void)
{
int err;
struct test_vmlinux* skel;
struct test_vmlinux__bss *bss;
struct bpf_link *kprobe_link = NULL;
skel = test_vmlinux__open();
if (!ASSERT_OK_PTR(skel, "test_vmlinux__open"))
return;
err = setup_hrtimer_progs(skel);
if (!ASSERT_OK(err, "setup_hrtimer_progs"))
goto cleanup;
err = test_vmlinux__load(skel);
if (!ASSERT_OK(err, "test_vmlinux__load"))
goto cleanup;
bss = skel->bss;
err = test_vmlinux__attach(skel);
if (!ASSERT_OK(err, "test_vmlinux__attach"))
goto cleanup;
/* manually attach kprobe with the selected function */
if (hrtimer_func) {
kprobe_link = bpf_program__attach_kprobe(skel->progs.handle__kprobe,
false /* retprobe */, hrtimer_func);
if (!ASSERT_OK_PTR(kprobe_link, "bpf_program__attach_kprobe"))
goto cleanup;
}
/* trigger everything */
nsleep();
ASSERT_TRUE(bss->tp_called, "tp");
ASSERT_TRUE(bss->raw_tp_called, "raw_tp");
ASSERT_TRUE(bss->tp_btf_called, "tp_btf");
ASSERT_TRUE(bss->kprobe_called, "kprobe");
ASSERT_TRUE(bss->fentry_called, "fentry");
cleanup:
bpf_link__destroy(kprobe_link);
test_vmlinux__destroy(skel);
}
Annotation
- Immediate include surface: `test_progs.h`, `time.h`, `test_vmlinux.skel.h`.
- Detected declarations: `function nsleep`, `function setup_hrtimer_progs`, `function test_vmlinux`.
- 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.