tools/testing/selftests/bpf/prog_tests/prepare.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/prepare.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/prepare.c- Extension
.c- Size
- 2087 bytes
- Lines
- 100
- 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.hprepare.skel.h
Detected Declarations
function check_preparedfunction bpf_object__for_each_mapfunction test_prepare_no_loadfunction test_prepare_loadfunction test_prepare
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2025 Meta */
#include <test_progs.h>
#include <network_helpers.h>
#include "prepare.skel.h"
static bool check_prepared(struct bpf_object *obj)
{
bool is_prepared = true;
const struct bpf_map *map;
bpf_object__for_each_map(map, obj) {
if (bpf_map__fd(map) < 0)
is_prepared = false;
}
return is_prepared;
}
static void test_prepare_no_load(void)
{
struct prepare *skel;
int err;
LIBBPF_OPTS(bpf_test_run_opts, topts,
.data_in = &pkt_v4,
.data_size_in = sizeof(pkt_v4),
);
skel = prepare__open();
if (!ASSERT_OK_PTR(skel, "prepare__open"))
return;
if (!ASSERT_FALSE(check_prepared(skel->obj), "not check_prepared"))
goto cleanup;
err = bpf_object__prepare(skel->obj);
if (!ASSERT_TRUE(check_prepared(skel->obj), "check_prepared"))
goto cleanup;
if (!ASSERT_OK(err, "bpf_object__prepare"))
goto cleanup;
cleanup:
prepare__destroy(skel);
}
static void test_prepare_load(void)
{
struct prepare *skel;
int err, prog_fd;
LIBBPF_OPTS(bpf_test_run_opts, topts,
.data_in = &pkt_v4,
.data_size_in = sizeof(pkt_v4),
);
skel = prepare__open();
if (!ASSERT_OK_PTR(skel, "prepare__open"))
return;
if (!ASSERT_FALSE(check_prepared(skel->obj), "not check_prepared"))
goto cleanup;
err = bpf_object__prepare(skel->obj);
if (!ASSERT_OK(err, "bpf_object__prepare"))
goto cleanup;
err = prepare__load(skel);
if (!ASSERT_OK(err, "prepare__load"))
goto cleanup;
if (!ASSERT_TRUE(check_prepared(skel->obj), "check_prepared"))
goto cleanup;
prog_fd = bpf_program__fd(skel->progs.program);
if (!ASSERT_GE(prog_fd, 0, "prog_fd"))
goto cleanup;
err = bpf_prog_test_run_opts(prog_fd, &topts);
if (!ASSERT_OK(err, "test_run_opts err"))
goto cleanup;
if (!ASSERT_OK(topts.retval, "test_run_opts retval"))
goto cleanup;
ASSERT_EQ(skel->bss->err, 0, "err");
cleanup:
prepare__destroy(skel);
Annotation
- Immediate include surface: `test_progs.h`, `network_helpers.h`, `prepare.skel.h`.
- Detected declarations: `function check_prepared`, `function bpf_object__for_each_map`, `function test_prepare_no_load`, `function test_prepare_load`, `function test_prepare`.
- 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.