1 { system ? builtins.currentSystem,
3 pkgs ? import ../.. { inherit system config; }
6 with import ../lib/testing-python.nix { inherit system pkgs; };
9 readyFile = "/tmp/readerReady";
10 resultFile = "/tmp/readerResult";
12 testReader = pkgs.writeScript "test-input-reader" ''
13 rm -f ${resultFile} ${resultFile}.tmp
14 logger "testReader: START: Waiting for $1 characters, expecting '$2'."
19 if [ "$chars" == "$2" ]; then
20 logger -s "testReader: PASS: Got '$2' as expected." 2>${resultFile}.tmp
22 logger -s "testReader: FAIL: Expected '$2' but got '$chars'." 2>${resultFile}.tmp
24 # rename after the file is written to prevent a race condition
25 mv ${resultFile}.tmp ${resultFile}
29 mkKeyboardTest = layout: { extraConfig ? {}, tests }: with pkgs.lib; makeTest {
30 name = "keymap-${layout}";
32 machine.console.keyMap = mkOverride 900 layout;
33 machine.services.xserver.desktopManager.xterm.enable = false;
34 machine.services.xserver.layout = mkOverride 900 layout;
35 machine.imports = [ ./common/x11.nix extraConfig ];
42 def run_test_case(cmd, xorg_keymap, test_case_name, inputs, expected):
43 with subtest(test_case_name):
44 assert len(inputs) == len(expected)
45 machine.execute("rm -f ${readyFile} ${resultFile}")
47 # set up process that expects all the keys to be entered
49 "{} {} {} {} >&2 &".format(
53 shlex.quote("".join(expected)),
58 # make sure the xterm window is open and has focus
59 machine.wait_for_window("testterm")
60 machine.wait_until_succeeds(
61 "${pkgs.xdotool}/bin/xdotool search --sync --onlyvisible "
62 "--class testterm windowfocus --sync"
65 # wait for reader to be ready
66 machine.wait_for_file("${readyFile}")
73 # wait for result and check
74 machine.wait_for_file("${resultFile}")
75 machine.succeed("grep -q 'PASS:' ${resultFile}")
78 with open("${pkgs.writeText "tests.json" (builtins.toJSON tests)}") as json_file:
79 tests = json.load(json_file)
81 keymap_environments = {
82 "VT Keymap": "openvt -sw --",
83 "Xorg Keymap": "DISPLAY=:0 xterm -title testterm -class testterm -fullscreen -e",
88 for keymap_env_name, command in keymap_environments.items():
89 with subtest(keymap_env_name):
90 for test_case_name, test_data in tests.items():
101 in pkgs.lib.mapAttrs mkKeyboardTest {
104 azqw.qwerty = [ "q" "w" ];
105 azqw.expect = [ "a" "z" ];
106 altgr.qwerty = [ "alt_r-2" "alt_r-3" "alt_r-4" "alt_r-5" "alt_r-6" ];
107 altgr.expect = [ "~" "#" "{" "[" "|" ];
110 extraConfig.console.keyMap = "fr";
111 extraConfig.services.xserver.layout = "fr";
116 layer1.qwerty = [ "f" "j" ];
117 layer1.expect = [ "e" "n" ];
118 layer2.qwerty = [ "shift-f" "shift-j" "shift-6" ];
119 layer2.expect = [ "E" "N" "$" ];
120 layer3.qwerty = [ "caps_lock-d" "caps_lock-f" ];
121 layer3.expect = [ "{" "}" ];
124 extraConfig.console.keyMap = "bone";
125 extraConfig.services.xserver.layout = "de";
126 extraConfig.services.xserver.xkbVariant = "bone";
131 homerow.qwerty = [ "a" "s" "d" "f" "j" "k" "l" "semicolon" ];
132 homerow.expect = [ "a" "r" "s" "t" "n" "e" "i" "o" ];
135 extraConfig.console.keyMap = "colemak";
136 extraConfig.services.xserver.layout = "us";
137 extraConfig.services.xserver.xkbVariant = "colemak";
142 homerow.qwerty = [ "a" "s" "d" "f" "j" "k" "l" "semicolon" ];
143 homerow.expect = [ "a" "o" "e" "u" "h" "t" "n" "s" ];
144 symbols.qwerty = [ "q" "w" "e" "minus" "equal" ];
145 symbols.expect = [ "'" "," "." "[" "]" ];
148 extraConfig.console.keyMap = "dvorak";
149 extraConfig.services.xserver.layout = "us";
150 extraConfig.services.xserver.xkbVariant = "dvorak";
153 dvorak-programmer = {
155 homerow.qwerty = [ "a" "s" "d" "f" "j" "k" "l" "semicolon" ];
156 homerow.expect = [ "a" "o" "e" "u" "h" "t" "n" "s" ];
157 numbers.qwerty = map (x: "shift-${x}")
158 [ "1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "minus" ];
159 numbers.expect = [ "%" "7" "5" "3" "1" "9" "0" "2" "4" "6" "8" ];
160 symbols.qwerty = [ "1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "minus" ];
161 symbols.expect = [ "&" "[" "{" "}" "(" "=" "*" ")" "+" "]" "!" ];
164 extraConfig.console.keyMap = "dvorak-programmer";
165 extraConfig.services.xserver.layout = "us";
166 extraConfig.services.xserver.xkbVariant = "dvp";
171 layer1.qwerty = [ "f" "j" ];
172 layer1.expect = [ "e" "n" ];
173 layer2.qwerty = [ "shift-f" "shift-j" "shift-6" ];
174 layer2.expect = [ "E" "N" "$" ];
175 layer3.qwerty = [ "caps_lock-d" "caps_lock-f" ];
176 layer3.expect = [ "{" "}" ];
179 extraConfig.console.keyMap = "neo";
180 extraConfig.services.xserver.layout = "de";
181 extraConfig.services.xserver.xkbVariant = "neo";
186 zy.qwerty = [ "z" "y" ];
187 zy.expect = [ "y" "z" ];
188 altgr.qwerty = map (x: "alt_r-${x}")
189 [ "q" "less" "7" "8" "9" "0" ];
190 altgr.expect = [ "@" "|" "{" "[" "]" "}" ];
193 extraConfig.console.keyMap = "de";
194 extraConfig.services.xserver.layout = "de";