tools/testing/selftests/bpf/prog_tests/bpf_loop.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/bpf_loop.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/bpf_loop.c- Extension
.c- Size
- 4722 bytes
- Lines
- 208
- 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.hbpf_loop.skel.h
Detected Declarations
function check_nr_loopsfunction check_callback_fn_stopfunction check_null_callback_ctxfunction check_invalid_flagsfunction check_nested_callsfunction check_non_constant_callbackfunction check_stackfunction test_bpf_loop
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2021 Facebook */
#include <test_progs.h>
#include <network_helpers.h>
#include "bpf_loop.skel.h"
static void check_nr_loops(struct bpf_loop *skel)
{
struct bpf_link *link;
link = bpf_program__attach(skel->progs.test_prog);
if (!ASSERT_OK_PTR(link, "link"))
return;
/* test 0 loops */
skel->bss->nr_loops = 0;
usleep(1);
ASSERT_EQ(skel->bss->nr_loops_returned, skel->bss->nr_loops,
"0 loops");
/* test 500 loops */
skel->bss->nr_loops = 500;
usleep(1);
ASSERT_EQ(skel->bss->nr_loops_returned, skel->bss->nr_loops,
"500 loops");
ASSERT_EQ(skel->bss->g_output, (500 * 499) / 2, "g_output");
/* test exceeding the max limit */
skel->bss->nr_loops = -1;
usleep(1);
ASSERT_EQ(skel->bss->err, -E2BIG, "over max limit");
bpf_link__destroy(link);
}
static void check_callback_fn_stop(struct bpf_loop *skel)
{
struct bpf_link *link;
link = bpf_program__attach(skel->progs.test_prog);
if (!ASSERT_OK_PTR(link, "link"))
return;
/* testing that loop is stopped when callback_fn returns 1 */
skel->bss->nr_loops = 400;
skel->data->stop_index = 50;
usleep(1);
ASSERT_EQ(skel->bss->nr_loops_returned, skel->data->stop_index + 1,
"nr_loops_returned");
ASSERT_EQ(skel->bss->g_output, (50 * 49) / 2,
"g_output");
bpf_link__destroy(link);
}
static void check_null_callback_ctx(struct bpf_loop *skel)
{
struct bpf_link *link;
/* check that user is able to pass in a null callback_ctx */
link = bpf_program__attach(skel->progs.prog_null_ctx);
if (!ASSERT_OK_PTR(link, "link"))
return;
skel->bss->nr_loops = 10;
usleep(1);
ASSERT_EQ(skel->bss->nr_loops_returned, skel->bss->nr_loops,
"nr_loops_returned");
bpf_link__destroy(link);
}
static void check_invalid_flags(struct bpf_loop *skel)
{
struct bpf_link *link;
/* check that passing in non-zero flags returns -EINVAL */
link = bpf_program__attach(skel->progs.prog_invalid_flags);
if (!ASSERT_OK_PTR(link, "link"))
Annotation
- Immediate include surface: `test_progs.h`, `network_helpers.h`, `bpf_loop.skel.h`.
- Detected declarations: `function check_nr_loops`, `function check_callback_fn_stop`, `function check_null_callback_ctx`, `function check_invalid_flags`, `function check_nested_calls`, `function check_non_constant_callback`, `function check_stack`, `function test_bpf_loop`.
- 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.