diff mbox series

[RFC,hid,v1,08/10] selftests: hid: add XK-24 tests

Message ID 20221124151603.807536-9-benjamin.tissoires@redhat.com (mailing list archive)
State RFC
Headers show
Series HID-BPF: add support for in-tree BPF programs | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply, async
bpf/vmtest-bpf-PR success PR summary
bpf/vmtest-bpf-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-VM_Test-3 success Logs for build for aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-4 success Logs for build for s390x with gcc
bpf/vmtest-bpf-VM_Test-5 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-VM_Test-6 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-7 success Logs for llvm-toolchain
bpf/vmtest-bpf-VM_Test-8 success Logs for set-matrix
bpf/vmtest-bpf-VM_Test-9 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-10 success Logs for test_maps on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-11 pending Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-VM_Test-12 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-13 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-14 fail Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-15 fail Logs for test_progs on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-16 pending Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-VM_Test-17 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-18 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-19 fail Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-20 fail Logs for test_progs_no_alu32 on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-21 fail Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-VM_Test-22 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-23 fail Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-24 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-25 success Logs for test_progs_no_alu32_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-26 pending Logs for test_progs_no_alu32_parallel on s390x with gcc
bpf/vmtest-bpf-VM_Test-27 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-28 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-29 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-30 success Logs for test_progs_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-31 pending Logs for test_progs_parallel on s390x with gcc
bpf/vmtest-bpf-VM_Test-32 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-33 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-34 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-35 success Logs for test_verifier on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-36 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-VM_Test-37 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-38 success Logs for test_verifier on x86_64 with llvm-16

Commit Message

Benjamin Tissoires Nov. 24, 2022, 3:16 p.m. UTC
this is the first device to be added in the kernel with a bpf program
associated, so we better use it to ensure we get the things right.

We define another fixture that will reuse everything from hid_bpf except
for the variant parameters. And then we can use that easily in a new
dedicated test.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 tools/testing/selftests/hid/hid_bpf.c | 72 +++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
diff mbox series

Patch

diff --git a/tools/testing/selftests/hid/hid_bpf.c b/tools/testing/selftests/hid/hid_bpf.c
index 738ddb2c6a62..4bdd1cfa7d13 100644
--- a/tools/testing/selftests/hid/hid_bpf.c
+++ b/tools/testing/selftests/hid/hid_bpf.c
@@ -520,6 +520,51 @@  FIXTURE_SETUP(hid_bpf)
 	ASSERT_EQ(0, err) TEARDOWN_LOG("could not start udev listener: %d", err);
 }
 
+static unsigned char xk24_rdesc[] = {
+	0x05, 0x0c,                    // Usage Page (Consumer Devices)       0
+	0x09, 0x01,                    // Usage (Consumer Control)            2
+	0xa1, 0x01,                    // Collection (Application)            4
+	0xa1, 0x02,                    //  Collection (Logical)               6
+	0x05, 0x08,                    //   Usage Page (LEDs)                 8
+	0x09, 0x4b,                    //   Usage (Generic Indicator)         10
+	0x75, 0x08,                    //   Report Size (8)                   12
+	0x95, 0x23,                    //   Report Count (35)                 14
+	0x91, 0x02,                    //   Output (Data,Var,Abs)             16
+	0xc0,                          //  End Collection                     18
+	0xa1, 0x02,                    //  Collection (Logical)               19
+	0x05, 0x09,                    //   Usage Page (Button)               21
+	0x09, 0x4b,                    //   Usage (Vendor Usage 0x4b)         23
+	0x75, 0x08,                    //   Report Size (8)                   25
+	0x95, 0x20,                    //   Report Count (32)                 27
+	0x81, 0x02,                    //   Input (Data,Var,Abs)              29
+	0xc0,                          //  End Collection                     31
+	0xc0,                          // End Collection                      32
+};
+
+#define _test_data_hid_bpf_xkeys _test_data_hid_bpf
+#define _fixture_variant_hid_bpf_xkeys _fixture_variant_hid_bpf
+FIXTURE(hid_bpf_xkeys);
+FIXTURE_VARIANT(hid_bpf_xkeys);
+FIXTURE_VARIANT_ADD(hid_bpf_xkeys, xk24) {
+	.id = {
+		.bus = BUS_USB,
+		.vendor = 0x05F3,
+		.product = 0x0405,
+		.version = 0,
+		.rdesc = xk24_rdesc,
+		.rdesc_sz = sizeof(xk24_rdesc),
+	},
+};
+
+FIXTURE_SETUP(hid_bpf_xkeys)
+{
+	hid_bpf_setup(_metadata, self, variant);
+}
+FIXTURE_TEARDOWN(hid_bpf_xkeys)
+{
+	hid_bpf_teardown(_metadata, self, variant);
+}
+
 struct test_program {
 	const char *name;
 	int insert_head;
@@ -846,6 +891,33 @@  TEST_F(hid_bpf, test_rdesc_fixup)
 	ASSERT_EQ(rpt_desc.value[4], 0x42);
 }
 
+/*
+ * Attach an emulated XK24, which has an in-tree eBPF program, and ensure
+ * we got it loaded.
+ */
+TEST_F(hid_bpf_xkeys, test_xk24)
+{
+	struct hidraw_report_descriptor rpt_desc = {0};
+	int err, desc_size;
+
+	/* open the kernel provided hidraw node */
+	self->hidraw_fd = open_hidraw(self->dev_id, &variant->id);
+	ASSERT_GE(self->hidraw_fd, 0) TH_LOG("open_hidraw");
+
+	/* read the exposed report descriptor from hidraw */
+	err = ioctl(self->hidraw_fd, HIDIOCGRDESCSIZE, &desc_size);
+	ASSERT_GE(err, 0) TH_LOG("error while reading HIDIOCGRDESCSIZE: %d", err);
+
+	/* ensure the new size of the rdesc is bigger than the old one */
+	ASSERT_GT(desc_size, sizeof(xk24_rdesc));
+
+	rpt_desc.size = desc_size;
+	err = ioctl(self->hidraw_fd, HIDIOCGRDESC, &rpt_desc);
+	ASSERT_GE(err, 0) TH_LOG("error while reading HIDIOCGRDESC: %d", err);
+
+	ASSERT_EQ(rpt_desc.value[21], 0x09);
+}
+
 static int libbpf_print_fn(enum libbpf_print_level level,
 			   const char *format, va_list args)
 {