Skip to content

Commit

Permalink
selftests/hid: tablets: move move_to function to PenDigitizer
Browse files Browse the repository at this point in the history
We can easily subclass PenDigitizer for introducing firmware bugs when
subclassing Pen is harder.

Move move_to from Pen to PenDigitizer so we get that ability

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-6-c0350c2f5986@kernel.org
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
  • Loading branch information
Benjamin Tissoires committed Dec 7, 2023
1 parent d52f520 commit 881ccc3
Showing 1 changed file with 50 additions and 47 deletions.
97 changes: 50 additions & 47 deletions tools/testing/selftests/hid/tests/test_tablet.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def __init__(self, x, y):
self._old_values = None
self.current_state = None

def _restore(self):
def restore(self):
if self._old_values is not None:
for i in [
"x",
Expand All @@ -297,50 +297,8 @@ def _restore(self):
]:
setattr(self, i, getattr(self._old_values, i))

def move_to(self, state):
# fill in the previous values
if self.current_state == PenState.PEN_IS_OUT_OF_RANGE:
self._restore()

print(f"\n *** pen is moving to {state} ***")

if state == PenState.PEN_IS_OUT_OF_RANGE:
self._old_values = copy.copy(self)
self.x = 0
self.y = 0
self.tipswitch = False
self.tippressure = 0
self.azimuth = 0
self.inrange = False
self.width = 0
self.height = 0
self.invert = False
self.eraser = False
self.x_tilt = 0
self.y_tilt = 0
self.twist = 0
elif state == PenState.PEN_IS_IN_RANGE:
self.tipswitch = False
self.inrange = True
self.invert = False
self.eraser = False
elif state == PenState.PEN_IS_IN_CONTACT:
self.tipswitch = True
self.inrange = True
self.invert = False
self.eraser = False
elif state == PenState.PEN_IS_IN_RANGE_WITH_ERASING_INTENT:
self.tipswitch = False
self.inrange = True
self.invert = True
self.eraser = False
elif state == PenState.PEN_IS_ERASING:
self.tipswitch = False
self.inrange = True
self.invert = True
self.eraser = True

self.current_state = state
def backup(self):
self._old_values = copy.copy(self)

def __assert_axis(self, evdev, axis, value):
if (
Expand Down Expand Up @@ -384,6 +342,51 @@ def __init__(
continue
self.fields = [f.usage_name for f in r]

def move_to(self, pen, state):
# fill in the previous values
if pen.current_state == PenState.PEN_IS_OUT_OF_RANGE:
pen.restore()

print(f"\n *** pen is moving to {state} ***")

if state == PenState.PEN_IS_OUT_OF_RANGE:
pen.backup()
pen.x = 0
pen.y = 0
pen.tipswitch = False
pen.tippressure = 0
pen.azimuth = 0
pen.inrange = False
pen.width = 0
pen.height = 0
pen.invert = False
pen.eraser = False
pen.x_tilt = 0
pen.y_tilt = 0
pen.twist = 0
elif state == PenState.PEN_IS_IN_RANGE:
pen.tipswitch = False
pen.inrange = True
pen.invert = False
pen.eraser = False
elif state == PenState.PEN_IS_IN_CONTACT:
pen.tipswitch = True
pen.inrange = True
pen.invert = False
pen.eraser = False
elif state == PenState.PEN_IS_IN_RANGE_WITH_ERASING_INTENT:
pen.tipswitch = False
pen.inrange = True
pen.invert = True
pen.eraser = False
elif state == PenState.PEN_IS_ERASING:
pen.tipswitch = False
pen.inrange = True
pen.invert = True
pen.eraser = True

pen.current_state = state

def event(self, pen):
rs = []
r = self.create_report(application=self.cur_application, data=pen)
Expand Down Expand Up @@ -462,7 +465,7 @@ def _test_states(self, state_list, scribble):
cur_state = PenState.PEN_IS_OUT_OF_RANGE

p = Pen(50, 60)
p.move_to(PenState.PEN_IS_OUT_OF_RANGE)
uhdev.move_to(p, PenState.PEN_IS_OUT_OF_RANGE)
events = self.post(uhdev, p)
self.validate_transitions(cur_state, p, evdev, events)

Expand All @@ -475,7 +478,7 @@ def _test_states(self, state_list, scribble):
events = self.post(uhdev, p)
self.validate_transitions(cur_state, p, evdev, events)
assert len(events) >= 3 # X, Y, SYN
p.move_to(state)
uhdev.move_to(p, state)
if scribble and state != PenState.PEN_IS_OUT_OF_RANGE:
p.x += 1
p.y -= 1
Expand Down

0 comments on commit 881ccc3

Please sign in to comment.