tools/testing/selftests/bpf/prog_tests/stack_arg.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/stack_arg.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/stack_arg.c- Extension
.c- Size
- 3069 bytes
- Lines
- 140
- 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.hnetwork_helpers.hstack_arg.skel.hstack_arg_kfunc.skel.h
Detected Declarations
function run_subtestfunction test_global_manyfunction test_async_cb_manyfunction test_bpf2bpffunction test_kfuncfunction test_stack_arg
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
#include <test_progs.h>
#include <network_helpers.h>
#include "stack_arg.skel.h"
#include "stack_arg_kfunc.skel.h"
static void run_subtest(struct bpf_program *prog, int expected)
{
int err, prog_fd;
LIBBPF_OPTS(bpf_test_run_opts, topts,
.data_in = &pkt_v4,
.data_size_in = sizeof(pkt_v4),
.repeat = 1,
);
prog_fd = bpf_program__fd(prog);
err = bpf_prog_test_run_opts(prog_fd, &topts);
ASSERT_OK(err, "test_run");
ASSERT_EQ(topts.retval, expected, "retval");
}
static void test_global_many(void)
{
struct stack_arg *skel;
skel = stack_arg__open();
if (!ASSERT_OK_PTR(skel, "open"))
return;
if (!skel->rodata->has_stack_arg) {
test__skip();
goto out;
}
if (!ASSERT_OK(stack_arg__load(skel), "load"))
goto out;
run_subtest(skel->progs.test_global_many_args, 55);
out:
stack_arg__destroy(skel);
}
static void test_async_cb_many(void)
{
struct stack_arg *skel;
skel = stack_arg__open();
if (!ASSERT_OK_PTR(skel, "open"))
return;
if (!skel->rodata->has_stack_arg) {
test__skip();
goto out;
}
if (!ASSERT_OK(stack_arg__load(skel), "load"))
goto out;
run_subtest(skel->progs.test_async_cb_many_args, 0);
/* Wait for the timer callback to fire and verify the result.
* 10+20+30+40+50+60+70+80+90+100 = 550
*/
usleep(50);
ASSERT_EQ(skel->bss->timer_result, 550, "timer_result");
out:
stack_arg__destroy(skel);
}
static void test_bpf2bpf(void)
{
struct stack_arg *skel;
skel = stack_arg__open();
if (!ASSERT_OK_PTR(skel, "open"))
return;
if (!skel->rodata->has_stack_arg) {
test__skip();
goto out;
}
if (!ASSERT_OK(stack_arg__load(skel), "load"))
goto out;
run_subtest(skel->progs.test_bpf2bpf_ptr_stack_arg, 75);
Annotation
- Immediate include surface: `test_progs.h`, `network_helpers.h`, `stack_arg.skel.h`, `stack_arg_kfunc.skel.h`.
- Detected declarations: `function run_subtest`, `function test_global_many`, `function test_async_cb_many`, `function test_bpf2bpf`, `function test_kfunc`, `function test_stack_arg`.
- 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.