Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/hid: tablets: add a secondary barrel switch test

Some tablets report 2 barrel switches. We better test those too.

Use the same transistions description from the primary button tests.

Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Jiri Kosina <jkosina@suse.com>
Link: https://lore.kernel.org/r/20231206-wip-selftests-v2-12-c0350c2f5986@kernel.org
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>

+67
+67
tools/testing/selftests/hid/tests/test_tablet.py
··· 367 367 } 368 368 369 369 @staticmethod 370 + def legal_transitions_with_secondary_button() -> Dict[str, Tuple["PenState", ...]]: 371 + """We revisit the Windows Pen Implementation state machine: 372 + we now have a secondary button. 373 + Note: we don't looks for 2 buttons interactions. 374 + """ 375 + return { 376 + "hover-button": (PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON,), 377 + "hover-button -> out-of-range": ( 378 + PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, 379 + PenState.PEN_IS_OUT_OF_RANGE, 380 + ), 381 + "in-range -> button-press": ( 382 + PenState.PEN_IS_IN_RANGE, 383 + PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, 384 + ), 385 + "in-range -> button-press -> button-release": ( 386 + PenState.PEN_IS_IN_RANGE, 387 + PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, 388 + PenState.PEN_IS_IN_RANGE, 389 + ), 390 + "in-range -> touch -> button-press -> button-release": ( 391 + PenState.PEN_IS_IN_RANGE, 392 + PenState.PEN_IS_IN_CONTACT, 393 + PenState.PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON, 394 + PenState.PEN_IS_IN_CONTACT, 395 + ), 396 + "in-range -> touch -> button-press -> release -> button-release": ( 397 + PenState.PEN_IS_IN_RANGE, 398 + PenState.PEN_IS_IN_CONTACT, 399 + PenState.PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON, 400 + PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, 401 + PenState.PEN_IS_IN_RANGE, 402 + ), 403 + "in-range -> button-press -> touch -> release -> button-release": ( 404 + PenState.PEN_IS_IN_RANGE, 405 + PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, 406 + PenState.PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON, 407 + PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, 408 + PenState.PEN_IS_IN_RANGE, 409 + ), 410 + "in-range -> button-press -> touch -> button-release -> release": ( 411 + PenState.PEN_IS_IN_RANGE, 412 + PenState.PEN_IS_IN_RANGE_WITH_SECOND_BUTTON, 413 + PenState.PEN_IS_IN_CONTACT_WITH_SECOND_BUTTON, 414 + PenState.PEN_IS_IN_CONTACT, 415 + PenState.PEN_IS_IN_RANGE, 416 + ), 417 + } 418 + 419 + @staticmethod 370 420 def tolerated_transitions() -> Dict[str, Tuple["PenState", ...]]: 371 421 """This is not adhering to the Windows Pen Implementation state machine 372 422 but we should expect the kernel to behave properly, mostly for historical ··· 494 444 self.width = 10 495 445 self.height = 10 496 446 self.barrelswitch = False 447 + self.secondarybarrelswitch = False 497 448 self.invert = False 498 449 self.eraser = False 499 450 self.xtilt = 1 ··· 785 734 ) 786 735 def test_valid_primary_button_pen_states(self, state_list, scribble): 787 736 """Rework the transition state machine by adding the primary button.""" 737 + self._test_states(state_list, scribble) 738 + 739 + @pytest.mark.skip_if_uhdev( 740 + lambda uhdev: "Secondary Barrel Switch" not in uhdev.fields, 741 + "Device not compatible, missing Secondary Barrel Switch usage", 742 + ) 743 + @pytest.mark.parametrize("scribble", [True, False], ids=["scribble", "static"]) 744 + @pytest.mark.parametrize( 745 + "state_list", 746 + [ 747 + pytest.param(v, id=k) 748 + for k, v in PenState.legal_transitions_with_secondary_button().items() 749 + ], 750 + ) 751 + def test_valid_secondary_button_pen_states(self, state_list, scribble): 752 + """Rework the transition state machine by adding the secondary button.""" 788 753 self._test_states(state_list, scribble) 789 754 790 755 @pytest.mark.skip_if_uhdev(