summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/hid/hid_bpf.c
AgeCommit message (Collapse)AuthorFilesLines
2024-04-10selftests/hid: add tests for hid_bpf_input_reportBenjamin Tissoires1-2/+47
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>
2024-04-10selftests/hid: Add test for hid_bpf_hw_output_reportBenjamin Tissoires1-0/+63
This time we need to ensure uhid receives it, thus the new mutex and condition. Link: https://lore.kernel.org/r/20240315-b4-hid-bpf-new-funcs-v4-4-079c282469d3@kernel.org Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
2023-01-19selftests: hid: enforce new attach APIBenjamin Tissoires1-5/+1
Now that the new API for hid_bpf_attach_prog() is in place, ensure we get an fd when calling this function. And remove the fallback code. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2023-01-19selftests: hid: prepare tests for HID_BPF API changeBenjamin Tissoires1-4/+25
We plan on changing the return value of hid_bpf_attach_prog(). Instead of returning an error code, it will return an fd to a bpf_link. This bpf_link is responsible for the binding between the bpf program and the hid device. Add a fallback mechanism to not break bisections by pinning the program when we run this test against the non changed kernel. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2023-01-19selftests: hid: ensure the program is correctly pinnedBenjamin Tissoires1-1/+2
Turns out that if bpffs was not mounted, the test was silently passing. So ensure it passes by checking the mount command result. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2023-01-19selftests: hid: attach/detach 2 bpf programs, not just oneBenjamin Tissoires1-1/+7
Add a second BPF program to attach to the device, as the development of this feature showed that we also need to ensure we can detach multiple programs to a device (hid_bpf_link->hid_table_index was actually not set initially, and this lead to any BPF program not being released except for the first one). Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2022-11-15selftests/hid: Add a test for BPF_F_INSERT_HEADBenjamin Tissoires1-0/+43
Insert 3 programs to check that we are doing the correct thing: '2', '1', '3' are inserted, but '1' is supposed to be executed first. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2022-11-15selftests/hid: add report descriptor fixup testsBenjamin Tissoires1-0/+32
Simple report descriptor override in HID: replace part of the report descriptor from a static definition in the bpf kernel program. Note that this test should be run last because we disconnect/reconnect the device, meaning that it changes the overall uhid device. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2022-11-15selftests/hid: add tests for bpf_hid_hw_requestBenjamin Tissoires1-1/+55
Add tests for the newly implemented function. We test here only the GET_REPORT part because the other calls are pure HID protocol and won't infer the result of the test of the bpf hook. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2022-11-15selftests/hid: add test to change the report sizeBenjamin Tissoires1-0/+41
Use a different report with a bigger size and ensures we are doing things properly. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2022-11-15selftests: add tests for the HID-bpf initial implementationBenjamin Tissoires1-0/+675
The tests are pretty basic: - create a virtual uhid device that no userspace will like (to not mess up the running system) - attach a BPF prog to it - open the matching hidraw node - inject one event and check: * that the BPF program can do something on the event stream * can modify the event stream - add another test where we attach/detach BPF programs to see if we get errors Note: the Makefile is extracted from selftests/bpf so we can rebuild the libbpf and bpftool components from the current kernel tree without relying on system installed components. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>