tools/testing/selftests/hid/hid_bpf.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/hid/hid_bpf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/hid/hid_bpf.c- Extension
.c- Size
- 23492 bytes
- Lines
- 912
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
hid.skel.hhid_common.hbpf/bpf.h
Detected Declarations
struct hid_hw_request_syscall_argsstruct test_programfunction detach_bpffunction load_programsfunction libbpf_print_fnfunction main
Annotated Snippet
struct hid_hw_request_syscall_args {
__u8 data[10];
unsigned int hid;
int retval;
size_t size;
enum hid_report_type type;
__u8 request_type;
};
FIXTURE(hid_bpf) {
struct uhid_device hid;
int hidraw_fd;
struct hid *skel;
struct bpf_link *hid_links[3]; /* max number of programs loaded in a single test */
};
static void detach_bpf(FIXTURE_DATA(hid_bpf) * self)
{
int i;
if (self->hidraw_fd)
close(self->hidraw_fd);
self->hidraw_fd = 0;
if (!self->skel)
return;
hid__detach(self->skel);
for (i = 0; i < ARRAY_SIZE(self->hid_links); i++) {
if (self->hid_links[i])
bpf_link__destroy(self->hid_links[i]);
}
hid__destroy(self->skel);
self->skel = NULL;
}
FIXTURE_TEARDOWN(hid_bpf) {
void *uhid_err;
uhid_destroy(_metadata, &self->hid);
detach_bpf(self);
pthread_join(self->hid.tid, &uhid_err);
}
#define TEARDOWN_LOG(fmt, ...) do { \
TH_LOG(fmt, ##__VA_ARGS__); \
hid_bpf_teardown(_metadata, self, variant); \
} while (0)
FIXTURE_SETUP(hid_bpf)
{
int err;
err = setup_uhid(_metadata, &self->hid, BUS_USB, 0x0001, 0x0a36, rdesc, sizeof(rdesc));
ASSERT_OK(err);
}
struct test_program {
const char *name;
int insert_head;
};
#define LOAD_PROGRAMS(progs) \
load_programs(progs, ARRAY_SIZE(progs), _metadata, self, variant)
#define LOAD_BPF \
load_programs(NULL, 0, _metadata, self, variant)
static void load_programs(const struct test_program programs[],
const size_t progs_count,
struct __test_metadata *_metadata,
FIXTURE_DATA(hid_bpf) * self,
const FIXTURE_VARIANT(hid_bpf) * variant)
{
struct bpf_map *iter_map;
int err = -EINVAL;
ASSERT_LE(progs_count, ARRAY_SIZE(self->hid_links))
TH_LOG("too many programs are to be loaded");
/* open the bpf file */
self->skel = hid__open();
ASSERT_OK_PTR(self->skel) TEARDOWN_LOG("Error while calling hid__open");
for (int i = 0; i < progs_count; i++) {
struct bpf_program *prog;
struct bpf_map *map;
int *ops_hid_id;
prog = bpf_object__find_program_by_name(*self->skel->skeleton->obj,
programs[i].name);
ASSERT_OK_PTR(prog) TH_LOG("can not find program by name '%s'", programs[i].name);
Annotation
- Immediate include surface: `hid.skel.h`, `hid_common.h`, `bpf/bpf.h`.
- Detected declarations: `struct hid_hw_request_syscall_args`, `struct test_program`, `function detach_bpf`, `function load_programs`, `function libbpf_print_fn`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.