History log of /linux-master/tools/testing/selftests/hid/hid_bpf.c
Revision Date Author Comments
# 6e021d64 13-Jan-2023 Benjamin Tissoires <benjamin.tissoires@redhat.com>

selftests: hid: enforce new attach API

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>


# 2574917a 13-Jan-2023 Benjamin Tissoires <benjamin.tissoires@redhat.com>

selftests: hid: prepare tests for HID_BPF API change

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>


# d9db1bb5 13-Jan-2023 Benjamin Tissoires <benjamin.tissoires@redhat.com>

selftests: hid: ensure the program is correctly pinned

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>


# cea6c4d9 13-Jan-2023 Benjamin Tissoires <benjamin.tissoires@redhat.com>

selftests: hid: attach/detach 2 bpf programs, not just one

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>


# 80e189f2 03-Nov-2022 Benjamin Tissoires <benjamin.tissoires@redhat.com>

selftests/hid: Add a test for BPF_F_INSERT_HEAD

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>


# e8445737 03-Nov-2022 Benjamin Tissoires <benjamin.tissoires@redhat.com>

selftests/hid: add report descriptor fixup tests

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>


# 4f7153cf 03-Nov-2022 Benjamin Tissoires <benjamin.tissoires@redhat.com>

selftests/hid: add tests for bpf_hid_hw_request

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>


# 0330f725 03-Nov-2022 Benjamin Tissoires <benjamin.tissoires@redhat.com>

selftests/hid: add test to change the report size

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>


# dbb60c8a 03-Nov-2022 Benjamin Tissoires <benjamin.tissoires@redhat.com>

selftests: add tests for the HID-bpf initial implementation

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>