tools/testing/selftests/bpf/prog_tests/test_struct_ops_module.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/test_struct_ops_module.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/test_struct_ops_module.c- Extension
.c- Size
- 8781 bytes
- Lines
- 318
- 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.htime.hsys/epoll.hstruct_ops_module.skel.hstruct_ops_nulled_out_cb.skel.hstruct_ops_forgotten_cb.skel.hstruct_ops_detach.skel.hunsupported_ops.skel.h
Detected Declarations
function check_map_infofunction attach_ops_and_checkfunction test_struct_ops_loadfunction test_struct_ops_not_zeroedfunction test_struct_ops_incompatiblefunction test_struct_ops_nulled_out_cbfunction test_struct_ops_forgotten_cbfunction test_detach_linkfunction serial_test_struct_ops_module
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
#include <test_progs.h>
#include <time.h>
#include <sys/epoll.h>
#include "struct_ops_module.skel.h"
#include "struct_ops_nulled_out_cb.skel.h"
#include "struct_ops_forgotten_cb.skel.h"
#include "struct_ops_detach.skel.h"
#include "unsupported_ops.skel.h"
static void check_map_info(struct bpf_map_info *info)
{
struct bpf_btf_info btf_info;
char btf_name[256];
u32 btf_info_len = sizeof(btf_info);
int err, fd;
fd = bpf_btf_get_fd_by_id(info->btf_vmlinux_id);
if (!ASSERT_GE(fd, 0, "get_value_type_btf_obj_fd"))
return;
memset(&btf_info, 0, sizeof(btf_info));
btf_info.name = ptr_to_u64(btf_name);
btf_info.name_len = sizeof(btf_name);
err = bpf_btf_get_info_by_fd(fd, &btf_info, &btf_info_len);
if (!ASSERT_OK(err, "get_value_type_btf_obj_info"))
goto cleanup;
if (!ASSERT_EQ(strcmp(btf_name, "bpf_testmod"), 0, "get_value_type_btf_obj_name"))
goto cleanup;
cleanup:
close(fd);
}
static int attach_ops_and_check(struct struct_ops_module *skel,
struct bpf_map *map,
int expected_test_2_result)
{
struct bpf_link *link;
link = bpf_map__attach_struct_ops(map);
ASSERT_OK_PTR(link, "attach_test_mod_1");
if (!link)
return -1;
/* test_{1,2}() would be called from bpf_dummy_reg() in bpf_testmod.c */
ASSERT_EQ(skel->bss->test_1_result, 0xdeadbeef, "test_1_result");
ASSERT_EQ(skel->bss->test_2_result, expected_test_2_result, "test_2_result");
bpf_link__destroy(link);
return 0;
}
static void test_struct_ops_load(void)
{
struct struct_ops_module *skel;
struct bpf_map_info info = {};
int err;
u32 len;
skel = struct_ops_module__open();
if (!ASSERT_OK_PTR(skel, "struct_ops_module_open"))
return;
skel->struct_ops.testmod_1->data = 13;
skel->struct_ops.testmod_1->test_2 = skel->progs.test_3;
/* Since test_2() is not being used, it should be disabled from
* auto-loading, or it will fail to load.
*/
bpf_program__set_autoload(skel->progs.test_2, false);
bpf_map__set_autocreate(skel->maps.testmod_zeroed, false);
err = struct_ops_module__load(skel);
if (!ASSERT_OK(err, "struct_ops_module_load"))
goto cleanup;
len = sizeof(info);
err = bpf_map_get_info_by_fd(bpf_map__fd(skel->maps.testmod_1), &info,
&len);
if (!ASSERT_OK(err, "bpf_map_get_info_by_fd"))
goto cleanup;
check_map_info(&info);
/* test_3() will be called from bpf_dummy_reg() in bpf_testmod.c
*
* In bpf_testmod.c it will pass 4 and 13 (the value of data) to
Annotation
- Immediate include surface: `test_progs.h`, `time.h`, `sys/epoll.h`, `struct_ops_module.skel.h`, `struct_ops_nulled_out_cb.skel.h`, `struct_ops_forgotten_cb.skel.h`, `struct_ops_detach.skel.h`, `unsupported_ops.skel.h`.
- Detected declarations: `function check_map_info`, `function attach_ops_and_check`, `function test_struct_ops_load`, `function test_struct_ops_not_zeroed`, `function test_struct_ops_incompatible`, `function test_struct_ops_nulled_out_cb`, `function test_struct_ops_forgotten_cb`, `function test_detach_link`, `function serial_test_struct_ops_module`.
- 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.