All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Tissoires <benjamin.tissoires@redhat.com>
To: Greg KH <gregkh@linuxfoundation.org>,
	Jiri Kosina <jikos@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Tero Kristo <tero.kristo@linux.intel.com>,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
	netdev@vger.kernel.org, bpf@vger.kernel.org,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>
Subject: [RFC hid v1 08/10] selftests: hid: add XK-24 tests
Date: Thu, 24 Nov 2022 16:16:01 +0100	[thread overview]
Message-ID: <20221124151603.807536-9-benjamin.tissoires@redhat.com> (raw)
In-Reply-To: <20221124151603.807536-1-benjamin.tissoires@redhat.com>

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 --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)
 {
-- 
2.38.1


  parent reply	other threads:[~2022-11-24 15:19 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-24 15:15 [RFC hid v1 00/10] HID-BPF: add support for in-tree BPF programs Benjamin Tissoires
2022-11-24 15:15 ` [RFC hid v1 01/10] bpftool: generate json output of skeletons Benjamin Tissoires
2022-11-30 23:05   ` Andrii Nakryiko
2022-12-01 14:22     ` Benjamin Tissoires
2022-12-01 18:21       ` Andrii Nakryiko
2022-11-24 15:15 ` [RFC hid v1 02/10] WIP: bpf: allow to pin programs from the kernel when bpffs is mounted Benjamin Tissoires
2022-11-24 15:15 ` [RFC hid v1 03/10] HID: add a tool to convert a bpf source into a generic bpf loader Benjamin Tissoires
2022-11-24 15:15 ` [RFC hid v1 04/10] HID: add the bpf loader that can attach a generic hid-bpf program Benjamin Tissoires
2022-11-25  2:48   ` kernel test robot
2022-11-25  2:48   ` kernel test robot
2022-11-25  8:01   ` kernel test robot
2022-11-24 15:15 ` [RFC hid v1 05/10] HID: add report descriptor override for the X-Keys XK24 Benjamin Tissoires
2022-11-24 15:15 ` [RFC hid v1 06/10] selftests: hid: add vmtest.sh Benjamin Tissoires
2022-11-24 15:16 ` [RFC hid v1 07/10] selftests: hid: Add a variant parameter so we can emulate specific devices Benjamin Tissoires
2022-11-24 15:16 ` Benjamin Tissoires [this message]
2022-11-24 15:16 ` [RFC hid v1 09/10] selftests: hid: ensure the program is correctly pinned Benjamin Tissoires
2022-11-24 15:16 ` [RFC hid v1 10/10] wip: vmtest aarch64 Benjamin Tissoires

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221124151603.807536-9-benjamin.tissoires@redhat.com \
    --to=benjamin.tissoires@redhat.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=tero.kristo@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.