test: add a keysym tester A simple script that creates a new layout with the given keysym replacing TLDE. Then we compile a keymap and search for the keysym being assigned to TLDE and bail if that fails. The list of keysyms is manually maintained but we only need to add one or two to spot-check whenever the xorgproto is updated. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
diff --git a/meson.build b/meson.build
index 47c436f..9478fcf 100644
--- a/meson.build
+++ b/meson.build
@@ -389,11 +389,11 @@ if build_tools
dependencies: tools_dep, install: true)
install_man('tools/xkbcli.1')
- executable('xkbcli-compile-keymap',
- 'tools/compile-keymap.c',
- dependencies: tools_dep,
- install: true,
- install_dir: dir_libexec)
+ xkbcli_compile_keymap = executable('xkbcli-compile-keymap',
+ 'tools/compile-keymap.c',
+ dependencies: tools_dep,
+ install: true,
+ install_dir: dir_libexec)
install_man('tools/xkbcli-compile-keymap.1')
# The same tool again, but with access to some private APIs.
executable('compile-keymap',
@@ -657,6 +657,22 @@ if build_tools
find_program('test/tool-option-parsing.py'),
env: test_env,
suite: ['python-tests'])
+
+ # A set of keysyms to test for. Add one or two symbols to this array
+ # whenever the xorgproto gets updated to make sure we resolve them.
+ keysyms_to_test = [
+ 'XF86Macro23',
+ ]
+
+ env = environment()
+ env.set('XKB_CONFIG_ROOT', meson.source_root()/'test'/'data')
+ foreach keysym: keysyms_to_test
+ test('keysym-test-@0@'.format(keysym),
+ find_program('test/test-keysym.py'),
+ env: env,
+ args: [keysym, '--tool', xkbcli_compile_keymap],
+ suite: ['python-tests'])
+ endforeach
endif
valgrind = find_program('valgrind', required: false)
diff --git a/test/test-keysym.py b/test/test-keysym.py
new file mode 100755
index 0000000..d237f31
--- /dev/null
+++ b/test/test-keysym.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python3
+#
+# This script creates a custom layout, overriding the TDLE key with the first
+# argument given.
+
+import argparse
+import tempfile
+from pathlib import Path
+import subprocess
+import os
+import re
+import sys
+
+# Template to force our key to TLDE
+template = """
+default
+xkb_symbols "basic" {{
+ include "us(basic)"
+ replace key <TLDE> {{ [ {} ] }};
+}};
+"""
+
+parser = argparse.ArgumentParser(
+ description='Tool to verify whether a keysym is resolved'
+)
+parser.add_argument('keysym', type=str, help='XKB keysym')
+parser.add_argument('--tool', type=str, nargs=1,
+ default=['xkbcli', 'compile-keymap'],
+ help='Full path to the xkbcli-compile-keymap tool')
+args = parser.parse_args()
+
+with tempfile.TemporaryDirectory() as tmpdir:
+ symfile = Path(tmpdir) / "symbols" / "keytest"
+ symfile.parent.mkdir()
+ with symfile.open(mode='w') as f:
+ f.write(template.format(args.keysym))
+
+ try:
+ cmd = [
+ *args.tool,
+ '--layout', 'keytest',
+ ]
+
+ env = os.environ.copy()
+ env['XKB_CONFIG_EXTRA_PATH'] = tmpdir
+
+ result = subprocess.run(cmd, env=env, capture_output=True,
+ universal_newlines=True)
+ if result.returncode != 0:
+ print('ERROR: Failed to compile:')
+ print(result.stderr)
+ sys.exit(1)
+
+ # grep for TLDE actually being remapped
+ for l in result.stdout.split('\n'):
+ match = re.match(r'\s+key \<TLDE\>\s+{\s+\[\s+(?P<keysym>\w+)\s+\]\s+}', l)
+ if match:
+ if args.keysym == match.group('keysym'):
+ sys.exit(0)
+ elif match.group('keysym') == 'NoSymbol':
+ print('ERROR: key {} not resolved:'.format(args.keysym), l)
+ else:
+ print('ERROR: key {} mapped to wrong key:'.format(args.keysym), l)
+ sys.exit(1)
+
+ print(result.stdout)
+ print('ERROR: above keymap is missing key mapping for {}'.format(args.keysym))
+ sys.exit(1)
+ except FileNotFoundError as err:
+ print('ERROR: invalid or missing tool: {}'.format(err))
+ sys.exit(1)