tools/testing/selftests/bpf/prog_tests/cgroup_get_current_cgroup_id.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/cgroup_get_current_cgroup_id.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/cgroup_get_current_cgroup_id.c- Extension
.c- Size
- 1126 bytes
- Lines
- 47
- 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/stat.hsys/sysmacros.htest_progs.hcgroup_helpers.hget_cgroup_id_kern.skel.h
Detected Declarations
function test_cgroup_get_current_cgroup_id
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include "test_progs.h"
#include "cgroup_helpers.h"
#include "get_cgroup_id_kern.skel.h"
#define TEST_CGROUP "/test-bpf-get-cgroup-id/"
void test_cgroup_get_current_cgroup_id(void)
{
struct get_cgroup_id_kern *skel;
const struct timespec req = {
.tv_sec = 0,
.tv_nsec = 1,
};
int cgroup_fd;
__u64 ucgid;
cgroup_fd = cgroup_setup_and_join(TEST_CGROUP);
if (!ASSERT_OK_FD(cgroup_fd, "cgroup switch"))
return;
skel = get_cgroup_id_kern__open_and_load();
if (!ASSERT_OK_PTR(skel, "load program"))
goto cleanup_cgroup;
if (!ASSERT_OK(get_cgroup_id_kern__attach(skel), "attach bpf program"))
goto cleanup_progs;
skel->bss->expected_pid = getpid();
/* trigger the syscall on which is attached the tested prog */
if (!ASSERT_OK(syscall(__NR_nanosleep, &req, NULL), "nanosleep"))
goto cleanup_progs;
ucgid = get_cgroup_id(TEST_CGROUP);
ASSERT_EQ(skel->bss->cg_id, ucgid, "compare cgroup ids");
cleanup_progs:
get_cgroup_id_kern__destroy(skel);
cleanup_cgroup:
close(cgroup_fd);
cleanup_cgroup_environment();
}
Annotation
- Immediate include surface: `sys/stat.h`, `sys/sysmacros.h`, `test_progs.h`, `cgroup_helpers.h`, `get_cgroup_id_kern.skel.h`.
- Detected declarations: `function test_cgroup_get_current_cgroup_id`.
- 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.