tools/testing/selftests/bpf/prog_tests/wakeup_source.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/wakeup_source.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/wakeup_source.c- Extension
.c- Size
- 2584 bytes
- Lines
- 119
- 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.hfcntl.htest_wakeup_source.skel.hwakeup_source_fail.skel.hprogs/wakeup_source.h
Detected Declarations
struct rb_ctxfunction lock_wsfunction unlock_wsfunction process_samplefunction test_wakeup_source
Annotated Snippet
struct rb_ctx {
const char *name;
bool found;
long long active_time_ns;
long long total_time_ns;
};
static int process_sample(void *ctx, void *data, size_t len)
{
struct rb_ctx *rb_ctx = ctx;
struct wakeup_event_t *e = data;
if (strcmp(e->name, rb_ctx->name) == 0) {
rb_ctx->found = true;
rb_ctx->active_time_ns = e->active_time_ns;
rb_ctx->total_time_ns = e->total_time_ns;
}
return 0;
}
void test_wakeup_source(void)
{
struct btf *btf;
int id;
btf = btf__load_vmlinux_btf();
if (!ASSERT_OK_PTR(btf, "btf_vmlinux"))
return;
id = btf__find_by_name_kind(btf, "bpf_wakeup_sources_get_head", BTF_KIND_FUNC);
btf__free(btf);
if (id < 0) {
printf("%s:SKIP:bpf_wakeup_sources_get_head kfunc not found in BTF\n", __func__);
test__skip();
return;
}
if (test__start_subtest("iterate_and_verify_times")) {
struct test_wakeup_source *skel;
struct ring_buffer *rb = NULL;
struct rb_ctx rb_ctx = {
.name = "bpf_selftest_ws_times",
.found = false,
};
int err;
skel = test_wakeup_source__open_and_load();
if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
return;
rb = ring_buffer__new(bpf_map__fd(skel->maps.rb), process_sample, &rb_ctx, NULL);
if (!ASSERT_OK_PTR(rb, "ring_buffer__new"))
goto destroy;
/* Create a temporary wakeup source */
if (!ASSERT_OK(lock_ws(rb_ctx.name), "lock_ws"))
goto unlock;
err = bpf_prog_test_run_opts(bpf_program__fd(
skel->progs.iterate_wakeupsources), NULL);
ASSERT_OK(err, "bpf_prog_test_run");
ring_buffer__consume(rb);
ASSERT_TRUE(rb_ctx.found, "found_test_ws_in_rb");
ASSERT_GT(rb_ctx.active_time_ns, 0, "active_time_gt_0");
ASSERT_GT(rb_ctx.total_time_ns, 0, "total_time_gt_0");
unlock:
unlock_ws(rb_ctx.name);
destroy:
if (rb)
ring_buffer__free(rb);
test_wakeup_source__destroy(skel);
}
RUN_TESTS(wakeup_source_fail);
}
Annotation
- Immediate include surface: `test_progs.h`, `bpf/btf.h`, `fcntl.h`, `test_wakeup_source.skel.h`, `wakeup_source_fail.skel.h`, `progs/wakeup_source.h`.
- Detected declarations: `struct rb_ctx`, `function lock_ws`, `function unlock_ws`, `function process_sample`, `function test_wakeup_source`.
- 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.