test: add a tool to test-compile all LVO combinations from xkeyboard-config This test contains of two parts: - a simple program to convert RMLVO commandline arguments into a keymap (and print that keymap if requested). - a python script that runs through rules/evdev.xml, and tries to compile a keymap for sort-of every layout/variant/option combination. Sort-of, because we can have multiple options and it really only does one per layout(variant) combination. Same thing can be done using xkbcomp, but right now it doesn't take that as argument, it's hard-coded. This takes quite a while, installing python-tqdm is recommended to see fancy progress bars instead of just miles of dumps. 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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
diff --git a/Makefile.am b/Makefile.am
index a7492d0..3f53b03 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -219,6 +219,7 @@ build_run_tests = \
test/compose
build_only_tests = \
test/rmlvo-to-kccgst \
+ test/rmlvo-to-keymap \
test/print-compiled-keymap
run_only_tests = \
test/symbols-leak-test.bash
@@ -240,6 +241,7 @@ test_state_LDADD = $(TESTS_LDADD)
test_keyseq_LDADD = $(TESTS_LDADD)
test_rulescomp_LDADD = $(TESTS_LDADD)
test_rmlvo_to_kccgst_LDADD = $(TESTS_LDADD)
+test_rmlvo_to_keymap_LDADD = $(TESTS_LDADD)
test_print_compiled_keymap_LDADD = $(TESTS_LDADD)
test_compose_LDADD = $(TESTS_LDADD) $(RT_LIBS)
diff --git a/meson.build b/meson.build
index 9effe29..587f3d3 100644
--- a/meson.build
+++ b/meson.build
@@ -390,6 +390,7 @@ executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
# Demo programs.
executable('rmlvo-to-kccgst', 'test/rmlvo-to-kccgst.c', dependencies: test_dep)
+executable('rmlvo-to-keymap', 'test/rmlvo-to-keymap.c', dependencies: test_dep)
executable('print-compiled-keymap', 'test/print-compiled-keymap.c', dependencies: test_dep)
if cc.has_header('linux/input.h')
executable('interactive-evdev', 'test/interactive-evdev.c', dependencies: test_dep)
@@ -426,6 +427,15 @@ You can disable the Wayland demo programs with -Denable-wayland=false.''')
executable('interactive-wayland', 'test/interactive-wayland.c', xdg_shell_sources, dependencies: [test_dep, wayland_client_dep])
endif
+# xkeyboard-config "verifier"
+xkct_config = configuration_data()
+xkct_config.set('MESON_BUILD_ROOT', meson.build_root())
+xkct_config.set('XKB_CONFIG_ROOT', XKBCONFIGROOT)
+configure_file(input: 'test/xkeyboard-config-test.py.in',
+ output: 'xkeyboard-config-test',
+ configuration: xkct_config,
+ install: false)
+
# Benchmarks.
libxkbcommon_bench_internal = static_library(
diff --git a/test/.gitignore b/test/.gitignore
index 1be56ad..def76f0 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -13,6 +13,7 @@ keyseq
log
interactive-evdev
rmlvo-to-kccgst
+rmlvo-to-keymap
print-compiled-keymap
atom
x11
diff --git a/test/rmlvo-to-keymap.c b/test/rmlvo-to-keymap.c
new file mode 100644
index 0000000..ed48e49
--- /dev/null
+++ b/test/rmlvo-to-keymap.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright © 2018 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include <assert.h>
+#include <errno.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include "xkbcommon/xkbcommon.h"
+
+static bool print = false;
+
+static void
+usage(void)
+{
+ printf("Usage: %s [--print] [--rules <rules>] [--layout <layout>] [--variant <variant>] [--options <option>]\n",
+ program_invocation_short_name);
+ printf("This tool tests the compilation from RMLVO to a keymap.\n");
+ printf("--print print the resulting keymap\n");
+}
+
+static bool
+parse_options(int argc, char **argv, struct xkb_rule_names *names)
+{
+ enum options {
+ OPT_PRINT,
+ OPT_RULES,
+ OPT_MODEL,
+ OPT_LAYOUT,
+ OPT_VARIANT,
+ OPT_OPTION,
+ };
+ static struct option opts[] = {
+ {"help", no_argument, 0, 'h'},
+ {"print", no_argument, 0, OPT_PRINT},
+ {"rules", required_argument, 0, OPT_RULES},
+ {"model", required_argument, 0, OPT_MODEL},
+ {"layout", required_argument, 0, OPT_LAYOUT},
+ {"variant", required_argument, 0, OPT_VARIANT},
+ {"options", required_argument, 0, OPT_OPTION},
+ {0, 0, 0, 0},
+ };
+
+ while (1) {
+ int c;
+ int option_index = 0;
+ c = getopt_long(argc, argv, "h", opts, &option_index);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'h':
+ usage();
+ exit(0);
+ case OPT_PRINT:
+ print = true;
+ break;
+ case OPT_RULES:
+ names->rules = optarg;
+ break;
+ case OPT_MODEL:
+ names->model = optarg;
+ break;
+ case OPT_LAYOUT:
+ names->layout = optarg;
+ break;
+ case OPT_VARIANT:
+ names->variant = optarg;
+ break;
+ case OPT_OPTION:
+ names->options = optarg;
+ break;
+ default:
+ usage();
+ exit(1);
+ }
+
+ }
+
+ return true;
+}
+
+int
+main(int argc, char **argv)
+{
+ struct xkb_context *ctx;
+ struct xkb_keymap *keymap;
+ struct xkb_rule_names names = {
+ .rules = NULL,
+ .model = NULL,
+ .layout = NULL,
+ .variant = NULL,
+ .options = NULL,
+ };
+ int rc;
+
+ if (argc <= 1) {
+ usage();
+ return 1;
+ }
+
+ if (!parse_options(argc, argv, &names))
+ return 1;
+
+ ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
+ assert(ctx);
+
+ keymap = xkb_keymap_new_from_names(ctx, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);
+ rc = (keymap == NULL);
+
+ if (rc == 0 && print)
+ printf("%s\n", xkb_keymap_get_as_string(keymap,
+ XKB_KEYMAP_FORMAT_TEXT_V1));
+
+ xkb_keymap_unref(keymap);
+ xkb_context_unref(ctx);
+
+ return rc;
+}
diff --git a/test/xkeyboard-config-test.py.in b/test/xkeyboard-config-test.py.in
new file mode 100755
index 0000000..345ebd5
--- /dev/null
+++ b/test/xkeyboard-config-test.py.in
@@ -0,0 +1,129 @@
+#!/usr/bin/env python
+import sys
+import subprocess
+import os
+import xml.etree.ElementTree as ET
+
+
+verbose = True
+
+DEFAULT_RULES_XML = '@XKB_CONFIG_ROOT@/rules/evdev.xml'
+
+# Meson needs to fill this in so we can call the tool in the buildir.
+EXTRA_PATH='@MESON_BUILD_ROOT@'
+os.environ['PATH'] = ':'.join([EXTRA_PATH, os.getenv('PATH')])
+
+
+# The function generating the progress bar (if any).
+progress_bar = lambda x, desc: x
+if os.isatty(sys.stdout.fileno()):
+ try:
+ from tqdm import tqdm
+ progress_bar = tqdm
+
+ verbose = False
+ except ImportError:
+ pass
+
+
+def xkbcommontool(r='evdev', m='pc105', l='us', v=None, o=None):
+ args = [
+ 'rmlvo-to-keymap',
+ '--rules', r,
+ '--model', m,
+ '--layout', l,
+ ]
+ if v is not None:
+ args += ['--variant', v]
+ if o is not None:
+ args += ['--options', o]
+
+ if verbose:
+ print(':: {}'.format(' '.join(args)))
+
+ try:
+ output = subprocess.check_output(args, stderr=subprocess.STDOUT)
+ if verbose:
+ print(output.decode('utf-8'))
+ except subprocess.CalledProcessError as err:
+ print('ERROR: Failed to compile: {}'.format(' '.join(args)))
+ print(err.output.decode('utf-8'))
+ sys.exit(1)
+
+
+def xkbcomp(r='evdev', m='pc105', l='us', v='', o=''):
+ args = ['setxkbmap', '-print']
+ if r is not None:
+ args.append('-rules')
+ args.append('{}'.format(r))
+ if m is not None:
+ args.append('-model')
+ args.append('{}'.format(m))
+ if l is not None:
+ args.append('-layout')
+ args.append('{}'.format(l))
+ if o is not None:
+ args.append('-option')
+ args.append('{}'.format(o))
+
+ if verbose:
+ print(':: {}'.format(' '.join(args)))
+
+ try:
+ xkbcomp_args = ['xkbcomp', '-xkb', '-', '-']
+
+ setxkbmap = subprocess.Popen(args, stdout=subprocess.PIPE)
+ xkbcomp = subprocess.Popen(xkbcomp_args, stdin=setxkbmap.stdout,
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ setxkbmap.stdout.close()
+ stdout, stderr = xkbcomp.communicate()
+ if xkbcomp.returncode != 0:
+ print('ERROR: Failed to compile: {}'.format(' '.join(args)))
+ if xkbcomp.returncode != 0 or verbose:
+ print(stdout.decode('utf-8'))
+ print(stderr.decode('utf-8'))
+
+ # This catches setxkbmap errors.
+ except subprocess.CalledProcessError as err:
+ print('ERROR: Failed to compile: {}'.format(' '.join(args)))
+ print(err.output.decode('utf-8'))
+
+
+def parse(root):
+ layouts = root.findall('layoutList/layout')
+
+ options = [
+ e.text
+ for e in root.findall('optionList/group/option/configItem/name')
+ ]
+
+ # Switch this to xkbcomp if needed.
+ tool = xkbcommontool
+ # tool = xkbcomp
+
+ for l in progress_bar(layouts, 'layout '):
+ layout = l.find('configItem/name').text
+ tool(l=layout)
+
+ variants = l.findall('variantList/variant')
+ for v in progress_bar(variants, 'variant'):
+ variant = v.find('configItem/name').text
+ tool(l=layout, v=variant)
+
+ for option in progress_bar(options, 'option '):
+ tool(l=layout, v=variant, o=option)
+
+
+def main(args):
+ try:
+ path = args[1]
+ except IndexError:
+ path = DEFAULT_RULES_XML
+
+ with open(path) as f:
+ root = ET.fromstring(f.read())
+ parse(root)
+
+
+if __name__ == '__main__':
+ main(sys.argv)