diff options
author | Benjamin Tissoires <bentiss@kernel.org> | 2024-03-15 15:44:43 +0100 |
---|---|---|
committer | Benjamin Tissoires <bentiss@kernel.org> | 2024-04-10 16:38:37 +0200 |
commit | 2c0e8ced7d4bf746923fc424415844d695f07808 (patch) | |
tree | 1f66356c79242fa9b030d75c07f754e765b107bd /tools/testing/selftests/hid/progs | |
parent | 9be50ac30a83896a753ab9f64e941763bb7900be (diff) |
selftests/hid: add tests for hid_bpf_input_report
Usual way of testing, we call the function and ensures we receive
the event
Link: https://lore.kernel.org/r/20240315-b4-hid-bpf-new-funcs-v4-6-079c282469d3@kernel.org
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
Diffstat (limited to 'tools/testing/selftests/hid/progs')
-rw-r--r-- | tools/testing/selftests/hid/progs/hid.c | 22 | ||||
-rw-r--r-- | tools/testing/selftests/hid/progs/hid_bpf_helpers.h | 4 |
2 files changed, 26 insertions, 0 deletions
diff --git a/tools/testing/selftests/hid/progs/hid.c b/tools/testing/selftests/hid/progs/hid.c index 2c2b679a83b1..f67d35def142 100644 --- a/tools/testing/selftests/hid/progs/hid.c +++ b/tools/testing/selftests/hid/progs/hid.c @@ -125,6 +125,28 @@ int hid_user_output_report(struct hid_hw_request_syscall_args *args) return 0; } +SEC("syscall") +int hid_user_input_report(struct hid_hw_request_syscall_args *args) +{ + struct hid_bpf_ctx *ctx; + const size_t size = args->size; + int i, ret = 0; + + if (size > sizeof(args->data)) + return -7; /* -E2BIG */ + + ctx = hid_bpf_allocate_context(args->hid); + if (!ctx) + return -1; /* EPERM check */ + + ret = hid_bpf_input_report(ctx, HID_INPUT_REPORT, args->data, size); + args->retval = ret; + + hid_bpf_release_context(ctx); + + return 0; +} + static const __u8 rdesc[] = { 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ 0x09, 0x32, /* USAGE (Z) */ diff --git a/tools/testing/selftests/hid/progs/hid_bpf_helpers.h b/tools/testing/selftests/hid/progs/hid_bpf_helpers.h index 50c6a0d5765e..9cd56821d0f1 100644 --- a/tools/testing/selftests/hid/progs/hid_bpf_helpers.h +++ b/tools/testing/selftests/hid/progs/hid_bpf_helpers.h @@ -96,5 +96,9 @@ extern int hid_bpf_hw_request(struct hid_bpf_ctx *ctx, enum hid_class_request reqtype) __ksym; extern int hid_bpf_hw_output_report(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz) __ksym; +extern int hid_bpf_input_report(struct hid_bpf_ctx *ctx, + enum hid_report_type type, + __u8 *data, + size_t buf__sz) __ksym; #endif /* __HID_BPF_HELPERS_H */ |