tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c- Extension
.c- Size
- 17337 bytes
- Lines
- 625
- 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/btf.hbind4_prog.skel.hfreplace_progmap.skel.hxdp_dummy.skel.h
Detected Declarations
function check_data_mapfunction bpf_object__for_each_mapfunction test_fexit_bpf2bpf_commonfunction bpf_object__for_each_programfunction bpf_object__for_each_programfunction test_target_no_calleesfunction test_target_yes_calleesfunction test_func_replacefunction test_func_replace_verifyfunction test_second_attachfunction test_func_replace_multifunction test_fmod_ret_freplacefunction test_func_sockmap_updatefunction test_func_replace_voidfunction test_obj_load_failure_commonfunction test_func_replace_return_codefunction test_func_map_prog_compatibilityfunction test_func_replace_unreliablefunction test_func_replace_global_funcfunction test_func_replace_int_with_voidfunction find_prog_btf_idfunction load_fentryfunction test_fentry_to_cgroup_bpffunction test_func_replace_progmapfunction serial_test_fexit_bpf2bpf
Annotated Snippet
if (bpf_map__is_internal(map)) {
data_map = map;
break;
}
if (CHECK(!data_map, "find_data_map", "data map not found\n"))
goto out;
ret = bpf_map_lookup_elem(bpf_map__fd(data_map), &zero, result);
if (CHECK(ret, "get_result",
"failed to get output data: %d\n", ret))
goto out;
for (i = 0; i < prog_cnt; i++) {
if (CHECK(result[i] != 1, "result",
"fexit_bpf2bpf result[%d] failed err %llu\n",
i, result[i]))
goto out;
result[i] = 0;
}
if (reset) {
ret = bpf_map_update_elem(bpf_map__fd(data_map), &zero, result, 0);
if (CHECK(ret, "reset_result", "failed to reset result\n"))
goto out;
}
ret = 0;
out:
free(result);
return ret;
}
static void test_fexit_bpf2bpf_common(const char *obj_file,
const char *target_obj_file,
int prog_cnt,
const char **prog_name,
bool run_prog,
test_cb cb)
{
struct bpf_object *obj = NULL, *tgt_obj;
__u32 tgt_prog_id, info_len;
struct bpf_prog_info prog_info = {};
struct bpf_program **prog = NULL, *p;
struct bpf_link **link = NULL;
int err, tgt_fd, i;
struct btf *btf;
LIBBPF_OPTS(bpf_test_run_opts, topts,
.data_in = &pkt_v6,
.data_size_in = sizeof(pkt_v6),
.repeat = 1,
);
err = bpf_prog_test_load(target_obj_file, BPF_PROG_TYPE_UNSPEC,
&tgt_obj, &tgt_fd);
if (!ASSERT_OK(err, "tgt_prog_load"))
return;
info_len = sizeof(prog_info);
err = bpf_prog_get_info_by_fd(tgt_fd, &prog_info, &info_len);
if (!ASSERT_OK(err, "tgt_fd_get_info"))
goto close_prog;
tgt_prog_id = prog_info.id;
btf = bpf_object__btf(tgt_obj);
link = calloc(sizeof(struct bpf_link *), prog_cnt);
if (!ASSERT_OK_PTR(link, "link_ptr"))
goto close_prog;
prog = calloc(sizeof(struct bpf_program *), prog_cnt);
if (!ASSERT_OK_PTR(prog, "prog_ptr"))
goto close_prog;
obj = bpf_object__open_file(obj_file, NULL);
if (!ASSERT_OK_PTR(obj, "obj_open"))
goto close_prog;
bpf_object__for_each_program(p, obj) {
err = bpf_program__set_attach_target(p, tgt_fd, NULL);
ASSERT_OK(err, "set_attach_target");
}
err = bpf_object__load(obj);
if (!ASSERT_OK(err, "obj_load"))
goto close_prog;
for (i = 0; i < prog_cnt; i++) {
struct bpf_link_info link_info;
struct bpf_program *pos;
const char *pos_sec_name;
const char *tgt_name;
Annotation
- Immediate include surface: `test_progs.h`, `network_helpers.h`, `bpf/btf.h`, `bind4_prog.skel.h`, `freplace_progmap.skel.h`, `xdp_dummy.skel.h`.
- Detected declarations: `function check_data_map`, `function bpf_object__for_each_map`, `function test_fexit_bpf2bpf_common`, `function bpf_object__for_each_program`, `function bpf_object__for_each_program`, `function test_target_no_callees`, `function test_target_yes_callees`, `function test_func_replace`, `function test_func_replace_verify`, `function test_second_attach`.
- 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.