tools/testing/selftests/bpf/prog_tests/ns_current_pid_tgid.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/ns_current_pid_tgid.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/ns_current_pid_tgid.c- Extension
.c- Size
- 5627 bytes
- Lines
- 228
- 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.htest_ns_current_pid_tgid.skel.hsys/stat.hsys/types.hunistd.hsys/syscall.hsched.hsys/wait.hsys/mount.hfcntl.hnetwork_helpers.h
Detected Declarations
function get_pid_tgidfunction test_current_pid_tgid_tpfunction test_current_pid_tgid_cgrpfunction test_current_pid_tgid_sk_msgfunction test_ns_current_pid_tgid_new_nsfunction serial_test_current_pid_tgidfunction test_ns_current_pid_tgid_cgrpfunction test_ns_current_pid_tgid_sk_msg
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2020 Carlos Neira cneirabustos@gmail.com */
#define _GNU_SOURCE
#include <test_progs.h>
#include "test_ns_current_pid_tgid.skel.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sched.h>
#include <sys/wait.h>
#include <sys/mount.h>
#include <fcntl.h>
#include "network_helpers.h"
#define STACK_SIZE (1024 * 1024)
static char child_stack[STACK_SIZE];
static int get_pid_tgid(pid_t *pid, pid_t *tgid,
struct test_ns_current_pid_tgid__bss *bss)
{
struct stat st;
int err;
*pid = sys_gettid();
*tgid = getpid();
err = stat("/proc/self/ns/pid", &st);
if (!ASSERT_OK(err, "stat /proc/self/ns/pid"))
return err;
bss->dev = st.st_dev;
bss->ino = st.st_ino;
bss->user_pid = 0;
bss->user_tgid = 0;
return 0;
}
static int test_current_pid_tgid_tp(void *args)
{
struct test_ns_current_pid_tgid__bss *bss;
struct test_ns_current_pid_tgid *skel;
int ret = -1, err;
pid_t tgid, pid;
skel = test_ns_current_pid_tgid__open();
if (!ASSERT_OK_PTR(skel, "test_ns_current_pid_tgid__open"))
return ret;
bpf_program__set_autoload(skel->progs.tp_handler, true);
err = test_ns_current_pid_tgid__load(skel);
if (!ASSERT_OK(err, "test_ns_current_pid_tgid__load"))
goto cleanup;
bss = skel->bss;
if (get_pid_tgid(&pid, &tgid, bss))
goto cleanup;
err = test_ns_current_pid_tgid__attach(skel);
if (!ASSERT_OK(err, "test_ns_current_pid_tgid__attach"))
goto cleanup;
/* trigger tracepoint */
usleep(1);
if (!ASSERT_EQ(bss->user_pid, pid, "pid"))
goto cleanup;
if (!ASSERT_EQ(bss->user_tgid, tgid, "tgid"))
goto cleanup;
ret = 0;
cleanup:
test_ns_current_pid_tgid__destroy(skel);
return ret;
}
static int test_current_pid_tgid_cgrp(void *args)
{
struct test_ns_current_pid_tgid__bss *bss;
struct test_ns_current_pid_tgid *skel;
int server_fd = -1, ret = -1, err;
int cgroup_fd = *(int *)args;
pid_t tgid, pid;
skel = test_ns_current_pid_tgid__open();
if (!ASSERT_OK_PTR(skel, "test_ns_current_pid_tgid__open"))
return ret;
bpf_program__set_autoload(skel->progs.cgroup_bind4, true);
Annotation
- Immediate include surface: `test_progs.h`, `test_ns_current_pid_tgid.skel.h`, `sys/stat.h`, `sys/types.h`, `unistd.h`, `sys/syscall.h`, `sched.h`, `sys/wait.h`.
- Detected declarations: `function get_pid_tgid`, `function test_current_pid_tgid_tp`, `function test_current_pid_tgid_cgrp`, `function test_current_pid_tgid_sk_msg`, `function test_ns_current_pid_tgid_new_ns`, `function serial_test_current_pid_tgid`, `function test_ns_current_pid_tgid_cgrp`, `function test_ns_current_pid_tgid_sk_msg`.
- 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.