diff options
-rwxr-xr-x | bin/multitap_test.py | 89 | ||||
-rw-r--r-- | units/touchscreen/jobs.pxu | 26 |
2 files changed, 109 insertions, 6 deletions
diff --git a/bin/multitap_test.py b/bin/multitap_test.py new file mode 100755 index 0000000..15759cf --- /dev/null +++ b/bin/multitap_test.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +# Copyright 2018 Canonical Ltd. +# Written by: +# Maciej Kisielewski <maciej.kisielewski@canonical.com> + +""" +Run `xinput test-xi2` and monitor it for multifinger tap on a touchscreen. +""" + +import re +import subprocess +import sys + +EVENT_HEADER_RE = re.compile(r'^EVENT type (\d+) \((\w+)\)') + + +class Xi2Parser: + def __init__(self): + self._current_payload = '' + self._current_event = () + self._callbacks = dict() + + def register_callback(self, event_type, fn): + self._callbacks[event_type] = fn + + def parse_line(self, line): + if line.startswith(' '): + self._current_payload += line + else: + matches = EVENT_HEADER_RE.match(line) + if not matches: + return + if self._current_event: + self._emit_event() + self._current_event = (matches.groups()) + + def eof(self): + if self._current_event: + self._emit_event() + + def _emit_event(self): + event_data = dict() + for line in self._current_payload.split('\n'): + if ':' in line: + k, v = line.strip().split(':', 1) + event_data[k] = v + cb = self._callbacks.get(self._current_event[1]) + if cb: + cb(event_data) + self._current_payload = '' + self._current_event = () + + +def main(): + if len(sys.argv) != 2 or not sys.argv[1].isnumeric(): + raise SystemExit('Usage {} FINGER_COUNT'.format(sys.argv[0])) + print('Waiting for {}-finger tap'.format(sys.argv[1])) + + parser = Xi2Parser() + fingers = 0 + + def begin(ev): + nonlocal fingers + fingers += 1 + if fingers == int(sys.argv[1]): + print('SUCCESS! {}-finger tap detected!'.format(sys.argv[1])) + raise SystemExit(0) + + def end(ev): + nonlocal fingers + fingers -= 1 + if fingers < 0: + # it may happen if the program started with finger already touching + fingers = 0 + + parser.register_callback('TouchBegin', begin) + parser.register_callback('TouchEnd', end) + proc = subprocess.Popen( + ['xinput', 'test-xi2', '--root'], stdout=subprocess.PIPE) + while not proc.stdout.closed: + line = proc.stdout.readline().decode(sys.stdout.encoding) + if not line: + break + parser.parse_line(line) + parser.eof() + + +if __name__ == '__main__': + main() diff --git a/units/touchscreen/jobs.pxu b/units/touchscreen/jobs.pxu index 98a2d4f..225c168 100644 --- a/units/touchscreen/jobs.pxu +++ b/units/touchscreen/jobs.pxu @@ -135,19 +135,27 @@ _description: Validate that 3-touch tap is operating as expected STEPS: 1. Commence the test + {%- if 'Unity' in __system_env__["XDG_CURRENT_DESKTOP"] %} 2. Tap the screen within the test area with 3 fingers simultaneously. 3. Once 3 fingers are on the screen you should see the indicator they are recognized. VERIFICATION: Did you see the green circles around the three fingers? + {%- else %} + 2. Tap the screen with 3 fingers simultaneously. + 3. If the tap is not detected the test will time out after 20 seconds. + VERIFICATION: + Was the tap detected? + {% endif %} command: - {%- if __system_env__["XDG_CURRENT_DESKTOP"] == 'Unity' %} + {%- if 'Unity' in __system_env__["XDG_CURRENT_DESKTOP"] %} manage_compiz_plugin unityshell disable - {% endif %} qmlscene -qt5 3 $PLAINBOX_PROVIDER_DATA/touch_tap_test.qml 2>&1 | grep -o PASS EXIT=$? sleep 5 - {%- if __system_env__["XDG_CURRENT_DESKTOP"] == 'Unity' %} manage_compiz_plugin unityshell enable + {%- else %} + timeout 20 multitap_test.py 3 || (>&2 echo "FAILED TO DETECT TAP"; false) + EXIT=$? {% endif %} exit $EXIT @@ -163,18 +171,24 @@ _description: Validate that 4-touch tap is operating as expected STEPS: 1. Commence the test + {%- if 'Unity' in __system_env__["XDG_CURRENT_DESKTOP"] %} 2. Tap the screen within the test area with 4 fingers simultaneously. 3. Once 4 fingers are on the screen you should see the indicator they are recognized. VERIFICATION: Did you see the green circles around the four fingers? + {%- else %} + 2. Tap the screen with 4 fingers simultaneously. + 3. If the tap is not detected the test will time out after 20 seconds. + {% endif %} command: - {%- if __system_env__["XDG_CURRENT_DESKTOP"] == 'Unity' %} + {%- if 'Unity' in __system_env__["XDG_CURRENT_DESKTOP"] %} manage_compiz_plugin unityshell disable - {% endif %} qmlscene -qt5 4 $PLAINBOX_PROVIDER_DATA/touch_tap_test.qml 2>&1 | grep -o PASS EXIT=$? sleep 5 - {%- if __system_env__["XDG_CURRENT_DESKTOP"] == 'Unity' %} manage_compiz_plugin unityshell enable + {%- else %} + timeout 20 multitap_test.py 4 || (>&2 echo "FAILED TO DETECT TAP"; false) + EXIT=$? {% endif %} exit $EXIT |