Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nixpkgs-channels
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e932b5be269f
Choose a base ref
...
head repository: NixOS/nixpkgs-channels
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d5d2e66a895e
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Apr 24, 2018

  1. nixos/tests/keymap: improve keymap tests

    simplify tests, prevent timeouts and non-deterministic failures
    
    (cherry picked from commit 84a6e18)
    Backport #39400
    xeji authored and Sarah Brofeldt committed Apr 24, 2018

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    marsam Mario Rodas
    Copy the full SHA
    d5d2e66 View commit details
Showing with 43 additions and 84 deletions.
  1. +43 −84 nixos/tests/keymap.nix
127 changes: 43 additions & 84 deletions nixos/tests/keymap.nix
Original file line number Diff line number Diff line change
@@ -3,116 +3,75 @@
with import ../lib/testing.nix { inherit system; };

let
readyFile = "/tmp/readerReady";
resultFile = "/tmp/readerResult";

testReader = pkgs.writeScript "test-input-reader" ''
#!${pkgs.stdenv.shell}
readInput() {
touch /tmp/reader.ready
echo "Waiting for '$1' to be typed"
read -r -n1 c
if [ "$c" = "$2" ]; then
echo "SUCCESS: Got back '$c' as expected."
echo 0 >&2
else
echo "FAIL: Expected '$2' but got '$c' instead."
echo 1 >&2
fi
}
main() {
error=0
while [ $# -gt 0 ]; do
ret="$((readInput "$2" "$3" | systemd-cat -t "$1") 2>&1)"
if [ $ret -ne 0 ]; then error=1; fi
shift 3
done
return $error
}
main "$@"; echo -n $? > /tmp/reader.exit
rm -f ${resultFile}
logger "testReader: START: Waiting for $1 characters, expecting '$2'."
touch ${readyFile}
read -r -N $1 chars
rm -f ${readyFile}
if [ "$chars" == "$2" ]; then
logger -s "testReader: PASS: Got '$2' as expected." 2>${resultFile}
else
logger -s "testReader: FAIL: Expected '$2' but got '$chars'." 2>${resultFile}
fi
'';

mkReaderInput = testname: { qwerty, expect }: with pkgs.lib; let
lq = length qwerty;
le = length expect;
msg = "`qwerty' (${lq}) and `expect' (${le}) lists"
+ " need to be of the same length!";
result = flatten (zipListsWith (a: b: [testname a b]) qwerty expect);
in if lq != le then throw msg else result;

mkKeyboardTest = layout: { extraConfig ? {}, tests }: with pkgs.lib; let
readerInput = flatten (mapAttrsToList mkReaderInput tests);
combinedTests = foldAttrs (acc: val: acc ++ val) [] (builtins.attrValues tests);
perlStr = val: "'${escape ["'" "\\"] val}'";
perlReaderInput = concatMapStringsSep ", " perlStr readerInput;
lq = length combinedTests.qwerty;
le = length combinedTests.expect;
msg = "length mismatch between qwerty (${toString lq}) and expect (${toString le}) lists!";
send = concatMapStringsSep ", " perlStr combinedTests.qwerty;
expect = if (lq == le) then concatStrings combinedTests.expect else throw msg;

in makeTest {
name = "keymap-${layout}";

machine.services.xserver.desktopManager.xterm.enable = false;
machine.i18n.consoleKeyMap = mkOverride 900 layout;
machine.services.xserver.layout = mkOverride 900 layout;
machine.imports = [ ./common/x11.nix extraConfig ];
machine.services.xserver.displayManager.slim = {
enable = true;

# Use a custom theme in order to get best OCR results
theme = pkgs.runCommand "slim-theme-ocr" {
nativeBuildInputs = [ pkgs.imagemagick ];
} ''
mkdir "$out"
convert -size 1x1 xc:white "$out/background.jpg"
convert -size 200x100 xc:white "$out/panel.jpg"
cat > "$out/slim.theme" <<EOF
background_color #ffffff
background_style tile
input_fgcolor #000000
msg_color #000000
session_color #000000
session_font Verdana:size=16:bold
username_msg Username:
username_font Verdana:size=16:bold
username_color #000000
username_x 50%
username_y 40%
password_msg Password:
password_x 50%
password_y 40%
EOF
'';
};

testScript = ''
sub waitCatAndDelete ($) {
return $machine->succeed(
"for i in \$(seq 600); do if [ -e '$_[0]' ]; then ".
"cat '$_[0]' && rm -f '$_[0]' && exit 0; ".
"fi; sleep 0.1; done; echo timed out after 60 seconds >&2; exit 1"
);
};
sub mkTest ($$) {
my ($desc, $cmd) = @_;
my @testdata = (${perlReaderInput});
my $shellTestdata = join ' ', map { "'".s/'/'\\'''/gr."'" } @testdata;
subtest $desc, sub {
$machine->succeed("$cmd ${testReader} $shellTestdata &");
while (my ($testname, $qwerty, $expect) = splice(@testdata, 0, 3)) {
waitCatAndDelete "/tmp/reader.ready";
$machine->sendKeys($qwerty);
};
my $exitcode = waitCatAndDelete "/tmp/reader.exit";
die "tests for $desc failed" if $exitcode ne 0;
# prepare and start testReader
$machine->execute("rm -f ${readyFile} ${resultFile}");
$machine->succeed("$cmd ${testReader} ${toString le} ".q(${escapeShellArg expect} & ));
if ($desc eq "Xorg keymap") {
# make sure the xterm window is open and has focus
$machine->waitForWindow(qr/testterm/);
$machine->succeed("${pkgs.xdotool}/bin/xdotool search --name testterm windowactivate --sync");
}
# wait for reader to be ready
$machine->waitForFile("${readyFile}");
$machine->sleep(1);
# send all keys
foreach ((${send})) { $machine->sendKeys($_); };
# wait for result and check
$machine->waitForFile("${resultFile}");
$machine->succeed("grep -q 'PASS:' ${resultFile}");
};
}
};
$machine->waitForX;
mkTest "VT keymap", "openvt -sw --";
mkTest "Xorg keymap", "DISPLAY=:0 xterm -fullscreen -e";
mkTest "Xorg keymap", "DISPLAY=:0 xterm -title testterm -fullscreen -e";
'';
};