From nobody Sun Feb 8 22:50:14 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12F44181D19; Wed, 10 Apr 2024 17:20:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712769616; cv=none; b=F549auH/I0INfauc6hiivzoJEA5ddRaa5U/X22Kc0TG/xp6xLZfI2q5QrN89h77z6wHSXjjqyW754Z1j2I0MoE48IES/AsjAr8ETc/mgssPVj4n6KXzYtf5DqBBlRRiWQ89FHLxO/C0rOuv1Nv1nSCVsMHHHncbHmNYkD76yN1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712769616; c=relaxed/simple; bh=o7rFwp+LxU5iuTsW+OL7909j23iSbmm85+cUyDXhNaE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tEoT06fQe4bJB7CGESe05M01k2SpJ24ENcJ3AhNmO7VaAE6EsN5AM/bA/PYbMGeyAQrItgzfjovzMuh17kkFXgLCAoDA8fpehW5wjn5rceYy4Y/fUlvQN5bZPda2TCIEf9ggkjgIUH6UaLK+hBQCtRJ4uDGw2/ZnJek+ba+IG0g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tH6y6g7F; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tH6y6g7F" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1823CC43394; Wed, 10 Apr 2024 17:20:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712769615; bh=o7rFwp+LxU5iuTsW+OL7909j23iSbmm85+cUyDXhNaE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=tH6y6g7F+XUok4ibtHpTJSALNEQwUL3j4Mfu1Q2UectpsbvTcYdZ7e6LsEqIxsprw fzQE59HjgEchRAvEEMKP853zXxrN/sYNI6NHFsBhcbPcuDCeKIXIa4LhJ/NM/C28bC Vk1Bq1hXvoMwqfVPcr5oYzGwhITsH2GCVqXsM+OlPvEzZ6jWces0uBcmAkiJMU6iqU Jmqqeb29ZWQQWwAFEQkEa71G9Y5oWMNYInqAbAJ/8fkVGVY0dmzaaV3BE1umfdLxOC q/hHwwyw/8eY/YW7fTAK3wbwDlDatxROQ6xdVvxvw/9KJrstrzjOgeE4N6sAA5pBXy go4k2bLDBIfXg== From: Benjamin Tissoires Date: Wed, 10 Apr 2024 19:19:32 +0200 Subject: [PATCH 12/18] selftests/hid: tablets: reduce the number of pen state Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240410-bpf_sources-v1-12-a8bf16033ef8@kernel.org> References: <20240410-bpf_sources-v1-0-a8bf16033ef8@kernel.org> In-Reply-To: <20240410-bpf_sources-v1-0-a8bf16033ef8@kernel.org> To: Jiri Kosina , Benjamin Tissoires , Shuah Khan , Peter Hutterer Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1712769589; l=22185; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=o7rFwp+LxU5iuTsW+OL7909j23iSbmm85+cUyDXhNaE=; b=t8fmW5bq1Him9BGv7agFyfh6sspCqir2ETCVuUJiRhUvng126egDSzBY/u0P3aEVmjTP6MJ8m HvlUJPOEde8A0qnDSRg8IQHR+3GLUQ+inVoeXhGuPHB2Wr4v4Tf4/K1 X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= All the *_WITH*BUTTON states were almost identical except for the button itself. I need to add a new device with a third button, and adding a bunch of states is going to be quite cumbersome. So convert the `button` parameter of PenState as a boolean, and store which button is the target as an argument to all functions that need it. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/tests/test_tablet.py | 272 +++++++------------= ---- 1 file changed, 81 insertions(+), 191 deletions(-) diff --git a/tools/testing/selftests/hid/tests/test_tablet.py b/tools/testi= ng/selftests/hid/tests/test_tablet.py index 903f19f7cbe9..df1134e5713c 100644 --- a/tools/testing/selftests/hid/tests/test_tablet.py +++ b/tools/testing/selftests/hid/tests/test_tablet.py @@ -44,58 +44,28 @@ class PenState(Enum): We extend it with the various buttons when we need to check them. """ =20 - PEN_IS_OUT_OF_RANGE =3D BtnTouch.UP, None, None - PEN_IS_IN_RANGE =3D BtnTouch.UP, ToolType.PEN, None - PEN_IS_IN_RANGE_WITH_BUTTON =3D BtnTouch.UP, ToolType.PEN, BtnPressed.= PRIMARY_PRESSED - PEN_IS_IN_RANGE_WITH_SECOND_BUTTON =3D ( - BtnTouch.UP, - ToolType.PEN, - BtnPressed.SECONDARY_PRESSED, - ) - PEN_IS_IN_CONTACT =3D BtnTouch.DOWN, ToolType.PEN, None - PEN_IS_IN_CONTACT_WITH_BUTTON =3D ( - BtnTouch.DOWN, - ToolType.PEN, - BtnPressed.PRIMARY_PRESSED, - ) - PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON =3D ( - BtnTouch.DOWN, - ToolType.PEN, - BtnPressed.SECONDARY_PRESSED, - ) - PEN_IS_IN_RANGE_WITH_ERASING_INTENT =3D BtnTouch.UP, ToolType.RUBBER, = None - PEN_IS_IN_RANGE_WITH_ERASING_INTENT_WITH_BUTTON =3D ( - BtnTouch.UP, - ToolType.RUBBER, - BtnPressed.PRIMARY_PRESSED, - ) - PEN_IS_IN_RANGE_WITH_ERASING_INTENT_WITH_SECOND_BUTTON =3D ( - BtnTouch.UP, - ToolType.RUBBER, - BtnPressed.SECONDARY_PRESSED, - ) - PEN_IS_ERASING =3D BtnTouch.DOWN, ToolType.RUBBER, None - PEN_IS_ERASING_WITH_BUTTON =3D ( - BtnTouch.DOWN, - ToolType.RUBBER, - BtnPressed.PRIMARY_PRESSED, - ) - PEN_IS_ERASING_WITH_SECOND_BUTTON =3D ( - BtnTouch.DOWN, - ToolType.RUBBER, - BtnPressed.SECONDARY_PRESSED, - ) - - def __init__(self, touch: BtnTouch, tool: Optional[ToolType], button: = Optional[BtnPressed]): + PEN_IS_OUT_OF_RANGE =3D BtnTouch.UP, None, False + PEN_IS_IN_RANGE =3D BtnTouch.UP, ToolType.PEN, False + PEN_IS_IN_RANGE_WITH_BUTTON =3D BtnTouch.UP, ToolType.PEN, True + PEN_IS_IN_CONTACT =3D BtnTouch.DOWN, ToolType.PEN, False + PEN_IS_IN_CONTACT_WITH_BUTTON =3D BtnTouch.DOWN, ToolType.PEN, True + PEN_IS_IN_RANGE_WITH_ERASING_INTENT =3D BtnTouch.UP, ToolType.RUBBER, = False + PEN_IS_IN_RANGE_WITH_ERASING_INTENT_WITH_BUTTON =3D BtnTouch.UP, ToolT= ype.RUBBER, True + PEN_IS_ERASING =3D BtnTouch.DOWN, ToolType.RUBBER, False + PEN_IS_ERASING_WITH_BUTTON =3D BtnTouch.DOWN, ToolType.RUBBER, True + + def __init__( + self, touch: BtnTouch, tool: Optional[ToolType], button: Optional[= bool] + ): self.touch =3D touch # type: ignore self.tool =3D tool # type: ignore self.button =3D button # type: ignore =20 @classmethod - def from_evdev(cls, evdev) -> "PenState": + def from_evdev(cls, evdev, test_button) -> "PenState": touch =3D BtnTouch(evdev.value[libevdev.EV_KEY.BTN_TOUCH]) tool =3D None - button =3D None + button =3D False if ( evdev.value[libevdev.EV_KEY.BTN_TOOL_RUBBER] and not evdev.value[libevdev.EV_KEY.BTN_TOOL_PEN] @@ -112,19 +82,20 @@ class PenState(Enum): ): raise ValueError("2 tools are not allowed") =20 - # we take only the highest button in account - for b in [libevdev.EV_KEY.BTN_STYLUS, libevdev.EV_KEY.BTN_STYLUS2]: - if bool(evdev.value[b]): - button =3D BtnPressed(b) + # we take only the provided button into account + if test_button is not None: + button =3D bool(evdev.value[test_button.value]) =20 # the kernel tends to insert an EV_SYN once removing the tool, so # the button will be released after if tool is None: - button =3D None + button =3D False =20 return cls((touch, tool, button)) # type: ignore =20 - def apply(self, events: List[libevdev.InputEvent], strict: bool) -> "P= enState": + def apply( + self, events: List[libevdev.InputEvent], strict: bool, test_button= : BtnPressed + ) -> "PenState": if libevdev.EV_SYN.SYN_REPORT in events: raise ValueError("EV_SYN is in the event sequence") touch =3D self.touch @@ -148,19 +119,16 @@ class PenState(Enum): raise ValueError(f"duplicated BTN_TOOL_* in {events}") tool_found =3D True tool =3D ToolType(ev.code) if ev.value else None - elif ev in ( - libevdev.InputEvent(libevdev.EV_KEY.BTN_STYLUS), - libevdev.InputEvent(libevdev.EV_KEY.BTN_STYLUS2), - ): + elif test_button is not None and ev in (test_button.value,): if button_found: raise ValueError(f"duplicated BTN_STYLUS* in {events}") button_found =3D True - button =3D BtnPressed(ev.code) if ev.value else None + button =3D bool(ev.value) =20 # the kernel tends to insert an EV_SYN once removing the tool, so # the button will be released after if tool is None: - button =3D None + button =3D False =20 new_state =3D PenState((touch, tool, button)) # type: ignore if strict: @@ -183,11 +151,9 @@ class PenState(Enum): PenState.PEN_IS_OUT_OF_RANGE, PenState.PEN_IS_IN_RANGE, PenState.PEN_IS_IN_RANGE_WITH_BUTTON, - PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, PenState.PEN_IS_IN_RANGE_WITH_ERASING_INTENT, PenState.PEN_IS_IN_CONTACT, PenState.PEN_IS_IN_CONTACT_WITH_BUTTON, - PenState.PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON, PenState.PEN_IS_ERASING, ) =20 @@ -195,7 +161,6 @@ class PenState(Enum): return ( PenState.PEN_IS_IN_RANGE, PenState.PEN_IS_IN_RANGE_WITH_BUTTON, - PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, PenState.PEN_IS_OUT_OF_RANGE, PenState.PEN_IS_IN_CONTACT, ) @@ -204,7 +169,6 @@ class PenState(Enum): return ( PenState.PEN_IS_IN_CONTACT, PenState.PEN_IS_IN_CONTACT_WITH_BUTTON, - PenState.PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON, PenState.PEN_IS_IN_RANGE, ) =20 @@ -236,21 +200,6 @@ class PenState(Enum): PenState.PEN_IS_IN_RANGE_WITH_BUTTON, ) =20 - if self =3D=3D PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON: - return ( - PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, - PenState.PEN_IS_IN_RANGE, - PenState.PEN_IS_OUT_OF_RANGE, - PenState.PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON, - ) - - if self =3D=3D PenState.PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON: - return ( - PenState.PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON, - PenState.PEN_IS_IN_CONTACT, - PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, - ) - return tuple() =20 def historically_tolerated_transitions(self) -> Tuple["PenState", ...]: @@ -263,11 +212,9 @@ class PenState(Enum): PenState.PEN_IS_OUT_OF_RANGE, PenState.PEN_IS_IN_RANGE, PenState.PEN_IS_IN_RANGE_WITH_BUTTON, - PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, PenState.PEN_IS_IN_RANGE_WITH_ERASING_INTENT, PenState.PEN_IS_IN_CONTACT, PenState.PEN_IS_IN_CONTACT_WITH_BUTTON, - PenState.PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON, PenState.PEN_IS_ERASING, ) =20 @@ -275,7 +222,6 @@ class PenState(Enum): return ( PenState.PEN_IS_IN_RANGE, PenState.PEN_IS_IN_RANGE_WITH_BUTTON, - PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, PenState.PEN_IS_OUT_OF_RANGE, PenState.PEN_IS_IN_CONTACT, ) @@ -284,7 +230,6 @@ class PenState(Enum): return ( PenState.PEN_IS_IN_CONTACT, PenState.PEN_IS_IN_CONTACT_WITH_BUTTON, - PenState.PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON, PenState.PEN_IS_IN_RANGE, PenState.PEN_IS_OUT_OF_RANGE, ) @@ -319,22 +264,6 @@ class PenState(Enum): PenState.PEN_IS_OUT_OF_RANGE, ) =20 - if self =3D=3D PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON: - return ( - PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, - PenState.PEN_IS_IN_RANGE, - PenState.PEN_IS_OUT_OF_RANGE, - PenState.PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON, - ) - - if self =3D=3D PenState.PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON: - return ( - PenState.PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON, - PenState.PEN_IS_IN_CONTACT, - PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, - PenState.PEN_IS_OUT_OF_RANGE, - ) - return tuple() =20 @staticmethod @@ -402,9 +331,9 @@ class PenState(Enum): } =20 @staticmethod - def legal_transitions_with_primary_button() -> Dict[str, Tuple["PenSta= te", ...]]: + def legal_transitions_with_button() -> Dict[str, Tuple["PenState", ...= ]]: """We revisit the Windows Pen Implementation state machine: - we now have a primary button. + we now have a button. """ return { "hover-button": (PenState.PEN_IS_IN_RANGE_WITH_BUTTON,), @@ -450,56 +379,6 @@ class PenState(Enum): ), } =20 - @staticmethod - def legal_transitions_with_secondary_button() -> Dict[str, Tuple["PenS= tate", ...]]: - """We revisit the Windows Pen Implementation state machine: - we now have a secondary button. - Note: we don't looks for 2 buttons interactions. - """ - return { - "hover-button": (PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON,), - "hover-button -> out-of-range": ( - PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, - PenState.PEN_IS_OUT_OF_RANGE, - ), - "in-range -> button-press": ( - PenState.PEN_IS_IN_RANGE, - PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, - ), - "in-range -> button-press -> button-release": ( - PenState.PEN_IS_IN_RANGE, - PenState.PEN_IS_IN_RANGE_WITH_SECOND_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_SECOND_BUTTON, - PenState.PEN_IS_IN_CONTACT, - ), - "in-range -> touch -> button-press -> release -> button-releas= e": ( - PenState.PEN_IS_IN_RANGE, - PenState.PEN_IS_IN_CONTACT, - PenState.PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON, - PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, - PenState.PEN_IS_IN_RANGE, - ), - "in-range -> button-press -> touch -> release -> button-releas= e": ( - PenState.PEN_IS_IN_RANGE, - PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, - PenState.PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON, - PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, - PenState.PEN_IS_IN_RANGE, - ), - "in-range -> button-press -> touch -> button-release -> releas= e": ( - PenState.PEN_IS_IN_RANGE, - PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, - PenState.PEN_IS_IN_CONTACT_WITH_SECOND_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 ma= chine @@ -616,10 +495,21 @@ class Pen(object): evdev.value[axis] =3D=3D value ), f"assert evdev.value[{axis}] ({evdev.value[axis]}) !=3D {value}" =20 - def assert_expected_input_events(self, evdev): + def assert_expected_input_events(self, evdev, button): assert evdev.value[libevdev.EV_ABS.ABS_X] =3D=3D self.x assert evdev.value[libevdev.EV_ABS.ABS_Y] =3D=3D self.y - assert self.current_state =3D=3D PenState.from_evdev(evdev) + + # assert no other buttons than the tested ones are set + buttons =3D [ + BtnPressed.PRIMARY_PRESSED, + BtnPressed.SECONDARY_PRESSED, + ] + if button is not None: + buttons.remove(button) + for b in buttons: + assert evdev.value[b.value] is None or evdev.value[b.value] = =3D=3D False + + assert self.current_state =3D=3D PenState.from_evdev(evdev, button) =20 =20 class PenDigitizer(base.UHIDTestDevice): @@ -647,7 +537,7 @@ class PenDigitizer(base.UHIDTestDevice): continue self.fields =3D [f.usage_name for f in r] =20 - def move_to(self, pen, state): + def move_to(self, pen, state, button): # fill in the previous values if pen.current_state =3D=3D PenState.PEN_IS_OUT_OF_RANGE: pen.restore() @@ -690,29 +580,17 @@ class PenDigitizer(base.UHIDTestDevice): pen.inrange =3D True pen.invert =3D False pen.eraser =3D False - pen.barrelswitch =3D True - pen.secondarybarrelswitch =3D False + assert button is not None + pen.barrelswitch =3D button =3D=3D BtnPressed.PRIMARY_PRESSED + pen.secondarybarrelswitch =3D button =3D=3D BtnPressed.SECONDA= RY_PRESSED elif state =3D=3D PenState.PEN_IS_IN_CONTACT_WITH_BUTTON: pen.tipswitch =3D True pen.inrange =3D True pen.invert =3D False pen.eraser =3D False - pen.barrelswitch =3D True - pen.secondarybarrelswitch =3D False - elif state =3D=3D PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON: - pen.tipswitch =3D False - pen.inrange =3D True - pen.invert =3D False - pen.eraser =3D False - pen.barrelswitch =3D False - pen.secondarybarrelswitch =3D True - elif state =3D=3D PenState.PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON: - pen.tipswitch =3D True - pen.inrange =3D True - pen.invert =3D False - pen.eraser =3D False - pen.barrelswitch =3D False - pen.secondarybarrelswitch =3D True + assert button is not None + pen.barrelswitch =3D button =3D=3D BtnPressed.PRIMARY_PRESSED + pen.secondarybarrelswitch =3D button =3D=3D BtnPressed.SECONDA= RY_PRESSED elif state =3D=3D PenState.PEN_IS_IN_RANGE_WITH_ERASING_INTENT: pen.tipswitch =3D False pen.inrange =3D True @@ -730,7 +608,7 @@ class PenDigitizer(base.UHIDTestDevice): =20 pen.current_state =3D state =20 - def event(self, pen): + def event(self, pen, button): rs =3D [] r =3D self.create_report(application=3Dself.cur_application, data= =3Dpen) self.call_input_event(r) @@ -771,17 +649,17 @@ class BaseTest: def create_device(self): raise Exception("please reimplement me in subclasses") =20 - def post(self, uhdev, pen): - r =3D uhdev.event(pen) + def post(self, uhdev, pen, test_button): + r =3D uhdev.event(pen, test_button) events =3D uhdev.next_sync_events() self.debug_reports(r, uhdev, events) return events =20 def validate_transitions( - self, from_state, pen, evdev, events, allow_intermediate_states + self, from_state, pen, evdev, events, allow_intermediate_state= s, button ): # check that the final state is correct - pen.assert_expected_input_events(evdev) + pen.assert_expected_input_events(evdev, button) =20 state =3D from_state =20 @@ -794,12 +672,14 @@ class BaseTest: events =3D events[idx + 1 :] =20 # now check for a valid transition - state =3D state.apply(sync_events, not allow_intermediate_= states) + state =3D state.apply(sync_events, not allow_intermediate_= states, button) =20 if events: - state =3D state.apply(sync_events, not allow_intermediate_= states) + state =3D state.apply(sync_events, not allow_intermediate_= states, button) =20 - def _test_states(self, state_list, scribble, allow_intermediate_st= ates): + def _test_states( + self, state_list, scribble, allow_intermediate_states, button= =3DNone + ): """Internal method to test against a list of transition between states. state_list is a list of PenState objects @@ -812,10 +692,10 @@ class BaseTest: cur_state =3D PenState.PEN_IS_OUT_OF_RANGE =20 p =3D Pen(50, 60) - uhdev.move_to(p, PenState.PEN_IS_OUT_OF_RANGE) - events =3D self.post(uhdev, p) + uhdev.move_to(p, PenState.PEN_IS_OUT_OF_RANGE, button) + events =3D self.post(uhdev, p, button) self.validate_transitions( - cur_state, p, evdev, events, allow_intermediate_states + cur_state, p, evdev, events, allow_intermediate_states, bu= tton ) =20 cur_state =3D p.current_state @@ -824,18 +704,18 @@ class BaseTest: if scribble and cur_state !=3D PenState.PEN_IS_OUT_OF_RANG= E: p.x +=3D 1 p.y -=3D 1 - events =3D self.post(uhdev, p) + events =3D self.post(uhdev, p, button) self.validate_transitions( - cur_state, p, evdev, events, allow_intermediate_st= ates + cur_state, p, evdev, events, allow_intermediate_st= ates, button ) assert len(events) >=3D 3 # X, Y, SYN - uhdev.move_to(p, state) + uhdev.move_to(p, state, button) if scribble and state !=3D PenState.PEN_IS_OUT_OF_RANGE: p.x +=3D 1 p.y -=3D 1 - events =3D self.post(uhdev, p) + events =3D self.post(uhdev, p, button) self.validate_transitions( - cur_state, p, evdev, events, allow_intermediate_states + cur_state, p, evdev, events, allow_intermediate_states= , button ) cur_state =3D p.current_state =20 @@ -874,12 +754,17 @@ class BaseTest: "state_list", [ pytest.param(v, id=3Dk) - for k, v in PenState.legal_transitions_with_primary_button= ().items() + for k, v in PenState.legal_transitions_with_button().items= () ], ) def test_valid_primary_button_pen_states(self, state_list, scribbl= e): """Rework the transition state machine by adding the primary b= utton.""" - self._test_states(state_list, scribble, allow_intermediate_sta= tes=3DFalse) + self._test_states( + state_list, + scribble, + allow_intermediate_states=3DFalse, + button=3DBtnPressed.PRIMARY_PRESSED, + ) =20 @pytest.mark.skip_if_uhdev( lambda uhdev: "Secondary Barrel Switch" not in uhdev.fields, @@ -890,12 +775,17 @@ class BaseTest: "state_list", [ pytest.param(v, id=3Dk) - for k, v in PenState.legal_transitions_with_secondary_butt= on().items() + for k, v in PenState.legal_transitions_with_button().items= () ], ) def test_valid_secondary_button_pen_states(self, state_list, scrib= ble): """Rework the transition state machine by adding the secondary= button.""" - self._test_states(state_list, scribble, allow_intermediate_sta= tes=3DFalse) + self._test_states( + state_list, + scribble, + allow_intermediate_states=3DFalse, + button=3DBtnPressed.SECONDARY_PRESSED, + ) =20 @pytest.mark.skip_if_uhdev( lambda uhdev: "Invert" not in uhdev.fields, @@ -956,7 +846,7 @@ class BaseTest: =20 =20 class GXTP_pen(PenDigitizer): - def event(self, pen): + def event(self, pen, test_button): if not hasattr(self, "prev_tip_state"): self.prev_tip_state =3D False =20 @@ -977,7 +867,7 @@ class GXTP_pen(PenDigitizer): if pen.eraser: internal_pen.invert =3D False =20 - return super().event(internal_pen) + return super().event(internal_pen, test_button) =20 =20 class USIPen(PenDigitizer): --=20 2.44.0