From patchwork Thu Nov 24 15:16:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 25619 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3459291wrr; Thu, 24 Nov 2022 07:22:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf7pHl7V+aZ5TIeBFhQlZ93nwxgMvbUnIfTwL035kHdT81HCRz1T4c7DM9nio8w6Kda2eMLK X-Received: by 2002:a63:c41:0:b0:46f:81cc:5ecb with SMTP id 1-20020a630c41000000b0046f81cc5ecbmr12191576pgm.459.1669303378996; Thu, 24 Nov 2022 07:22:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669303378; cv=none; d=google.com; s=arc-20160816; b=T6er4GLXxLKuCAIxa8iACdlAQtrDKGWbLxZ7JpLGeHR7KATQCJ5jR3BMvtoYJypRNt 9lpH8RKSpIWwXKsaF6VvcKWwB8E0aWyWCrffsrkALB9bhoAQ4PB3/3TsfTz93kDFZb5g ea97AyHU7Xpu5Q3/wOdM6K0gAvcUm2T2Sl7+MosOOQQDv8lwaSUyN3Ovg3XFb+SWoftL yiUchhQHpp1D3UMvr/De6mxdVTh91KJjWuD3KDXCujWQx5AjZnXj2s5GDEBxddtYPRis QQAcT048FdQR3jQb7CaCOydIjbjV3cXpIe75K+YvCkSKTHDOXtmzntmcFJOGYsmkMz21 Vb4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=boFPFiLPbdkddr+SwOKpAMOQtmzRdgMD7Ts21Pm6sEE=; b=Zt2egFu8IOgFNX3ovfCOWAAUiuiu48ZlQ2WNj3TAhHaGqwNN+xsZbRtTlIQUCoi7gB ZooFjfm0DSyRf62I9N42ks/0RNvEaSwOfSc6w1/o1ug1YNMVIll/cTcTaFb43GSFZ0od gud4CMDoLk9Qbv4mZ/R3b5f/kVGzxCCr5tUzTxflvjDeMEJdv/givMumjxP0oK1QcTTX FcQ8TCXia8qc71nr573YckMU4d3ldwc9NVUlpFp25KU7MI8onV71NCZBjdsQTnHyJpgr u3kG+166rnhboi3fbs0KxKZVSG+0fW2soiZuA6lShFndDpOzTHgeI3LfvORmou9sZmWN AUPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FGa9lY7y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n5-20020a632705000000b0043c3f90f7c8si1702063pgn.655.2022.11.24.07.22.46; Thu, 24 Nov 2022 07:22:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FGa9lY7y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230023AbiKXPTP (ORCPT + 99 others); Thu, 24 Nov 2022 10:19:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230014AbiKXPTC (ORCPT ); Thu, 24 Nov 2022 10:19:02 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63B2016F0D8 for ; Thu, 24 Nov 2022 07:16:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669302987; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=boFPFiLPbdkddr+SwOKpAMOQtmzRdgMD7Ts21Pm6sEE=; b=FGa9lY7yciN1GLkOtb6bFRO79BFGrdab744ihP2FX6NYFU/NstHXCZoZyqTau2IV3uOmTz xKOugymcFAiHVP5t9JMu5d+h9DnYmn5f1l//NpReh5e7hOQkT/fC7ypHRpxUkrc+3gicyr 7jT2sTgbUGCRGjdwmOlTNCu1qEELuwA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-67-MQYtX7HwMFyrXd4icQ2u4g-1; Thu, 24 Nov 2022 10:16:26 -0500 X-MC-Unique: MQYtX7HwMFyrXd4icQ2u4g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BF918185A78B; Thu, 24 Nov 2022 15:16:25 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.193.200]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0BB6040C2064; Thu, 24 Nov 2022 15:16:23 +0000 (UTC) From: Benjamin Tissoires To: Greg KH , Jiri Kosina , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Dmitry Torokhov Cc: Tero Kristo , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Benjamin Tissoires Subject: [RFC hid v1 08/10] selftests: hid: add XK-24 tests Date: Thu, 24 Nov 2022 16:16:01 +0100 Message-Id: <20221124151603.807536-9-benjamin.tissoires@redhat.com> In-Reply-To: <20221124151603.807536-1-benjamin.tissoires@redhat.com> References: <20221124151603.807536-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750391460196961422?= X-GMAIL-MSGID: =?utf-8?q?1750391460196961422?= 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 --- 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) {