tools/testing/selftests/bpf/prog_tests/task_under_cgroup.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/task_under_cgroup.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/task_under_cgroup.c- Extension
.c- Size
- 1465 bytes
- Lines
- 61
- 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/syscall.htest_progs.hcgroup_helpers.htest_task_under_cgroup.skel.h
Detected Declarations
function test_task_under_cgroup
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2023 Bytedance */
#include <sys/syscall.h>
#include <test_progs.h>
#include <cgroup_helpers.h>
#include "test_task_under_cgroup.skel.h"
#define FOO "/foo"
void test_task_under_cgroup(void)
{
struct test_task_under_cgroup *skel;
int ret, foo;
pid_t pid;
foo = test__join_cgroup(FOO);
if (!ASSERT_OK(foo < 0, "cgroup_join_foo"))
return;
skel = test_task_under_cgroup__open();
if (!ASSERT_OK_PTR(skel, "test_task_under_cgroup__open"))
goto cleanup;
skel->rodata->local_pid = getpid();
skel->bss->remote_pid = getpid();
skel->rodata->cgid = get_cgroup_id(FOO);
ret = test_task_under_cgroup__load(skel);
if (!ASSERT_OK(ret, "test_task_under_cgroup__load"))
goto cleanup;
/* First, attach the LSM program, and then it will be triggered when the
* TP_BTF program is attached.
*/
skel->links.lsm_run = bpf_program__attach_lsm(skel->progs.lsm_run);
if (!ASSERT_OK_PTR(skel->links.lsm_run, "attach_lsm"))
goto cleanup;
skel->links.tp_btf_run = bpf_program__attach_trace(skel->progs.tp_btf_run);
if (!ASSERT_OK_PTR(skel->links.tp_btf_run, "attach_tp_btf"))
goto cleanup;
pid = fork();
if (pid == 0)
exit(0);
ret = (pid == -1);
if (ASSERT_OK(ret, "fork process"))
wait(NULL);
test_task_under_cgroup__detach(skel);
ASSERT_NEQ(skel->bss->remote_pid, skel->rodata->local_pid,
"test task_under_cgroup");
cleanup:
test_task_under_cgroup__destroy(skel);
close(foo);
}
Annotation
- Immediate include surface: `sys/syscall.h`, `test_progs.h`, `cgroup_helpers.h`, `test_task_under_cgroup.skel.h`.
- Detected declarations: `function test_task_under_cgroup`.
- 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.