Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp884921rdb; Wed, 6 Dec 2023 02:47:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFBCgu5t5GQE1FK7VbCjJrRJ99iQHIbTrUMkhX4j0u2tDGYAF7pBB648t8Y7WJpH0LUPB/I X-Received: by 2002:a05:6358:5e11:b0:170:2c2d:9d8f with SMTP id q17-20020a0563585e1100b001702c2d9d8fmr894401rwn.1.1701859654654; Wed, 06 Dec 2023 02:47:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701859654; cv=none; d=google.com; s=arc-20160816; b=GwGxg4z24MAyeGzu6hJcQxxORMFgA6PwbMoB0c2eZIftZHw+CPgkXAT/pP5Kpwf3yb zDCD4gmOXNN/Zp4ksP2PENCC+iBacJL5pM60LbGv8ig4l7hwN62j6H2I1sgC1aQIewPg j8fZg0+xBefhYUkwmJTgpHc5uH7tCYQnH1raYc5J78O93DUCbKNLexckqr+UfgaVVljB 6tAIu8VFf24Y29tCCyZTlgc+SztFhy5vTLJF/rxzwrT3lvkCEhPlt57/gVF9EjspH/du qMIZGXSMO07Yj9TatjtQgOqZa0bkxnY1GfkPwNQ5CMmomqsapo3Oa8gH7iQN62xKg8jt nIIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=ek1Ci/QTIplTFWx51W7OIFpsJ521uVozys+W1mcmnAo=; fh=M/4CRKlsQR53kOvbvsHfGDOrpcvBUt/h3Rh4tB3zkdA=; b=mLAEgQbGrqfNUslpdZyxSLGrMCIxfIQxuyuJUyZq/DZKpBj0zYo9UcswXJzo9QP8kB 4YJLrsXfnUxJWuL6iuNk6eyXvWPC/5DbbgmtS/R53bt+aKYSIIkgWB5YqnFWBJ2GulxS g260NJB/3efdQv6dQ5vbr/UB3uAGh9IzYov8/QW1UeoxVUbeAWcsccR0yWSPfQtpvWW2 Ni6WwHFuzy1ZztU0vrTY/lGuHQW2Uz8LxVQCkB1pAEBN7P9oKfjBxfWGGDm0zjTo+RIu bsZwbCyc5+CNPNsoE80NfpNnMvA8RPN5QTsmd+PNHV6V9JPkmRJow0meUBBtkR+JJwt0 VLUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TD66XrJ6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id u25-20020a056a00099900b006cdd83f45c0si2106388pfg.229.2023.12.06.02.47.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 02:47:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TD66XrJ6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 250E480C2553; Wed, 6 Dec 2023 02:47:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377791AbjLFKrP (ORCPT + 99 others); Wed, 6 Dec 2023 05:47:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377602AbjLFKqo (ORCPT ); Wed, 6 Dec 2023 05:46:44 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1739D19A8 for ; Wed, 6 Dec 2023 02:46:30 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB92EC433CC; Wed, 6 Dec 2023 10:46:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701859589; bh=OoqmC4Pw/8fhP04WnZybsenjId387ZEbXBhKeYmIoVg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TD66XrJ6uWb0gclXQTkAOg8MGIoSskV1kXdPJ0kKYuAFOklGGJdste5qwydlxPkFu kUpxuwOAN0nL9OdyD4Gx5B38Q5G/aIpZoLp7XzuOcQvoQRK6UNuwDh9WxI0BJOVQFV MPCU9bt4lSBN9CTbr/87u4Y79BbaOSYMvv+4uYzgMnlVdj3TSm4vM2q0mYRfI/CDWh pW/ErROcD66aWFLAxzha2IjcwL34v16/BF/gX3bSw9qB8SRgF8bEZBhyYXXqcXLTQY SxkCW1P6EBMuaIg60riyf11S3CaPiZ3/usbaSCgKo0hm8U2t6GPM/XCnY2D5ZKTqSt +y0n/PIXMILdA== From: Benjamin Tissoires Date: Wed, 06 Dec 2023 11:46:02 +0100 Subject: [PATCH v2 11/15] selftests/hid: tablets: convert the primary button tests MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231206-wip-selftests-v2-11-c0350c2f5986@kernel.org> References: <20231206-wip-selftests-v2-0-c0350c2f5986@kernel.org> In-Reply-To: <20231206-wip-selftests-v2-0-c0350c2f5986@kernel.org> To: Jiri Kosina , Benjamin Tissoires , Shuah Khan , Peter Hutterer Cc: linux-input@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1701859565; l=8645; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=OoqmC4Pw/8fhP04WnZybsenjId387ZEbXBhKeYmIoVg=; b=vk/1M8DMdVlisGfM3sduSPeaB4MJTn23FrM+264q/aGiNwvU1IAHPB35PHp3RnjmU3wYLEAY6 wJ+lb++ahWFBjbgSTF693T8SGzV5U6ygFCtKz+08Id6Y7/iCwO+DI53 X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 06 Dec 2023 02:47:31 -0800 (PST) We get more descriptive in what we are doing, and also get more information of what is actually being tested. Instead of having a non exhaustive button changes that are semi-randomly done, we can describe all the states we want to test. Reviewed-by: Peter Hutterer Signed-off-by: Benjamin Tissoires --- no changes in v2 --- tools/testing/selftests/hid/tests/test_tablet.py | 160 +++++++++-------------- 1 file changed, 65 insertions(+), 95 deletions(-) diff --git a/tools/testing/selftests/hid/tests/test_tablet.py b/tools/testing/selftests/hid/tests/test_tablet.py index a77534f23c75..20a7a7fdcd9d 100644 --- a/tools/testing/selftests/hid/tests/test_tablet.py +++ b/tools/testing/selftests/hid/tests/test_tablet.py @@ -317,6 +317,55 @@ class PenState(Enum): ), } + @staticmethod + def legal_transitions_with_primary_button() -> Dict[str, Tuple["PenState", ...]]: + """We revisit the Windows Pen Implementation state machine: + we now have a primary button. + """ + return { + "hover-button": (PenState.PEN_IS_IN_RANGE_WITH_BUTTON,), + "hover-button -> out-of-range": ( + PenState.PEN_IS_IN_RANGE_WITH_BUTTON, + PenState.PEN_IS_OUT_OF_RANGE, + ), + "in-range -> button-press": ( + PenState.PEN_IS_IN_RANGE, + PenState.PEN_IS_IN_RANGE_WITH_BUTTON, + ), + "in-range -> button-press -> button-release": ( + PenState.PEN_IS_IN_RANGE, + PenState.PEN_IS_IN_RANGE_WITH_BUTTON, + PenState.PEN_IS_IN_RANGE, + ), + "in-range -> touch -> button-press -> button-release": ( + PenState.PEN_IS_IN_RANGE, + PenState.PEN_IS_IN_CONTACT, + PenState.PEN_IS_IN_CONTACT_WITH_BUTTON, + PenState.PEN_IS_IN_CONTACT, + ), + "in-range -> touch -> button-press -> release -> button-release": ( + PenState.PEN_IS_IN_RANGE, + PenState.PEN_IS_IN_CONTACT, + PenState.PEN_IS_IN_CONTACT_WITH_BUTTON, + PenState.PEN_IS_IN_RANGE_WITH_BUTTON, + PenState.PEN_IS_IN_RANGE, + ), + "in-range -> button-press -> touch -> release -> button-release": ( + PenState.PEN_IS_IN_RANGE, + PenState.PEN_IS_IN_RANGE_WITH_BUTTON, + PenState.PEN_IS_IN_CONTACT_WITH_BUTTON, + PenState.PEN_IS_IN_RANGE_WITH_BUTTON, + PenState.PEN_IS_IN_RANGE, + ), + "in-range -> button-press -> touch -> button-release -> release": ( + PenState.PEN_IS_IN_RANGE, + PenState.PEN_IS_IN_RANGE_WITH_BUTTON, + PenState.PEN_IS_IN_CONTACT_WITH_BUTTON, + PenState.PEN_IS_IN_CONTACT, + PenState.PEN_IS_IN_RANGE, + ), + } + @staticmethod def tolerated_transitions() -> Dict[str, Tuple["PenState", ...]]: """This is not adhering to the Windows Pen Implementation state machine @@ -671,6 +720,22 @@ class BaseTest: reasons.""" self._test_states(state_list, scribble) + @pytest.mark.skip_if_uhdev( + lambda uhdev: "Barrel Switch" not in uhdev.fields, + "Device not compatible, missing Barrel Switch usage", + ) + @pytest.mark.parametrize("scribble", [True, False], ids=["scribble", "static"]) + @pytest.mark.parametrize( + "state_list", + [ + pytest.param(v, id=k) + for k, v in PenState.legal_transitions_with_primary_button().items() + ], + ) + def test_valid_primary_button_pen_states(self, state_list, scribble): + """Rework the transition state machine by adding the primary button.""" + self._test_states(state_list, scribble) + @pytest.mark.skip_if_uhdev( lambda uhdev: "Invert" not in uhdev.fields, "Device not compatible, missing Invert usage", @@ -728,101 +793,6 @@ class BaseTest: state machine.""" self._test_states(state_list, scribble) - @pytest.mark.skip_if_uhdev( - lambda uhdev: "Barrel Switch" not in uhdev.fields, - "Device not compatible, missing Barrel Switch usage", - ) - def test_primary_button(self): - """Primary button (stylus) pressed, reports as pressed even while hovering. - Actual reporting from the device: hid=TIPSWITCH,BARRELSWITCH,INRANGE (code=TOUCH,STYLUS,PEN): - { 0, 0, 1 } <- hover - { 0, 1, 1 } <- primary button pressed - { 0, 1, 1 } <- liftoff - { 0, 0, 0 } <- leaves - """ - - uhdev = self.uhdev - evdev = uhdev.get_evdev() - - p = Pen(50, 60) - p.inrange = True - events = self.post(uhdev, p) - assert libevdev.InputEvent(libevdev.EV_KEY.BTN_TOOL_PEN, 1) in events - assert evdev.value[libevdev.EV_ABS.ABS_X] == 50 - assert evdev.value[libevdev.EV_ABS.ABS_Y] == 60 - assert not evdev.value[libevdev.EV_KEY.BTN_STYLUS] - - p.barrelswitch = True - events = self.post(uhdev, p) - assert libevdev.InputEvent(libevdev.EV_KEY.BTN_STYLUS, 1) in events - - p.x += 1 - p.y -= 1 - events = self.post(uhdev, p) - assert len(events) == 3 # X, Y, SYN - assert libevdev.InputEvent(libevdev.EV_ABS.ABS_X, 51) in events - assert libevdev.InputEvent(libevdev.EV_ABS.ABS_Y, 59) in events - - p.barrelswitch = False - events = self.post(uhdev, p) - assert libevdev.InputEvent(libevdev.EV_KEY.BTN_STYLUS, 0) in events - - p.inrange = False - events = self.post(uhdev, p) - assert libevdev.InputEvent(libevdev.EV_KEY.BTN_TOOL_PEN, 0) in events - - @pytest.mark.skip_if_uhdev( - lambda uhdev: "Barrel Switch" not in uhdev.fields, - "Device not compatible, missing Barrel Switch usage", - ) - def test_contact_primary_button(self): - """Primary button (stylus) pressed, reports as pressed even while hovering. - Actual reporting from the device: hid=TIPSWITCH,BARRELSWITCH,INRANGE (code=TOUCH,STYLUS,PEN): - { 0, 0, 1 } <- hover - { 0, 1, 1 } <- primary button pressed - { 1, 1, 1 } <- touch-down - { 1, 1, 1 } <- still touch, scribble on the screen - { 0, 1, 1 } <- liftoff - { 0, 0, 0 } <- leaves - """ - - uhdev = self.uhdev - evdev = uhdev.get_evdev() - - p = Pen(50, 60) - p.inrange = True - events = self.post(uhdev, p) - assert libevdev.InputEvent(libevdev.EV_KEY.BTN_TOOL_PEN, 1) in events - assert evdev.value[libevdev.EV_ABS.ABS_X] == 50 - assert evdev.value[libevdev.EV_ABS.ABS_Y] == 60 - assert not evdev.value[libevdev.EV_KEY.BTN_STYLUS] - - p.barrelswitch = True - events = self.post(uhdev, p) - assert libevdev.InputEvent(libevdev.EV_KEY.BTN_STYLUS, 1) in events - - p.tipswitch = True - events = self.post(uhdev, p) - assert libevdev.InputEvent(libevdev.EV_KEY.BTN_TOUCH, 1) in events - assert evdev.value[libevdev.EV_KEY.BTN_STYLUS] - - p.x += 1 - p.y -= 1 - events = self.post(uhdev, p) - assert len(events) == 3 # X, Y, SYN - assert libevdev.InputEvent(libevdev.EV_ABS.ABS_X, 51) in events - assert libevdev.InputEvent(libevdev.EV_ABS.ABS_Y, 59) in events - - p.tipswitch = False - events = self.post(uhdev, p) - assert libevdev.InputEvent(libevdev.EV_KEY.BTN_TOUCH, 0) in events - - p.barrelswitch = False - p.inrange = False - events = self.post(uhdev, p) - assert libevdev.InputEvent(libevdev.EV_KEY.BTN_TOOL_PEN, 0) in events - assert libevdev.InputEvent(libevdev.EV_KEY.BTN_STYLUS, 0) in events - class GXTP_pen(PenDigitizer): def event(self, pen): -- 2.41.0