tools/testing/selftests/bpf/prog_tests/module_attach.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/module_attach.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/module_attach.c- Extension
.c- Size
- 5052 bytes
- Lines
- 195
- 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.hstdbool.htest_module_attach.skel.htesting_helpers.h
Detected Declarations
function trigger_module_test_writablefunction test_module_attach_progfunction test_module_attach_writablefunction test_module_attach_detachfunction test_module_attach
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2020 Facebook */
#include <test_progs.h>
#include <stdbool.h>
#include "test_module_attach.skel.h"
#include "testing_helpers.h"
static const char * const read_tests[] = {
"handle_raw_tp",
"handle_tp_btf",
"handle_fentry",
"handle_fentry_explicit",
"handle_fmod_ret",
};
static const char * const detach_tests[] = {
"handle_fentry",
"handle_fexit",
"kprobe_multi",
};
static const int READ_SZ = 456;
static const int WRITE_SZ = 457;
static int trigger_module_test_writable(int *val)
{
int fd, err;
char buf[65];
ssize_t rd;
fd = open(BPF_TESTMOD_TEST_FILE, O_RDONLY);
err = -errno;
if (!ASSERT_GE(fd, 0, "testmode_file_open"))
return err;
rd = read(fd, buf, sizeof(buf) - 1);
err = -errno;
if (!ASSERT_GT(rd, 0, "testmod_file_rd_val")) {
close(fd);
return err;
}
buf[rd] = '\0';
*val = strtol(buf, NULL, 0);
close(fd);
return 0;
}
static void test_module_attach_prog(const char *prog_name, int sz,
const char *attach_target, int ret)
{
struct test_module_attach *skel;
struct bpf_program *prog;
int err;
skel = test_module_attach__open();
if (!ASSERT_OK_PTR(skel, "module_attach open"))
return;
prog = bpf_object__find_program_by_name(skel->obj, prog_name);
if (!ASSERT_OK_PTR(prog, "module_attach find_program"))
goto cleanup;
bpf_program__set_autoload(prog, true);
if (attach_target) {
err = bpf_program__set_attach_target(prog, 0, attach_target);
if (!ASSERT_OK(err, attach_target))
goto cleanup;
}
err = test_module_attach__load(skel);
if (!ASSERT_OK(err, "module_attach load"))
goto cleanup;
err = test_module_attach__attach(skel);
if (!ASSERT_OK(err, "module_attach attach"))
goto cleanup;
if (sz) {
/* trigger both read and write though each test uses only one */
ASSERT_OK(trigger_module_test_read(sz), "trigger_read");
ASSERT_OK(trigger_module_test_write(sz), "trigger_write");
ASSERT_EQ(skel->bss->sz, sz, prog_name);
}
if (ret)
ASSERT_EQ(skel->bss->retval, ret, "ret");
Annotation
- Immediate include surface: `test_progs.h`, `stdbool.h`, `test_module_attach.skel.h`, `testing_helpers.h`.
- Detected declarations: `function trigger_module_test_writable`, `function test_module_attach_prog`, `function test_module_attach_writable`, `function test_module_attach_detach`, `function test_module_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.