tools/testing/selftests/bpf/prog_tests/task_kfunc.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/task_kfunc.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/task_kfunc.c- Extension
.c- Size
- 4797 bytes
- Lines
- 219
- 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
sys/wait.htest_progs.hunistd.htask_kfunc_failure.skel.htask_kfunc_success.skel.h
Detected Declarations
function run_success_testfunction run_syscall_success_testfunction run_vpid_testfunction run_vpid_success_testfunction test_task_kfunc
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
#define _GNU_SOURCE
#include <sys/wait.h>
#include <test_progs.h>
#include <unistd.h>
#include "task_kfunc_failure.skel.h"
#include "task_kfunc_success.skel.h"
static struct task_kfunc_success *open_load_task_kfunc_skel(void)
{
struct task_kfunc_success *skel;
int err;
skel = task_kfunc_success__open();
if (!ASSERT_OK_PTR(skel, "skel_open"))
return NULL;
skel->bss->pid = getpid();
err = task_kfunc_success__load(skel);
if (!ASSERT_OK(err, "skel_load"))
goto cleanup;
return skel;
cleanup:
task_kfunc_success__destroy(skel);
return NULL;
}
static void run_success_test(const char *prog_name)
{
struct task_kfunc_success *skel;
int status;
pid_t child_pid;
struct bpf_program *prog;
struct bpf_link *link = NULL;
skel = open_load_task_kfunc_skel();
if (!ASSERT_OK_PTR(skel, "open_load_skel"))
return;
if (!ASSERT_OK(skel->bss->err, "pre_spawn_err"))
goto cleanup;
prog = bpf_object__find_program_by_name(skel->obj, prog_name);
if (!ASSERT_OK_PTR(prog, "bpf_object__find_program_by_name"))
goto cleanup;
link = bpf_program__attach(prog);
if (!ASSERT_OK_PTR(link, "attached_link"))
goto cleanup;
child_pid = fork();
if (!ASSERT_GT(child_pid, -1, "child_pid"))
goto cleanup;
if (child_pid == 0)
_exit(0);
waitpid(child_pid, &status, 0);
ASSERT_OK(skel->bss->err, "post_wait_err");
cleanup:
bpf_link__destroy(link);
task_kfunc_success__destroy(skel);
}
static void run_syscall_success_test(const char *prog_name)
{
LIBBPF_OPTS(bpf_test_run_opts, opts);
struct task_kfunc_success *skel;
struct bpf_program *prog;
int err;
skel = open_load_task_kfunc_skel();
if (!ASSERT_OK_PTR(skel, "open_load_skel"))
return;
if (!ASSERT_OK(skel->bss->err, "pre_run_err"))
goto cleanup;
prog = bpf_object__find_program_by_name(skel->obj, prog_name);
if (!ASSERT_OK_PTR(prog, "bpf_object__find_program_by_name"))
goto cleanup;
err = bpf_prog_test_run_opts(bpf_program__fd(prog), &opts);
if (!ASSERT_OK(err, "bpf_prog_test_run_opts"))
Annotation
- Immediate include surface: `sys/wait.h`, `test_progs.h`, `unistd.h`, `task_kfunc_failure.skel.h`, `task_kfunc_success.skel.h`.
- Detected declarations: `function run_success_test`, `function run_syscall_success_test`, `function run_vpid_test`, `function run_vpid_success_test`, `function test_task_kfunc`.
- 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.